[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH] mini-os: Avoid segfaults in tc{g,s}etattr
Jason Andryuk, le dim. 26 avril 2020 23:40:19 -0400, a ecrit: > 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@xxxxxxxxx> Reviewed-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx> Thanks! > --- > 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 >
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |