xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mini-os: Avoid segfaults in tc{g,s}etattr
@ 2020-04-27  3:40 Jason Andryuk
  2020-04-27  7:54 ` Samuel Thibault
  0 siblings, 1 reply; 10+ messages in thread
From: Jason Andryuk @ 2020-04-27  3:40 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: samuel.thibault, Jason Andryuk

Commit c96c22f1d94 "mini-os: minimal implementations of some termios
functions" introduced implementations of tcgetattr and tcsetattr.
However, they do not check if files[fildes].cons.dev is non-NULL before
dereferencing.  This is not a problem for FDs allocated through
alloc_fd, but the files array pre-allocates FDs 0-2 for stdio.  Those
entries have a NULL .dev, so tc{g,s}etattr on them segfault.

ioemu-stubdom segfaults when term_init() calls tcgetattr on FD 0.

Restore tcgetattr and tcsetattr behavior when .dev is NULL equivalent to
unsupported_function as it was before c96c22f1d94.

Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
---
I can't get ioemu-stubdom to start without this.  With this, the guest
just reboots immediately, but it does that with a non-stubdom
device_model_version="qemu-xen-traditional" .  The same guest disk image
(cirros 0.5.1) boots with a linux stubdom or non-stubdom Ubuntu
qemu-system-x86_64.

 lib/sys.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/sys.c b/lib/sys.c
index da434fc..c6a7b9f 100644
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -1472,6 +1472,11 @@ int tcsetattr(int fildes, int action, const struct termios *tios)
             return -1;
     }
 
+    if (files[fildes].cons.dev == NULL) {
+        errno = ENOSYS;
+        return -1;
+    }
+
     if (tios->c_oflag & OPOST)
         files[fildes].cons.dev->is_raw = false;
     else
@@ -1492,6 +1497,11 @@ int tcgetattr(int fildes, struct termios *tios)
         return -1;
     }
 
+    if (files[fildes].cons.dev == NULL) {
+        errno = ENOSYS;
+        return 0;
+    }
+
     if (tios == NULL) {
         errno = EINVAL;
         return -1;
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-05-12 19:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27  3:40 [PATCH] mini-os: Avoid segfaults in tc{g,s}etattr Jason Andryuk
2020-04-27  7:54 ` Samuel Thibault
2020-04-27 13:30   ` Jason Andryuk
2020-04-28 11:16     ` Wei Liu
2020-04-28 11:24       ` Andrew Cooper
2020-04-28 11:44       ` Jason Andryuk
2020-04-28 11:55         ` Andrew Cooper
2020-04-29 12:34           ` Andrew Cooper
2020-05-12 19:31             ` rombios triple fault with -fcf-protection Jason Andryuk
2020-04-28 11:18   ` [PATCH] mini-os: Avoid segfaults in tc{g,s}etattr Wei Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).