Commit 525bd65a authored by Eric Sandeen's avatar Eric Sandeen Committed by Christian Brauner

fuse: verify {g,u}id mount options correctly

As was done in
0200679f ("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: c30da2e9 ("fuse: convert to use the new mount API")
Cc: stable@vger.kernel.org # 5.4+
Signed-off-by: default avatarEric Sandeen <sandeen@redhat.com>
Link: https://lore.kernel.org/r/8f07d45d-c806-484d-a2e3-7a2199df1cd2@redhat.comReviewed-by: default avatarChristian Brauner <brauner@kernel.org>
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent d02f0bb3
...@@ -755,6 +755,8 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param) ...@@ -755,6 +755,8 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param)
struct fs_parse_result result; struct fs_parse_result result;
struct fuse_fs_context *ctx = fsc->fs_private; struct fuse_fs_context *ctx = fsc->fs_private;
int opt; int opt;
kuid_t kuid;
kgid_t kgid;
if (fsc->purpose == FS_CONTEXT_FOR_RECONFIGURE) { if (fsc->purpose == FS_CONTEXT_FOR_RECONFIGURE) {
/* /*
...@@ -799,16 +801,30 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param) ...@@ -799,16 +801,30 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param)
break; break;
case OPT_USER_ID: case OPT_USER_ID:
ctx->user_id = make_kuid(fsc->user_ns, result.uint_32); kuid = make_kuid(fsc->user_ns, result.uint_32);
if (!uid_valid(ctx->user_id)) if (!uid_valid(kuid))
return invalfc(fsc, "Invalid user_id"); return invalfc(fsc, "Invalid user_id");
/*
* The requested uid must be representable in the
* filesystem's idmapping.
*/
if (!kuid_has_mapping(fsc->user_ns, kuid))
return invalfc(fsc, "Invalid user_id");
ctx->user_id = kuid;
ctx->user_id_present = true; ctx->user_id_present = true;
break; break;
case OPT_GROUP_ID: case OPT_GROUP_ID:
ctx->group_id = make_kgid(fsc->user_ns, result.uint_32); kgid = make_kgid(fsc->user_ns, result.uint_32);;
if (!gid_valid(ctx->group_id)) if (!gid_valid(kgid))
return invalfc(fsc, "Invalid group_id");
/*
* The requested gid must be representable in the
* filesystem's idmapping.
*/
if (!kgid_has_mapping(fsc->user_ns, kgid))
return invalfc(fsc, "Invalid group_id"); return invalfc(fsc, "Invalid group_id");
ctx->group_id = kgid;
ctx->group_id_present = true; ctx->group_id_present = true;
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment