Linux userland API discussions
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: fsdevel@vger.kernel.org
Cc: bpf@vger.kernel.org, containers@lists.linux.dev,
	linux-api@vger.kernel.org, linux-arch@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@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>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Andy Lutomirski" <luto@amacapital.net>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Baolin Wang" <baolin.wang@linux.alibaba.com>,
	"Ben Segall" <bsegall@google.com>,
	"Christian Brauner" <brauner@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"David Hildenbrand" <david@kernel.org>,
	"David Howells" <dhowells@redhat.com>,
	"David Woodhouse" <dwmw2@infradead.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"Georgia Garcia" <georgia.garcia@canonical.com>,
	"Giuseppe Scrivano" <giuseppe@scrivano.org>,
	"Günther Noack" <gnoack@google.com>,
	"Hugh Dickins" <hughd@google.com>,
	"Ihor Solodrai" <ihor.solodrai@linux.dev>,
	"Ingo Molnar" <mingo@redhat.com>,
	"James Morris" <jmorris@namei.org>, "Jan Kara" <jack@suse.cz>,
	"Jason Gunthorpe" <jgg@nvidia.com>,
	"Jeff Layton" <jlayton@kernel.org>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"John Johansen" <john.johansen@canonical.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Josef Bacik" <josef@toxicpanda.com>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Kees Cook" <kees@kernel.org>,
	"K Prateek Nayak" <kprateek.nayak@amd.com>,
	"KP Singh" <kpsingh@kernel.org>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Lennart Poettering" <lennart@poettering.net>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Manfred Spraul" <manfred@colorfullife.com>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Matt Bobrowski" <matt@bobrowski.net>,
	"Mel Gorman" <mgorman@suse.de>, "Michal Hocko" <mhocko@suse.com>,
	"Mickaël Salaün" <mic@digikod.net>,
	"Mike Rapoport" <rppt@kernel.org>, "Neal Gompa" <neal@gompa.dev>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Paul Moore" <paul@paul-moore.com>,
	"Pavel Tikhomirov" <ptikhomirov@virtuozzo.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	"Serge Hallyn" <sergeh@kernel.org>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Song Liu" <song@kernel.org>,
	"Stephen Smalley" <stephen.smalley.work@gmail.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Valentin Schneider" <vschneid@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Zygmunt Krynicki" <zygmunt.krynicki@canonical.com>
Subject: Re: [RFC PATCH v9 00/29] nsexec: Staged namespace execution
Date: Tue, 1 Dec 2026 06:02:44 +0200	[thread overview]
Message-ID: <aw5G5IPF-J-soJ_F@kernel.org> (raw)
In-Reply-To: <20261201031002.593830-1-jarkko@kernel.org>

On Tue, Dec 01, 2026 at 05:09:32AM +0200, Jarkko Sakkinen wrote:
> MOTIVATION
> ==========
> 
> Self-modifying uninitialized state in containers is probably one of the
> biggest security challenges we have at the moment.
> 
> The primitives for namespaces, credentials, and mounts were designed to be
> invoked from inside the process being isolated, one step at a time.
> 
> Container runtimes and sandboxes (runc, systemd-nspawn, bubblewrap, etc.)
> approach the problem with a chain of short-lived helper processes, which
> are managed by pausing them behind pipes or socket pairs.
> 
> While this is happening, the parent process does the whole shebang of
> obscure management tasks:
> 
> 1. Writes /proc/<pid>/uid_map and /proc/<pid>/gid_map.
> 2. Clones the host's entire mount table only to tear it back down with
>    pivot_root() and fork yet again before PID 1 can finally call execve().
> 
>    runc has one of the worst-case scenarios in this regard given that the
>    Go runtime is always multi-threaded. This disallows calling
>    unshare(CLONE_NEWUSER | CLONE_NEWNS) or setns(CLONE_NEWUSER) directly
>    from Go. The workaround addressing this is based on a C trampoline.
> 
> I.e., packing the cargo happens exactly at the time when the ship is
> lifting the anchor and detaching from the harbor, and with the current
> syscall API there's no common-sense way around this.
> 
> For what it is worth, any practical cryptography such as authenticated
> measurement is also not doable, because the primitives can only measure a
> static and immutable target.
> 
> OVERVIEW
> ========
> 
> If the root of the problem is that an isolated process has to assemble its
> own prison from the inside while already running, the natural alternative
> is to invert the sequence: construct the entire execution environment from
> the outside while it is still inert, and only spawn a process once setup
> is complete.
> 
> Building on David Howells' earlier work on kernel container objects [1],
> this series introduces nsexec: an anonymous-inode control descriptor that
> splits namespace setup and process execution into distinct build and live
> phases.
> 
> Opening an nsexec descriptor allocates a fresh user namespace together
> with a detached set of mount, PID, UTS, IPC, network, cgroup, and time
> namespaces. Crucially, the mount namespace starts completely empty
> (CLONE_EMPTY_MNTNS) rather than cloning the caller's mount table, and no
> task exists inside any of the new namespaces during the build phase
> (NSEXEC_INIT).
> 
> Because the caller's own credentials, root directory, and thread group are
> never mutated during construction, even a multi-threaded runtime such as Go
> can drive the entire setup directly over file descriptors without helper
> processes or C trampolines. Rather than introducing a parallel namespace
> API, nsexec plugs into existing descriptor-based syscalls for ID mapping,
> filesystem configuration, mount placement, process creation, waiting, and
> signaling.
> 
> [1] https://lwn.net/Articles/780364/
> 
> SOLUTION
> ========
> 
> The standalone primitives at the front of the series (patches 01-09) make
> both user namespaces and mount namespaces configurable via nsfs file
> descriptors without a paused child task, while the remaining patches tie
> them together around the nsexec lifecycle.
> 
> 1. Allocating namespaces and programming ID maps
> 
> A manager begins by calling nsexec_open(), which returns a close-on-exec
> control descriptor in NSEXEC_INIT. While in this build phase, the manager
> can optionally opt individual cgroup, IPC, UTS, network, or time
> namespaces into existing nsfs descriptors via ioctl(NSEXEC_SHARE_NSFD), or
> extract nsfs descriptors for member namespaces via ioctl(NSEXEC_GET_NSFD).
> 
> Instead of formatting text into /proc/<pid>/uid_map and gid_map while a
> helper blocks on a pipe, userns_set_idmap() programs UID, GID, and project
> ID extents (along with USERNS_SETGROUPS_ALLOWED) atomically on the user
> namespace descriptor:
> 
>     nsexec_fd = nsexec_open(NSEXEC_AUTOKILL);
>     userns_fd = ioctl(nsexec_fd, NSEXEC_GET_NSFD, CLONE_NEWUSER);
>     mntns_fd  = ioctl(nsexec_fd, NSEXEC_GET_NSFD, CLONE_NEWNS);
> 
>     struct userns_idmap_extent ext = {
>             .first = 0,
>             .lower_first = 1000,
>             .count = 1,
>     };
>     struct userns_idmap map = {
>             .nr_uid_extents = 1,
>             .nr_gid_extents = 1,
>             .uid_extents = (__u64)(uintptr_t)&ext,
>             .gid_extents = (__u64)(uintptr_t)&ext,
>     };
> 
>     userns_set_idmap(userns_fd, &map, sizeof(map), 0);
> 
> Parent ID ranges are authorized against the caller of userns_set_idmap(),
> allowing an unprivileged runtime to pass userns_fd over SCM_RIGHTS to a
> privileged mapping helper without keeping an embryonic child alive.
> 
> 2. Assembling the mount tree without pivot_root()
> 
> With ID mappings in place, superblocks can be instantiated directly inside
> the nsexec's user, network, PID (proc), and IPC (mqueue) namespaces by
> binding a mount-API context via FSCONFIG_SET_NSEXEC. Filesystems opt into
> unprivileged delegation with FS_NSEXEC_MOUNT (tmpfs, ramfs, devpts, proc,
> and mqueue) or FS_USERNS_DELEGATABLE.
> 
> To populate the empty mount namespace without entering it, move_mount()
> learns two flags: MOVE_MOUNT_T_MNTNS resolves to_dfd as a mount namespace
> descriptor (attaching "/" onto its nullfs root once, and resolving
> relative paths beneath that root thereafter), and MOVE_MOUNT_CLONE
> recursively bind-clones a source tree without requiring OPEN_TREE_CLONE or
> host CAP_SYS_ADMIN:
> 
>     fs_fd = fsopen("tmpfs", FSOPEN_CLOEXEC);
>     fsconfig(fs_fd, FSCONFIG_SET_NSEXEC, NULL, NULL, nsexec_fd);
>     fsconfig(fs_fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0);
>     root_fd = fsmount(fs_fd, FSMOUNT_CLOEXEC, 0);
> 
>     mkdirat(root_fd, "usr", 0755);
>     move_mount(root_fd, "", mntns_fd, "/",
>                MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_MNTNS);
>     move_mount(AT_FDCWD, "/usr", mntns_fd, "usr",
>                MOVE_MOUNT_T_MNTNS | MOVE_MOUNT_CLONE);
> 
> Mounts crossing user namespace boundaries are locked with MNT_LOCKED, and
> LSMs mediate MOVE_MOUNT_CLONE as MS_BIND | MS_REC. The same
> MOVE_MOUNT_T_MNTNS path remains available after boot for live mount
> hotplug, which workloads can observe via fanotify(FAN_MNT_ATTACH) and
> statmount().
> 
> 3. Spawning PID 1 and supervising the lifecycle
> 
> Once "/" has been installed, clone3() with CLONE_INTO_NSEXEC spawns the
> first child directly into the configured environment as PID 1,
> transitioning the descriptor from NSEXEC_INIT through NSEXEC_FORKING to
> NSEXEC_RUNNING:
> 
>     struct clone_args args = {
>             .flags = CLONE_INTO_NSEXEC,
>             .nsexec = nsexec_fd,
>     };
> 
>     pid = clone3(&args, sizeof(args));
>     if (pid == 0)
>             execve("/sbin/init", argv, envp);
> 
>     waitid(P_NSEXEC, nsexec_fd, &info, WEXITED);
> 
> Subsequent CLONE_INTO_NSEXEC calls join the running PID namespace directly
> for management or diagnostic sessions. To prevent half-transitioned task
> state, CLONE_VM, CLONE_FILES, CLONE_FS, and CLONE_SIGHAND are rejected;
> when the caller originates outside the target user namespace,
> exec_state->user_ns stays anchored in that outer namespace with
> dumpability reset to suid_dumpable until execve(), blocking member tasks
> from tracing the child or reading /proc/<pid>/{exe,mem,fd}.
> 
> At runtime, pidfd_send_signal() broadcasts signals across member thread
> groups, poll() reports EPOLLHUP once PID 1 exits and the PID namespace is
> reaped, and waitid(P_NSEXEC) reads init's exit status without consuming
> it. Dedicated LSM hooks (wired into Landlock and BPF LSM) mediate
> allocation, namespace sharing, process entry, and signaling.
> 
> Experimental userspace support with runtime fallback on older kernels is
> maintained for systemd [2], bubblewrap [3], and podman [4], integrated end
> to end in linux-tpmdd-test [5].
> 
> [2] https://github.com/jarkkojs/systemd/commits/nsexec
> [3] https://github.com/jarkkojs/bubblewrap/commits/nsexec
> [4] https://github.com/jarkkojs/podman/commits/nsexec
> [5] https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd-test.git/
> 
> CHANGES
> =======
> 
> v9:
> - The main theme is the refactorization of userland_open() into nsexec()
>   and rewriting the cover letter to be focused on execution rather than
>   data structures, as latter should be only consequence of the former.
> - Rewrite the kselftest as a seed-replayable model-based fuzzer.
> - Rename userland to nsexec across syscalls, ioctls, clone3(), waitid(),
>   fsconfig(), LSM hooks, documentation, selftests, and MAINTAINERS.
> - Rename USERLAND_KILL_ON_CLOSE to NSEXEC_AUTOKILL and drop
>   USERLAND_CLOEXEC in favor of unconditional O_CLOEXEC on nsexec_open().
> - Recheck CAP_SYS_ADMIN on fc->user_ns after ->set_nsexec(), gate
>   FSCONFIG_SET_NSEXEC on CONFIG_NSEXEC, preserve proc and mqueue
>   namespaces on FS_CONTEXT_FOR_RECONFIGURE, and validate proc gid= against
>   fc->user_ns via fsparam_gid().
> - NOTE: Despite the patch set size grows, the feature size does not,
>   which is about 2400 lines added and 260 removed. This patch set is
>   dominated by the Python test suite (for a good reason).
> 
> v8:
> - Pass MOVE_MOUNT_* flags to security_move_mount(), mediate
>   MOVE_MOUNT_CLONE as MS_BIND | MS_REC in AppArmor, and enforce Landlock
>   namespace restrictions on userland entry and sharing (Sashiko).
> - Move USERLAND_ALL_FLAGS out of uAPI, rename USERLAND_CLOSE_ON_EXEC to
>   USERLAND_CLOEXEC, drop unused userland_copy(), userland_exit(), and
>   fsconfig_set_userland() code, and reset exec_state->dumpable whenever
>   exec_state->user_ns originates outside the target user namespace
>   (Sashiko, Askar Safin).
> - Fix sys_userns_set_idmap() kernel-doc range syntax and document
>   CLONE_INTO_USERLAND pre-execve() ptrace_may_access() isolation
>   (Sashiko, Askar Safin).
> - Route unshare() and setns() via ctypes for Python 3.9 compatibility,
>   isolate /tmp mount propagation when running as root, and derive the
>   E2BIG buffer size from SC_PAGE_SIZE in selftests/userland (Sashiko).
> 
> v7:
> - Move userland_copy() outside tasklist_lock, loop in userland_waitid()
>   across bootstrap retries, defer fsmount() may_mount() on
>   userland_bound contexts, and clean up mount/idmap helpers (Sashiko).
> - Move userland.rst prose into modular kernel-doc comments, document
>   ->set_userland() in mount_api.rst, and harden selftests/userland for
>   x32/i386, CONFIG_TIME_NS=n, and SOCK_SEQPACKET fd passing (Sashiko).
> 
> v6:
> - Rename rootns to userland, replace ROOTNS_WAIT and ROOTNS_KILL ioctls
>   with waitid(P_USERLAND) and pidfd_send_signal(), and add
>   USERLAND_SHARE_NSFD plus security_userland_share().
> - Gate FSCONFIG_SET_USERLAND on FS_USERLAND_MOUNT, pass
>   USERNS_SETGROUPS_ALLOWED via syscall flags, bound userns_set_idmap()
>   size to PAGE_SIZE, and tighten mount and pidns checks (Sashiko).
> 
> v5:
> - Split standalone fd-based user and mount namespace setup ahead of core
>   control object patches, and add userns_set_idmap() (Andy Lutomirski)
>   plus MOVE_MOUNT_CLONE.
> 
> v4:
> - Consolidate control syscalls into an anonymous-inode fd, add LSM hooks
>   and bpf_lsm wiring, disallow CLONE_VM, and rewrite kselftests in
>   Python (Sashiko).
> 
> v3:
> - Replace MOVE_MOUNT_T_ROOTNS_ROOT with MOVE_MOUNT_T_MNTNS, add
>   GET_NSFD ioctl, and support unprivileged FSCONFIG_SET_ROOTNS mount
>   configuration (Andy Lutomirski, Sashiko).
> 
> v2:
> - Rely on user_namespace ownership for setns() isolation and replace
>   rootns_enter() with clone3() entry (Andy Lutomirski).
> 
> VERSIONS
> ========
> 
> v8: https://lore.kernel.org/linux-fsdevel/20261128235808.2369970-1-jarkko@kernel.org/
> v7: https://lore.kernel.org/linux-fsdevel/20261122193539.3334213-1-jarkko@kernel.org/
> v6: https://lore.kernel.org/linux-fsdevel/20261122011809.2667684-1-jarkko@kernel.org/
> v5: https://lore.kernel.org/linux-fsdevel/20261121000844.1863324-1-jarkko@kernel.org/
> v4: https://lore.kernel.org/linux-fsdevel/20261119224312.1037966-1-jarkko@kernel.org/
> v3: https://lore.kernel.org/linux-fsdevel/20261118193539.240065-1-jarkko@kernel.org/
> v2: https://lore.kernel.org/linux-fsdevel/20261117231352.3816603-1-jarkko@kernel.org/
> v1: https://lore.kernel.org/linux-fsdevel/20261117050841.3289652-1-jarkko@kernel.org/
> 
> Cc: bpf@vger.kernel.org
> Cc: containers@lists.linux.dev
> Cc: linux-api@vger.kernel.org
> Cc: linux-arch@vger.kernel.org
> Cc: linux-doc@vger.kernel.org
> Cc: linux-fsdevel@vger.kernel.org
> Cc: linux-integrity@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-kselftest@vger.kernel.org
> Cc: linux-mm@kvack.org
> Cc: linux-security-module@vger.kernel.org
> Cc: Aleksa Sarai <aleksa@amutable.com>
> Cc: Alexander Mikhalitsyn <alex@amutable.com>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Andrii Nakryiko <andrii@kernel.org>
> Cc: Andy Lutomirski <luto@amacapital.net>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
> Cc: Ben Segall <bsegall@google.com>
> Cc: Christian Brauner <brauner@kernel.org>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: David Hildenbrand <david@kernel.org>
> Cc: David Howells <dhowells@redhat.com>
> Cc: David Woodhouse <dwmw2@infradead.org>
> Cc: Davidlohr Bueso <dave@stgolabs.net>
> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
> Cc: Eduard Zingerman <eddyz87@gmail.com>
> Cc: Emil Tsalapatis <emil@etsalapatis.com>
> Cc: Eric Biggers <ebiggers@kernel.org>
> Cc: Georgia Garcia <georgia.garcia@canonical.com>
> Cc: Giuseppe Scrivano <giuseppe@scrivano.org>
> Cc: "Günther Noack" <gnoack@google.com>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Ihor Solodrai <ihor.solodrai@linux.dev>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: James Morris <jmorris@namei.org>
> Cc: Jan Kara <jack@suse.cz>
> Cc: Jason Gunthorpe <jgg@nvidia.com>
> Cc: Jarkko Sakkinen <jarkko@kernel.org>
> Cc: Jeff Layton <jlayton@kernel.org>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: John Johansen <john.johansen@canonical.com>
> Cc: Jonathan Corbet <corbet@lwn.net>
> Cc: Josef Bacik <josef@toxicpanda.com>
> Cc: Juri Lelli <juri.lelli@redhat.com>
> Cc: Kees Cook <kees@kernel.org>
> Cc: K Prateek Nayak <kprateek.nayak@amd.com>
> Cc: KP Singh <kpsingh@kernel.org>
> Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> Cc: Lennart Poettering <lennart@poettering.net>
> Cc: "Liam R. Howlett" <liam@infradead.org>
> Cc: Manfred Spraul <manfred@colorfullife.com>
> Cc: Martin KaFai Lau <martin.lau@linux.dev>
> Cc: Matt Bobrowski <matt@bobrowski.net>
> Cc: Mel Gorman <mgorman@suse.de>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: "Mickaël Salaün" <mic@digikod.net>
> Cc: Mickaël Salaün <mic@digikod.net>
> Cc: Mike Rapoport <rppt@kernel.org>
> Cc: Neal Gompa <neal@gompa.dev>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Paul Moore <paul@paul-moore.com>
> Cc: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: "Serge E. Hallyn" <serge@hallyn.com>
> Cc: Serge Hallyn <sergeh@kernel.org>
> Cc: Shuah Khan <skhan@linuxfoundation.org>
> Cc: Song Liu <song@kernel.org>
> Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Valentin Schneider <vschneid@redhat.com>
> Cc: Vincent Guittot <vincent.guittot@linaro.org>
> Cc: Yonghong Song <yonghong.song@linux.dev>
> Cc: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
> 
> Jarkko Sakkinen (29):
>   userns: Factor out idmap validation and commit helpers
>   userns: Add userns_set_idmap() system call
>   arch: Wire up userns_set_idmap() system call
>   mount: Add mnt_ns_get_root()
>   mount: Enforce mount_too_revealing() for foreign mntns
>   mount: Support MOVE_MOUNT_T_MNTNS in move_mount()
>   security: Pass flags to security_move_mount()
>   mount: Support MOVE_MOUNT_CLONE with MOVE_MOUNT_T_MNTNS
>   apparmor: Mediate MOVE_MOUNT_CLONE as recursive bind
>   userns: Factor out install_user_ns_cred()
>   nsproxy: Expose create_new_namespaces()
>   nsexec: Add core infrastructure
>   nsexec: Track init lifecycle via copy_process() and pid_namespace
>   nsexec: Add nsexec_open() system call
>   nsexec: Add NSEXEC_GET_NSFD ioctl
>   nsexec: Add NSEXEC_SHARE_NSFD ioctl
>   exit: Support P_NSEXEC in waitid()
>   signal: Support nsexec fds in pidfd_send_signal()
>   fork: Support CLONE_INTO_NSEXEC in clone3()
>   fs: Support FSCONFIG_SET_NSEXEC in fsconfig()
>   proc: Implement ->set_nsexec() fs_context operation
>   ipc/mqueue: Implement ->set_nsexec() fs_context operation
>   security: Add nsexec LSM hooks
>   landlock: Enforce namespace use restrictions on nsexec
>   bpf: Register nsexec LSM hooks
>   arch: Wire up nsexec_open() system call
>   docs: Document nsexec uAPI
>   selftests/nsexec: Add nsexec test suite
>   MAINTAINERS: Add entry for NSEXEC
> 
>  Documentation/filesystems/mount_api.rst       |   35 +-
>  Documentation/userspace-api/index.rst         |    1 +
>  .../userspace-api/ioctl/ioctl-number.rst      |    1 +
>  Documentation/userspace-api/nsexec.rst        |   77 +
>  MAINTAINERS                                   |   11 +
>  arch/alpha/kernel/syscalls/syscall.tbl        |    2 +
>  arch/arm/tools/syscall.tbl                    |    2 +
>  arch/arm64/tools/syscall_32.tbl               |    2 +
>  arch/m68k/kernel/syscalls/syscall.tbl         |    2 +
>  arch/microblaze/kernel/syscalls/syscall.tbl   |    2 +
>  arch/mips/kernel/syscalls/syscall_n32.tbl     |    2 +
>  arch/mips/kernel/syscalls/syscall_n64.tbl     |    2 +
>  arch/mips/kernel/syscalls/syscall_o32.tbl     |    2 +
>  arch/parisc/kernel/syscalls/syscall.tbl       |    2 +
>  arch/powerpc/kernel/syscalls/syscall.tbl      |    2 +
>  arch/s390/kernel/syscalls/syscall.tbl         |    2 +
>  arch/sh/kernel/syscalls/syscall.tbl           |    2 +
>  arch/sparc/kernel/syscalls/syscall.tbl        |    2 +
>  arch/x86/entry/syscalls/syscall_32.tbl        |    2 +
>  arch/x86/entry/syscalls/syscall_64.tbl        |    2 +
>  arch/xtensa/kernel/syscalls/syscall.tbl       |    2 +
>  fs/devpts/inode.c                             |    8 +-
>  fs/filesystems.c                              |   15 +
>  fs/fs_context.c                               |   21 +-
>  fs/fsopen.c                                   |  131 +-
>  fs/internal.h                                 |    7 +-
>  fs/namespace.c                                |  376 ++-
>  fs/pnode.c                                    |    7 +-
>  fs/pnode.h                                    |    3 +-
>  fs/proc/root.c                                |   61 +-
>  fs/ramfs/inode.c                              |    2 +-
>  include/linux/cred.h                          |    4 +-
>  include/linux/fs.h                            |    1 +
>  include/linux/fs_context.h                    |    6 +
>  include/linux/lsm_hook_defs.h                 |   10 +-
>  include/linux/lsm_hooks.h                     |    3 +
>  include/linux/mnt_namespace.h                 |    2 +
>  include/linux/nsexec.h                        |  136 +
>  include/linux/nsfs.h                          |    1 +
>  include/linux/nsproxy.h                       |    8 +-
>  include/linux/pid_namespace.h                 |    4 +
>  include/linux/sched/task.h                    |    6 +
>  include/linux/security.h                      |   43 +-
>  include/linux/syscalls.h                      |    5 +
>  include/linux/user_namespace.h                |    9 +-
>  include/uapi/asm-generic/unistd.h             |   10 +-
>  include/uapi/linux/mount.h                    |    5 +-
>  include/uapi/linux/nsexec.h                   |   55 +
>  include/uapi/linux/nsfs.h                     |   46 +
>  include/uapi/linux/sched.h                    |    5 +
>  include/uapi/linux/wait.h                     |    1 +
>  init/Kconfig                                  |   10 +
>  ipc/mqueue.c                                  |   28 +-
>  kernel/Makefile                               |    2 +
>  kernel/bpf/bpf_lsm.c                          |   11 +
>  kernel/cred.c                                 |   20 +-
>  kernel/exit.c                                 |    4 +
>  kernel/fork.c                                 |   85 +-
>  kernel/nsexec.c                               |  760 +++++
>  kernel/nsproxy.c                              |   15 +-
>  kernel/pid_namespace.c                        |    2 +
>  kernel/signal.c                               |    4 +
>  kernel/sys_ni.c                               |    4 +
>  kernel/user_namespace.c                       |  459 ++-
>  mm/shmem.c                                    |    5 +-
>  scripts/syscall.tbl                           |    2 +
>  security/apparmor/include/mount.h             |    2 +-
>  security/apparmor/include/path.h              |    1 +
>  security/apparmor/lsm.c                       |    4 +-
>  security/apparmor/mount.c                     |   50 +-
>  security/apparmor/path.c                      |    6 +-
>  security/apparmor/policy_unpack.c             |    6 +-
>  security/landlock/fs.c                        |    3 +-
>  security/landlock/ns.c                        |   63 +-
>  security/lsm_init.c                           |    6 +
>  security/security.c                           |   79 +-
>  security/selinux/hooks.c                      |    2 +-
>  tools/include/uapi/asm-generic/unistd.h       |   10 +-
>  .../perf/arch/arm/entry/syscalls/syscall.tbl  |    2 +
>  .../arch/mips/entry/syscalls/syscall_n64.tbl  |    2 +
>  .../arch/powerpc/entry/syscalls/syscall.tbl   |    2 +
>  .../perf/arch/s390/entry/syscalls/syscall.tbl |    2 +
>  tools/perf/arch/sh/entry/syscalls/syscall.tbl |    2 +
>  .../arch/sparc/entry/syscalls/syscall.tbl     |    2 +
>  .../arch/x86/entry/syscalls/syscall_32.tbl    |    2 +
>  .../arch/x86/entry/syscalls/syscall_64.tbl    |    2 +
>  .../arch/xtensa/entry/syscalls/syscall.tbl    |    2 +
>  tools/scripts/syscall.tbl                     |    2 +
>  tools/testing/selftests/Makefile              |    1 +
>  tools/testing/selftests/nsexec/Makefile       |    7 +
>  tools/testing/selftests/nsexec/cells.py       | 1560 +++++++++
>  tools/testing/selftests/nsexec/config         |   13 +
>  tools/testing/selftests/nsexec/machine.py     |  333 ++
>  tools/testing/selftests/nsexec/oracle.py      |  386 +++
>  tools/testing/selftests/nsexec/selftest.py    | 2887 +++++++++++++++++
>  tools/testing/selftests/nsexec/settings       |    1 +
>  tools/testing/selftests/nsexec/test_smoke.sh  |   11 +
>  97 files changed, 7745 insertions(+), 265 deletions(-)
>  create mode 100644 Documentation/userspace-api/nsexec.rst
>  create mode 100644 include/linux/nsexec.h
>  create mode 100644 include/uapi/linux/nsexec.h
>  create mode 100644 kernel/nsexec.c
>  create mode 100644 tools/testing/selftests/nsexec/Makefile
>  create mode 100644 tools/testing/selftests/nsexec/cells.py
>  create mode 100644 tools/testing/selftests/nsexec/config
>  create mode 100644 tools/testing/selftests/nsexec/machine.py
>  create mode 100644 tools/testing/selftests/nsexec/oracle.py
>  create mode 100755 tools/testing/selftests/nsexec/selftest.py
>  create mode 100644 tools/testing/selftests/nsexec/settings
>  create mode 100755 tools/testing/selftests/nsexec/test_smoke.sh
> 
> 
> base-commit: fd7e96c6c90bb18c9b23f2bbfbbde4d89ac6d88a
> --
> 2.47.3
> 

