From bb611b669fa6dd3363cde11fe2c078ec6627172d Mon Sep 17 00:00:00 2001 From: Alessio Balsini Date: Fri, 19 Mar 2021 15:05:14 +0000 Subject: [PATCH] UPSTREAM: fuse: fix matching of FUSE_DEV_IOC_CLONE command With commit f8425c939663 ("fuse: 32-bit user space ioctl compat for fuse device") the matching constraints for the FUSE_DEV_IOC_CLONE ioctl command are relaxed, limited to the testing of command type and number. As Arnd noticed, this is wrong as it wouldn't ensure the correctness of the data size or direction for the received FUSE device ioctl. Fix by bringing back the comparison of the ioctl received by the FUSE device to the originally generated FUSE_DEV_IOC_CLONE. Mot-CRs-fixed: (CR) Fixes: f8425c939663 ("fuse: 32-bit user space ioctl compat for fuse device") Reported-by: Arnd Bergmann Signed-off-by: Alessio Balsini Signed-off-by: M(CR) Szeredi Signed-off-by: Lee Jones Signed-off-by: Alessio Balsini Change-Id: I372d8399db6d603ba20ef50528acf6645e4d3c66 (cherry picked from commit 6076f5f341e612152879bfda99f0b76c1953bf0b) Reviewed-on: https://gerrit.mot.com/2294435 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Huosheng Liao Submit-Approved: Jira Key --- fs/fuse/dev.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index fdf74cbfc516..a4b663f50701 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -2269,11 +2269,8 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd, int oldfd; struct fuse_dev *fud = NULL; - if (_IOC_TYPE(cmd) != FUSE_DEV_IOC_MAGIC) - return -EINVAL; - - switch (_IOC_NR(cmd)) { - case _IOC_NR(FUSE_DEV_IOC_CLONE): + switch (cmd) { + case FUSE_DEV_IOC_CLONE: res = -EFAULT; if (!get_user(oldfd, (__u32 __user *)arg)) { struct file *old = fget(oldfd); @@ -2298,7 +2295,7 @@ static long fuse_dev_ioctl(struct file *file, unsigned int cmd, } } break; - case _IOC_NR(FUSE_DEV_IOC_PASSTHROUGH_OPEN): + case FUSE_DEV_IOC_PASSTHROUGH_OPEN: res = -EFAULT; if (!get_user(oldfd, (__u32 __user *)arg)) { res = -EINVAL;