BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jarkko Sakkinen" <jarkko@kernel.org>
Cc: bpf@vger.kernel.org, linux-mm@kvack.org,
	linux-security-module@vger.kernel.org,
	"Aleksa Sarai" <aleksa@amutable.com>,
	"Alexander Mikhalitsyn" <alex@amutable.com>,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Andy Lutomirski" <luto@amacapital.net>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Christian Brauner" <brauner@kernel.org>,
	"David Howells" <dhowells@redhat.com>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"Giuseppe Scrivano" <giuseppe@scrivano.org>,
	"Hugh Dickins" <hughd@google.com>, "Jan Kara" <jack@suse.cz>,
	"Jeff Layton" <jlayton@kernel.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Josef Bacik" <josef@toxicpanda.com>,
	"Kees Cook" <kees@kernel.org>, "KP Singh" <kpsingh@kernel.org>,
	"Lennart Poettering" <lennart@poettering.net>,
	"Neal Gompa" <neal@gompa.dev>, "Oleg Nesterov" <oleg@redhat.com>,
	"Paul Moore" <paul@paul-moore.com>,
	"Pavel Tikhomirov" <ptikhomirov@virtuozzo.com>,
	"Serge Hallyn" <sergeh@kernel.org>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Zygmunt Krynicki" <zygmunt.krynicki@canonical.com>
Subject: Re: [RFC PATCH v7 17/26] fork: Support CLONE_INTO_USERLAND in clone3()
Date: Sun, 22 Nov 2026 20:01:29 +0000	[thread overview]
Message-ID: <sashiko-outbox-228304@kernel.org> (raw)
In-Reply-To: <20261122193539.3334213-18-jarkko@kernel.org>

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@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

  reply	other threads:[~2026-11-22 20:01 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 19:35 [RFC PATCH v7 00/26] userland: Userland containers Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 01/26] userns: Factor out idmap validation and commit helpers Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 02/26] userns: Add userns_set_idmap() system call Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 03/26] arch: Wire up " Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 04/26] mount: Add mnt_ns_get_root() Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 05/26] mount: Enforce mount_too_revealing() for foreign mntns Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 06/26] mount: Support MOVE_MOUNT_T_MNTNS in move_mount() Jarkko Sakkinen
2026-11-22 20:02   ` sashiko-bot
2026-11-22 19:35 ` [RFC PATCH v7 07/26] mount: Support MOVE_MOUNT_CLONE with MOVE_MOUNT_T_MNTNS Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 08/26] userns: Factor out install_user_ns_cred() Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 09/26] nsproxy: Expose create_new_namespaces() Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 10/26] userland: Add core infrastructure Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 11/26] userland: Track init lifecycle via copy_process() and pid_namespace Jarkko Sakkinen
2026-11-22 20:09   ` bot+bpf-ci
2026-11-22 19:35 ` [RFC PATCH v7 12/26] userland: Add userland_open() system call Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 13/26] userland: Add USERLAND_GET_NSFD ioctl Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 14/26] userland: Add USERLAND_SHARE_NSFD ioctl Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 15/26] exit: Support P_USERLAND in waitid() Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 16/26] signal: Support userland fds in pidfd_send_signal() Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 17/26] fork: Support CLONE_INTO_USERLAND in clone3() Jarkko Sakkinen
2026-11-22 20:01   ` sashiko-bot [this message]
2026-11-22 19:35 ` [RFC PATCH v7 18/26] fs: Support FSCONFIG_SET_USERLAND in fsconfig() Jarkko Sakkinen
2026-11-22 19:58   ` sashiko-bot
2026-11-22 19:35 ` [RFC PATCH v7 19/26] proc: Implement ->set_userland() fs_context operation Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 20/26] ipc/mqueue: " Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 21/26] security: Add userland LSM hooks Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 22/26] bpf: Register " Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 23/26] arch: Wire up userland_open() system call Jarkko Sakkinen
2026-11-22 19:35 ` [RFC PATCH v7 24/26] docs: Document userland uAPI Jarkko Sakkinen
2026-11-22 20:09   ` bot+bpf-ci
2026-11-22 19:35 ` [RFC PATCH v7 25/26] selftests/userland: Add userland test suite Jarkko Sakkinen
2026-11-22 19:52   ` sashiko-bot
2026-11-22 19:35 ` [RFC PATCH v7 26/26] MAINTAINERS: Add entry for USERLAND Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-228304@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aleksa@amutable.com \
    --cc=alex@amutable.com \
    --cc=arnd@arndb.de \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dhowells@redhat.com \
    --cc=ebiggers@kernel.org \
    --cc=giuseppe@scrivano.org \
    --cc=hughd@google.com \
    --cc=jack@suse.cz \
    --cc=jarkko@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=kees@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=lennart@poettering.net \
    --cc=linux-mm@kvack.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=neal@gompa.dev \
    --cc=oleg@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=ptikhomirov@virtuozzo.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sergeh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zygmunt.krynicki@canonical.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox