[PATCH v5.4.y] fuse: verify {g,u}id mount options correctly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



commit 049584807f1d797fc3078b68035450a9769eb5c3 upstream.

As was done in
0200679fc795 ("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: c30da2e981a7 ("fuse: convert to use the new mount API")
Cc: stable@xxxxxxxxxxxxxxx # 5.4+
Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>

---

(compile-tested only)

This backport required working around several missing dependencies
(fsc vs fc, invalfc vs invalf, integers vs. booleans) so probably best to
just do the one-off backport here like this, vs a string of dependencies.

diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 287e850fbd64..e558612be606 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -490,6 +490,8 @@ static int fuse_parse_param(struct fs_context *fc, struct fs_parameter *param)
 	struct fs_parse_result result;
 	struct fuse_fs_context *ctx = fc->fs_private;
 	int opt;
+	kuid_t kuid;
+	kgid_t kgid;
 
 	/*
 	 * Ignore options coming from mount(MS_REMOUNT) for backward
@@ -530,16 +532,30 @@ static int fuse_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		break;
 
 	case OPT_USER_ID:
-		ctx->user_id = make_kuid(fc->user_ns, result.uint_32);
-		if (!uid_valid(ctx->user_id))
+		kuid = make_kuid(fc->user_ns, result.uint_32);
+		if (!uid_valid(kuid))
 			return invalf(fc, "fuse: Invalid user_id");
+		/*
+		 * The requested uid must be representable in the
+		 * filesystem's idmapping.
+		 */
+		if (!kuid_has_mapping(fc->user_ns, kuid))
+			return invalf(fc, "fuse: Invalid user_id");
+		ctx->user_id = kuid;
 		ctx->user_id_present = 1;
 		break;
 
 	case OPT_GROUP_ID:
-		ctx->group_id = make_kgid(fc->user_ns, result.uint_32);
-		if (!gid_valid(ctx->group_id))
+		kgid = make_kgid(fc->user_ns, result.uint_32);
+		if (!gid_valid(kgid))
+			return invalf(fc, "fuse: Invalid group_id");
+		/*
+		 * The requested gid must be representable in the
+		 * filesystem's idmapping.
+		 */
+		if (!kgid_has_mapping(fc->user_ns, kgid))
 			return invalf(fc, "fuse: Invalid group_id");
+		ctx->group_id = kgid;
 		ctx->group_id_present = 1;
 		break;
 





[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux