[RFC PATCH v8 00/29] userland: Userland containers

Jarkko Sakkinen jarkko at kernel.org
Sat Nov 28 23:57:39 UTC 2026


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/<pid>/{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/<pid>/{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/<pid>/{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 at vger.kernel.org
Cc: containers at lists.linux.dev
Cc: linux-api at vger.kernel.org
Cc: linux-arch at vger.kernel.org
Cc: linux-doc at vger.kernel.org
Cc: linux-fsdevel at vger.kernel.org
Cc: linux-kernel at vger.kernel.org
Cc: linux-kselftest at vger.kernel.org
Cc: linux-mm at kvack.org
Cc: linux-security-module at vger.kernel.org
Cc: Aleksa Sarai <aleksa at amutable.com>
Cc: Alexander Mikhalitsyn <alex at amutable.com>
Cc: Alexander Viro <viro at zeniv.linux.org.uk>
Cc: Andy Lutomirski <luto at amacapital.net>
Cc: Arnd Bergmann <arnd at arndb.de>
Cc: Christian Brauner <brauner at kernel.org>
Cc: David Howells <dhowells at redhat.com>
Cc: Eric Biggers <ebiggers at kernel.org>
Cc: Georgia Garcia <georgia.garcia at canonical.com>
Cc: Giuseppe Scrivano <giuseppe at scrivano.org>
Cc: Hugh Dickins <hughd at google.com>
Cc: James Morris <jmorris at namei.org>
Cc: Jan Kara <jack at suse.cz>
Cc: Jeff Layton <jlayton at kernel.org>
Cc: John Johansen <john.johansen at canonical.com>
Cc: Jonathan Corbet <corbet at lwn.net>
Cc: Josef Bacik <josef at toxicpanda.com>
Cc: Kees Cook <kees at kernel.org>
Cc: KP Singh <kpsingh at kernel.org>
Cc: Lennart Poettering <lennart at poettering.net>
Cc: Matt Bobrowski <matt at bobrowski.net>
Cc: Mickaël Salaün <mic at digikod.net>
Cc: Neal Gompa <neal at gompa.dev>
Cc: Oleg Nesterov <oleg at redhat.com>
Cc: Paul Moore <paul at paul-moore.com>
Cc: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Cc: Serge Hallyn <sergeh at kernel.org>
Cc: Shuah Khan <skhan at linuxfoundation.org>
Cc: Stephen Smalley <stephen.smalley.work at gmail.com>
Cc: Zygmunt Krynicki <zygmunt.krynicki at 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()
  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




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