Re: [RFC PATCH v6 02/26] userns: Add userns_set_idmap() system call
From: bot+bpf-ci
Date: Sat Nov 21 2026 - 21:13:57 EST
> userns: Add userns_set_idmap() system call
TL;DR: Design nit only: the new idmap permission checks in userns_set_idmap()
seem to duplicate existing new_idmap_permitted()/verify_root_map() logic; the
review suggests a shared helper. No bug is claimed.
> diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
> --- a/kernel/user_namespace.c
> +++ b/kernel/user_namespace.c
[ ... ]
> +static bool idmap_maps_root(const struct uid_gid_map *new_map)
> +{
> + unsigned int idx;
> +
> + for (idx = 0; idx < new_map->nr_extents; idx++) {
> + const struct uid_gid_extent *e;
> +
> + if (new_map->nr_extents <= UID_GID_MAP_MAX_BASE_EXTENTS)
> + e = &new_map->extent[idx];
> + else
> + e = &new_map->forward[idx];
> + if (e->lower_first == 0)
> + return true;
> + }
> + return false;
> +}
> +
> +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 (new_map->nr_extents == 1 && new_map->extent[0].count == 1 &&
> + uid_eq(ns->owner, cred->euid)) {
> + u32 id = new_map->extent[0].lower_first;
[ ... ]
This isn't a bug, but the root-mapping loop in idmap_maps_root() and the
single-extent unprivileged block here look like copies of the logic in
verify_root_map() and new_idmap_permitted(), differing only in where the
cred (current_cred() vs file->f_cred) and the setgroups flags (ns_flags
vs ns->flags) come from.
Could new_idmap_permitted()/verify_root_map() and
caller_idmap_permitted()/idmap_maps_root() share a helper that takes the
cred and the setgroups flags, so the unprivileged single-ID rule and the
root-mapping test are written only once?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44972669664