From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795910300; b=5lLS/By17Z7rApS0F91K5nLo/iG7DVmpbylxj4i4nkpKkE147QjAdYz1TwAJrCP4D3tL VxjT0ezbPyn9yq3NplRBXz+nnW2se+uivVrCwuoXI0Xqf7kjFoS06Lm0pKswQCE24h31p 7t4YzL5w+YeQnMITyTyw0XVrLGhPPZWv3ttL03qKvl5UNS14E8kc9i3iP7//bbBxJ/Flw L5IX1k6wrj8K0jiHWwu2VB/DigIjCN9wyEHYZROoc2FkjjedBtbVJPnUCzU/ZyNsf0emz B6T2rMKXxOm75CRHrqOwsaPiXxgIsOLw2KlXHByvPU8lNsaD+9mc8BbgjS0jdQFWYHA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795910300; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=73UmZlDMn7DlPLhm2vUoO+2mt5Ag2MKKXYj/P3QMvxI=; b=O/PiRs/K0f0hvlNetHetECL+BlTDoduOoshUYCn99pUk2mgoXaDj552/Y9t1lozeog6H xfkAnKnVfAJhf48xz5HnkzQ2bCnKgnx97j3141ZzUy2oFk+x27eAhB5UGdYj0Z1Y8DDaB nGeY3j9Sa6BpkzGMtiWfGk8PyElbDEUqOo5JJSd/QkjdoxSEa7pv2k9TXV1nhzK3/TkYs nCMaEyL/yV5qDzqf9Ls6a3RHLeKDBgxOT7pOhABG5YHPlyJ0+GKKNdw8UytecMYh1yUDh 1WN8Hv2LY229Z1/EAonjmUrJoKQAn+IJ44QiXjllOToP2pQ1a3IGmCm2KhwGbFwa1hw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hJM26tdF; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id 2EEC8606A31C; Sat, 28 Nov 2026 23:58:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hJM26tdF Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 07D741F00893; Sat, 28 Nov 2026 23:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795910299; bh=73UmZlDMn7DlPLhm2vUoO+2mt5Ag2MKKXYj/P3QMvxI=; h=From:To:Cc:Subject:Date; b=hJM26tdFhYwsV4TKfBQHdWPM4mRsGER5o8yGjcjNmCTJJ3T6w0yItz6Vi8T3Xb8CR vVKDjJw1hK16zrHzGCy+FhjBYI1McrrXgwIJkjJ0sA4TRlCmOHG6Kovf9tw4U/b1mm gNSVT52fijWziBnPA9M04f8RMaX/QFwFxeXtqghyyt54Fo0SgfaQXI6dMqhM4tqeqv b4T6lZK3J37qTq5BKZe9ZQcKZox9zvjXGErNRS+NrCdmdtjRenVYpQYDH2rTQWjUeR SEdAqPZ/xNws6MrUZlBhVMSO3/zPtQ0hSUScw65k0OHBEqgo7vamCjqVFbY8hXfPeT 8oS/cCmlArsog== From: Jarkko Sakkinen To: fsdevel@vger.kernel.org Cc: Jarkko Sakkinen , 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-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, Aleksa Sarai , Alexander Mikhalitsyn , Alexander Viro , Andy Lutomirski , Arnd Bergmann , Christian Brauner , David Howells , Eric Biggers , Georgia Garcia , Giuseppe Scrivano , Hugh Dickins , James Morris , Jan Kara , Jeff Layton , John Johansen , Jonathan Corbet , Josef Bacik , Kees Cook , KP Singh , Lennart Poettering , Matt Bobrowski , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Neal Gompa , Oleg Nesterov , Paul Moore , Pavel Tikhomirov , Serge Hallyn , Shuah Khan , Stephen Smalley , Zygmunt Krynicki Subject: [RFC PATCH v8 00/29] userland: Userland containers Date: Sun, 29 Nov 2026 01:57:39 +0200 Message-ID: <20261128235808.2369970-1-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OVERVIEW ======== This is it. This final RFC v8 closes down the circle and wires everything together. It demonstrates, an alternative, a sequencing based path forward. A userland is an anonymous-inode control object with separate build and live phases that binds together: 1. A full set of detached namespaces owned by a fresh user namespace, with optional build-phase opt-in sharing (USERLAND_SHARE_NSFD). 2. A dedicated PID namespace for spawning processes into, signaling members, and polling or waiting on PID 1 exit. 3. An initially empty mount namespace (CLONE_EMPTY_MNTNS) populated directly in its target user namespace before going live, without inheriting host mounts or cloning staged trees, while still allowing new mounts to be attached at runtime. Container runtimes today fork helper processes to write /proc//{setgroups,uid_map,gid_map}, stage mounts via unshare(), setns(), and pivot_root(), and coordinate half-configured state across live tasks. Building on David Howells' earlier container object work [1], the lifecycle follows a two-phase staircase model (similar to Intel SGX enclave build vs. live state) with no embryonic task state and no parallel namespace syscall API: ID mappings, shared-namespace allow-lists, and mounts are configured on file descriptors before any process exists, mediated by LSM hooks, with runtime mount hotplug preserved. [1] https://lwn.net/Articles/780364/ SYSCALLS ======== New system calls: 1. userland_open(): open an anonymous-inode container control fd in its build phase (USERLAND_INIT), owning a fresh user namespace and detached mount, PID, UTS, IPC, network, cgroup, and time namespaces. 2. userns_set_idmap(): atomically configure USERNS_SETGROUPS_ALLOWED and UID, GID, and project ID map extents on a CLONE_NEWUSER nsfs fd. Extensions to existing system calls: 1. move_mount() (MOVE_MOUNT_T_MNTNS, MOVE_MOUNT_CLONE): install "/" and relative submounts into a mount namespace fd before entry or at runtime, and recursively bind-clone subtrees without OPEN_TREE_CLONE. 2. clone3() (CLONE_INTO_USERLAND, struct clone_args.userland): spawn PID 1 and subsequent processes directly into a userland without mutating the caller's own live state. 3. fsopen() / fsconfig() / fsmount() (FSCONFIG_SET_USERLAND): bind a filesystem context to a userland's namespaces and create mounts directly in its user namespace. 4. waitid() (P_USERLAND): wait on a userland fd for PID 1 exit and read its exit status without consuming it. 5. pidfd_send_signal(): broadcast signals to member thread groups via a userland fd. 6. ioctl() (USERLAND_GET_NSFD, USERLAND_SHARE_NSFD): open member nsfs fds and opt cgroup, IPC, UTS, network, or time namespaces into existing nsfs fds during USERLAND_INIT. IMPLEMENTATION ============== Standalone fd-based setup (patches 01-09) decouples user and mount namespace configuration from live helper tasks. userns_set_idmap() validates parent ID ranges against current_cred() so an unprivileged creator can delegate a userns fd via SCM_RIGHTS to a privileged mapping daemon. move_mount(..., MOVE_MOUNT_T_MNTNS) installs "/" onto the nullfs root once and attaches submounts before entry or at runtime, while MOVE_MOUNT_CLONE mediates recursive bind clones as MS_BIND | MS_REC in LSMs. Superblocks are configured in the target user namespace via FSCONFIG_SET_USERLAND for filesystems opting into FS_USERLAND_MOUNT (tmpfs, ramfs, devpts, proc, mqueue) or FS_USERNS_DELEGATABLE. Once "/" is installed, clone3(CLONE_INTO_USERLAND) transitions the userland through USERLAND_FORKING to USERLAND_RUNNING for PID 1 and admits subsequent processes until teardown begins. CLONE_VM, CLONE_FILES, CLONE_FS, and CLONE_SIGHAND are rejected, and whenever the caller's exec_state originates outside the target user namespace, exec_state->user_ns stays in that outer user namespace with dumpability reset to suid_dumpable so member processes cannot ptrace the child or access /proc//{exe,mem,fd} before execve() (e.g. via openat2(RESOLVE_IN_ROOT) and execveat()). Once PID 1 exits and zap_pid_ns_processes() reaps all members, poll() reports EPOLLHUP and waitid(P_USERLAND) returns init's exit status. Dedicated LSM hooks (wired into Landlock and BPF LSM) mediate userland allocation, teardown, namespace sharing, process entry, and signaling. HOTPLUG ======= 1. Open a userland, set ID maps, populate "/", and spawn PID 1 with clone3(CLONE_INTO_USERLAND). 2. PID 1 watches /proc/self/ns/mnt via fanotify(FAN_REPORT_MNT | FAN_MARK_MNTNS, FAN_MNT_ATTACH). 3. Host prepares a mount via fsopen() / fsconfig(FSCONFIG_SET_USERLAND) / fsmount() (or a bind source) and creates the mountpoint with openat2(RESOLVE_IN_ROOT) + mkdirat(). 4. Host attaches the mount via move_mount(..., MOVE_MOUNT_T_MNTNS); PID 1 receives FAN_MNT_ATTACH and queries it with statmount(). WIRING ====== Experimental userspace integrations probe userns_set_idmap() and userland_open() at runtime and fall back to /proc//{setgroups,uid_map,gid_map} and classic namespace cloning on older kernels: 1. SystemD: atomic ID mapping via userns_set_idmap(), systemd-nspawn bootstrap via userland_open(), USERLAND_SHARE_NSFD, MOVE_MOUNT_T_MNTNS, and clone3(CLONE_INTO_USERLAND), plus live systemd-machined bind mounts and udev device hotplug. https://github.com/jarkkojs/systemd/commits/userland 2. Bubblewrap: opportunistic userns_set_idmap() and direct sandbox mount population via userland_open(), FSCONFIG_SET_USERLAND, MOVE_MOUNT_T_MNTNS, and clone3(CLONE_INTO_USERLAND) without pivot_root(). https://github.com/jarkkojs/bubblewrap/commits/userland 3. Podman: opportunistic userns_set_idmap() and a built-in "userland" runtime (--runtime=userland, also used opportunistically for default pod infra containers) backed by userland_open(), MOVE_MOUNT_T_MNTNS, CLONE_INTO_USERLAND, waitid(P_USERLAND), and pidfd_send_signal(). https://github.com/jarkkojs/podman/commits/userland CHANGES ======= 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 ======== 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-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 Cc: Alexander Mikhalitsyn Cc: Alexander Viro Cc: Andy Lutomirski Cc: Arnd Bergmann Cc: Christian Brauner Cc: David Howells Cc: Eric Biggers Cc: Georgia Garcia Cc: Giuseppe Scrivano Cc: Hugh Dickins Cc: James Morris Cc: Jan Kara Cc: Jeff Layton Cc: John Johansen Cc: Jonathan Corbet Cc: Josef Bacik Cc: Kees Cook Cc: KP Singh Cc: Lennart Poettering Cc: Matt Bobrowski Cc: Mickaël Salaün Cc: Neal Gompa Cc: Oleg Nesterov Cc: Paul Moore Cc: Pavel Tikhomirov Cc: Serge Hallyn Cc: Shuah Khan Cc: Stephen Smalley Cc: Zygmunt Krynicki 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() userland: Add core infrastructure userland: Track init lifecycle via copy_process() and pid_namespace userland: Add userland_open() system call userland: Add USERLAND_GET_NSFD ioctl userland: Add USERLAND_SHARE_NSFD ioctl exit: Support P_USERLAND in waitid() signal: Support userland fds in pidfd_send_signal() fork: Support CLONE_INTO_USERLAND in clone3() fs: Support FSCONFIG_SET_USERLAND in fsconfig() proc: Implement ->set_userland() fs_context operation ipc/mqueue: Implement ->set_userland() fs_context operation security: Add userland LSM hooks landlock: Enforce namespace use restrictions on userland bpf: Register userland LSM hooks arch: Wire up userland_open() system call docs: Document userland uAPI selftests/userland: Add userland test suite MAINTAINERS: Add entry for USERLAND Documentation/filesystems/mount_api.rst | 32 +- Documentation/userspace-api/index.rst | 1 + .../userspace-api/ioctl/ioctl-number.rst | 1 + Documentation/userspace-api/userland.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 | 125 +- fs/internal.h | 7 +- fs/namespace.c | 374 ++- fs/pnode.c | 7 +- fs/pnode.h | 3 +- fs/proc/root.c | 26 +- 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/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/linux/userland.h | 136 + include/uapi/asm-generic/unistd.h | 10 +- include/uapi/linux/mount.h | 5 +- include/uapi/linux/nsfs.h | 46 + include/uapi/linux/sched.h | 5 + include/uapi/linux/userland.h | 57 + include/uapi/linux/wait.h | 1 + init/Kconfig | 10 + ipc/mqueue.c | 18 +- kernel/Makefile | 2 + kernel/bpf/bpf_lsm.c | 11 + kernel/cred.c | 20 +- kernel/exit.c | 4 + kernel/fork.c | 85 +- kernel/nsproxy.c | 15 +- kernel/pid_namespace.c | 2 + kernel/signal.c | 4 + kernel/sys_ni.c | 4 + kernel/user_namespace.c | 459 ++- kernel/userland.c | 760 +++++ mm/shmem.c | 5 +- scripts/syscall.tbl | 2 + security/apparmor/include/mount.h | 2 +- security/apparmor/lsm.c | 4 +- security/apparmor/mount.c | 12 +- 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/userland/Makefile | 6 + tools/testing/selftests/userland/config | 10 + .../testing/selftests/userland/test_smoke.sh | 11 + .../selftests/userland/userland_cells.py | 1103 +++++++ .../selftests/userland/userland_test.py | 2633 +++++++++++++++++ 91 files changed, 6240 insertions(+), 230 deletions(-) create mode 100644 Documentation/userspace-api/userland.rst create mode 100644 include/linux/userland.h create mode 100644 include/uapi/linux/userland.h create mode 100644 kernel/userland.c create mode 100644 tools/testing/selftests/userland/Makefile create mode 100644 tools/testing/selftests/userland/config create mode 100755 tools/testing/selftests/userland/test_smoke.sh create mode 100644 tools/testing/selftests/userland/userland_cells.py create mode 100755 tools/testing/selftests/userland/userland_test.py base-commit: 822ba3a89c7896b26e4beb70e2ebffb881924dfe prerequisite-patch-id: 6b9f0c26cb5c2290d5a2a78c18ccf225b09a6bbb prerequisite-patch-id: 0f71199bbbbaf9fe1fa82afb1926b452c493532e prerequisite-patch-id: 97be79eb77addef7282d5cb9966c4208cf0e965e prerequisite-patch-id: 4517a290b914c1a79717aece49041479eca4b399 prerequisite-patch-id: 0b49963321abe30437c8e82ffd64fa235c9746bd -- 2.47.3