I.e. this is the beef:

	int nsexec_fd = nsexec();
	if (nsexec_fd < 0) {
		perror("nsexec");
		exit(1);
	}

	/*
	 * Configure mount points and shared namespaces
	 * (NSEXEC_SHARE_NSFD), credentials (userns_set_idmap()) and
	 * what not. Nothing is going on right now except cargo
	 * is being loaded.
	 */
	bootstrap(nsexec_fd);

	struct clone_args args = {
		.flags = CLONE_INTO_NSEXEC,
		.nsexec = nsexec_fd,
	};

	int pid = clone3(&args, sizeof(args));
	if (pid == 0)
		execve("/sbin/init", argv, envp);

	waitid(P_NSEXEC, nsexec_fd, &info, WEXITED);


Br, Jarkko

      parent reply	other threads:[~2026-12-01  4:02 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  3:09 [RFC PATCH v9 00/29] nsexec: Staged namespace execution Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 01/29] userns: Factor out idmap validation and commit helpers Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 02/29] userns: Add userns_set_idmap() system call Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 03/29] arch: Wire up " Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 04/29] mount: Add mnt_ns_get_root() Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 05/29] mount: Enforce mount_too_revealing() for foreign mntns Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 06/29] mount: Support MOVE_MOUNT_T_MNTNS in move_mount() Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 07/29] security: Pass flags to security_move_mount() Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 08/29] mount: Support MOVE_MOUNT_CLONE with MOVE_MOUNT_T_MNTNS Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 09/29] apparmor: Mediate MOVE_MOUNT_CLONE as recursive bind Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 10/29] userns: Factor out install_user_ns_cred() Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 11/29] nsproxy: Expose create_new_namespaces() Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 12/29] nsexec: Add core infrastructure Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 13/29] nsexec: Track init lifecycle via copy_process() and pid_namespace Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 14/29] nsexec: Add nsexec_open() system call Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 15/29] nsexec: Add NSEXEC_GET_NSFD ioctl Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 16/29] nsexec: Add NSEXEC_SHARE_NSFD ioctl Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 17/29] exit: Support P_NSEXEC in waitid() Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 18/29] signal: Support nsexec fds in pidfd_send_signal() Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 19/29] fork: Support CLONE_INTO_NSEXEC in clone3() Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 20/29] fs: Support FSCONFIG_SET_NSEXEC in fsconfig() Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 21/29] proc: Implement ->set_nsexec() fs_context operation Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 22/29] ipc/mqueue: " Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 23/29] security: Add nsexec LSM hooks Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 24/29] landlock: Enforce namespace use restrictions on nsexec Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 25/29] bpf: Register nsexec LSM hooks Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 26/29] arch: Wire up nsexec_open() system call Jarkko Sakkinen
