Re: [RFC PATCH v10 02/28] userns: Add NS_SET_IDMAP ioctl

From: bot+bpf-ci

Date: Fri Dec 04 2026 - 23:03:09 EST


> userns: Add NS_SET_IDMAP ioctl

TL;DR: NS_SET_IDMAP in userns_set_idmap() runs both caller and opener
capability checks eagerly, so successful calls may log spurious audited
LSM/SELinux denials; the review suggests a noaudit check first.

> diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
> --- a/kernel/user_namespace.c
> +++ b/kernel/user_namespace.c

[ ... ]

> +long userns_set_idmap(struct file *filp, struct user_namespace *ns,
> + const struct userns_idmap __user *map, size_t size)
> +{

[ ... ]

> + if (!ns->parent)
> + return -EPERM;
> + if (current_user_ns() != ns && current_user_ns() != ns->parent)
> + return -EPERM;
> +
> + file_ok = (filp->f_cred->user_ns == ns ||
> + filp->f_cred->user_ns == ns->parent) &&
> + file_ns_capable(filp, ns, CAP_SYS_ADMIN);
> + if (!ns_capable(ns, CAP_SYS_ADMIN) && !file_ok)
> + return -EPERM;

Is it intended that both capability checks always run here? file_ok is
computed eagerly through file_ns_capable(), and ns_capable() is then
evaluated as well. Both are audited checks, so every NS_SET_IDMAP call
produces two LSM capability decisions.

In the main use case from the commit message, an unprivileged owner opens
its user namespace and passes the fd to a privileged mapping helper. The
helper's ns_capable() check is sufficient, but the opener check still runs
and SELinux checks cap_userns { sys_admin } for the opener's domain. If
policy denies that, an AVC denial is logged for an ioctl that then
succeeds.

The reverse case behaves the same way: a caller without the capability,
whose fd opener had it, gets an audited ns_capable() failure before
file_ok allows the ioctl.

Other code that accepts either of two capability checks uses the noaudit
variant for the first one, for example checkpoint_restore_ns_capable_noaudit()
in include/linux/capability.h and pid_table_root_permissions() in
kernel/pid.c.

Could the caller be checked first with ns_capable_noaudit(ns,
CAP_SYS_ADMIN), consulting the opener through file_ns_capable() only when
that fails?

This does not appear to be addressed later in the series; the capability
check in userns_set_idmap() is unchanged at the end of it.


---
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/47474652355