From f71d0b0da7c99bb22706e5d14121b558d62a5a97 Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky Date: Thu, 1 Feb 2018 19:57:21 +0000 Subject: [PATCH] Fix some recent regressions after r328436 in the LinuxKPI: 1) The OPW() function macro should have the same return type like the function it executes. 2) The DEVFS I/O-limit should be enforced for all character device reads and writes. 3) The character device file handle should be passable, same as for DEVFS based file handles. Reported by: jbeich @ MFC after: 1 week Sponsored by: Mellanox Technologies --- sys/compat/linuxkpi/common/src/linux_compat.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index f4d2773be12..08ddbbec45c 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -669,7 +669,7 @@ static struct cdev_pager_ops linux_cdev_pager_ops[2] = { #define OPW(fp,td,code) ({ \ struct file *__fpop; \ - int __retval; \ + __typeof(code) __retval; \ \ __fpop = (td)->td_fpop; \ (td)->td_fpop = (fp); \ @@ -1277,6 +1277,8 @@ linux_file_read(struct file *file, struct uio *uio, struct ucred *active_cred, /* XXX no support for I/O vectors currently */ if (uio->uio_iovcnt != 1) return (EOPNOTSUPP); + if (uio->uio_resid > DEVFS_IOSIZE_MAX) + return (EINVAL); linux_set_current(td); if (filp->f_op->read) { bytes = OPW(file, td, filp->f_op->read(filp, uio->uio_iov->iov_base, @@ -1314,6 +1316,8 @@ linux_file_write(struct file *file, struct uio *uio, struct ucred *active_cred, /* XXX no support for I/O vectors currently */ if (uio->uio_iovcnt != 1) return (EOPNOTSUPP); + if (uio->uio_resid > DEVFS_IOSIZE_MAX) + return (EINVAL); linux_set_current(td); if (filp->f_op->write) { bytes = OPW(file, td, filp->f_op->write(filp, uio->uio_iov->iov_base, @@ -1556,6 +1560,7 @@ struct fileops linuxfileops = { .fo_chmod = invfo_chmod, .fo_chown = invfo_chown, .fo_sendfile = invfo_sendfile, + .fo_flags = DFLAG_PASSABLE, }; /*