From: Josef Bacik <josef@toxicpanda.com>
To: Christian Brauner <brauner@kernel.org>,
James Bottomley <James.Bottomley@HansenPartnership.com>,
Andrew Halaney <andrew@amutable.com>,
Jeremy Bingham <jbingham@gmail.com>,
Tahera Fahimi <taherafahimi@linux.microsoft.com>,
Serge Hallyn <sergeh@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Josef Bacik <josef@toxicpanda.com>
Subject: [PATCH RFC v3 12/90] fs: add kuid_has_fsmapping() and kgid_has_fsmapping()
Date: Thu, 05 Nov 2026 14:57:03 +0000 [thread overview]
Message-ID: <20261105-b4-cells-v3-12-bc9095937a84@toxicpanda.com> (raw)
In-Reply-To: <20261105-b4-cells-v3-0-bc9095937a84@toxicpanda.com>
Several places ask whether a filesystem can hold a given id. Each of them
calls kuid_has_mapping() or kgid_has_mapping() on the user namespace of
the filesystem:
- fsuidgid_has_mapping(), when a file is created
- posix_acl_valid(), for an ACL entry
- the uid and gid mount options of tmpfs, fuse and bpffs
- ovl_copy_up_one(), which runs with the credentials of the mounter, so
current_user_ns() there is the user namespace of the overlay
The same two helpers are also used for many unrelated questions. Nothing
distinguishes the callers that ask about a filesystem, so there is no
place for a rule that should apply to filesystems only.
Add kuid_has_fsmapping() and kgid_has_fsmapping(), next to
vfsuid_has_fsmapping() and vfsgid_has_fsmapping(), and use them in the
places listed above.
No functional change.
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
fs/fuse/inode.c | 4 ++--
fs/overlayfs/copy_up.c | 4 ++--
fs/posix_acl.c | 4 ++--
include/linux/fs.h | 4 ++--
include/linux/mnt_idmapping.h | 31 +++++++++++++++++++++++++++++++
kernel/bpf/inode.c | 4 ++--
mm/shmem.c | 4 ++--
7 files changed, 43 insertions(+), 12 deletions(-)
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 1341b681d0ed..37712fce905b 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -888,7 +888,7 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param)
* The requested uid must be representable in the
* filesystem's idmapping.
*/
- if (!kuid_has_mapping(fsc->user_ns, kuid))
+ if (!kuid_has_fsmapping(fsc->user_ns, kuid))
return invalfc(fsc, "Invalid user_id");
ctx->user_id = kuid;
ctx->user_id_present = true;
@@ -900,7 +900,7 @@ static int fuse_parse_param(struct fs_context *fsc, struct fs_parameter *param)
* The requested gid must be representable in the
* filesystem's idmapping.
*/
- if (!kgid_has_mapping(fsc->user_ns, kgid))
+ if (!kgid_has_fsmapping(fsc->user_ns, kgid))
return invalfc(fsc, "Invalid group_id");
ctx->group_id = kgid;
ctx->group_id_present = true;
diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index c147ad155b79..48cd09a2b69b 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -1173,8 +1173,8 @@ static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
if (err)
return err;
- if (!kuid_has_mapping(current_user_ns(), ctx.stat.uid) ||
- !kgid_has_mapping(current_user_ns(), ctx.stat.gid))
+ if (!kuid_has_fsmapping(current_user_ns(), ctx.stat.uid) ||
+ !kgid_has_fsmapping(current_user_ns(), ctx.stat.gid))
return -EOVERFLOW;
/*
diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index fe77934ea8f2..a2e2ca984d95 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -260,7 +260,7 @@ posix_acl_valid(struct user_namespace *user_ns, const struct posix_acl *acl)
case ACL_USER:
if (state != ACL_USER)
return -EINVAL;
- if (!kuid_has_mapping(user_ns, pa->e_uid))
+ if (!kuid_has_fsmapping(user_ns, pa->e_uid))
return -EINVAL;
needs_mask = 1;
break;
@@ -275,7 +275,7 @@ posix_acl_valid(struct user_namespace *user_ns, const struct posix_acl *acl)
case ACL_GROUP:
if (state != ACL_GROUP)
return -EINVAL;
- if (!kgid_has_mapping(user_ns, pa->e_gid))
+ if (!kgid_has_fsmapping(user_ns, pa->e_gid))
return -EINVAL;
needs_mask = 1;
break;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 88748be03505..ea9b9d5a667d 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1589,8 +1589,8 @@ static inline bool fsuidgid_has_mapping(struct super_block *sb,
kgid = mapped_fsgid(idmap, fs_userns);
if (!gid_valid(kgid))
return false;
- return kuid_has_mapping(fs_userns, kuid) &&
- kgid_has_mapping(fs_userns, kgid);
+ return kuid_has_fsmapping(fs_userns, kuid) &&
+ kgid_has_fsmapping(fs_userns, kgid);
}
struct timespec64 current_time(struct inode *inode);
diff --git a/include/linux/mnt_idmapping.h b/include/linux/mnt_idmapping.h
index 78eeef4c2996..b5e0772aa190 100644
--- a/include/linux/mnt_idmapping.h
+++ b/include/linux/mnt_idmapping.h
@@ -136,6 +136,37 @@ kuid_t from_vfsuid(const struct mnt_idmap *idmap,
kgid_t from_vfsgid(const struct mnt_idmap *idmap,
struct user_namespace *fs_userns, vfsgid_t vfsgid);
+/**
+ * kuid_has_fsmapping - check whether a filesystem can hold a kuid
+ * @fs_userns: the filesystem's idmapping
+ * @kuid: the kuid, after the idmapping of the mount has been applied
+ *
+ * Use this function, and not kuid_has_mapping(), for a kuid that is about to end
+ * up in a filesystem: as the owner of a file, in an ACL, by a mount option.
+ *
+ * Return: true if @kuid has a mapping in the filesystem, false if not.
+ */
+static inline bool kuid_has_fsmapping(struct user_namespace *fs_userns,
+ kuid_t kuid)
+{
+ return kuid_has_mapping(fs_userns, kuid);
+}
+
+/**
+ * kgid_has_fsmapping - check whether a filesystem can hold a kgid
+ * @fs_userns: the filesystem's idmapping
+ * @kgid: the kgid, after the idmapping of the mount has been applied
+ *
+ * See kuid_has_fsmapping().
+ *
+ * Return: true if @kgid has a mapping in the filesystem, false if not.
+ */
+static inline bool kgid_has_fsmapping(struct user_namespace *fs_userns,
+ kgid_t kgid)
+{
+ return kgid_has_mapping(fs_userns, kgid);
+}
+
/**
* vfsuid_has_fsmapping - check whether a vfsuid maps into the filesystem
* @idmap: the mount's idmapping
diff --git a/kernel/bpf/inode.c b/kernel/bpf/inode.c
index c6f328e4752e..504bb7accb39 100644
--- a/kernel/bpf/inode.c
+++ b/kernel/bpf/inode.c
@@ -1026,7 +1026,7 @@ static int bpf_parse_param(struct fs_context *fc, struct fs_parameter *param)
* The requested uid must be representable in the
* filesystem's idmapping.
*/
- if (!kuid_has_mapping(fc->user_ns, uid))
+ if (!kuid_has_fsmapping(fc->user_ns, uid))
goto bad_value;
opts->uid = uid;
@@ -1040,7 +1040,7 @@ static int bpf_parse_param(struct fs_context *fc, struct fs_parameter *param)
* The requested gid must be representable in the
* filesystem's idmapping.
*/
- if (!kgid_has_mapping(fc->user_ns, gid))
+ if (!kgid_has_fsmapping(fc->user_ns, gid))
goto bad_value;
opts->gid = gid;
diff --git a/mm/shmem.c b/mm/shmem.c
index af21a89abb0f..8e7b51797ab8 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -4793,7 +4793,7 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param)
* The requested uid must be representable in the
* filesystem's idmapping.
*/
- if (!kuid_has_mapping(fc->user_ns, kuid))
+ if (!kuid_has_fsmapping(fc->user_ns, kuid))
goto bad_value;
ctx->uid = kuid;
@@ -4805,7 +4805,7 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param)
* The requested gid must be representable in the
* filesystem's idmapping.
*/
- if (!kgid_has_mapping(fc->user_ns, kgid))
+ if (!kgid_has_fsmapping(fc->user_ns, kgid))
goto bad_value;
ctx->gid = kgid;
--
2.55.0
next prev parent reply other threads:[~2026-11-05 14:58 UTC|newest]
Thread overview: 93+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 14:56 [PATCH RFC v3 00/90] cells: a container as one kernel object Josef Bacik
2026-11-05 14:56 ` [PATCH RFC v3 01/90] Documentation: add a design document for cells Josef Bacik
2026-11-05 17:06 ` Serge E. Hallyn
2026-11-05 18:23 ` Josef Bacik
2026-11-05 14:56 ` [PATCH RFC v3 02/90] Documentation: add examples " Josef Bacik
2026-11-05 14:56 ` [PATCH RFC v3 03/90] cells: reserve a window of ids Josef Bacik
2026-11-05 14:56 ` [PATCH RFC v3 04/90] user_namespace: let a cell own a user namespace Josef Bacik
2026-11-05 14:56 ` [PATCH RFC v3 05/90] user_namespace: refuse setns() into a cell Josef Bacik
2026-11-05 14:56 ` [PATCH RFC v3 06/90] capability: give the owner no say over " Josef Bacik
2026-11-05 14:56 ` [PATCH RFC v3 07/90] ucount: count the id blocks a user holds Josef Bacik
2026-11-05 14:56 ` [PATCH RFC v3 08/90] user_namespace: let the kernel map the ids of a cell Josef Bacik
2026-11-05 14:57 ` [PATCH RFC v3 09/90] user_namespace: keep legacy maps out of the window Josef Bacik
2026-11-05 14:57 ` [PATCH RFC v3 10/90] user: add uid_range_in_use() Josef Bacik
2026-11-05 14:57 ` [PATCH RFC v3 11/90] keys: add key_user_range_in_use() Josef Bacik
2026-11-05 14:57 ` Josef Bacik [this message]
2026-11-05 14:57 ` [PATCH RFC v3 13/90] fs: never store an id that was lent to a cell Josef Bacik
2026-11-05 14:57 ` [PATCH RFC v3 14/90] fs: take no id of a cell for a mount option Josef Bacik
2026-11-05 14:57 ` [PATCH RFC v3 15/90] fs: let an idmapping pin the ids of a cell Josef Bacik
2026-11-05 14:57 ` [PATCH RFC v3 16/90] cgroup: let a cgroup become the budget " Josef Bacik
2026-11-05 14:57 ` [PATCH RFC v3 17/90] cgroup: add cgroup_cell_chown() Josef Bacik
2026-11-05 14:57 ` [PATCH RFC v3 18/90] cgroup: give the budget of a cell back Josef Bacik
2026-11-05 14:57 ` [PATCH RFC v3 19/90] cgroup: add cgroup_cell_kill() Josef Bacik
2026-11-05 14:57 ` [PATCH RFC v3 20/90] cgroup: root a cgroup namespace at a given cgroup Josef Bacik
2026-11-05 14:57 ` [PATCH RFC v3 21/90] fs: seal a mount namespace for a cell Josef Bacik
2026-11-05 14:57 ` [PATCH RFC v3 22/90] nsfs: make open_namespace() available outside of fs/ Josef Bacik
2026-11-05 14:57 ` [PATCH RFC v3 23/90] nsproxy: build the nsproxy the tasks of a cell share Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 24/90] cells: add the cell object and cell_create() Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 25/90] cells: add cell_kill() Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 26/90] cells: add cell_configure() Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 27/90] cells: add the "budget" slot Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 28/90] cells: add the "root" slot Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 29/90] cells: add the "ids" slot, for a single id Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 30/90] cells: lend a cell a block of ids Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 31/90] cells: reserve the "spawn" slot Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 32/90] cells: add CELL_CMD_SEAL Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 33/90] cells: add cell_open() Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 34/90] pid: allocate a struct pid ahead of its numbers Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 35/90] fork: let copy_process() place a task in a cell Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 36/90] cgroup: fork a task of a cell into the budget Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 37/90] x86: give a task without an mm no user state Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 38/90] uprobes: cope with a new task that has no mm Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 39/90] fork: add tasks that start out with nothing Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 40/90] pidfd: add PIDFD_EMPTY Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 41/90] pidfd: add pidfd_configure() Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 42/90] pidfd: let pidfd_configure() place files Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 43/90] pidfd: let pidfd_configure() set credentials Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 44/90] pidfd: let pidfd_configure() name a cgroup to start in Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 45/90] ptrace: keep everybody off an embryo Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 46/90] cells: end a cell when its init exits Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 47/90] cells: refuse a task of a cell a change of namespaces Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 48/90] fs: refuse a task of a cell a new mount namespace Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 49/90] nsproxy: refuse to enter a namespace of a cell Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 50/90] cgroup: keep a task of a cell within the budget Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 51/90] cgroup: let nothing but a spawn into a budget Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 52/90] kernfs: let a filesystem refuse a change to a node Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 53/90] cgroup: let a cell change nothing outside its budget Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 54/90] cgroup: leave the limits of a budget to who is above Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 55/90] fs: let a filesystem hold ids that go with the cell Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 56/90] cgroup: let a cell make cgroups below its budget Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 57/90] resctrl: let a cell change nothing Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 58/90] cred: let no id count across cells Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 59/90] ptrace: refuse PTRACE_TRACEME " Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 60/90] keys: ignore an equal uid or gid " Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 61/90] fs: accept a cellfd for MOUNT_ATTR_IDMAP Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 62/90] fs: let a cell set no set-id bits Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 63/90] fs: drop privileges from what a cell may write to Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 64/90] cells: add the "caps" slot Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 65/90] capabilities: take nothing from a file in a cell Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 66/90] capabilities: let a cell shrink its bounding sets Josef Bacik
2026-11-05 15:02 ` [PATCH RFC v3 67/90] af_unix: deliver ancillary data only within a cell Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 68/90] af_unix: tell a sender that control data will not cross Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 69/90] net: do not identify a peer in another cell Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 70/90] seccomp: let a listener put no file into a cell Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 71/90] umh: run no program for a task of " Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 72/90] coredump: let no core dump leave " Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 73/90] cells: add the "net" slot Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 74/90] net: give a cell without a network no sockets Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 75/90] net: add net_may() Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 76/90] rtnetlink: use net_may() for requests that change state Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 77/90] net: use net_may() in the configuration ioctls Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 78/90] netfilter: use net_may() for configuration Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 79/90] tun: use net_may() to create and attach to devices Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 80/90] net: use net_may() for the net sysctls Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 81/90] net: use net_may() for privileged socket options Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 82/90] net: use net_may() for raw and packet sockets Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 83/90] cells: add the "net-rights" slot Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 84/90] net: honour the rights of a cell in net_may() Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 85/90] tun: ignore an equal uid or gid across cells Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 86/90] cells: add cell_info() Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 87/90] cells: add CONFIG_CELLS Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 88/90] arch: wire up the cell system calls Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 89/90] MAINTAINERS: add an entry for cells Josef Bacik
2026-11-05 15:03 ` [PATCH RFC v3 90/90] selftests: add tests " Josef Bacik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261105-b4-cells-v3-12-bc9095937a84@toxicpanda.com \
--to=josef@toxicpanda.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=andrew@amutable.com \
--cc=brauner@kernel.org \
--cc=jbingham@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sergeh@kernel.org \
--cc=taherafahimi@linux.microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®