[PATCH 3/8] userns: allow restricting capability bounding set via clone3()

sashiko-bot at kernel.org sashiko-bot at kernel.org
Thu Oct 29 22:18:26 UTC 2026


Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] fork: copy_clone_args_from_user() validates cap_bset outside flag gate
--

commit ad8aaabe65c03fa30d8b9e523721be228b373956
Author: Hallgrimur H. Gunnarsson <halg at google.com>

userns: allow restricting capability bounding set via clone3()

This commit introduces the CLONE_NEWUSER_BSET flag and adds a cap_bset
field to struct clone_args (CLONE_ARGS_SIZE_VER3). When specified with
CLONE_NEWUSER during clone3(), the new user namespace's capability bounding
set is intersected with cap_bset.

> diff --git a/kernel/fork.c b/kernel/fork.c
> index c0f7520e754ab..a09f62cadeac1 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
[ ... ]
> @@ -2962,6 +2964,11 @@ static noinline int copy_clone_args_from_user(struct kernel_clone_args *kargs,
>  	    (args.cgroup > INT_MAX || usize < CLONE_ARGS_SIZE_VER2))
>  		return -EINVAL;
>  
> +	if ((args.flags & CLONE_NEWUSER_BSET) && usize < CLONE_ARGS_SIZE_VER3)
> +		return -EINVAL;
> +	if (!(args.flags & CLONE_NEWUSER_BSET) && args.cap_bset)
> +		return -EINVAL;

[Severity: Medium]
Should copy_clone_args_from_user() in kernel/fork.c really reject a non-zero
args.cap_bset when CLONE_NEWUSER_BSET is not set in args.flags?

In include/uapi/linux/sched.h, cap_bset in struct clone_args is documented
as a flag-gated field:

 * @cap_bset:     If CLONE_NEWUSER_BSET is specified, this
 *                specifies the capability bounding set mask to
 *                apply to the new user namespace. Unknown
 *                capability bits (> CAP_LAST_CAP) are ignored.

Other flag-gated fields in struct clone_args (such as cgroup gated by
CLONE_INTO_CGROUP right above, or pidfd, child_tid, parent_tid, and tls) are
only validated and consumed when their corresponding flag is set, and
copy_creds() in kernel/cred.c only reads kargs->cap_bset when
CLONE_NEWUSER_BSET is present:

	if (clone_flags & CLONE_NEWUSER) {
		kernel_cap_t cap_bset = CAP_FULL_SET;

		if (clone_flags & CLONE_NEWUSER_BSET)
			cap_bset = (kernel_cap_t){ .val = kargs->cap_bset };

If userspace invokes sys_clone3() -> copy_clone_args_from_user() with
usize >= CLONE_ARGS_SIZE_VER3 and without CLONE_NEWUSER_BSET set, while
args.cap_bset is non-zero (for instance, when reusing a struct clone_args
buffer after clearing CLONE_NEWUSER_BSET or only initializing fields for the
flags being passed), won't this check cause the syscall to fail spuriously
with -EINVAL?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261028221705.3915340-1-halg@google.com?part=3



More information about the Linux-security-module-archive mailing list