[RFC PATCH v7 17/26] fork: Support CLONE_INTO_USERLAND in clone3()

bot+bpf-ci at kernel.org bot+bpf-ci at kernel.org
Sun Nov 22 20:28:17 UTC 2026


> fork: Support CLONE_INTO_USERLAND in clone3()

TL;DR: In copy_creds() for CLONE_INTO_USERLAND, the dumpable-reset condition
looks redundant with a user namespace change, so the cred_cap_issubset() term
and init_task_exec_state check may be removable. Not a bug.

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

[ ... ]

> @@ -251,6 +254,9 @@ struct cred *prepare_exec_creds(void)
>  	return new;
>  }
>  
> +static bool cred_cap_issubset(const struct cred *set,
> +			      const struct cred *subset);
> +

[ ... ]

> @@ -287,6 +294,24 @@ int copy_creds(struct task_struct *p, u64 clone_flags)
>  	if (!new)
>  		return -ENOMEM;
>  
> +	if (userland) {
> +		const struct cred *old = current_cred();
> +
> +		if (new->user_ns != userland->user_ns) {
> +			ret = install_user_ns_cred(new, userland->user_ns);
> +			if (ret < 0)
> +				goto error_put;
> +		}
> +		if (!cred_cap_issubset(old, new) ||
> +		    old->user_ns != new->user_ns) {
> +			struct task_exec_state *exec_state;
> +
> +			exec_state = rcu_dereference_protected(p->exec_state, true);
> +			if (exec_state != &init_task_exec_state)
> +				WRITE_ONCE(exec_state->dumpable, suid_dumpable);
> +		}
> +	}
> +

this isn't a bug, but does the !cred_cap_issubset(old, new) term ever
change the result here?

new is a prepare_creds() copy of current->cred, so there are two cases:

  - same user namespace: install_user_ns_cred() is skipped, the
    capability sets are unchanged, cred_cap_issubset() returns true, and
    old->user_ns != new->user_ns is false, so no reset happens.

  - different user namespace: install_user_ns_cred() switched
    new->user_ns, so old->user_ns != new->user_ns is true regardless of
    cred_cap_issubset().

The condition looks equivalent to old->user_ns != new->user_ns, which is
the same as "install_user_ns_cred() ran".  It reads as if it follows the
commit_creds() rule that skips the reset when old->euid owns the target
namespace, but the reset always happens on a namespace change, which
matches the "dumpability reset to suid_dumpable" text in the kernel/userland.c
documentation comment.

Also, is the exec_state != &init_task_exec_state test ever false on this
path?  For CLONE_INTO_USERLAND, copy_exec_state() runs before copy_creds()
and always takes the task_exec_state_copy() branch, which allocates a fresh
exec_state.

Could the dumpable reset move into the
if (new->user_ns != userland->user_ns) block, which would let the
cred_cap_issubset() forward declaration and the init_task_exec_state test
go away?  If commit_creds()-like semantics were intended instead, then the
old->user_ns != new->user_ns operand and the documentation comment would
need to change.


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


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