Skip to contentSkip to conversation

fuse: reject a duplicate fd= mount option

PATCH Applied Baokun Li 3 participants 3 messages Aug 11 – Aug 18

Subsystems (2)
lore
Share & tools
lore

Baokun Li

author
#0 lore raw

PATCH 1/1 fuse: reject a duplicate fd= mount option

fuse_opt_fd() stored the fuse device in ctx->fud and bumped its refcount unconditionally:

        ctx->fud = fuse_dev_grab(file);

If fd= is given twice (two fsconfig FSCONFIG_SET_FD calls), the second call overwrites ctx->fud and grabs the new device, while the reference taken on the first device is never released - a permanent refcount leak that pins the first fuse_dev until reboot.

Reject a second fd= outright. ctx is zeroed on allocation, so a non-NULL ctx->fud reliably means the option was already processed.

Fixes d42eb23b2ef9 ("fuse: don't require /dev/fuse fd to be kept open during mount")
---
 fs/fuse/inode.c | 3 +++
 1 file changed, 3 insertions(+)
fs/fuse/inode.c +3 -0
index 455c7feba057..2372e6ed333f 100644
@@ -791,6 +791,9 @@ static int fuse_opt_fd(struct fs_context *fsc, struct file *file)
 {
 	struct fuse_fs_context *ctx = fsc->fs_private;
 
+	if (ctx->fud)
+		return invalfc(fsc, "Multiple fd specified");
+
 	if (file->f_op != &fuse_dev_operations)
 		return invalfc(fsc, "fd is not a fuse device");
 	/*
Signature · 1 line
2.43.7
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Baokun Li

fuse_opt_fd() stored the fuse device in ctx->fud and bumped its refcount unconditionally:

        ctx->fud = fuse_dev_grab(file);

If fd= is given twice (two fsconfig FSCONFIG_SET_FD calls), the second call overwrites ctx->fud and grabs the new device, while the reference taken on the first device is never released - a permanent refcount leak that pins the first fuse_dev until reboot.

Quoted 5 lines

Reject a second fd= outright. ctx is zeroed on allocation, so a non-NULL ctx->fud reliably means the option was already processed.

Fixes d42eb23b2ef9 ("fuse: don't require /dev/fuse fd to be kept open during mount")

LGTM.

Quoted 18 lines
---
 fs/fuse/inode.c | 3 +++
 1 file changed, 3 insertions(+)
fs/fuse/inode.c +3 -0
index 455c7feba057..2372e6ed333f 100644
@@ -791,6 +791,9 @@ static int fuse_opt_fd(struct fs_context *fsc, struct file *file)
 {
 	struct fuse_fs_context *ctx = fsc->fs_private;
 
+	if (ctx->fud)
+		return invalfc(fsc, "Multiple fd specified");
+
 	if (file->f_op != &fuse_dev_operations)
 		return invalfc(fsc, "fd is not a fuse device");
 	/*
Signature · 2 lines
Thanks,
Jingbo
maintainer Applied
#2 lore raw
In reply to Baokun Li
Quoted 11 lines · Baokun Li

fuse_opt_fd() stored the fuse device in ctx->fud and bumped its refcount unconditionally:

        ctx->fud = fuse_dev_grab(file);

If fd= is given twice (two fsconfig FSCONFIG_SET_FD calls), the second call overwrites ctx->fud and grabs the new device, while the reference taken on the first device is never released - a permanent refcount leak that pins the first fuse_dev until reboot.

Quoted 5 lines

Reject a second fd= outright. ctx is zeroed on allocation, so a non-NULL ctx->fud reliably means the option was already processed.

Fixes d42eb23b2ef9 ("fuse: don't require /dev/fuse fd to be kept open during mount")

Applied, thanks.

Miklos