2026-12-01  3:09 ` [RFC PATCH v9 27/29] docs: Document nsexec uAPI Jarkko Sakkinen
2026-12-01  3:10 ` [RFC PATCH v9 28/29] selftests/nsexec: Add nsexec test suite Jarkko Sakkinen
2026-12-01  3:10 ` [RFC PATCH v9 29/29] MAINTAINERS: Add entry for NSEXEC Jarkko Sakkinen
2026-12-01  4:02 ` Jarkko Sakkinen [this message]

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=aw5G5IPF-J-soJ_F@kernel.org \
    --to=jarkko@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=aleksa@amutable.com \
    --cc=alex@amutable.com \
    --cc=andrii@kernel.org \
    --cc=arnd@arndb.de \
    --cc=ast@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=bsegall@google.com \
    --cc=containers@lists.linux.dev \
    --cc=corbet@lwn.net \
    --cc=daniel@iogearbox.net \
    --cc=dave@stgolabs.net \
    --cc=david@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=dwmw2@infradead.org \
    --cc=ebiggers@kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=fsdevel@vger.kernel.org \
    --cc=georgia.garcia@canonical.com \
    --cc=giuseppe@scrivano.org \
    --cc=gnoack@google.com \
    --cc=hughd@google.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jack@suse.cz \
    --cc=jgg@nvidia.com \
    --cc=jlayton@kernel.org \
    --cc=jmorris@namei.org \
    --cc=john.johansen@canonical.com \
    --cc=jolsa@kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=juri.lelli@redhat.com \
    --cc=kees@kernel.org \
    --cc=kprateek.nayak@amd.com \
    --cc=kpsingh@kernel.org \
    --cc=lennart@poettering.net \
    --cc=liam@infradead.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=manfred@colorfullife.com \
    --cc=martin.lau@linux.dev \
    --cc=matt@bobrowski.net \
    --cc=memxor@gmail.com \
    --cc=mgorman@suse.de \
    --cc=mhocko@suse.com \
    --cc=mic@digikod.net \
    --cc=mingo@redhat.com \
    --cc=neal@gompa.dev \
    --cc=oleg@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=peterz@infradead.org \
    --cc=ptikhomirov@virtuozzo.com \
    --cc=rdunlap@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=serge@hallyn.com \
    --cc=sergeh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=song@kernel.org \
    --cc=stephen.smalley.work@gmail.com \
    --cc=vincent.guittot@linaro.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vschneid@redhat.com \
    --cc=yonghong.song@linux.dev \
    --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