[RFC PATCH v9 02/29] userns: Add userns_set_idmap() system call
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Tue Dec 1 03:26:06 UTC 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] userns: caller_idmap_permitted() rejects delegated projid_map
without CAP_SETUID
--
commit 58bf5f681d11a23cb6edc84d8207c82688e2ecbb
Author: Jarkko Sakkinen <jarkko at kernel.org>
userns: Add userns_set_idmap() system call
This commit adds the userns_set_idmap() system call to atomically configure
UID, GID, and project ID mappings as well as the setgroups policy on a
user namespace file descriptor.
> diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
> index caba2ac33077e..e5054e273e939 100644
> --- a/kernel/user_namespace.c
> +++ b/kernel/user_namespace.c
[ ... ]
> @@ -1176,6 +1180,228 @@ static ssize_t map_write(struct file *file, const char __user *buf,
> return ret;
> }
>
> +static bool caller_idmap_permitted(struct user_namespace *ns, int cap_setid,
> + unsigned long ns_flags,
> + const struct uid_gid_map *new_map)
> +{
> + const struct cred *cred = current_cred();
> +
> + if (cap_setid == CAP_SETUID && idmap_maps_root(new_map)) {
> + if (cred->user_ns == ns) {
> + if (!ns->parent_could_setfcap)
> + return false;
> + } else {
> + if (!ns_capable(ns->parent, CAP_SETFCAP))
> + return false;
> + }
> + }
> +
> + if (unpriv_idmap_permitted(ns, cred, cap_setid, ns_flags, new_map))
> + return true;
> +
> + if (!cap_valid(cap_setid))
> + return ns_capable(ns, CAP_SYS_ADMIN) ||
> + ns_capable(ns->parent, CAP_SETUID);
[Severity: Medium]
Should !cap_valid(cap_setid) return true here, matching new_idmap_permitted()
for project ID mappings?
sys_userns_set_idmap() already verifies that either the caller or the file
opener holds CAP_SYS_ADMIN in ns, and project ID mappings do not require any
parent namespace capability. Requiring the caller itself to hold
CAP_SYS_ADMIN in ns or CAP_SETUID in ns->parent causes configuring
projid_extents via a delegated userns fd to fail with -EPERM when the caller
does not have CAP_SETUID (for example, an unprivileged process or a helper
holding only CAP_SETGID).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201031002.593830-1-jarkko@kernel.org?part=2
More information about the Linux-security-module-archive
mailing list