Skip to content

Commit 525bd65

Browse files
Eric Sandeenbrauner
authored andcommitted
fuse: verify {g,u}id mount options correctly
As was done in 0200679 ("tmpfs: verify {g,u}id mount options correctly") we need to validate that the requested uid and/or gid is representable in the filesystem's idmapping. Cribbing from the above commit log, The contract for {g,u}id mount options and {g,u}id values in general set from userspace has always been that they are translated according to the caller's idmapping. In so far, fuse has been doing the correct thing. But since fuse is mountable in unprivileged contexts it is also necessary to verify that the resulting {k,g}uid is representable in the namespace of the superblock. Fixes: c30da2e ("fuse: convert to use the new mount API") Cc: [email protected] # 5.4+ Signed-off-by: Eric Sandeen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Christian Brauner <[email protected]> Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent d02f0bb commit 525bd65

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

fs/fuse/inode.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param)
755755
struct fs_parse_result result;
756756
struct fuse_fs_context *ctx = fsc->fs_private;
757757
int opt;
758+
kuid_t kuid;
759+
kgid_t kgid;
758760

759761
if (fsc->purpose == FS_CONTEXT_FOR_RECONFIGURE) {
760762
/*
@@ -799,16 +801,30 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param)
799801
break;
800802

801803
case OPT_USER_ID:
802-
ctx->user_id = make_kuid(fsc->user_ns, result.uint_32);
803-
if (!uid_valid(ctx->user_id))
804+
kuid = make_kuid(fsc->user_ns, result.uint_32);
805+
if (!uid_valid(kuid))
804806
return invalfc(fsc, "Invalid user_id");
807+
/*
808+
* The requested uid must be representable in the
809+
* filesystem's idmapping.
810+
*/
811+
if (!kuid_has_mapping(fsc->user_ns, kuid))
812+
return invalfc(fsc, "Invalid user_id");
813+
ctx->user_id = kuid;
805814
ctx->user_id_present = true;
806815
break;
807816

808817
case OPT_GROUP_ID:
809-
ctx->group_id = make_kgid(fsc->user_ns, result.uint_32);
810-
if (!gid_valid(ctx->group_id))
818+
kgid = make_kgid(fsc->user_ns, result.uint_32);;
819+
if (!gid_valid(kgid))
820+
return invalfc(fsc, "Invalid group_id");
821+
/*
822+
* The requested gid must be representable in the
823+
* filesystem's idmapping.
824+
*/
825+
if (!kgid_has_mapping(fsc->user_ns, kgid))
811826
return invalfc(fsc, "Invalid group_id");
827+
ctx->group_id = kgid;
812828
ctx->group_id_present = true;
813829
break;
814830

0 commit comments

Comments
 (0)