Skip to content

Commit

Permalink
fuse: Fix parameter for FS_IOC_{GET,SET}FLAGS
Browse files Browse the repository at this point in the history
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/[email protected]/T/
[2]: https://sourceforge.net/p/fuse/mailman/message/31771759/

Signed-off-by: Chirantan Ekbote <[email protected]>
Fixes: 59efec7 ("fuse: implement ioctl support")
Cc: <[email protected]>
Signed-off-by: Miklos Szeredi <[email protected]>
  • Loading branch information
jynnantonix authored and Miklos Szeredi committed Jul 15, 2020
1 parent 7779b04 commit 31070f6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion fs/fuse/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <linux/swap.h>
#include <linux/falloc.h>
#include <linux/uio.h>
#include <linux/fs.h>

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

iov->iov_base = (void __user *)arg;
iov->iov_len = _IOC_SIZE(cmd);

switch (cmd) {
case FS_IOC_GETFLAGS:
case FS_IOC_SETFLAGS:
iov->iov_len = sizeof(int);
break;
default:
iov->iov_len = _IOC_SIZE(cmd);
break;
}

if (_IOC_DIR(cmd) & _IOC_WRITE) {
in_iov = iov;
Expand Down

0 comments on commit 31070f6

Please sign in to comment.