[RFC PATCH v7 17/26] fork: Support CLONE_INTO_USERLAND in clone3()
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Sun Nov 22 20:01:29 UTC 2026
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] userland: missing namespace owner permission check in
userland_prepare_fork()
- [Medium] fork: missing ancestor PID namespace liveness check in
copy_process()
- [Medium] userland: missing Landlock namespace-use check in
userland_prepare_fork()
--
commit ae368fbd705dc27859acdfc3d94bc11f009bc3b0
Author: Jarkko Sakkinen <jarkko at kernel.org>
fork: Support CLONE_INTO_USERLAND in clone3()
This patch adds CLONE_INTO_USERLAND and struct clone_args.userland to
allow clone3() to spawn a child process directly into an initialized
userland's namespaces and root mount.
[ ... ]
> diff --git a/kernel/fork.c b/kernel/fork.c
> index d87ab7cbad5e9..d8fc18a9af220 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
[ ... ]
> @@ -2510,6 +2526,11 @@ __latent_entropy struct task_struct *copy_process(
> goto bad_fork_core_free;
> }
>
> + if (unlikely(args->userland_bootstrapping && !is_child_reaper(pid))) {
> + retval = -EBUSY;
> + goto bad_fork_core_free;
> + }
> +
> /* Let kill terminate clone/fork in the middle */
> if (fatal_signal_pending(current)) {
> retval = -EINTR;
[Severity: Medium]
Can copy_process() attach a child into a dying ancestor PID namespace when
cloning into a nested userland?
Immediately above this check, copy_process() only tests PIDNS_ADDING on
the leaf ns_of_pid(pid). When current is in an outer PID namespace A and
spawns into a nested userland C whose parent PID namespace is B, B can
enter zap_pid_ns_processes() after alloc_pid() succeeds:
CPU0 (in pid_ns A) CPU1 (init of pid_ns B)
copy_process()
alloc_pid(C)
zap_pid_ns_processes(B)
disable_pid_allocation(B)
read_lock(&tasklist_lock)
/* sends SIGKILL to tasks in B */
read_unlock(&tasklist_lock)
write_lock_irq(&tasklist_lock)
!(C->pid_allocated & PIDNS_ADDING)
-> false (C still has PIDNS_ADDING)
attach_pid(p, PIDTYPE_PID) <-- attached into dying B after SIGKILL
Because current is in A, fatal_signal_pending(current) does not trigger,
and if C is bootstrapping it has no tasks in B->idr to trigger C's
teardown. The new child (with SIGNAL_UNKILLABLE if PID 1 in C) then runs
inside dying namespace B, blocking B's child_reaper in
zap_pid_ns_processes() until the child exits.
[ ... ]
> diff --git a/kernel/userland.c b/kernel/userland.c
> index f449e2ff91522..2375442733b66 100644
> --- a/kernel/userland.c
> +++ b/kernel/userland.c
[ ... ]
> +int userland_prepare_fork(struct kernel_clone_args *args)
> +{
> + struct file *file __free(fput) = fget(args->userland_fd);
> + struct path root __free(path_put) = {};
> + struct pid_namespace *pid_ns;
> + bool bootstrapping = false;
> + struct userland *userland;
> + int ret;
> +
> + if (!file)
> + return -EBADF;
> + if (!userland_is_file(file))
> + return -EINVAL;
> +
> + userland = file->private_data;
> + if (!ns_capable(userland->user_ns, CAP_SYS_ADMIN) ||
> + !ns_capable(userland->user_ns, CAP_SYS_CHROOT))
> + return -EPERM;
> + if (current_chrooted() && !ns_capable(current_user_ns(), CAP_SYS_CHROOT))
> + return -EPERM;
[Severity: High]
Does userland_prepare_fork() allow a process to join shared namespaces in
userland->ns without being a member of those namespaces or holding
CAP_SYS_ADMIN in their owning user namespaces?
userland_share_nsfd() allows binding a cgroup, IPC, UTS, network, or time
namespace owned by a more privileged user namespace (such as init_user_ns)
into userland->ns without CAP_SYS_ADMIN in ns->ops->owner(ns) whenever
is_current_namespace(ns) is true at ioctl time:
kernel/userland.c:userland_share_nsfd() {
...
if (!ns_capable(c->user_ns, CAP_SYS_ADMIN))
return -EPERM;
if (!is_current_namespace(ns) &&
!ns_capable(ns->ops->owner(ns), CAP_SYS_ADMIN))
return -EPERM;
...
}
If the caller (or another process holding the userland fd) later enters a
separate network, IPC, UTS, cgroup, or time namespace,
clone3(CLONE_INTO_USERLAND) only checks capabilities in userland->user_ns
and installs userland->ns directly in copy_namespaces(), letting the
caller escape its namespace isolation into the previously bound namespace.
[Severity: Medium]
Does spawning into a userland also bypass Landlock's
LANDLOCK_PERMISSION_NAMESPACE_USE check?
Landlock mediates entering existing namespaces through the
namespace_install LSM hook (called from validate_ns() during setns()), and
does not implement a userland_clone hook in commit "security: Add userland
LSM hooks". Because userland_prepare_fork(), copy_creds(), and
copy_namespaces() install userland->user_ns and userland->ns without
calling security_namespace_install(), a Landlock-sandboxed task holding a
pre-opened userland fd can enter its namespaces even when
LANDLOCK_PERMISSION_NAMESPACE_USE denies them.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261122193539.3334213-1-jarkko@kernel.org?part=17
More information about the Linux-security-module-archive
mailing list