fuse: add missing NULL check for fget() in fuse_parse_param()
Subsystems (2)
PATCH 1/1 fuse: add missing NULL check for fget() in fuse_parse_param()
In the OPT_FD case of fuse_parse_param(), when using the old mount API, fget() is called on the user-supplied file descriptor but its return value is not checked for NULL before being passed to fuse_opt_fd(). fuse_opt_fd() unconditionally dereferences file->f_op, causing a kernel NULL pointer dereference.
This is user-triggerable via: mount -t fuse -o fd=99999 dummy /mnt where fd 99999 is not open.
The new mount API path (FSCONFIG_SET_FD) is not affected because fsopen.c validates the fd with fget_raw() + NULL check before setting param->file.
Add a NULL check after fget() and return an error via invalfc() when the fd is invalid.
--- fs/fuse/inode.c | 2 ++ 1 file changed, 2 insertions(+)
fs/fuse/inode.c +2 -0
@@ -862,6 +862,8 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param)return fuse_opt_fd (fsc, param->file); }else { struct file *file __free(fput) = fget(result.uint_32); +if (!file) +return invalfc (fsc,"Invalid fuse fd" );return fuse_opt_fd (fsc, file); }
Signature · 1 line
2.53.0
Quoted 28 lines · David Carlier
In the
OPT_FDcase offuse_parse_param(), when using the old mount API,fget()is called on the user-supplied file descriptor but its return value is not checked for NULL before being passed tofuse_opt_fd().fuse_opt_fd()unconditionally dereferencesfile->f_op, causing a kernel NULL pointer dereference.This is user-triggerable via: mount -t fuse -o fd=99999 dummy /mnt where fd 99999 is not open.
The new mount API path (
FSCONFIG_SET_FD) is not affected becausefsopen.cvalidates the fd withfget_raw()+ NULL check before settingparam->file.Add a NULL check after
fget()and return an error viainvalfc()when the fd is invalid.Fixes 3f2496deff35 ("fuse: don't require /dev/fuse fd to be kept open during mount")Signed-off-by David Carlier <[email protected]>--- fs/fuse/inode.c | 2 ++ 1 file changed, 2 insertions(+)fs/fuse/inode.c +0
-0
fs/fuse/inode.c static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param) · line 869
Quoted 8 lines
fs/fuse/inode.c +2
-0@@ -862,6 +862,8 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param)return fuse_opt_fd (fsc, param->file); }else { struct file *file __free(fput) = fget(result.uint_32); +if (!file) +return invalfc (fsc,"Invalid fuse fd" );return fuse_opt_fd (fsc, file); }
Hi David,
I think this is already going to be fixed up in the fuse tree by Miklos when he applies the next version of his cleanup series, as per the conversation in [1].
Thanks,
Joanne
[1] https://lore.kernel.org/linux-fsdevel/[email protected]/t/#u
Quoted 4 lines
--
2.53.0