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

sashiko-bot at kernel.org sashiko-bot at kernel.org
Sun Nov 22 01:43:45 UTC 2026


Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] userland: missing namespace owner permission check in
  userland_prepare_fork()
- [Medium] userland: missing namespace_install LSM check in
  userland_prepare_fork()
--

commit 705db8da85300ec68db1d2ce6e9711aa2f376bb1
Author: Jarkko Sakkinen <jarkko at kernel.org>

fork: Support CLONE_INTO_USERLAND in clone3()

This commit 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/userland.c b/kernel/userland.c
> index 739f6b98c1035..283b90869d2c6 100644
> --- a/kernel/userland.c
> +++ b/kernel/userland.c
> @@ -541,3 +542,135 @@ SYSCALL_DEFINE1(userland_open, unsigned int, flags)
>  
>  	return fd;
>  }
> +

[ ... ]

> +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;

[Severity: Medium]
Should userland_prepare_fork() also invoke security_namespace_install() or
a matching LSM check for the target namespaces in userland->user_ns and
userland->ns?

Landlock enforces LANDLOCK_PERMISSION_NAMESPACE_USE via its
namespace_install hook when entering pre-opened namespaces with setns(),
and commit "security: Add userland LSM hooks" later in this series does
not wire Landlock up to security_userland_clone().  Without an LSM check
on those namespaces, a Landlock-sandboxed task holding a pre-opened
userland fd can use clone3(CLONE_INTO_USERLAND) to enter namespaces that
its Landlock domain denies.

> +	if (current_chrooted() && !ns_capable(current_user_ns(), CAP_SYS_CHROOT))
> +		return -EPERM;
> +
> +	pid_ns = userland->ns->pid_ns_for_children;
> +	if (!pidns_is_ancestor(pid_ns, task_active_pid_ns(current)))
> +		return -EXDEV;

[Severity: High]
Does userland_prepare_fork() need to verify that current either already
belongs to each namespace in userland->ns or holds CAP_SYS_ADMIN in that
namespace's owning user namespace?

In userland_share_nsfd(), a cgroup, IPC, UTS, network, or time namespace
owned by a more privileged user namespace (such as init_user_ns) can be
attached to userland->ns without CAP_SYS_ADMIN in ns->ops->owner(ns) as
long as the caller is currently in that namespace:

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;
    ...
}

Because userland_prepare_fork() only checks capabilities against
userland->user_ns and current_user_ns() before copy_namespaces() installs
userland->ns on the child, a process that shares a parent or host
namespace into a userland and later isolates itself with unshare() (for
example, unshare(CLONE_NEWNET)) can call clone3(CLONE_INTO_USERLAND) to
spawn a child back into the unisolated namespace without holding
CAP_SYS_ADMIN in its owning user namespace.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122011809.2667684-1-jarkko@kernel.org?part=17



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