Skip to content

Commit 31070f6

Browse files
jynnantonixMiklos Szeredi
authored andcommitted
fuse: Fix parameter for FS_IOC_{GET,SET}FLAGS
The ioctl encoding for this parameter is a long but the documentation says it should be an int and the kernel drivers expect it to be an int. If the fuse driver treats this as a long it might end up scribbling over the stack of a userspace process that only allocated enough space for an int. This was previously discussed in [1] and a patch for fuse was proposed in [2]. From what I can tell the patch in [2] was nacked in favor of adding new, "fixed" ioctls and using those from userspace. However there is still no "fixed" version of these ioctls and the fact is that it's sometimes infeasible to change all userspace to use the new one. Handling the ioctls specially in the fuse driver seems like the most pragmatic way for fuse servers to support them without causing crashes in userspace applications that call them. [1]: https://lore.kernel.org/linux-fsdevel/20131126200559.GH20559@hall.aurel32.net/T/ [2]: https://sourceforge.net/p/fuse/mailman/message/31771759/ Signed-off-by: Chirantan Ekbote <chirantan@chromium.org> Fixes: 59efec7 ("fuse: implement ioctl support") Cc: <stable@vger.kernel.org> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 7779b04 commit 31070f6

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎fs/fuse/file.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/swap.h>
1919
#include <linux/falloc.h>
2020
#include <linux/uio.h>
21+
#include <linux/fs.h>
2122

2223
static struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags,
2324
struct fuse_page_desc **desc)
@@ -2775,7 +2776,16 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
27752776
struct iovec *iov = iov_page;
27762777

27772778
iov->iov_base = (void __user *)arg;
2778-
iov->iov_len = _IOC_SIZE(cmd);
2779+
2780+
switch (cmd) {
2781+
case FS_IOC_GETFLAGS:
2782+
case FS_IOC_SETFLAGS:
2783+
iov->iov_len = sizeof(int);
2784+
break;
2785+
default:
2786+
iov->iov_len = _IOC_SIZE(cmd);
2787+
break;
2788+
}
27792789

27802790
if (_IOC_DIR(cmd) & _IOC_WRITE) {
27812791
in_iov = iov;

0 commit comments

Comments
 (0)