Linux Documentation
 help / color / mirror / Atom feed
* [RFC PATCH v10 00/28] runfd: Staged namespace execution
@ 2026-12-05  3:26 Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 01/28] userns: Factor out idmap validation and commit helpers Jarkko Sakkinen
                   ` (27 more replies)
  0 siblings, 28 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

OVERVIEW
========

The previous approaches, including David's original patches and Cells, have
an off-by-one architectural flaw. They model the "ship", while actually the
target should be the "dock". The launch and its concurrency properties is
the focal point.

For me this target was obvious from SGX, and overall on how to manage more
abstract payloads where it makes sense to focus on launch rather than the
object being launched. The latter is a dragon's tail and destined to
ultimate failure.

It's also noteworthy that runfd is not a subsystem of any existing
subsystem. It has only caller- or callback-relations. I.e., it is fully
decoupled from decision making and architecture of namespaces, and does not
introduce any constraining bottlenecks.

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.

This also complicates authenticated measurement: a measurement of one
setup step does not describe the final environment.

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 runfd: an anonymous-inode control descriptor that
splits namespace setup and process execution into distinct build and live
phases. The kernel provides the launch mechanism for one container run,
not a container model. OCI runtimes still decide what to run and how to
configure it.

Calling runfd() allocates a fresh user namespace together with a detached
set of mount, PID, UTS, IPC, network, cgroup, and (where enabled) 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
(RUNFD_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, runfd plugs into existing descriptor-based syscalls for ID mapping,
filesystem configuration, mount placement, process creation, waiting, and
signaling.

SOLUTION
========

The standalone primitives at the front of the series (patches 01-08) 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 run lifecycle.

1. Allocating namespaces and programming ID maps
------------------------------------------------

A manager begins by calling runfd(), which returns a close-on-exec
control descriptor in RUNFD_INIT. While in this build phase, the manager
can substitute existing cgroup, IPC, UTS, network, or time namespaces
with RUNFD_SHARE_NSFD, or obtain nsfs descriptors for member namespaces
with RUNFD_GET_NSFD.

Instead of formatting text into /proc/<pid>/uid_map and gid_map while a
helper blocks on a pipe, the NS_SET_IDMAP ioctl installs UID, GID, and
project ID extents atomically on the user namespace descriptor. The caller
can request USERNS_SETGROUPS_ALLOWED when installing a GID map:

    run_fd = runfd(RUNFD_AUTOKILL);
    userns_fd = ioctl(run_fd, RUNFD_GET_NSFD, CLONE_NEWUSER);
    mntns_fd  = ioctl(run_fd, RUNFD_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,
    };

    ioctl(userns_fd, NS_SET_IDMAP, &map);

Parent ID ranges are authorized against the ioctl caller,
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 run's user, network, PID (proc), and IPC (mqueue) namespaces by
binding a mount-API context via FSCONFIG_SET_RUN. Filesystems opt into
unprivileged delegation with FS_RUN_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
CAP_SYS_ADMIN in the caller's mount namespace. CAP_SYS_ADMIN is checked
in the target mount namespace's owning user namespace:

    fs_fd = fsopen("tmpfs", FSOPEN_CLOEXEC);
    fsconfig(fs_fd, FSCONFIG_SET_RUN, NULL, NULL, run_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
AppArmor mediates 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_RUN spawns the
first child directly into the configured environment as PID 1,
transitioning the descriptor from RUNFD_INIT through RUNFD_FORKING to
RUNFD_RUNNING:

    struct clone_args args = {
            .flags = CLONE_INTO_RUN,
            .runfd = run_fd,
    };

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

    waitid(P_RUNFD, run_fd, &info, WEXITED);

Subsequent CLONE_INTO_RUN 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_RUNFD) reads init's exit status without consuming
it. Run LSM hooks cover allocation, namespace sharing, process entry,
and signaling. Landlock checks namespace sharing and entry, and the hooks
are also available to BPF LSM.

RESOURCES
=========

[1] https://lwn.net/Articles/780364/
[2] https://github.com/jarkkojs/systemd/tree/main
[3] https://github.com/jarkkojs/bubblewrap/tree/main
[4] https://github.com/jarkkojs/podman/tree/main
[5] https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/ucells.git/
[6] https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd-test.git/

CHANGES
=======

v10:
- Reduced to *SINGLE* new syscall.
- Rename nsexec_open() to runfd() and update the related interface names.
- Replace userns_set_idmap() with the NS_SET_IDMAP ioctl on the user
  namespace descriptor.
- Drop the in-tree nsexec selftests and package the standalone ucells
  runner in the Buildroot runfd image.
- Include the runfd kernel-doc in the userspace API manual and register
  the ioctl range in a separate patch.

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

v9: https://lore.kernel.org/linux-fsdevel/20261201031002.593830-1-jarkko@kernel.org/
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 (28):
  userns: Factor out idmap validation and commit helpers
  userns: Add NS_SET_IDMAP ioctl
  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()
  runfd: Add core infrastructure
  runfd: Track init lifecycle via copy_process() and pid_namespace
  runfd: Add runfd() system call
  runfd: Add RUNFD_GET_NSFD ioctl
  runfd: Add RUNFD_SHARE_NSFD ioctl
  exit: Support P_RUNFD in waitid()
  signal: Support run fds in pidfd_send_signal()
  fork: Support CLONE_INTO_RUN in clone3()
  fs: Support FSCONFIG_SET_RUN in fsconfig()
  proc: Implement ->set_run() fs_context operation
  ipc/mqueue: Implement ->set_run() fs_context operation
  security: Add run LSM hooks
  landlock: Enforce namespace use restrictions on run
  bpf: Register run LSM hooks
  arch: Wire up runfd() system call
  ioctl: Register the runfd ioctl range
  docs: Include runfd kernel-doc in the userspace API manual
  MAINTAINERS: Add entry for RUNFD

 Documentation/filesystems/mount_api.rst       |  35 +-
 Documentation/userspace-api/index.rst         |   1 +
 .../userspace-api/ioctl/ioctl-number.rst      |   1 +
 Documentation/userspace-api/runfd.rst         |  77 ++
 MAINTAINERS                                   |  10 +
 arch/alpha/kernel/syscalls/syscall.tbl        |   1 +
 arch/arm/tools/syscall.tbl                    |   1 +
 arch/arm64/tools/syscall_32.tbl               |   1 +
 arch/m68k/kernel/syscalls/syscall.tbl         |   1 +
 arch/microblaze/kernel/syscalls/syscall.tbl   |   1 +
 arch/mips/kernel/syscalls/syscall_n32.tbl     |   1 +
 arch/mips/kernel/syscalls/syscall_n64.tbl     |   1 +
 arch/mips/kernel/syscalls/syscall_o32.tbl     |   1 +
 arch/parisc/kernel/syscalls/syscall.tbl       |   1 +
 arch/powerpc/kernel/syscalls/syscall.tbl      |   1 +
 arch/s390/kernel/syscalls/syscall.tbl         |   1 +
 arch/sh/kernel/syscalls/syscall.tbl           |   1 +
 arch/sparc/kernel/syscalls/syscall.tbl        |   1 +
 arch/x86/entry/syscalls/syscall_32.tbl        |   1 +
 arch/x86/entry/syscalls/syscall_64.tbl        |   1 +
 arch/xtensa/kernel/syscalls/syscall.tbl       |   1 +
 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                                | 373 +++++++--
 fs/nsfs.c                                     |   9 +
 fs/pnode.c                                    |  39 +-
 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/nsfs.h                          |   1 +
 include/linux/nsproxy.h                       |   8 +-
 include/linux/pid_namespace.h                 |   4 +
 include/linux/runfd.h                         | 136 ++++
 include/linux/sched/task.h                    |   6 +
 include/linux/security.h                      |  43 +-
 include/linux/syscalls.h                      |   1 +
 include/linux/user_namespace.h                |  20 +-
 include/uapi/asm-generic/unistd.h             |   6 +-
 include/uapi/linux/mount.h                    |   5 +-
 include/uapi/linux/nsfs.h                     |  49 ++
 include/uapi/linux/runfd.h                    |  55 ++
 include/uapi/linux/sched.h                    |   5 +
 include/uapi/linux/wait.h                     |   1 +
 init/Kconfig                                  |  10 +
 ipc/mqueue.c                                  |  31 +-
 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/runfd.c                                | 761 ++++++++++++++++++
 kernel/signal.c                               |   4 +
 kernel/sys_ni.c                               |   3 +
 kernel/user_namespace.c                       | 434 +++++++---
 mm/shmem.c                                    |   5 +-
 scripts/syscall.tbl                           |   1 +
 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       |   6 +-
 .../perf/arch/arm/entry/syscalls/syscall.tbl  |   1 +
 .../arch/mips/entry/syscalls/syscall_n64.tbl  |   1 +
 .../arch/powerpc/entry/syscalls/syscall.tbl   |   1 +
 .../perf/arch/s390/entry/syscalls/syscall.tbl |   1 +
 tools/perf/arch/sh/entry/syscalls/syscall.tbl |   1 +
 .../arch/sparc/entry/syscalls/syscall.tbl     |   1 +
 .../arch/x86/entry/syscalls/syscall_32.tbl    |   1 +
 .../arch/x86/entry/syscalls/syscall_64.tbl    |   1 +
 .../arch/xtensa/entry/syscalls/syscall.tbl    |   1 +
 tools/scripts/syscall.tbl                     |   1 +
 89 files changed, 2536 insertions(+), 265 deletions(-)
 create mode 100644 Documentation/userspace-api/runfd.rst
 create mode 100644 include/linux/runfd.h
 create mode 100644 include/uapi/linux/runfd.h
 create mode 100644 kernel/runfd.c


base-commit: 2076c0591c1f232f3c1e6ce047f189bcf59610b4
--
2.47.3


^ permalink raw reply	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 01/28] userns: Factor out idmap validation and commit helpers
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  4:01   ` bot+bpf-ci
  2026-12-05  3:26 ` [RFC PATCH v10 02/28] userns: Add NS_SET_IDMAP ioctl Jarkko Sakkinen
                   ` (26 subsequent siblings)
  27 siblings, 1 reply; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

map_write() and its permission helpers validate extent ranges, check
root and unprivileged self-mappings, translate parent ID ranges, sort
extents, and install the resulting map inline for procfs text writes,
preventing non-procfs callers from reusing the same validation and
commit path.

Extract idmap_maps_root(), unpriv_idmap_permitted(),
validate_and_insert_extent(), free_new_idmap(), resolve_new_idmap(), and
commit_new_idmap() with no functional change.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 kernel/user_namespace.c | 229 +++++++++++++++++++++-------------------
 1 file changed, 122 insertions(+), 107 deletions(-)

diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index cd748e1cbace..caba2ac33077 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -884,6 +884,22 @@ VISIBLE_IF_KUNIT int uid_gid_map_sort(struct uid_gid_map *map)
 }
 EXPORT_SYMBOL_IF_KUNIT(uid_gid_map_sort);
 
+static bool idmap_maps_root(const struct uid_gid_map *new_map)
+{
+	unsigned int idx;
+
+	for (idx = 0; idx < new_map->nr_extents; idx++) {
+		const struct uid_gid_extent *e;
+
+		if (new_map->nr_extents <= UID_GID_MAP_MAX_BASE_EXTENTS)
+			e = &new_map->extent[idx];
+		else
+			e = &new_map->forward[idx];
+		if (e->lower_first == 0)
+			return true;
+	}
+	return false;
+}
 /**
  * verify_root_map() - check the uid 0 mapping
  * @file: idmapping file
@@ -900,22 +916,9 @@ static bool verify_root_map(const struct file *file,
 			    struct user_namespace *map_ns,
 			    struct uid_gid_map *new_map)
 {
-	int idx;
 	const struct user_namespace *file_ns = file->f_cred->user_ns;
-	struct uid_gid_extent *extent0 = NULL;
-
-	for (idx = 0; idx < new_map->nr_extents; idx++) {
-		if (new_map->nr_extents <= UID_GID_MAP_MAX_BASE_EXTENTS)
-			extent0 = &new_map->extent[idx];
-		else
-			extent0 = &new_map->forward[idx];
-		if (extent0->lower_first == 0)
-			break;
-
-		extent0 = NULL;
-	}
 
-	if (!extent0)
+	if (!idmap_maps_root(new_map))
 		return true;
 
 	if (map_ns == file_ns) {
@@ -938,6 +941,103 @@ static bool verify_root_map(const struct file *file,
 	return true;
 }
 
+static int validate_and_insert_extent(struct uid_gid_map *new_map,
+				      struct uid_gid_extent *extent)
+{
+	if ((extent->first == (u32)-1) || (extent->lower_first == (u32)-1))
+		return -EINVAL;
+
+	if ((extent->first + extent->count) <= extent->first)
+		return -EINVAL;
+	if ((extent->lower_first + extent->count) <= extent->lower_first)
+		return -EINVAL;
+
+	if (mappings_overlap(new_map, extent))
+		return -EINVAL;
+
+	if (new_map->nr_extents >= UID_GID_MAP_MAX_EXTENTS)
+		return -EINVAL;
+
+	return uid_gid_map_insert_extent(new_map, extent);
+}
+
+static void free_new_idmap(struct uid_gid_map *new_map)
+{
+	if (new_map->nr_extents > UID_GID_MAP_MAX_BASE_EXTENTS) {
+		kfree(new_map->forward);
+		kfree(new_map->reverse);
+	}
+	memset(new_map, 0, sizeof(*new_map));
+}
+
+static int resolve_new_idmap(struct uid_gid_map *new_map,
+			     struct uid_gid_map *parent_map)
+{
+	unsigned int idx;
+
+	if (new_map->nr_extents == 0)
+		return -EINVAL;
+
+	for (idx = 0; idx < new_map->nr_extents; idx++) {
+		struct uid_gid_extent *e;
+		u32 lower_first;
+
+		if (new_map->nr_extents <= UID_GID_MAP_MAX_BASE_EXTENTS)
+			e = &new_map->extent[idx];
+		else
+			e = &new_map->forward[idx];
+
+		lower_first = map_id_range_down(parent_map,
+						e->lower_first,
+						e->count);
+		if (lower_first == (u32)-1)
+			return -EPERM;
+
+		e->lower_first = lower_first;
+	}
+
+	return uid_gid_map_sort(new_map);
+}
+
+static void commit_new_idmap(struct uid_gid_map *map,
+			     struct uid_gid_map *new_map)
+{
+	if (new_map->nr_extents <= UID_GID_MAP_MAX_BASE_EXTENTS) {
+		memcpy(map->extent, new_map->extent,
+		       new_map->nr_extents * sizeof(new_map->extent[0]));
+	} else {
+		map->forward = new_map->forward;
+		map->reverse = new_map->reverse;
+	}
+	/*
+	 * Pairs with smp_rmb() in map_id_range_down(), map_id_range_up(),
+	 * and m_start().
+	 */
+	smp_wmb();
+	map->nr_extents = new_map->nr_extents;
+	memset(new_map, 0, sizeof(*new_map));
+}
+
+static bool unpriv_idmap_permitted(const struct user_namespace *ns,
+				   const struct cred *cred, int cap_setid,
+				   unsigned long ns_flags,
+				   const struct uid_gid_map *new_map)
+{
+	u32 id;
+
+	if (new_map->nr_extents != 1 || new_map->extent[0].count != 1 ||
+	    !uid_eq(ns->owner, cred->euid))
+		return false;
+
+	id = new_map->extent[0].lower_first;
+	if (cap_setid == CAP_SETUID)
+		return uid_eq(make_kuid(ns->parent, id), cred->euid);
+	if (cap_setid == CAP_SETGID)
+		return !(ns_flags & USERNS_SETGROUPS_ALLOWED) &&
+		       gid_eq(make_kgid(ns->parent, id), cred->egid);
+	return false;
+}
+
 /*
  * Parse the decimal u32 at *pos, up to the next whitespace or NUL, and
  * leave *pos pointing at that character.
@@ -966,8 +1066,7 @@ static ssize_t map_write(struct file *file, const char __user *buf,
 {
 	struct seq_file *seq = file->private_data;
 	struct user_namespace *map_ns = seq->private;
-	struct uid_gid_map new_map;
-	unsigned idx;
+	struct uid_gid_map new_map = {};
 	struct uid_gid_extent extent;
 	char *kbuf, *pos, *next_line;
 	ssize_t ret;
@@ -1002,8 +1101,6 @@ static ssize_t map_write(struct file *file, const char __user *buf,
 	 */
 	mutex_lock(&userns_state_mutex);
 
-	memset(&new_map, 0, sizeof(struct uid_gid_map));
-
 	ret = -EPERM;
 	/* Only allow one successful write to the map */
 	if (map->nr_extents != 0)
@@ -1052,98 +1149,28 @@ static ssize_t map_write(struct file *file, const char __user *buf,
 		if (*pos != '\0')
 			goto out;
 
-		/* Verify we have been given valid starting values */
-		if ((extent.first == (u32) -1) ||
-		    (extent.lower_first == (u32) -1))
-			goto out;
-
-		/* Verify count is not zero and does not cause the
-		 * extent to wrap
-		 */
-		if ((extent.first + extent.count) <= extent.first)
-			goto out;
-		if ((extent.lower_first + extent.count) <=
-		     extent.lower_first)
-			goto out;
-
-		/* Do the ranges in extent overlap any previous extents? */
-		if (mappings_overlap(&new_map, &extent))
-			goto out;
-
-		if ((new_map.nr_extents + 1) == UID_GID_MAP_MAX_EXTENTS &&
-		    (next_line != NULL))
-			goto out;
-
-		ret = uid_gid_map_insert_extent(&new_map, &extent);
+		ret = validate_and_insert_extent(&new_map, &extent);
 		if (ret < 0)
 			goto out;
 		ret = -EINVAL;
 	}
-	/* Be very certain the new map actually exists */
+
 	if (new_map.nr_extents == 0)
 		goto out;
 
 	ret = -EPERM;
-	/* Validate the user is allowed to use user id's mapped to. */
 	if (!new_idmap_permitted(file, map_ns, cap_setid, &new_map))
 		goto out;
 
-	ret = -EPERM;
-	/* Map the lower ids from the parent user namespace to the
-	 * kernel global id space.
-	 */
-	for (idx = 0; idx < new_map.nr_extents; idx++) {
-		struct uid_gid_extent *e;
-		u32 lower_first;
-
-		if (new_map.nr_extents <= UID_GID_MAP_MAX_BASE_EXTENTS)
-			e = &new_map.extent[idx];
-		else
-			e = &new_map.forward[idx];
-
-		lower_first = map_id_range_down(parent_map,
-						e->lower_first,
-						e->count);
-
-		/* Fail if we can not map the specified extent to
-		 * the kernel global id space.
-		 */
-		if (lower_first == (u32) -1)
-			goto out;
-
-		e->lower_first = lower_first;
-	}
-
-	/*
-	 * If we want to use binary search for lookup, this clones the extent
-	 * array and sorts both copies.
-	 */
-	ret = uid_gid_map_sort(&new_map);
+	ret = resolve_new_idmap(&new_map, parent_map);
 	if (ret < 0)
 		goto out;
 
-	/* Install the map */
-	if (new_map.nr_extents <= UID_GID_MAP_MAX_BASE_EXTENTS) {
-		memcpy(map->extent, new_map.extent,
-		       new_map.nr_extents * sizeof(new_map.extent[0]));
-	} else {
-		map->forward = new_map.forward;
-		map->reverse = new_map.reverse;
-	}
-	smp_wmb();
-	map->nr_extents = new_map.nr_extents;
-
+	commit_new_idmap(map, &new_map);
 	*ppos = count;
 	ret = count;
 out:
-	if (ret < 0 && new_map.nr_extents > UID_GID_MAP_MAX_BASE_EXTENTS) {
-		kfree(new_map.forward);
-		kfree(new_map.reverse);
-		map->forward = NULL;
-		map->reverse = NULL;
-		map->nr_extents = 0;
-	}
-
+	free_new_idmap(&new_map);
 	mutex_unlock(&userns_state_mutex);
 	kfree(kbuf);
 	return ret;
@@ -1213,20 +1240,8 @@ static bool new_idmap_permitted(const struct file *file,
 	/* Don't allow mappings that would allow anything that wouldn't
 	 * be allowed without the establishment of unprivileged mappings.
 	 */
-	if ((new_map->nr_extents == 1) && (new_map->extent[0].count == 1) &&
-	    uid_eq(ns->owner, cred->euid)) {
-		u32 id = new_map->extent[0].lower_first;
-		if (cap_setid == CAP_SETUID) {
-			kuid_t uid = make_kuid(ns->parent, id);
-			if (uid_eq(uid, cred->euid))
-				return true;
-		} else if (cap_setid == CAP_SETGID) {
-			kgid_t gid = make_kgid(ns->parent, id);
-			if (!(ns->flags & USERNS_SETGROUPS_ALLOWED) &&
-			    gid_eq(gid, cred->egid))
-				return true;
-		}
-	}
+	if (unpriv_idmap_permitted(ns, cred, cap_setid, ns->flags, new_map))
+		return true;
 
 	/* Allow anyone to set a mapping that doesn't require privilege */
 	if (!cap_valid(cap_setid))
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 02/28] userns: Add NS_SET_IDMAP ioctl
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 01/28] userns: Factor out idmap validation and commit helpers Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  4:02   ` bot+bpf-ci
  2026-12-05 13:47   ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 03/28] mount: Add mnt_ns_get_root() Jarkko Sakkinen
                   ` (25 subsequent siblings)
  27 siblings, 2 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

ID mappings are set up by writing text to /proc/<pid>/uid_map and its
siblings. This requires a live task inside the namespace, and the
capabilities are checked against whoever opened the proc file. As a
result, an unprivileged process cannot pass its user namespace to a
privileged mapping helper.

Add NS_SET_IDMAP, which installs the UID, GID and project ID mappings of
a user namespace fd in one atomic operation. When a GID mapping is
installed, setgroups(2) is denied unless USERNS_SETGROUPS_ALLOWED is set.

The caller or the opener of the fd must have CAP_SYS_ADMIN over the
target namespace. Parent ID ranges are always checked against the
caller.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 fs/nsfs.c                      |   9 ++
 include/linux/user_namespace.h |  13 ++-
 include/uapi/linux/nsfs.h      |  49 ++++++++
 kernel/user_namespace.c        | 201 +++++++++++++++++++++++++++++++++
 4 files changed, 270 insertions(+), 2 deletions(-)

diff --git a/fs/nsfs.c b/fs/nsfs.c
index 8179d69da038..c3c511133d80 100644
--- a/fs/nsfs.c
+++ b/fs/nsfs.c
@@ -194,6 +194,8 @@ static bool nsfs_ioctl_valid(unsigned int cmd)
 		return extensible_ioctl_valid(cmd, NS_MNT_GET_NEXT, MNT_NS_INFO_SIZE_VER0);
 	case _IOC_NR(NS_MNT_GET_PREV):
 		return extensible_ioctl_valid(cmd, NS_MNT_GET_PREV, MNT_NS_INFO_SIZE_VER0);
+	case _IOC_NR(NS_SET_IDMAP):
+		return extensible_ioctl_valid(cmd, NS_SET_IDMAP, USERNS_IDMAP_SIZE_VER0);
 	}
 
 	return false;
@@ -360,6 +362,13 @@ static long ns_ioctl(struct file *filp, unsigned int ioctl,
 		ret = fd_publish(fdf);
 		break;
 	}
+	case _IOC_NR(NS_SET_IDMAP):
+		if (ns->ns_type != CLONE_NEWUSER)
+			return -EINVAL;
+
+		return userns_set_idmap(filp, to_user_ns(ns),
+					(const struct userns_idmap __user *)arg,
+					_IOC_SIZE(ioctl));
 	default:
 		ret = -ENOTTY;
 	}
diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
index 91232053775d..190e8c1fe202 100644
--- a/include/linux/user_namespace.h
+++ b/include/linux/user_namespace.h
@@ -35,11 +35,10 @@ struct uid_gid_map { /* 64 bytes -- 1 cache line */
 	};
 };
 
-#define USERNS_SETGROUPS_ALLOWED 1UL
-
 #define USERNS_INIT_FLAGS USERNS_SETGROUPS_ALLOWED
 
 struct ucounts;
+struct userns_idmap;
 
 enum ucount_type {
 	UCOUNT_USER_NAMESPACES,
@@ -207,6 +206,8 @@ extern bool in_userns(const struct user_namespace *ancestor,
 		       const struct user_namespace *child);
 extern bool current_in_userns(const struct user_namespace *target_ns);
 struct ns_common *ns_get_owner(struct ns_common *ns);
+long userns_set_idmap(struct file *file, struct user_namespace *ns,
+		      const struct userns_idmap __user *map, size_t size);
 
 #if IS_ENABLED(CONFIG_KUNIT)
 extern int uid_gid_map_insert_extent(struct uid_gid_map *map,
@@ -258,6 +259,14 @@ static inline struct ns_common *ns_get_owner(struct ns_common *ns)
 {
 	return ERR_PTR(-EPERM);
 }
+
+static inline long userns_set_idmap(struct file *file,
+				    struct user_namespace *ns,
+				    const struct userns_idmap __user *map,
+				    size_t size)
+{
+	return -EPERM;
+}
 #endif
 
 #endif /* _LINUX_USER_H */
diff --git a/include/uapi/linux/nsfs.h b/include/uapi/linux/nsfs.h
index e5909266ec3f..5fc59e2f23bd 100644
--- a/include/uapi/linux/nsfs.h
+++ b/include/uapi/linux/nsfs.h
@@ -44,6 +44,55 @@ struct mnt_ns_info {
 #define NS_GET_MNTNS_ID		_IOR(NSIO, 5,  __u64)
 #define NS_GET_ID		_IOR(NSIO, 13, __u64)
 
+/**
+ * struct userns_idmap_extent - Single ID mapping range for NS_SET_IDMAP
+ * @first: First ID inside the target user namespace.
+ * @lower_first: First ID inside the parent user namespace.
+ * @count: Number of consecutive IDs in the range.
+ * @reserved: Reserved for future use; must be zero.
+ */
+struct userns_idmap_extent {
+	__u32 first;
+	__u32 lower_first;
+	__u32 count;
+	__u32 reserved;
+};
+
+/**
+ * enum userns_flags - User namespace flags
+ * @USERNS_SETGROUPS_ALLOWED: Allow setgroups(2) inside the user namespace
+ *                            once its GID mapping is established.
+ */
+enum userns_flags {
+	USERNS_SETGROUPS_ALLOWED	= (1 << 0),
+};
+
+/**
+ * struct userns_idmap - Arguments for NS_SET_IDMAP
+ * @nr_uid_extents: Number of entries in @uid_extents.
+ * @nr_gid_extents: Number of entries in @gid_extents.
+ * @nr_projid_extents: Number of entries in @projid_extents.
+ * @flags: Bitmask of &enum userns_flags values.
+ * @uid_extents: User pointer to array of &struct userns_idmap_extent for UIDs.
+ * @gid_extents: User pointer to array of &struct userns_idmap_extent for GIDs.
+ * @projid_extents: User pointer to array of &struct userns_idmap_extent for
+ *                  project IDs.
+ */
+struct userns_idmap {
+	__u32 nr_uid_extents;
+	__u32 nr_gid_extents;
+	__u32 nr_projid_extents;
+	__u32 flags;
+	__aligned_u64 uid_extents;
+	__aligned_u64 gid_extents;
+	__aligned_u64 projid_extents;
+};
+
+#define USERNS_IDMAP_SIZE_VER0 40 /* sizeof first published struct */
+
+/* Set ID mappings of a user namespace. */
+#define NS_SET_IDMAP		_IOW(NSIO, 14, struct userns_idmap)
+
 enum init_ns_ino {
 	IPC_NS_INIT_INO		= 0xEFFFFFFFU,
 	UTS_NS_INIT_INO		= 0xEFFFFFFEU,
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index caba2ac33077..73daac18e634 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -23,6 +23,7 @@
 #include <linux/bsearch.h>
 #include <linux/sort.h>
 #include <linux/nstree.h>
+#include <uapi/linux/nsfs.h>
 
 static struct kmem_cache *user_ns_cachep __ro_after_init;
 static DEFINE_MUTEX(userns_state_mutex);
@@ -1176,6 +1177,206 @@ static ssize_t map_write(struct file *file, const char __user *buf,
 	return ret;
 }
 
+static bool caller_idmap_permitted(struct user_namespace *ns, int cap_setid,
+				   unsigned long ns_flags,
+				   const struct uid_gid_map *new_map)
+{
+	const struct cred *cred = current_cred();
+
+	if (cap_setid == CAP_SETUID && idmap_maps_root(new_map)) {
+		if (cred->user_ns == ns) {
+			if (!ns->parent_could_setfcap)
+				return false;
+		} else {
+			if (!ns_capable(ns->parent, CAP_SETFCAP))
+				return false;
+		}
+	}
+
+	if (unpriv_idmap_permitted(ns, cred, cap_setid, ns_flags, new_map))
+		return true;
+
+	/* Project IDs require no privilege, as in new_idmap_permitted(). */
+	if (!cap_valid(cap_setid))
+		return true;
+
+	return ns_capable(ns->parent, cap_setid);
+}
+
+static int prepare_caller_idmap(struct user_namespace *ns, int cap_setid,
+				unsigned long ns_flags,
+				struct uid_gid_map *new_map,
+				struct uid_gid_map *parent_map)
+{
+	if (!caller_idmap_permitted(ns, cap_setid, ns_flags, new_map))
+		return -EPERM;
+
+	return resolve_new_idmap(new_map, parent_map);
+}
+
+static int parse_user_idmap_extents(__u64 uptr, __u32 nr_extents,
+				    struct uid_gid_map *new_map)
+{
+	const struct userns_idmap_extent __user *uext = u64_to_user_ptr(uptr);
+	unsigned int i;
+	int ret;
+
+	if (!nr_extents || nr_extents > UID_GID_MAP_MAX_EXTENTS || !uptr)
+		return -EINVAL;
+
+	for (i = 0; i < nr_extents; i++) {
+		struct userns_idmap_extent kext;
+		struct uid_gid_extent extent;
+
+		if (copy_from_user(&kext, &uext[i], sizeof(kext)))
+			return -EFAULT;
+		if (kext.reserved)
+			return -EINVAL;
+
+		extent.first = kext.first;
+		extent.lower_first = kext.lower_first;
+		extent.count = kext.count;
+
+		ret = validate_and_insert_extent(new_map, &extent);
+		if (ret < 0)
+			return ret;
+	}
+	return 0;
+}
+
+/**
+ * userns_set_idmap - Handle %NS_SET_IDMAP on a user namespace nsfs file
+ * @filp: ``nsfs`` file referencing @ns
+ * @ns: Target user namespace
+ * @map: User pointer to &struct userns_idmap configuration
+ * @size: Size of @map in bytes, encoded in the ioctl number
+ *
+ * Atomically configure UID, GID, and project ID mappings (and, when
+ * @map->nr_gid_extents is non-zero, the %USERNS_SETGROUPS_ALLOWED policy) of
+ * @ns. Requires ``CAP_SYS_ADMIN`` over @ns in the caller's or @filp opener's
+ * credentials, with parent ID ranges authorized against the caller's
+ * credentials.
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+long userns_set_idmap(struct file *filp, struct user_namespace *ns,
+		      const struct userns_idmap __user *map, size_t size)
+{
+	struct uid_gid_map new_uid = {}, new_gid = {}, new_projid = {};
+	struct userns_idmap req = {};
+	unsigned long new_flags;
+	unsigned int flags;
+	bool file_ok;
+	int ret;
+
+	BUILD_BUG_ON(sizeof(struct userns_idmap) != USERNS_IDMAP_SIZE_VER0);
+
+	ret = copy_struct_from_user(&req, sizeof(req), map, size);
+	if (ret)
+		return ret;
+	flags = req.flags;
+	if (flags & ~USERNS_SETGROUPS_ALLOWED)
+		return -EINVAL;
+	if (!req.nr_uid_extents != !req.uid_extents ||
+	    !req.nr_gid_extents != !req.gid_extents ||
+	    !req.nr_projid_extents != !req.projid_extents)
+		return -EINVAL;
+	if (!req.nr_uid_extents && !req.nr_gid_extents &&
+	    !req.nr_projid_extents)
+		return -EINVAL;
+	if ((flags & USERNS_SETGROUPS_ALLOWED) && !req.nr_gid_extents)
+		return -EINVAL;
+
+	if (!ns->parent)
+		return -EPERM;
+	if (current_user_ns() != ns && current_user_ns() != ns->parent)
+		return -EPERM;
+
+	file_ok = (filp->f_cred->user_ns == ns ||
+		   filp->f_cred->user_ns == ns->parent) &&
+		  file_ns_capable(filp, ns, CAP_SYS_ADMIN);
+	if (!ns_capable(ns, CAP_SYS_ADMIN) && !file_ok)
+		return -EPERM;
+
+	if (req.nr_uid_extents) {
+		ret = parse_user_idmap_extents(req.uid_extents,
+					       req.nr_uid_extents, &new_uid);
+		if (ret < 0)
+			goto out_free;
+	}
+	if (req.nr_gid_extents) {
+		ret = parse_user_idmap_extents(req.gid_extents,
+					       req.nr_gid_extents, &new_gid);
+		if (ret < 0)
+			goto out_free;
+	}
+	if (req.nr_projid_extents) {
+		ret = parse_user_idmap_extents(req.projid_extents,
+					       req.nr_projid_extents,
+					       &new_projid);
+		if (ret < 0)
+			goto out_free;
+	}
+
+	mutex_lock(&userns_state_mutex);
+	new_flags = ns->flags;
+	ret = -EPERM;
+
+	if (req.nr_uid_extents && ns->uid_map.nr_extents != 0)
+		goto out_unlock;
+	if (req.nr_gid_extents && ns->gid_map.nr_extents != 0)
+		goto out_unlock;
+	if (req.nr_projid_extents && ns->projid_map.nr_extents != 0)
+		goto out_unlock;
+
+	if (req.nr_gid_extents) {
+		if ((flags & USERNS_SETGROUPS_ALLOWED) &&
+		    !(new_flags & USERNS_SETGROUPS_ALLOWED))
+			goto out_unlock;
+		if (!(flags & USERNS_SETGROUPS_ALLOWED))
+			new_flags &= ~USERNS_SETGROUPS_ALLOWED;
+	}
+
+	if (req.nr_uid_extents) {
+		ret = prepare_caller_idmap(ns, CAP_SETUID, new_flags, &new_uid,
+					   &ns->parent->uid_map);
+		if (ret < 0)
+			goto out_unlock;
+	}
+	if (req.nr_gid_extents) {
+		ret = prepare_caller_idmap(ns, CAP_SETGID, new_flags, &new_gid,
+					   &ns->parent->gid_map);
+		if (ret < 0)
+			goto out_unlock;
+	}
+	if (req.nr_projid_extents) {
+		ret = prepare_caller_idmap(ns, -1, new_flags, &new_projid,
+					   &ns->parent->projid_map);
+		if (ret < 0)
+			goto out_unlock;
+	}
+
+	if (new_flags != ns->flags)
+		WRITE_ONCE(ns->flags, new_flags);
+	if (req.nr_uid_extents)
+		commit_new_idmap(&ns->uid_map, &new_uid);
+	if (req.nr_gid_extents)
+		commit_new_idmap(&ns->gid_map, &new_gid);
+	if (req.nr_projid_extents)
+		commit_new_idmap(&ns->projid_map, &new_projid);
+
+	mutex_unlock(&userns_state_mutex);
+	return 0;
+
+out_unlock:
+	mutex_unlock(&userns_state_mutex);
+out_free:
+	free_new_idmap(&new_uid);
+	free_new_idmap(&new_gid);
+	free_new_idmap(&new_projid);
+	return ret;
+}
+
 ssize_t proc_uid_map_write(struct file *file, const char __user *buf,
 			   size_t size, loff_t *ppos)
 {
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 03/28] mount: Add mnt_ns_get_root()
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 01/28] userns: Factor out idmap validation and commit helpers Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 02/28] userns: Add NS_SET_IDMAP ioctl Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05 13:47   ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 04/28] mount: Enforce mount_too_revealing() for foreign mntns Jarkko Sakkinen
                   ` (24 subsequent siblings)
  27 siblings, 1 reply; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

Empty mount namespaces created with CLONE_EMPTY_MNTNS start with only an
internal nullfs root mount until a real root filesystem is mounted over
it, and external callers have no helper to resolve the live root path of
an unentered mount namespace.

Add mnt_ns_get_root() to look up "/" with LOOKUP_DOWN from the mount
namespace's base root mount and return -ENOENT if no filesystem has been
mounted over the initial nullfs root yet.

Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 fs/namespace.c                | 16 ++++++++++++++++
 include/linux/mnt_namespace.h |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/fs/namespace.c b/fs/namespace.c
index aecd05ac0170..781380945d78 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -6708,6 +6708,22 @@ static void mntns_put(struct ns_common *ns)
 	put_mnt_ns(to_mnt_ns(ns));
 }
 
+int mnt_ns_get_root(struct mnt_namespace *mnt_ns, struct path *root)
+{
+	int err;
+
+	err = vfs_path_lookup(mnt_ns->root->mnt.mnt_root, &mnt_ns->root->mnt,
+			      "/", LOOKUP_DOWN, root);
+	if (err)
+		return err;
+	if (root->mnt == &mnt_ns->root->mnt) {
+		path_put(root);
+		*root = (struct path){};
+		return -ENOENT;
+	}
+	return 0;
+}
+
 static int mntns_install(struct nsset *nsset, struct ns_common *ns)
 {
 	struct nsproxy *nsproxy = nsset->nsproxy;
diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
index 0acd1089d149..98188d1f7428 100644
--- a/include/linux/mnt_namespace.h
+++ b/include/linux/mnt_namespace.h
@@ -8,6 +8,7 @@
 
 struct mnt_namespace;
 struct fs_struct;
+struct path;
 struct user_namespace;
 struct ns_common;
 
@@ -15,6 +16,7 @@ extern struct mnt_namespace init_mnt_ns;
 
 extern struct mnt_namespace *copy_mnt_ns(u64, struct mnt_namespace *,
 		struct user_namespace *, struct fs_struct *);
+int mnt_ns_get_root(struct mnt_namespace *mnt_ns, struct path *root);
 extern void put_mnt_ns(struct mnt_namespace *ns);
 DEFINE_FREE(put_mnt_ns, struct mnt_namespace *, if (!IS_ERR_OR_NULL(_T)) put_mnt_ns(_T))
 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 04/28] mount: Enforce mount_too_revealing() for foreign mntns
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (2 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 03/28] mount: Add mnt_ns_get_root() Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05 13:47   ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 05/28] mount: Support MOVE_MOUNT_T_MNTNS in move_mount() Jarkko Sakkinen
                   ` (23 subsequent siblings)
  27 siblings, 1 reply; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

mount_too_revealing() skips visibility checks whenever
current->nsproxy->mnt_ns belongs to init_user_ns, assuming the caller
holds CAP_SYS_ADMIN in its current mount namespace. That assumption does
not hold when an unprivileged caller creates mounts for a child user
namespace while running in init_mnt_ns or another foreign mount
namespace.

Require CAP_SYS_ADMIN in init_user_ns before bypassing
mount_too_revealing() for init_mnt_ns, reject chrooted callers lacking
CAP_SYS_ADMIN in their current mount namespace, and treat existing
mounts and child overmounts in a foreign mount namespace as locked
during mnt_already_visible() checks.

Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 fs/namespace.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 781380945d78..1bb9f90a6523 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -6580,7 +6580,7 @@ bool current_chrooted(void)
 
 static bool mnt_already_visible(struct mnt_namespace *ns,
 				const struct super_block *sb,
-				int *new_mnt_flags)
+				int *new_mnt_flags, bool foreign_ns)
 {
 	int new_flags = *new_mnt_flags;
 	struct mount *mnt;
@@ -6606,11 +6606,16 @@ static bool mnt_already_visible(struct mnt_namespace *ns,
 			continue;
 
 		/* A local view of the mount flags */
-		mnt_flags = mnt->mnt.mnt_flags;
+		mnt_flags = READ_ONCE(mnt->mnt.mnt_flags);
 
 		/* Don't miss readonly hidden in the superblock flags */
 		if (sb_rdonly(mnt->mnt.mnt_sb))
 			mnt_flags |= MNT_LOCK_READONLY;
+		if (foreign_ns) {
+			if (mnt_flags & MNT_READONLY)
+				mnt_flags |= MNT_LOCK_READONLY;
+			mnt_flags |= MNT_LOCK_ATIME;
+		}
 
 		/* Verify the mount flags are equal to or more permissive
 		 * than the proposed new mount.
@@ -6629,7 +6634,7 @@ static bool mnt_already_visible(struct mnt_namespace *ns,
 		list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) {
 			struct inode *inode = child->mnt_mountpoint->d_inode;
 			/* Only worry about locked mounts */
-			if (!(child->mnt.mnt_flags & MNT_LOCKED))
+			if (!foreign_ns && !(READ_ONCE(child->mnt.mnt_flags) & MNT_LOCKED))
 				continue;
 			/* Is the directory permanently empty? */
 			if (!is_empty_dir_inode(inode))
@@ -6649,14 +6654,19 @@ static bool mount_too_revealing(const struct super_block *sb, int *new_mnt_flags
 	const unsigned long required_iflags = SB_I_NOEXEC | SB_I_NODEV;
 	struct mnt_namespace *ns = current->nsproxy->mnt_ns;
 	unsigned long s_iflags;
-
-	if (ns->user_ns == &init_user_ns)
-		return false;
+	bool foreign_ns;
 
 	/* Can this filesystem be too revealing? */
 	if (!(sb->s_type->fs_flags & FS_USERNS_MOUNT_RESTRICTED))
 		return false;
 
+	foreign_ns = !ns_capable_noaudit(ns->user_ns, CAP_SYS_ADMIN);
+	if (ns->user_ns == &init_user_ns && !foreign_ns)
+		return false;
+
+	if (foreign_ns && current_chrooted())
+		return true;
+
 	s_iflags = sb->s_iflags;
 	if ((s_iflags & required_iflags) != required_iflags) {
 		WARN_ONCE(1, "Expected s_iflags to contain 0x%lx\n",
@@ -6671,7 +6681,7 @@ static bool mount_too_revealing(const struct super_block *sb, int *new_mnt_flags
 	if (s_iflags & SB_I_RESTRICTED_VARIANT)
 		return false;
 
-	return !mnt_already_visible(ns, sb, new_mnt_flags);
+	return !mnt_already_visible(ns, sb, new_mnt_flags, foreign_ns);
 }
 
 bool mnt_may_suid(struct vfsmount *mnt)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 05/28] mount: Support MOVE_MOUNT_T_MNTNS in move_mount()
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (3 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 04/28] mount: Enforce mount_too_revealing() for foreign mntns Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 06/28] security: Pass flags to security_move_mount() Jarkko Sakkinen
                   ` (22 subsequent siblings)
  27 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

move_mount() currently resolves target paths only against the caller's
filesystem view or anonymous mount fds, preventing an external manager
from populating an empty mount namespace or hot-mounting into an
existing container's mount namespace without entering it first.

Add MOVE_MOUNT_T_MNTNS to attach detached anonymous mount trees into a
target mount namespace nsfs file descriptor. Installing "/" attaches the
initial root mount onto the nullfs root of an empty mount namespace at
most once, while relative target paths resolve with LOOKUP_IN_ROOT
beneath the live mount namespace root and reject root-mount aliases
under namespace_lock().

Check CAP_SYS_ADMIN in the target mount namespace's owning user
namespace instead of caller may_mount(), check nsfs mount loops against
the destination mount namespace, and lock moved mount trees inside
attach_recursive_mnt() when crossing user namespace boundaries.

Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 fs/namespace.c             | 245 ++++++++++++++++++++++++++++++-------
 fs/pnode.c                 |  39 +++++-
 fs/pnode.h                 |   3 +-
 include/uapi/linux/mount.h |   3 +-
 4 files changed, 244 insertions(+), 46 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 1bb9f90a6523..45a7f9547c8e 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2202,7 +2202,8 @@ struct mnt_namespace *mnt_ns_from_dentry(struct dentry *dentry)
 	return to_mnt_ns(get_proc_ns(dentry->d_inode));
 }
 
-static bool mnt_ns_loop(struct dentry *dentry)
+static bool mnt_ns_loop_target(struct dentry *dentry,
+			       struct mnt_namespace *target_mnt_ns)
 {
 	/* Could bind mounting the mount namespace inode cause a
 	 * mount namespace loop?
@@ -2212,7 +2213,12 @@ static bool mnt_ns_loop(struct dentry *dentry)
 	if (!mnt_ns)
 		return false;
 
-	return current->nsproxy->mnt_ns->ns.ns_id >= mnt_ns->ns.ns_id;
+	return target_mnt_ns->ns.ns_id >= mnt_ns->ns.ns_id;
+}
+
+static bool mnt_ns_loop(struct dentry *dentry)
+{
+	return mnt_ns_loop_target(dentry, current->nsproxy->mnt_ns);
 }
 
 struct mount *copy_tree(struct mount *src_root, struct dentry *dentry,
@@ -2239,9 +2245,13 @@ struct mount *copy_tree(struct mount *src_root, struct dentry *dentry,
 
 		for (src_mnt = src_root_child; src_mnt;
 		    src_mnt = next_mnt(src_mnt, src_root_child)) {
+			bool src_locked = (src_mnt->mnt.mnt_flags & MNT_LOCKED) ||
+					  ((flag & CL_LOCK_SOURCE) &&
+					   list_empty(&src_mnt->mnt_expire));
+
 			if (!(flag & CL_COPY_UNBINDABLE) &&
 			    IS_MNT_UNBINDABLE(src_mnt)) {
-				if (src_mnt->mnt.mnt_flags & MNT_LOCKED) {
+				if (src_locked) {
 					/* Both unbindable and locked. */
 					dst_mnt = ERR_PTR(-EPERM);
 					goto out;
@@ -2252,7 +2262,7 @@ struct mount *copy_tree(struct mount *src_root, struct dentry *dentry,
 			}
 			if (!(flag & CL_COPY_MNT_NS_FILE) &&
 			    is_mnt_ns_file(src_mnt->mnt.mnt_root)) {
-				if (src_mnt->mnt.mnt_flags & MNT_LOCKED) {
+				if (src_locked) {
 					/* Both a mount namespace file and locked. */
 					dst_mnt = ERR_PTR(-EPERM);
 					goto out;
@@ -2423,10 +2433,11 @@ static bool __has_children(struct mount *mnt, struct dentry *dentry)
  *
  * locks: mount_locked_reader || namespace_shared && pinned(subtree)
  */
-static bool check_for_nsfs_mounts(struct mount *subtree)
+static bool check_for_nsfs_mounts(struct mount *subtree,
+				  struct mnt_namespace *target_mnt_ns)
 {
 	for (struct mount *p = subtree; p; p = next_mnt(p, subtree))
-		if (mnt_ns_loop(p->mnt.mnt_root))
+		if (mnt_ns_loop_target(p->mnt.mnt_root, target_mnt_ns))
 			return false;
 	return true;
 }
@@ -2464,7 +2475,7 @@ struct vfsmount *clone_private_mount(const struct path *path)
 		if (!anon_ns_root(old_mnt))
 			return ERR_PTR(-EINVAL);
 
-		if (!check_for_nsfs_mounts(old_mnt))
+		if (!check_for_nsfs_mounts(old_mnt, current->nsproxy->mnt_ns))
 			return ERR_PTR(-EINVAL);
 	}
 
@@ -2564,12 +2575,16 @@ int count_mounts(struct mnt_namespace *ns, struct mount *mnt)
 enum mnt_tree_flags_t {
 	MNT_TREE_BENEATH = BIT(0),
 	MNT_TREE_PROPAGATION = BIT(1),
+	MNT_TREE_MNTNS = BIT(2),
+	MNT_TREE_MNTNS_INIT = BIT(3),
 };
 
 /**
  * attach_recursive_mnt - attach a source mount tree
  * @source_mnt: mount tree to be attached
  * @dest:	the context for mounting at the place where the tree should go
+ * @src_user_ns: owning user namespace of @source_mnt for MOVE_MOUNT_T_MNTNS,
+ *               or NULL
  *
  *  NOTE: in the table below explains the semantics when a source mount
  *  of a given type is attached to a destination mount of a given type.
@@ -2632,7 +2647,8 @@ enum mnt_tree_flags_t {
  *         Otherwise a negative error code is returned.
  */
 static int attach_recursive_mnt(struct mount *source_mnt,
-				const struct pinned_mountpoint *dest)
+				const struct pinned_mountpoint *dest,
+				struct user_namespace *src_user_ns)
 {
 	struct mount *dest_mnt = dest->parent;
 	struct mountpoint *dest_mp = dest->mp;
@@ -2688,7 +2704,8 @@ static int attach_recursive_mnt(struct mount *source_mnt,
 		err = invent_group_ids(source_mnt, true);
 		if (err)
 			goto out;
-		err = propagate_mnt(dest_mnt, dest_mp, source_mnt, &tree_list);
+		err = propagate_mnt(dest_mnt, dest_mp, source_mnt, &tree_list,
+				    src_user_ns);
 	}
 	lock_mount_hash();
 	if (err)
@@ -2725,11 +2742,22 @@ static int attach_recursive_mnt(struct mount *source_mnt,
 	hlist_add_head(&source_mnt->mnt_hash, &tree_list);
 
 	hlist_for_each_entry_safe(child, n, &tree_list, mnt_hash) {
+		struct user_namespace *child_user_ns =
+			child->mnt_parent->mnt_ns->user_ns;
+		bool cross_child_src = src_user_ns &&
+				       !in_userns(child_user_ns, src_user_ns);
 		struct mount *q;
+
 		hlist_del_init(&child->mnt_hash);
-		/* Notice when we are propagating across user namespaces */
-		if (child->mnt_parent->mnt_ns->user_ns != user_ns)
+		/*
+		 * Notice when we are propagating or attaching a foreign
+		 * source tree across user namespaces.
+		 */
+		if (child_user_ns != user_ns || cross_child_src) {
 			lock_mnt_tree(child);
+			if (cross_child_src && list_empty(&child->mnt_expire))
+				child->mnt.mnt_flags |= MNT_LOCKED;
+		}
 		q = __lookup_mnt(&child->mnt_parent->mnt,
 				 child->mnt_mountpoint);
 		commit_tree(child);
@@ -2937,7 +2965,7 @@ static int graft_tree(struct mount *mnt, const struct pinned_mountpoint *mp)
 	      d_is_dir(mnt->mnt.mnt_root))
 		return -ENOTDIR;
 
-	return attach_recursive_mnt(mnt, mp);
+	return attach_recursive_mnt(mnt, mp, NULL);
 }
 
 static int may_change_propagation(const struct mount *m)
@@ -3131,7 +3159,7 @@ static int do_loopback(const struct path *path, const char *old_name,
 		return PTR_ERR(mnt);
 
 	/* the copy may carry mount namespace files from below the source */
-	if (recurse && !check_for_nsfs_mounts(mnt))
+	if (recurse && !check_for_nsfs_mounts(mnt, current->nsproxy->mnt_ns))
 		err = -EINVAL;
 	else
 		err = graft_tree(mnt, &mp);
@@ -3776,9 +3804,12 @@ static inline bool may_use_mount(struct mount *mnt)
 
 static int do_move_mount(const struct path *old_path,
 			 const struct path *new_path,
-			 enum mnt_tree_flags_t flags)
+			 enum mnt_tree_flags_t flags,
+			 struct mnt_namespace *target_mnt_ns)
 {
 	struct mount *old = real_mount(old_path->mnt);
+	struct user_namespace *src_user_ns = NULL;
+	struct mnt_namespace *dest_mnt_ns;
 	int err;
 	bool beneath = flags & MNT_TREE_BENEATH;
 
@@ -3792,7 +3823,30 @@ static int do_move_mount(const struct path *old_path,
 	if (IS_ERR(mp.parent))
 		return PTR_ERR(mp.parent);
 
-	if (check_mnt(old)) {
+	if (flags & MNT_TREE_MNTNS) {
+		u64 seq;
+
+		if (!anon_ns_root(old) || old->mnt_ns == mp.parent->mnt_ns ||
+		    mp.parent->mnt_ns != target_mnt_ns)
+			return -EINVAL;
+		seq = old->mnt_ns->seq_origin;
+		if (seq && seq != target_mnt_ns->ns.ns_id &&
+		    seq != current->nsproxy->mnt_ns->ns.ns_id)
+			return -EINVAL;
+		src_user_ns = old->mnt_ns->user_ns;
+		if (flags & MNT_TREE_MNTNS_INIT) {
+			if (mp.parent != target_mnt_ns->root)
+				return -EBUSY;
+		} else if (mp.mp->m_dentry == mp.parent->mnt.mnt_root) {
+			const struct mount *m = mp.parent;
+
+			while (m != target_mnt_ns->root && mnt_has_parent(m) &&
+			       m->mnt_mountpoint == m->mnt_parent->mnt.mnt_root)
+				m = m->mnt_parent;
+			if (m == target_mnt_ns->root)
+				return beneath ? -EINVAL : -EBUSY;
+		}
+	} else if (check_mnt(old)) {
 		/* if the source is in our namespace... */
 		/* ... it should be detachable from parent */
 		if (!mnt_has_parent(old) || IS_MNT_LOCKED(old))
@@ -3840,12 +3894,14 @@ static int do_move_mount(const struct path *old_path,
 	 */
 	if (IS_MNT_SHARED(mp.parent) && tree_contains_unbindable(old))
 		return -EINVAL;
-	if (!check_for_nsfs_mounts(old))
+	dest_mnt_ns = is_anon_ns(mp.parent->mnt_ns) ?
+		      current->nsproxy->mnt_ns : mp.parent->mnt_ns;
+	if (!check_for_nsfs_mounts(old, dest_mnt_ns))
 		return -ELOOP;
 	if (mount_is_ancestor(old, mp.parent))
 		return -ELOOP;
 
-	return attach_recursive_mnt(old, &mp);
+	return attach_recursive_mnt(old, &mp, src_user_ns);
 }
 
 static int do_move_mount_old(const struct path *path, const char *old_name)
@@ -3860,7 +3916,7 @@ static int do_move_mount_old(const struct path *path, const char *old_name)
 	if (err)
 		return err;
 
-	return do_move_mount(&old_path, path, 0);
+	return do_move_mount(&old_path, path, 0, NULL);
 }
 
 /*
@@ -4725,7 +4781,8 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
 
 static inline int vfs_move_mount(const struct path *from_path,
 				 const struct path *to_path,
-				 enum mnt_tree_flags_t mflags)
+				 enum mnt_tree_flags_t mflags,
+				 struct mnt_namespace *target_mnt_ns)
 {
 	int ret;
 
@@ -4736,7 +4793,123 @@ static inline int vfs_move_mount(const struct path *from_path,
 	if (mflags & MNT_TREE_PROPAGATION)
 		return do_set_group(from_path, to_path);
 
-	return do_move_mount(from_path, to_path, mflags);
+	return do_move_mount(from_path, to_path, mflags, target_mnt_ns);
+}
+
+static int lookup_move_mount_from(int from_dfd,
+				  const char __user *from_pathname,
+				  unsigned int flags, struct path *from_path)
+{
+	unsigned int uflags = 0;
+	unsigned int lflags = 0;
+
+	if (flags & MOVE_MOUNT_F_EMPTY_PATH)
+		uflags = AT_EMPTY_PATH;
+
+	CLASS(filename_maybe_null, from_name)(from_pathname, uflags);
+	if (!from_name && from_dfd >= 0) {
+		CLASS(fd_raw, f_from)(from_dfd);
+		if (fd_empty(f_from))
+			return -EBADF;
+
+		*from_path = fd_file(f_from)->f_path;
+		path_get(from_path);
+		return 0;
+	}
+
+	if (flags & MOVE_MOUNT_F_SYMLINKS)
+		lflags |= LOOKUP_FOLLOW;
+	if (flags & MOVE_MOUNT_F_AUTOMOUNTS)
+		lflags |= LOOKUP_AUTOMOUNT;
+	return filename_lookup(from_dfd, from_name, lflags, from_path, NULL);
+}
+
+/**
+ * DOC: MOVE_MOUNT_T_MNTNS
+ *
+ * ``MOVE_MOUNT_T_MNTNS`` installs detached anonymous mount trees into a target
+ * mount namespace ``nsfs`` file descriptor supplied as ``to_dfd``:
+ *
+ * 1. ``to_pathname`` of ``"/"`` attaches the initial root mount onto the
+ *    ``nullfs`` root of an empty mount namespace at most once.
+ *
+ * 2. Relative ``to_pathname`` values resolve beneath the live root of the
+ *    target mount namespace.
+ *
+ * Capability is checked against ``CAP_SYS_ADMIN`` in the target mount
+ * namespace's owning user namespace, and source trees crossing user namespace
+ * boundaries are locked with ``MNT_LOCKED`` and locked mount flags.
+ */
+static int move_mount_mntns(int from_dfd, const char __user *from_pathname,
+			    int to_dfd, const char __user *to_pathname,
+			    unsigned int flags, enum mnt_tree_flags_t mflags)
+{
+	struct path from_path __free(path_put) = {};
+	struct path to_path __free(path_put) = {};
+	struct mnt_namespace *target_mnt_ns;
+	unsigned int lflags;
+	struct ns_common *ns;
+	bool is_root;
+	int ret;
+
+	CLASS(filename_maybe_null, to_name)(to_pathname, AT_EMPTY_PATH);
+	if (IS_ERR(to_name))
+		return PTR_ERR(to_name);
+	if (!to_name)
+		return -EINVAL;
+
+	CLASS(fd, f_mntns)(to_dfd);
+	if (fd_empty(f_mntns))
+		return -EBADF;
+	if (!proc_ns_file(fd_file(f_mntns)))
+		return -EINVAL;
+
+	ns = get_proc_ns(file_inode(fd_file(f_mntns)));
+	if (ns->ns_type != CLONE_NEWNS)
+		return -EINVAL;
+
+	target_mnt_ns = to_mnt_ns(ns);
+	if (is_anon_ns(target_mnt_ns))
+		return -EINVAL;
+	if (!ns_capable(target_mnt_ns->user_ns, CAP_SYS_ADMIN))
+		return -EPERM;
+
+	is_root = to_name->name[0] == '/' && to_name->name[1] == '\0';
+	if (is_root) {
+		if (flags & MOVE_MOUNT_BENEATH)
+			return -EINVAL;
+
+		to_path.mnt = mntget(&target_mnt_ns->root->mnt);
+		to_path.dentry = dget(target_mnt_ns->root->mnt.mnt_root);
+		mflags |= MNT_TREE_MNTNS_INIT;
+	} else {
+		struct path mntns_root __free(path_put) = {};
+
+		if (to_name->name[0] == '/')
+			return -EINVAL;
+
+		ret = mnt_ns_get_root(target_mnt_ns, &mntns_root);
+		if (ret)
+			return ret;
+
+		lflags = LOOKUP_IN_ROOT;
+		if (flags & MOVE_MOUNT_T_SYMLINKS)
+			lflags |= LOOKUP_FOLLOW;
+		if (flags & MOVE_MOUNT_T_AUTOMOUNTS)
+			lflags |= LOOKUP_AUTOMOUNT;
+		ret = filename_lookup(AT_FDCWD, to_name, lflags, &to_path,
+				      &mntns_root);
+		if (ret)
+			return ret;
+	}
+
+	ret = lookup_move_mount_from(from_dfd, from_pathname, flags,
+				     &from_path);
+	if (ret)
+		return ret;
+
+	return vfs_move_mount(&from_path, &to_path, mflags | MNT_TREE_MNTNS,
+			      target_mnt_ns);
 }
 
 /*
@@ -4758,7 +4931,7 @@ SYSCALL_DEFINE5(move_mount,
 	enum mnt_tree_flags_t mflags = 0;
 	int ret = 0;
 
-	if (!may_mount())
+	if (!(flags & MOVE_MOUNT_T_MNTNS) && !may_mount())
 		return -EPERM;
 
 	if (flags & ~MOVE_MOUNT__MASK)
@@ -4771,6 +4944,13 @@ SYSCALL_DEFINE5(move_mount,
 	if (flags & MOVE_MOUNT_SET_GROUP)	mflags |= MNT_TREE_PROPAGATION;
 	if (flags & MOVE_MOUNT_BENEATH)		mflags |= MNT_TREE_BENEATH;
 
+	if (unlikely(flags & MOVE_MOUNT_T_MNTNS)) {
+		if (flags & (MOVE_MOUNT_T_EMPTY_PATH | MOVE_MOUNT_SET_GROUP))
+			return -EINVAL;
+		return move_mount_mntns(from_dfd, from_pathname,
+					to_dfd, to_pathname, flags, mflags);
+	}
+
 	uflags = 0;
 	if (flags & MOVE_MOUNT_T_EMPTY_PATH)
 		uflags = AT_EMPTY_PATH;
@@ -4794,29 +4974,12 @@ SYSCALL_DEFINE5(move_mount,
 			return ret;
 	}
 
-	uflags = 0;
-	if (flags & MOVE_MOUNT_F_EMPTY_PATH)
-		uflags = AT_EMPTY_PATH;
-
-	CLASS(filename_maybe_null,from_name)(from_pathname, uflags);
-	if (!from_name && from_dfd >= 0) {
-		CLASS(fd_raw, f_from)(from_dfd);
-		if (fd_empty(f_from))
-			return -EBADF;
-
-		return vfs_move_mount(&fd_file(f_from)->f_path, &to_path, mflags);
-	}
-
-	lflags = 0;
-	if (flags & MOVE_MOUNT_F_SYMLINKS)
-		lflags |= LOOKUP_FOLLOW;
-	if (flags & MOVE_MOUNT_F_AUTOMOUNTS)
-		lflags |= LOOKUP_AUTOMOUNT;
-	ret = filename_lookup(from_dfd, from_name, lflags, &from_path, NULL);
+	ret = lookup_move_mount_from(from_dfd, from_pathname, flags,
+				     &from_path);
 	if (ret)
 		return ret;
 
-	return vfs_move_mount(&from_path, &to_path, mflags);
+	return vfs_move_mount(&from_path, &to_path, mflags, NULL);
 }
 
 /*
diff --git a/fs/pnode.c b/fs/pnode.c
index 5f07fa14099b..967188f37df7 100644
--- a/fs/pnode.c
+++ b/fs/pnode.c
@@ -9,6 +9,7 @@
 #include <linux/mount.h>
 #include <linux/fs.h>
 #include <linux/nsproxy.h>
+#include <linux/user_namespace.h>
 #include <uapi/linux/mount.h>
 #include "internal.h"
 #include "pnode.h"
@@ -271,6 +272,32 @@ static bool need_secondary(struct mount *m, struct mountpoint *dest_mp)
 	return true;
 }
 
+/*
+ * A secondary in a user namespace without privilege over @src_user_ns must not
+ * reveal what non-expiring submounts of the source tree cover. Copies chain
+ * from earlier copies, so decide once for the whole propagation: a copy that
+ * silently dropped a submount for a privileged peer must not become the
+ * source for an unprivileged one.
+ */
+static bool need_lock_source(struct mount *dest_mnt, struct mountpoint *dest_mp,
+			     struct user_namespace *src_user_ns)
+{
+	struct mount *m, *n;
+
+	if (!src_user_ns)
+		return false;
+
+	for (m = dest_mnt; m; m = next_group(m, dest_mnt)) {
+		n = m;
+		do {
+			if (n != dest_mnt && need_secondary(n, dest_mp) &&
+			    !in_userns(n->mnt_ns->user_ns, src_user_ns))
+				return true;
+		} while ((n = next_peer(n)) != m);
+	}
+	return false;
+}
+
 static struct mount *find_master(struct mount *m,
 				struct mount *last_copy,
 				struct mount *original)
@@ -302,6 +329,7 @@ static struct mount *find_master(struct mount *m,
  * @dest_mp:     destination mountpoint.
  * @source_mnt:  source mount.
  * @tree_list:   list of secondaries to be attached.
+ * @src_user_ns: owning user namespace of a foreign @source_mnt, or NULL.
  *
  * Create secondary copies for attaching a tree with root @source_mnt
  * at mount @dest_mnt with mountpoint @dest_mp.  Link all new mounts
@@ -309,10 +337,14 @@ static struct mount *find_master(struct mount *m,
  * link their roots into @tree_list via ->mnt_hash.
  */
 int propagate_mnt(struct mount *dest_mnt, struct mountpoint *dest_mp,
-		  struct mount *source_mnt, struct hlist_head *tree_list)
+		  struct mount *source_mnt, struct hlist_head *tree_list,
+		  struct user_namespace *src_user_ns)
 {
 	struct mount *m, *n, *copy, *this;
-	int err = 0, type;
+	int err = 0, type, lock_flag;
+
+	lock_flag = need_lock_source(dest_mnt, dest_mp, src_user_ns) ?
+		    CL_LOCK_SOURCE : 0;
 
 	if (dest_mnt->mnt_master)
 		SET_MNT_MARK(dest_mnt->mnt_master);
@@ -337,7 +369,8 @@ int propagate_mnt(struct mount *dest_mnt, struct mountpoint *dest_mp,
 				continue;
 			if (type & CL_SLAVE) // first in this peer group
 				copy = find_master(n, copy, source_mnt);
-			this = copy_tree(copy, copy->mnt.mnt_root, type);
+			this = copy_tree(copy, copy->mnt.mnt_root,
+					 type | lock_flag);
 			if (IS_ERR(this)) {
 				err = PTR_ERR(this);
 				break;
diff --git a/fs/pnode.h b/fs/pnode.h
index b029db225f33..72be9cbfb998 100644
--- a/fs/pnode.h
+++ b/fs/pnode.h
@@ -26,6 +26,7 @@
 #define CL_MAKE_SHARED 		0x08
 #define CL_PRIVATE 		0x10
 #define CL_COPY_MNT_NS_FILE	0x40
+#define CL_LOCK_SOURCE		0x80
 
 /*
  * EXCL[namespace_sem]
@@ -44,7 +45,7 @@ static inline bool peers(const struct mount *m1, const struct mount *m2)
 void change_mnt_propagation(struct mount *, int);
 void bulk_make_private(struct list_head *);
 int propagate_mnt(struct mount *, struct mountpoint *, struct mount *,
-		struct hlist_head *);
+		struct hlist_head *, struct user_namespace *);
 void propagate_umount(struct list_head *);
 int propagate_mount_busy(struct mount *, int);
 void propagate_mount_unlock(struct mount *);
diff --git a/include/uapi/linux/mount.h b/include/uapi/linux/mount.h
index ac865edac517..7d413418426a 100644
--- a/include/uapi/linux/mount.h
+++ b/include/uapi/linux/mount.h
@@ -75,9 +75,10 @@
 #define MOVE_MOUNT_T_SYMLINKS		0x00000010 /* Follow symlinks on to path */
 #define MOVE_MOUNT_T_AUTOMOUNTS		0x00000020 /* Follow automounts on to path */
 #define MOVE_MOUNT_T_EMPTY_PATH		0x00000040 /* Empty to path permitted */
+#define MOVE_MOUNT_T_MNTNS		0x00000080 /* Resolve to_dfd as mntns fd */
 #define MOVE_MOUNT_SET_GROUP		0x00000100 /* Set sharing group instead */
 #define MOVE_MOUNT_BENEATH		0x00000200 /* Mount beneath top mount */
-#define MOVE_MOUNT__MASK		0x00000377
+#define MOVE_MOUNT__MASK		0x000003f7
 
 /*
  * fsopen() flags.
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 06/28] security: Pass flags to security_move_mount()
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (4 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 05/28] mount: Support MOVE_MOUNT_T_MNTNS in move_mount() Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 07/28] mount: Support MOVE_MOUNT_CLONE with MOVE_MOUNT_T_MNTNS Jarkko Sakkinen
                   ` (21 subsequent siblings)
  27 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

Pass the MOVE_MOUNT_* flags from move_mount() to security_move_mount()
and the move_mount LSM hook so security modules can distinguish mount
operations that carry behavioral flags such as cloning versus moving.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 fs/namespace.c                | 9 +++++----
 include/linux/lsm_hook_defs.h | 2 +-
 include/linux/security.h      | 6 ++++--
 security/apparmor/lsm.c       | 2 +-
 security/landlock/fs.c        | 3 ++-
 security/security.c           | 7 ++++---
 security/selinux/hooks.c      | 2 +-
 7 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 45a7f9547c8e..d73a215c9ae5 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -4781,12 +4781,13 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
 
 static inline int vfs_move_mount(const struct path *from_path,
 				 const struct path *to_path,
+				 unsigned int flags,
 				 enum mnt_tree_flags_t mflags,
 				 struct mnt_namespace *target_mnt_ns)
 {
 	int ret;
 
-	ret = security_move_mount(from_path, to_path);
+	ret = security_move_mount(from_path, to_path, flags);
 	if (ret)
 		return ret;
 
@@ -4908,8 +4909,8 @@ static int move_mount_mntns(int from_dfd, const char __user *from_pathname,
 	if (ret)
 		return ret;
 
-	return vfs_move_mount(&from_path, &to_path, mflags | MNT_TREE_MNTNS,
-			      target_mnt_ns);
+	return vfs_move_mount(&from_path, &to_path, flags,
+			      mflags | MNT_TREE_MNTNS, target_mnt_ns);
 }
 
 /*
@@ -4979,7 +4980,7 @@ SYSCALL_DEFINE5(move_mount,
 	if (ret)
 		return ret;
 
-	return vfs_move_mount(&from_path, &to_path, mflags, NULL);
+	return vfs_move_mount(&from_path, &to_path, flags, mflags, NULL);
 }
 
 /*
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 87d9d06710cb..005a350681c3 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -80,7 +80,7 @@ LSM_HOOK(int, 0, sb_clone_mnt_opts, const struct super_block *oldsb,
 	 struct super_block *newsb, unsigned long kern_flags,
 	 unsigned long *set_kern_flags)
 LSM_HOOK(int, 0, move_mount, const struct path *from_path,
-	 const struct path *to_path)
+	 const struct path *to_path, unsigned int flags)
 LSM_HOOK(int, -EOPNOTSUPP, dentry_init_security, struct dentry *dentry,
 	 int mode, const struct qstr *name, const char **xattr_name,
 	 struct lsm_context *cp)
diff --git a/include/linux/security.h b/include/linux/security.h
index 40831fab5470..9c8f8da83251 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -387,7 +387,8 @@ int security_sb_clone_mnt_opts(const struct super_block *oldsb,
 				struct super_block *newsb,
 				unsigned long kern_flags,
 				unsigned long *set_kern_flags);
-int security_move_mount(const struct path *from_path, const struct path *to_path);
+int security_move_mount(const struct path *from_path,
+			const struct path *to_path, unsigned int flags);
 int security_dentry_init_security(struct dentry *dentry, int mode,
 				  const struct qstr *name,
 				  const char **xattr_name,
@@ -858,7 +859,8 @@ static inline int security_sb_clone_mnt_opts(const struct super_block *oldsb,
 }
 
 static inline int security_move_mount(const struct path *from_path,
-				      const struct path *to_path)
+				      const struct path *to_path,
+				      unsigned int flags)
 {
 	return 0;
 }
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index eaebc3c60c5a..aefa71bc1cd2 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -742,7 +742,7 @@ static int apparmor_sb_mount(const char *dev_name, const struct path *path,
 }
 
 static int apparmor_move_mount(const struct path *from_path,
-			       const struct path *to_path)
+			       const struct path *to_path, unsigned int flags)
 {
 	struct aa_label *label;
 	int error = 0;
diff --git a/security/landlock/fs.c b/security/landlock/fs.c
index 2ab67bcad198..32d882a79001 100644
--- a/security/landlock/fs.c
+++ b/security/landlock/fs.c
@@ -1547,7 +1547,8 @@ static int hook_sb_mount(const char *const dev_name,
 }
 
 static int hook_move_mount(const struct path *const from_path,
-			   const struct path *const to_path)
+			   const struct path *const to_path,
+			   unsigned int flags)
 {
 	size_t handle_layer;
 	const struct landlock_cred_security *const subject =
diff --git a/security/security.c b/security/security.c
index c50f833d55a6..c93c94103d2e 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1185,15 +1185,16 @@ EXPORT_SYMBOL(security_sb_clone_mnt_opts);
  * security_move_mount() - Check permissions for moving a mount
  * @from_path: source mount point
  * @to_path: destination mount point
+ * @flags: MOVE_MOUNT_* flags
  *
- * Check permission before a mount is moved.
+ * Check permission before a mount is moved or cloned.
  *
  * Return: Returns 0 if permission is granted.
  */
 int security_move_mount(const struct path *from_path,
-			const struct path *to_path)
+			const struct path *to_path, unsigned int flags)
 {
-	return call_int_hook(move_mount, from_path, to_path);
+	return call_int_hook(move_mount, from_path, to_path, flags);
 }
 
 /**
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 5f6a81868341..efa003d0e142 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -2835,7 +2835,7 @@ static int selinux_mount(const char *dev_name,
 }
 
 static int selinux_move_mount(const struct path *from_path,
-			      const struct path *to_path)
+			      const struct path *to_path, unsigned int flags)
 {
 	const struct cred *cred = current_cred();
 
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 07/28] mount: Support MOVE_MOUNT_CLONE with MOVE_MOUNT_T_MNTNS
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (5 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 06/28] security: Pass flags to security_move_mount() Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 08/28] apparmor: Mediate MOVE_MOUNT_CLONE as recursive bind Jarkko Sakkinen
                   ` (20 subsequent siblings)
  27 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

Unprivileged container managers cannot use open_tree(OPEN_TREE_CLONE) in
the host mount namespace because it requires may_mount() against the
caller's current mount namespace rather than the destination namespace.

Add MOVE_MOUNT_CLONE for use with MOVE_MOUNT_T_MNTNS so move_mount() can
recursively loopback-clone a path from the caller's mount namespace
directly into the target mount namespace file descriptor. Authorize the
operation against CAP_SYS_ADMIN in target_mnt_ns->user_ns, apply
CL_SLAVE | CL_COPY_UNBINDABLE | CL_LOCK_SOURCE when crossing into a
foreign user namespace, and lock cross-user-namespace cloned subtrees
with MNT_LOCKED inside attach_recursive_mnt().

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 fs/namespace.c             | 93 ++++++++++++++++++++++++++++++--------
 include/uapi/linux/mount.h |  3 +-
 2 files changed, 75 insertions(+), 21 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index d73a215c9ae5..ced125eff59b 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2577,6 +2577,7 @@ enum mnt_tree_flags_t {
 	MNT_TREE_PROPAGATION = BIT(1),
 	MNT_TREE_MNTNS = BIT(2),
 	MNT_TREE_MNTNS_INIT = BIT(3),
+	MNT_TREE_CLONE = BIT(4),
 };
 
 /**
@@ -3809,31 +3810,28 @@ static int do_move_mount(const struct path *old_path,
 {
 	struct mount *old = real_mount(old_path->mnt);
 	struct user_namespace *src_user_ns = NULL;
+	struct mount *cloned = NULL;
 	struct mnt_namespace *dest_mnt_ns;
 	int err;
 	bool beneath = flags & MNT_TREE_BENEATH;
 
-	if (!path_mounted(old_path))
+	if (!(flags & MNT_TREE_CLONE) && !path_mounted(old_path))
 		return -EINVAL;
 
 	if (d_is_dir(new_path->dentry) != d_is_dir(old_path->dentry))
 		return -EINVAL;
 
+	if ((flags & MNT_TREE_CLONE) &&
+	    mnt_ns_loop_target(old_path->dentry, target_mnt_ns))
+		return -EINVAL;
+
 	LOCK_MOUNT_MAYBE_BENEATH(mp, new_path, beneath);
 	if (IS_ERR(mp.parent))
 		return PTR_ERR(mp.parent);
 
 	if (flags & MNT_TREE_MNTNS) {
-		u64 seq;
-
-		if (!anon_ns_root(old) || old->mnt_ns == mp.parent->mnt_ns ||
-		    mp.parent->mnt_ns != target_mnt_ns)
-			return -EINVAL;
-		seq = old->mnt_ns->seq_origin;
-		if (seq && seq != target_mnt_ns->ns.ns_id &&
-		    seq != current->nsproxy->mnt_ns->ns.ns_id)
+		if (mp.parent->mnt_ns != target_mnt_ns)
 			return -EINVAL;
-		src_user_ns = old->mnt_ns->user_ns;
 		if (flags & MNT_TREE_MNTNS_INIT) {
 			if (mp.parent != target_mnt_ns->root)
 				return -EBUSY;
@@ -3846,6 +3844,38 @@ static int do_move_mount(const struct path *old_path,
 			if (m == target_mnt_ns->root)
 				return beneath ? -EINVAL : -EBUSY;
 		}
+		if (flags & MNT_TREE_CLONE) {
+			unsigned int copy_flags;
+
+			if (!check_mnt(old) || old->mnt_ns == target_mnt_ns ||
+			    (old->mnt.mnt_sb->s_flags & SB_NOUSER))
+				return -EINVAL;
+			src_user_ns = old->mnt_ns->user_ns;
+			if (!in_userns(target_mnt_ns->user_ns, src_user_ns))
+				copy_flags = CL_SLAVE | CL_COPY_UNBINDABLE |
+					     CL_LOCK_SOURCE;
+			else
+				copy_flags = CL_COPY_MNT_NS_FILE;
+			cloned = __do_loopback(old_path, true, copy_flags);
+			if (IS_ERR(cloned))
+				return PTR_ERR(cloned);
+			old = cloned;
+			if (d_is_symlink(old->mnt.mnt_root)) {
+				err = -EINVAL;
+				goto out_cloned;
+			}
+		} else {
+			u64 seq;
+
+			if (!anon_ns_root(old) ||
+			    old->mnt_ns == mp.parent->mnt_ns)
+				return -EINVAL;
+			seq = old->mnt_ns->seq_origin;
+			if (seq && seq != target_mnt_ns->ns.ns_id &&
+			    seq != current->nsproxy->mnt_ns->ns.ns_id)
+				return -EINVAL;
+			src_user_ns = old->mnt_ns->user_ns;
+		}
 	} else if (check_mnt(old)) {
 		/* if the source is in our namespace... */
 		/* ... it should be detachable from parent */
@@ -3885,23 +3915,36 @@ static int do_move_mount(const struct path *old_path,
 			over = mp.parent->overmount;
 		err = can_move_mount_beneath(old, over, &mp);
 		if (err)
-			return err;
+			goto out_cloned;
 	}
 
 	/*
 	 * Don't move a mount tree containing unbindable mounts to a destination
 	 * mount which is shared.
 	 */
-	if (IS_MNT_SHARED(mp.parent) && tree_contains_unbindable(old))
-		return -EINVAL;
+	if (IS_MNT_SHARED(mp.parent) && tree_contains_unbindable(old)) {
+		err = -EINVAL;
+		goto out_cloned;
+	}
 	dest_mnt_ns = is_anon_ns(mp.parent->mnt_ns) ?
 		      current->nsproxy->mnt_ns : mp.parent->mnt_ns;
-	if (!check_for_nsfs_mounts(old, dest_mnt_ns))
-		return -ELOOP;
-	if (mount_is_ancestor(old, mp.parent))
-		return -ELOOP;
+	if (!check_for_nsfs_mounts(old, dest_mnt_ns)) {
+		err = -ELOOP;
+		goto out_cloned;
+	}
+	if (mount_is_ancestor(old, mp.parent)) {
+		err = -ELOOP;
+		goto out_cloned;
+	}
 
-	return attach_recursive_mnt(old, &mp, src_user_ns);
+	err = attach_recursive_mnt(old, &mp, src_user_ns);
+out_cloned:
+	if (err && cloned) {
+		lock_mount_hash();
+		umount_tree(cloned, UMOUNT_SYNC);
+		unlock_mount_hash();
+	}
+	return err;
 }
 
 static int do_move_mount_old(const struct path *path, const char *old_name)
@@ -4828,8 +4871,8 @@ static int lookup_move_mount_from(int from_dfd,
 /**
  * DOC: MOVE_MOUNT_T_MNTNS
  *
- * ``MOVE_MOUNT_T_MNTNS`` installs detached anonymous mount trees into a target
- * mount namespace ``nsfs`` file descriptor supplied as ``to_dfd``:
+ * ``MOVE_MOUNT_T_MNTNS`` installs mount trees into a target mount namespace
+ * ``nsfs`` file descriptor supplied as ``to_dfd``:
  *
  * 1. ``to_pathname`` of ``"/"`` attaches the initial root mount onto the
  *    ``nullfs`` root of an empty mount namespace at most once.
@@ -4837,6 +4880,11 @@ static int lookup_move_mount_from(int from_dfd,
  * 2. Relative ``to_pathname`` values resolve beneath the live root of the
  *    target mount namespace.
  *
+ * 3. Combining ``MOVE_MOUNT_CLONE`` with ``MOVE_MOUNT_T_MNTNS`` recursively
+ *    loopback-clones ``from_pathname`` from the caller's mount namespace into
+ *    ``to_dfd`` without requiring ``OPEN_TREE_CLONE`` or ``may_mount()`` in
+ *    the caller's own mount namespace.
+ *
  * Capability is checked against ``CAP_SYS_ADMIN`` in the target mount
  * namespace's owning user namespace, and source trees crossing user namespace
  * boundaries are locked with ``MNT_LOCKED`` and locked mount flags.
@@ -4938,12 +4986,17 @@ SYSCALL_DEFINE5(move_mount,
 	if (flags & ~MOVE_MOUNT__MASK)
 		return -EINVAL;
 
+	if ((flags & MOVE_MOUNT_CLONE) && !(flags & MOVE_MOUNT_T_MNTNS))
+		return -EINVAL;
+
 	if ((flags & (MOVE_MOUNT_BENEATH | MOVE_MOUNT_SET_GROUP)) ==
 	    (MOVE_MOUNT_BENEATH | MOVE_MOUNT_SET_GROUP))
 		return -EINVAL;
 
 	if (flags & MOVE_MOUNT_SET_GROUP)	mflags |= MNT_TREE_PROPAGATION;
 	if (flags & MOVE_MOUNT_BENEATH)		mflags |= MNT_TREE_BENEATH;
+	if (flags & MOVE_MOUNT_CLONE)
+		mflags |= MNT_TREE_CLONE;
 
 	if (unlikely(flags & MOVE_MOUNT_T_MNTNS)) {
 		if (flags & (MOVE_MOUNT_T_EMPTY_PATH | MOVE_MOUNT_SET_GROUP))
diff --git a/include/uapi/linux/mount.h b/include/uapi/linux/mount.h
index 7d413418426a..cb4f7175db02 100644
--- a/include/uapi/linux/mount.h
+++ b/include/uapi/linux/mount.h
@@ -78,7 +78,8 @@
 #define MOVE_MOUNT_T_MNTNS		0x00000080 /* Resolve to_dfd as mntns fd */
 #define MOVE_MOUNT_SET_GROUP		0x00000100 /* Set sharing group instead */
 #define MOVE_MOUNT_BENEATH		0x00000200 /* Mount beneath top mount */
-#define MOVE_MOUNT__MASK		0x000003f7
+#define MOVE_MOUNT_CLONE		0x00000400 /* Recursively clone from path */
+#define MOVE_MOUNT__MASK		0x000007f7
 
 /*
  * fsopen() flags.
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 08/28] apparmor: Mediate MOVE_MOUNT_CLONE as recursive bind
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (6 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 07/28] mount: Support MOVE_MOUNT_CLONE with MOVE_MOUNT_T_MNTNS Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05 13:48   ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 09/28] userns: Factor out install_user_ns_cred() Jarkko Sakkinen
                   ` (19 subsequent siblings)
  27 siblings, 1 reply; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

When move_mount() is invoked with MOVE_MOUNT_CLONE, the source mount is
recursively loopback-cloned from the caller's mount namespace into a
target mount namespace file descriptor rather than moved or attached
from a detached anonymous mount.

Pass flags through aa_move_mount(), mediate MOVE_MOUNT_CLONE as
MS_BIND | MS_REC while keeping from_path, reject detached or foreign
MOVE_MOUNT_CLONE sources with -EINVAL, and resolve cross-namespace
MOVE_MOUNT_T_MNTNS destination paths against the target mount namespace
root instead of treating them as disconnected paths.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 security/apparmor/include/mount.h |  2 +-
 security/apparmor/include/path.h  |  1 +
 security/apparmor/lsm.c           |  2 +-
 security/apparmor/mount.c         | 50 ++++++++++++++++++++-----------
 security/apparmor/path.c          |  6 ++--
 security/apparmor/policy_unpack.c |  6 ++--
 6 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/security/apparmor/include/mount.h b/security/apparmor/include/mount.h
index 46834f828179..d771ee240d42 100644
--- a/security/apparmor/include/mount.h
+++ b/security/apparmor/include/mount.h
@@ -43,7 +43,7 @@ int aa_move_mount_old(const struct cred *subj_cred,
 		      const char *old_name);
 int aa_move_mount(const struct cred *subj_cred,
 		  struct aa_label *label, const struct path *from_path,
-		  const struct path *to_path);
+		  const struct path *to_path, unsigned int flags);
 
 int aa_new_mount(const struct cred *subj_cred,
 		 struct aa_label *label, const char *dev_name,
diff --git a/security/apparmor/include/path.h b/security/apparmor/include/path.h
index 250812a77e11..22f420d54950 100644
--- a/security/apparmor/include/path.h
+++ b/security/apparmor/include/path.h
@@ -23,6 +23,7 @@ enum path_flags {
 
 	PATH_DELEGATE_DELETED = 0x10000, /* delegate deleted files */
 	PATH_MEDIATE_DELETED = 0x20000,	 /* mediate deleted paths */
+	PATH_TARGET_MNTNS = 0x40000,	 /* resolve path in target mntns */
 };
 
 int aa_path_name(const struct path *path, int flags, char *buffer,
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index aefa71bc1cd2..797944de8273 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -751,7 +751,7 @@ static int apparmor_move_mount(const struct path *from_path,
 	label = __begin_current_label_crit_section(&needput);
 	if (!unconfined(label))
 		error = aa_move_mount(current_cred(), label, from_path,
-				      to_path);
+				      to_path, flags);
 	__end_current_label_crit_section(label, needput);
 
 	return error;
diff --git a/security/apparmor/mount.c b/security/apparmor/mount.c
index 4ed7b9136beb..2dfe26e99fc1 100644
--- a/security/apparmor/mount.c
+++ b/security/apparmor/mount.c
@@ -231,6 +231,7 @@ static int path_flags(const struct aa_profile *profile, const struct path *path)
  * @data: fs mount data (MAYBE NULL)
  * @binary: whether @data is binary
  * @devinfo: error str if (IS_ERR(@devname))
+ * @pflags: extra path lookup flags for @mntpath
  * @ad: apparmor audit data structure
  *
  * Returns: 0 on success else error
@@ -239,7 +240,7 @@ static int match_mnt_path_str(struct aa_profile *profile,
 			      const struct path *mntpath, char *buffer,
 			      const char *devname, const char *type,
 			      unsigned long flags, void *data, bool binary,
-			      const char *devinfo,
+			      const char *devinfo, int pflags,
 			      struct apparmor_audit_data *ad)
 {
 	struct aa_perms perms = { };
@@ -256,8 +257,8 @@ static int match_mnt_path_str(struct aa_profile *profile,
 
 	ad->mnt.type = type;
 
-	error = aa_path_name(mntpath, path_flags(profile, mntpath), buffer,
-			     &mntpnt, &ad->info, profile->disconnected);
+	error = aa_path_name(mntpath, path_flags(profile, mntpath) | pflags,
+			     buffer, &mntpnt, &ad->info, profile->disconnected);
 	if (error)
 		return aa_audit_perm_error(&profile->label, AA_MAY_MOUNT,
 					   error, ad, audit_cb);
@@ -294,6 +295,7 @@ static int match_mnt_path_str(struct aa_profile *profile,
  * @flags: mount flags to match
  * @data: fs mount data (MAYBE NULL)
  * @binary: whether @data is binary
+ * @pflags: extra path lookup flags for @path
  * @ad: apparmor audit data structure
  *
  * Returns: 0 on success else error
@@ -301,7 +303,8 @@ static int match_mnt_path_str(struct aa_profile *profile,
 static int match_mnt(struct aa_profile *profile, const struct path *path,
 		     char *buffer, const struct path *devpath, char *devbuffer,
 		     const char *type, unsigned long flags, void *data,
-		     bool binary, struct apparmor_audit_data *ad)
+		     bool binary, int pflags,
+		     struct apparmor_audit_data *ad)
 {
 	const char *devname = NULL, *info = NULL;
 	struct aa_ruleset *rules = profile->label.rules[0];
@@ -322,7 +325,8 @@ static int match_mnt(struct aa_profile *profile, const struct path *path,
 	}
 
 	return match_mnt_path_str(profile, path, buffer, devname,
-				  type, flags, data, binary, info, ad);
+				  type, flags, data, binary, info,
+				  pflags, ad);
 }
 
 int aa_remount(const struct cred *subj_cred,
@@ -346,7 +350,7 @@ int aa_remount(const struct cred *subj_cred,
 		return -ENOMEM;
 	error = fn_for_each(label, profile,
 			match_mnt(profile, path, buffer, NULL, NULL, NULL,
-				  flags, data, binary, &ad));
+				  flags, data, binary, 0, &ad));
 	aa_put_buffer(buffer);
 
 	return error;
@@ -384,7 +388,8 @@ int aa_bind_mount(const struct cred *subj_cred,
 
 	error = fn_for_each(label, profile,
 			match_mnt(profile, path, buffer, &old_path,
-				  old_buffer, NULL, flags, NULL, false, &ad));
+				  old_buffer, NULL, flags, NULL, false, 0,
+				  &ad));
 out:
 	aa_put_buffer(buffer);
 	aa_put_buffer(old_buffer);
@@ -415,7 +420,7 @@ int aa_mount_change_type(const struct cred *subj_cred,
 		return -ENOMEM;
 	error = fn_for_each(label, profile,
 			match_mnt(profile, path, buffer, NULL, NULL, NULL,
-				  flags, NULL, false, &ad));
+				  flags, NULL, false, 0, &ad));
 	aa_put_buffer(buffer);
 
 	return error;
@@ -423,31 +428,40 @@ int aa_mount_change_type(const struct cred *subj_cred,
 
 int aa_move_mount(const struct cred *subj_cred,
 		  struct aa_label *label, const struct path *from_path,
-		  const struct path *to_path)
+		  const struct path *to_path, unsigned int flags)
 {
 	struct aa_profile *profile;
 	char *to_buffer = NULL, *from_buffer = NULL;
+	unsigned long mnt_flags = (flags & MOVE_MOUNT_CLONE) ?
+				  (MS_BIND | MS_REC) : MS_MOVE;
+	int pflags = 0;
 	int error;
 	DEFINE_AUDIT_MOUNT(ad, OP_MOUNT, subj_cred);
-	ad.mnt.flags = MS_MOVE;
+	ad.mnt.flags = mnt_flags;
 
 	AA_BUG(!label);
 	AA_BUG(!from_path);
 	AA_BUG(!to_path);
 
+	if (!our_mnt(from_path->mnt)) {
+		if (flags & MOVE_MOUNT_CLONE)
+			return -EINVAL;
+		/* moving a mount detached from the namespace */
+		from_path = NULL;
+	}
+
 	to_buffer = aa_get_buffer(false);
 	from_buffer = aa_get_buffer(false);
 	error = -ENOMEM;
 	if (!to_buffer || !from_buffer)
 		goto out;
 
-	if (!our_mnt(from_path->mnt))
-		/* moving a mount detached from the namespace */
-		from_path = NULL;
+	if ((flags & MOVE_MOUNT_T_MNTNS) && !our_mnt(to_path->mnt))
+		pflags = PATH_TARGET_MNTNS;
 	error = fn_for_each(label, profile,
 			match_mnt(profile, to_path, to_buffer, from_path,
-				  from_buffer, NULL, MS_MOVE, NULL, false,
-				  &ad));
+				  from_buffer, NULL, mnt_flags, NULL, false,
+				  pflags, &ad));
 out:
 	aa_put_buffer(to_buffer);
 	aa_put_buffer(from_buffer);
@@ -467,7 +481,7 @@ int aa_move_mount_old(const struct cred *subj_cred, struct aa_label *label,
 	if (error)
 		return error;
 
-	error = aa_move_mount(subj_cred, label, &old_path, path);
+	error = aa_move_mount(subj_cred, label, &old_path, path, 0);
 	path_put(&old_path);
 
 	return error;
@@ -524,12 +538,12 @@ int aa_new_mount(const struct cred *subj_cred, struct aa_label *label,
 		error = fn_for_each(label, profile,
 				match_mnt(profile, path, buffer, dev_path,
 					  dev_buffer, type, flags, data,
-					  binary, &ad));
+					  binary, 0, &ad));
 	} else {
 		error = fn_for_each(label, profile,
 				match_mnt_path_str(profile, path, buffer,
 						   dev_name, type, flags, data,
-						   binary, NULL, &ad));
+						   binary, NULL, 0, &ad));
 	}
 
 out:
diff --git a/security/apparmor/path.c b/security/apparmor/path.c
index 2494e8101538..3443f5a86871 100644
--- a/security/apparmor/path.c
+++ b/security/apparmor/path.c
@@ -116,14 +116,14 @@ static int d_namespace_path(const struct path *path, char *buf, char **name,
 	}
 
 	/* resolve paths relative to chroot?*/
-	if (flags & PATH_CHROOT_REL) {
+	if ((flags & PATH_CHROOT_REL) && !(flags & PATH_TARGET_MNTNS)) {
 		struct path root;
 		get_fs_root(current->fs, &root);
 		res = __d_path(path, &root, buf, buflen);
 		path_put(&root);
 	} else {
 		res = d_absolute_path(path, buf, buflen);
-		if (!our_mnt(path->mnt))
+		if (!(flags & PATH_TARGET_MNTNS) && !our_mnt(path->mnt))
 			connected = 0;
 	}
 
@@ -143,7 +143,7 @@ static int d_namespace_path(const struct path *path, char *buf, char **name,
 			*name = buf;
 			goto out;
 		}
-	} else if (!our_mnt(path->mnt))
+	} else if (!(flags & PATH_TARGET_MNTNS) && !our_mnt(path->mnt))
 		connected = 0;
 
 	*name = res;
diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c
index 24fbce2e4322..0965e2f65509 100644
--- a/security/apparmor/policy_unpack.c
+++ b/security/apparmor/policy_unpack.c
@@ -1244,12 +1244,14 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
 		goto fail;
 
 	/* path_flags is optional */
-	if (aa_unpack_u32(e, &profile->path_flags, "path_flags"))
+	if (aa_unpack_u32(e, &profile->path_flags, "path_flags")) {
+		profile->path_flags &= ~PATH_TARGET_MNTNS;
 		profile->path_flags |= profile->label.flags &
 			PATH_MEDIATE_DELETED;
-	else
+	} else {
 		/* set a default value if path_flags field is not present */
 		profile->path_flags = PATH_MEDIATE_DELETED;
+	}
 
 	info = "failed to unpack profile capabilities";
 	if (!aa_unpack_cap_low(e, &rules->caps.allow, NULL))
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 09/28] userns: Factor out install_user_ns_cred()
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (7 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 08/28] apparmor: Mediate MOVE_MOUNT_CLONE as recursive bind Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 10/28] nsproxy: Expose create_new_namespaces() Jarkko Sakkinen
                   ` (18 subsequent siblings)
  27 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

userns_install() updates a credential's owning user namespace and
rebinds its ucounts inline, which cannot be reused by fork paths that
switch a newly allocated child credential into a target user namespace.

Factor this logic out into install_user_ns_cred() with a !CONFIG_USER_NS
stub so callers outside kernel/user_namespace.c can install a target
user namespace on a prepared struct cred.

Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 include/linux/user_namespace.h |  7 +++++++
 kernel/user_namespace.c        | 12 ++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
index 190e8c1fe202..7181c6011b44 100644
--- a/include/linux/user_namespace.h
+++ b/include/linux/user_namespace.h
@@ -183,6 +183,7 @@ static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
 }
 
 extern int create_user_ns(struct cred *new);
+int install_user_ns_cred(struct cred *cred, struct user_namespace *user_ns);
 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
 extern void __put_user_ns(struct user_namespace *ns);
 
@@ -227,6 +228,12 @@ static inline int create_user_ns(struct cred *new)
 	return -EINVAL;
 }
 
+static inline int install_user_ns_cred(struct cred *cred,
+				       struct user_namespace *user_ns)
+{
+	return -EINVAL;
+}
+
 static inline int unshare_userns(unsigned long unshare_flags,
 				 struct cred **new_cred)
 {
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 73daac18e634..0a6d77b57798 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -1588,6 +1588,13 @@ static void userns_put(struct ns_common *ns)
 	put_user_ns(to_user_ns(ns));
 }
 
+int install_user_ns_cred(struct cred *cred, struct user_namespace *user_ns)
+{
+	put_user_ns(cred->user_ns);
+	set_cred_user_ns(cred, get_user_ns(user_ns));
+	return set_cred_ucounts(cred);
+}
+
 static int userns_install(struct nsset *nsset, struct ns_common *ns)
 {
 	struct user_namespace *user_ns = to_user_ns(ns);
@@ -1613,10 +1620,7 @@ static int userns_install(struct nsset *nsset, struct ns_common *ns)
 	if (!cred)
 		return -EINVAL;
 
-	put_user_ns(cred->user_ns);
-	set_cred_user_ns(cred, get_user_ns(user_ns));
-
-	if (set_cred_ucounts(cred) < 0)
+	if (install_user_ns_cred(cred, user_ns) < 0)
 		return -EINVAL;
 
 	return 0;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 10/28] nsproxy: Expose create_new_namespaces()
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (8 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 09/28] userns: Factor out install_user_ns_cred() Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 11/28] runfd: Add core infrastructure Jarkko Sakkinen
                   ` (17 subsequent siblings)
  27 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

create_new_namespaces() is currently static to kernel/nsproxy.c,
preventing callers outside kernel/nsproxy.c from constructing a child
nsproxy without mutating a task.

Expose create_new_namespaces() in <linux/nsproxy.h> so runfd()
can allocate a detached namespace set from current.

Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 include/linux/nsproxy.h | 4 ++++
 kernel/nsproxy.c        | 6 +++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/linux/nsproxy.h b/include/linux/nsproxy.h
index dc2447f5f092..d611c40cb4ce 100644
--- a/include/linux/nsproxy.h
+++ b/include/linux/nsproxy.h
@@ -12,6 +12,7 @@ struct ipc_namespace;
 struct pid_namespace;
 struct cgroup_namespace;
 struct fs_struct;
+struct user_namespace;
 
 /*
  * A structure to contain pointers to all per-process
@@ -92,6 +93,9 @@ static inline struct cred *nsset_cred(struct nsset *set)
  *
  */
 
+struct nsproxy *create_new_namespaces(u64 flags, struct task_struct *tsk,
+				      struct user_namespace *user_ns,
+				      struct fs_struct *new_fs);
 int copy_namespaces(u64 flags, struct task_struct *tsk);
 void switch_cred_namespaces(const struct cred *old, const struct cred *new);
 void exit_nsproxy_namespaces(struct task_struct *tsk);
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index 2dcf105e8ee2..3c4161515c3c 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -85,9 +85,9 @@ void deactivate_nsproxy(struct nsproxy *ns)
  * Return the newly created nsproxy.  Do not attach this to the task,
  * leave it to the caller to do proper locking and attach it to task.
  */
-static struct nsproxy *create_new_namespaces(u64 flags,
-	struct task_struct *tsk, struct user_namespace *user_ns,
-	struct fs_struct *new_fs)
+struct nsproxy *create_new_namespaces(u64 flags, struct task_struct *tsk,
+				      struct user_namespace *user_ns,
+				      struct fs_struct *new_fs)
 {
 	struct nsproxy *new_nsp;
 	int err;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 11/28] runfd: Add core infrastructure
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (9 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 10/28] nsproxy: Expose create_new_namespaces() Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 12/28] runfd: Track init lifecycle via copy_process() and pid_namespace Jarkko Sakkinen
                   ` (16 subsequent siblings)
  27 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

Linux namespaces can be created and entered individually, but userspace
orchestrators lack a single control object that binds a full detached
namespace set and an init process lifecycle behind a pollable file
descriptor. Because this object manages process lifecycle, wait and
signal delivery, VFS mount delegation, and LSM state rather than
representing an nsfs namespace entity, model it as a distinct run
abstraction.

Add struct run, its lifecycle states, reference counting, uAPI
flags, and anonymous inode file operations under CONFIG_RUNFD. Drop
active and passive namespace references on final release, send SIGKILL
to the run init thread group on close when RUNFD_AUTOKILL
is set, and report EPOLLHUP from poll() once the run reaches
RUNFD_DEAD.

Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 include/linux/runfd.h      | 83 ++++++++++++++++++++++++++++++++
 include/uapi/linux/runfd.h | 22 +++++++++
 init/Kconfig               | 10 ++++
 kernel/Makefile            |  2 +
 kernel/runfd.c             | 96 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 213 insertions(+)
 create mode 100644 include/linux/runfd.h
 create mode 100644 include/uapi/linux/runfd.h
 create mode 100644 kernel/runfd.c

diff --git a/include/linux/runfd.h b/include/linux/runfd.h
new file mode 100644
index 000000000000..d7faba4da949
--- /dev/null
+++ b/include/linux/runfd.h
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2019 Red Hat, Inc. All Rights Reserved.
+ * Copyright (C) 2026 Opinsys Oy
+ */
+
+#ifndef _LINUX_RUNFD_H
+#define _LINUX_RUNFD_H
+
+#include <linux/refcount.h>
+#include <linux/spinlock.h>
+#include <linux/wait.h>
+#include <uapi/linux/runfd.h>
+
+#define RUNFD_ALL_FLAGS	RUNFD_AUTOKILL
+
+struct file;
+struct nsproxy;
+struct pid;
+struct user_namespace;
+
+/**
+ * enum runfd_state - run lifecycle states
+ * @RUNFD_INIT:	Build phase after ``runfd()`` before any
+ *			process has entered. ``RUNFD_SHARE_NSFD`` is
+ *			permitted, ID mappings may be configured on the owning
+ *			user namespace, and ``"/"`` must be mounted in the
+ *			mount namespace before entry.
+ * @RUNFD_FORKING:	Bootstrap phase while the first
+ *			``clone3(CLONE_INTO_RUN)`` call creates PID 1.
+ *			Concurrent callers wait killably; reverts to
+ *			%RUNFD_INIT if ``copy_process()`` fails, or advances
+ *			to %RUNFD_RUNNING once PID 1 is attached.
+ * @RUNFD_RUNNING:	Live phase while PID 1 is attached. Subsequent
+ *			``clone3(CLONE_INTO_RUN)`` calls join the PID
+ *			namespace until teardown begins,
+ *			``RUNFD_GET_NSFD(CLONE_NEWPID)`` and
+ *			``pidfd_send_signal()`` are enabled, and
+ *			``RUNFD_SHARE_NSFD`` returns ``-EBUSY``.
+ * @RUNFD_DEAD:	Terminal phase entered after PID 1 exits and the PID
+ *			namespace has killed and reaped all member processes.
+ *			``poll()`` reports ``EPOLLHUP`` and
+ *			``waitid(P_RUNFD, ...)`` reports PID 1's exit status
+ *			without consuming it.
+ *
+ * State transitions advance from %RUNFD_INIT through %RUNFD_FORKING and
+ * %RUNFD_RUNNING to %RUNFD_DEAD, reverting from %RUNFD_FORKING to
+ * %RUNFD_INIT only if the initial bootstrap fork fails.
+ */
+enum runfd_state {
+	RUNFD_INIT	= 0,
+	RUNFD_FORKING	= 1,
+	RUNFD_RUNNING	= 2,
+	RUNFD_DEAD	= 3,
+};
+
+struct run {
+	refcount_t		usage;
+	int			exit_code;
+	struct user_namespace	*user_ns;
+	struct nsproxy		*ns;
+	struct pid		*init_pid;
+	spinlock_t		lock;		/* Guards run lifecycle state */
+	wait_queue_head_t	waitq;
+	unsigned int		flags;
+	enum runfd_state	state;
+};
+
+#ifdef CONFIG_RUNFD
+void runfd_put(struct run *c);
+bool runfd_is_file(struct file *file);
+#else
+static inline void runfd_put(struct run *c)
+{
+}
+
+static inline bool runfd_is_file(struct file *file)
+{
+	return false;
+}
+#endif /* CONFIG_RUNFD */
+
+#endif /* _LINUX_RUNFD_H */
diff --git a/include/uapi/linux/runfd.h b/include/uapi/linux/runfd.h
new file mode 100644
index 000000000000..f46a757b1159
--- /dev/null
+++ b/include/uapi/linux/runfd.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2017-2019 Red Hat, Inc. All Rights Reserved.
+ * Copyright (C) 2026 Opinsys Oy
+ */
+
+#ifndef _UAPI_LINUX_RUNFD_H
+#define _UAPI_LINUX_RUNFD_H
+
+/**
+ * enum runfd_flags - Flags for runfd()
+ * @RUNFD_AUTOKILL:	Send %SIGKILL to run init on final fd release.
+ *
+ * Every run created by runfd() allocates a full set of
+ * detached namespaces owned by a fresh user namespace and sets %O_CLOEXEC
+ * on the returned control file descriptor.
+ */
+enum runfd_flags {
+	RUNFD_AUTOKILL	= 0x00000001,
+};
+
+#endif /* _UAPI_LINUX_RUNFD_H */
diff --git a/init/Kconfig b/init/Kconfig
index c8a7cfa60a6e..ffd0f1c19c4c 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1281,6 +1281,16 @@ config NET_NS
 	  Allow user space to create what appear to be multiple instances
 	  of the network stack.
 
+config RUNFD
+	bool "Container run descriptors"
+	depends on USER_NS && PID_NS && UTS_NS && IPC_NS && NET_NS && CGROUPS
+	help
+	  Allow user space to open and manage isolated runs and their init
+	  process lifecycle through an anonymous-inode control file descriptor
+	  via runfd(), waitid(P_RUNFD), pidfd_send_signal(),
+	  RUNFD_GET_NSFD, RUNFD_SHARE_NSFD, FSCONFIG_SET_RUN, and
+	  clone3() with CLONE_INTO_RUN.
+
 endif # NAMESPACES
 
 config CHECKPOINT_RESTORE
diff --git a/kernel/Makefile b/kernel/Makefile
index 4ff92e24680c..eb39bd150903 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -152,6 +152,8 @@ KCOV_INSTRUMENT_kstack_erase.o := n
 
 obj-$(CONFIG_SCF_TORTURE_TEST) += scftorture.o
 
+obj-$(CONFIG_RUNFD) += runfd.o
+
 $(obj)/configs.o: $(obj)/config_data.gz
 
 # .config is small, so it is compressed with gzip rather than the image compressor.
diff --git a/kernel/runfd.c b/kernel/runfd.c
new file mode 100644
index 000000000000..019e90e8bf2f
--- /dev/null
+++ b/kernel/runfd.c
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2017-2019 Red Hat, Inc. All Rights Reserved.
+ * Copyright (C) 2026 Opinsys Oy
+ */
+
+/**
+ * DOC: Overview
+ *
+ * A run is one instance of a container, from setup through init exit.
+ * ``runfd()`` creates a run and returns its control file descriptor before
+ * any process starts. Namespaces can be configured through file descriptors
+ * before ``clone3()`` starts init.
+ */
+
+#include <linux/poll.h>
+#include <linux/wait.h>
+#include <uapi/linux/wait.h>
+#include <linux/file.h>
+#include <linux/fs.h>
+#include <linux/anon_inodes.h>
+#include <linux/runfd.h>
+#include <linux/sched/signal.h>
+#include <linux/sched/task.h>
+#include <linux/slab.h>
+#include <linux/syscalls.h>
+#include <linux/uaccess.h>
+#include <linux/mnt_namespace.h>
+#include <linux/nsproxy.h>
+#include <linux/ns_common.h>
+#include <linux/nsfs.h>
+#include <linux/pid.h>
+#include <linux/pid_namespace.h>
+#include <linux/time_namespace.h>
+#include <linux/user_namespace.h>
+#include <linux/idr.h>
+#include <uapi/linux/runfd.h>
+
+void runfd_put(struct run *c)
+{
+	if (!c || !refcount_dec_and_test(&c->usage))
+		return;
+
+	if (c->ns)
+		put_nsproxy(c->ns);
+	if (c->init_pid)
+		put_pid(c->init_pid);
+	if (c->user_ns) {
+		ns_ref_active_put(c->user_ns);
+		put_user_ns(c->user_ns);
+	}
+	kfree(c);
+}
+
+static __poll_t runfd_poll(struct file *file, poll_table *wait)
+{
+	struct run *run = file->private_data;
+	__poll_t mask = 0;
+
+	poll_wait(file, &run->waitq, wait);
+
+	if (READ_ONCE(run->state) == RUNFD_DEAD)
+		mask |= EPOLLHUP;
+
+	return mask;
+}
+
+static int runfd_release(struct inode *inode, struct file *file)
+{
+	struct run *run = file->private_data;
+
+	if (run->flags & RUNFD_AUTOKILL) {
+		struct pid *pid = NULL;
+
+		scoped_guard(spinlock, &run->lock) {
+			if (run->state == RUNFD_RUNNING)
+				pid = get_pid(run->init_pid);
+		}
+		if (pid) {
+			kill_pid(pid, SIGKILL, true);
+			put_pid(pid);
+		}
+	}
+	runfd_put(run);
+	return 0;
+}
+
+static const struct file_operations runfd_fops = {
+	.poll		= runfd_poll,
+	.release	= runfd_release,
+};
+
+bool runfd_is_file(struct file *file)
+{
+	return file->f_op == &runfd_fops;
+}
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 12/28] runfd: Track init lifecycle via copy_process() and pid_namespace
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (10 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 11/28] runfd: Add core infrastructure Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 13/28] runfd: Add runfd() system call Jarkko Sakkinen
                   ` (15 subsequent siblings)
  27 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

A run needs to record its init thread group's PID when bootstrapped
and capture its exit status and UID once all processes in the run
have terminated, without serializing normal fork() and exit() paths
inside the run.

Commit the bootstrap child reaper and bind pid_ns->run in
runfd_copy() after copy_process() attaches PIDs and drops
tasklist_lock, and invoke runfd_exit() from zap_pid_ns_processes()
after the run's PID namespace has killed and reaped all member
tasks.

Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 include/linux/pid_namespace.h |  4 ++++
 include/linux/runfd.h         | 15 +++++++++++++
 kernel/fork.c                 |  4 ++++
 kernel/pid_namespace.c        |  2 ++
 kernel/runfd.c                | 41 +++++++++++++++++++++++++++++++++++
 5 files changed, 66 insertions(+)

diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
index b20baaa7e62b..996293e832db 100644
--- a/include/linux/pid_namespace.h
+++ b/include/linux/pid_namespace.h
@@ -15,6 +15,7 @@
 #define MAX_PID_NS_LEVEL 32
 
 struct fs_pin;
+struct run;
 
 #if defined(CONFIG_SYSCTL) && defined(CONFIG_MEMFD_CREATE)
 /* modes for vm.memfd_noexec sysctl */
@@ -45,6 +46,9 @@ struct pid_namespace {
 	struct user_namespace *user_ns;
 	struct ucounts *ucounts;
 	int reboot;	/* group exit code if this pidns was rebooted */
+#ifdef CONFIG_RUNFD
+	struct run *run;
+#endif
 	struct ns_common ns;
 	struct work_struct	work;
 } __randomize_layout;
diff --git a/include/linux/runfd.h b/include/linux/runfd.h
index d7faba4da949..8f18afee7d5b 100644
--- a/include/linux/runfd.h
+++ b/include/linux/runfd.h
@@ -9,6 +9,7 @@
 
 #include <linux/refcount.h>
 #include <linux/spinlock.h>
+#include <linux/uidgid.h>
 #include <linux/wait.h>
 #include <uapi/linux/runfd.h>
 
@@ -17,6 +18,8 @@
 struct file;
 struct nsproxy;
 struct pid;
+struct pid_namespace;
+struct task_struct;
 struct user_namespace;
 
 /**
@@ -60,6 +63,7 @@ struct run {
 	struct user_namespace	*user_ns;
 	struct nsproxy		*ns;
 	struct pid		*init_pid;
+	kuid_t			init_uid;
 	spinlock_t		lock;		/* Guards run lifecycle state */
 	wait_queue_head_t	waitq;
 	unsigned int		flags;
@@ -69,6 +73,8 @@ struct run {
 #ifdef CONFIG_RUNFD
 void runfd_put(struct run *c);
 bool runfd_is_file(struct file *file);
+void runfd_copy(struct pid *pid, struct run *run);
+void runfd_exit(struct pid_namespace *pid_ns, struct task_struct *tsk);
 #else
 static inline void runfd_put(struct run *c)
 {
@@ -78,6 +84,15 @@ static inline bool runfd_is_file(struct file *file)
 {
 	return false;
 }
+
+static inline void runfd_copy(struct pid *pid, struct run *run)
+{
+}
+
+static inline void runfd_exit(struct pid_namespace *pid_ns,
+			      struct task_struct *tsk)
+{
+}
 #endif /* CONFIG_RUNFD */
 
 #endif /* _LINUX_RUNFD_H */
diff --git a/kernel/fork.c b/kernel/fork.c
index 31c954cd00d7..46032e74e629 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -83,6 +83,7 @@
 #include <linux/fs_struct.h>
 #include <linux/magic.h>
 #include <linux/perf_event.h>
+#include <linux/runfd.h>
 #include <linux/posix-timers.h>
 #include <linux/user-return-notifier.h>
 #include <linux/oom.h>
@@ -2571,6 +2572,9 @@ __latent_entropy struct task_struct *copy_process(
 	syscall_tracepoint_update(p);
 	write_unlock_irq(&tasklist_lock);
 
+	if (likely(p->pid) && thread_group_leader(p))
+		runfd_copy(pid, NULL);
+
 	if (pidfile)
 		fd_install(pidfd, pidfile);
 
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 127a5fd23e70..4ffef95f5e28 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -24,6 +24,7 @@
 #include <linux/sched/signal.h>
 #include <linux/idr.h>
 #include <linux/nstree.h>
+#include <linux/runfd.h>
 #include <uapi/linux/wait.h>
 #include "pid_sysctl.h"
 
@@ -280,6 +281,7 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
 		current->signal->group_exit_code = pid_ns->reboot;
 
 	acct_exit_ns(pid_ns);
+	runfd_exit(pid_ns, me);
 	return;
 }
 
diff --git a/kernel/runfd.c b/kernel/runfd.c
index 019e90e8bf2f..2dfd5c55ca41 100644
--- a/kernel/runfd.c
+++ b/kernel/runfd.c
@@ -94,3 +94,44 @@ bool runfd_is_file(struct file *file)
 {
 	return file->f_op == &runfd_fops;
 }
+
+void runfd_copy(struct pid *pid, struct run *c)
+{
+	if (likely(!c || !is_child_reaper(pid)))
+		return;
+
+	scoped_guard(spinlock, &c->lock) {
+		if (c->state != RUNFD_FORKING)
+			return;
+		refcount_inc(&c->usage);
+		ns_of_pid(pid)->run = c;
+		WRITE_ONCE(c->init_pid, get_pid(pid));
+		WRITE_ONCE(c->state, RUNFD_RUNNING);
+	}
+}
+
+void runfd_exit(struct pid_namespace *pid_ns, struct task_struct *tsk)
+{
+	struct run *c = pid_ns->run;
+	struct task_struct *leader;
+	kuid_t uid;
+	int status;
+
+	if (!c)
+		return;
+
+	leader = tsk->group_leader;
+	uid = task_uid(leader);
+	status = (tsk->signal->flags & SIGNAL_GROUP_EXIT) ?
+		 tsk->signal->group_exit_code : leader->exit_code;
+
+	scoped_guard(spinlock, &c->lock) {
+		c->exit_code = status;
+		c->init_uid = uid;
+		WRITE_ONCE(c->state, RUNFD_DEAD);
+	}
+
+	pid_ns->run = NULL;
+	__wake_up(&c->waitq, TASK_NORMAL, 0, poll_to_key(EPOLLHUP));
+	runfd_put(c);
+}
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 13/28] runfd: Add runfd() system call
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (11 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 12/28] runfd: Track init lifecycle via copy_process() and pid_namespace Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 14/28] runfd: Add RUNFD_GET_NSFD ioctl Jarkko Sakkinen
                   ` (14 subsequent siblings)
  27 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

Setting up an isolated namespace environment from a multithreaded
manager process currently requires helper processes to call unshare()
and pass file descriptors back over sockets.

Add the runfd() system call to allocate a run owning a
fresh user namespace alongside dedicated empty mount
(CLONE_EMPTY_MNTNS), PID, UTS, IPC, network, cgroup, and time
namespaces, and return its anonymous-inode file descriptor. Because a
run encapsulates process lifecycle and mount delegation rather than
an nsfs namespace entity, keep it separate from namespace creation APIs.
Finalize the nsproxy time namespace and pin active references for the
lifetime of the run.

Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 include/linux/syscalls.h |   1 +
 kernel/runfd.c           | 107 +++++++++++++++++++++++++++++++++++++++
 kernel/sys_ni.c          |   3 ++
 3 files changed, 111 insertions(+)

diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 552d9710a0d5..2c2db703a005 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -1006,6 +1006,7 @@ asmlinkage long sys_lsm_get_self_attr(unsigned int attr, struct lsm_ctx __user *
 asmlinkage long sys_lsm_set_self_attr(unsigned int attr, struct lsm_ctx __user *ctx,
 				      u32 size, u32 flags);
 asmlinkage long sys_lsm_list_modules(u64 __user *ids, u32 __user *size, u32 flags);
+asmlinkage long sys_runfd(unsigned int flags);
 
 /*
  * Architecture-specific system calls
diff --git a/kernel/runfd.c b/kernel/runfd.c
index 2dfd5c55ca41..6b250796c24e 100644
--- a/kernel/runfd.c
+++ b/kernel/runfd.c
@@ -135,3 +135,110 @@ void runfd_exit(struct pid_namespace *pid_ns, struct task_struct *tsk)
 	__wake_up(&c->waitq, TASK_NORMAL, 0, poll_to_key(EPOLLHUP));
 	runfd_put(c);
 }
+
+static struct user_namespace *runfd_create_user_ns(void)
+{
+	struct user_namespace *user_ns;
+	struct cred *new;
+	int ret;
+
+	new = prepare_creds();
+	if (!new)
+		return ERR_PTR(-ENOMEM);
+
+	ret = create_user_ns(new);
+	if (ret < 0) {
+		abort_creds(new);
+		return ERR_PTR(ret);
+	}
+
+	user_ns = get_user_ns(new->user_ns);
+	abort_creds(new);
+	return user_ns;
+}
+
+static struct run *runfd_create(unsigned int flags)
+{
+	u64 clone_flags = CLONE_NEWNS | CLONE_EMPTY_MNTNS | CLONE_NEWPID |
+			  CLONE_NEWCGROUP | CLONE_NEWUTS | CLONE_NEWIPC |
+			  CLONE_NEWNET |
+			  (IS_ENABLED(CONFIG_TIME_NS) ? CLONE_NEWTIME : 0);
+	struct user_namespace *user_ns;
+	struct nsproxy *ns;
+	struct run *c;
+	int ret;
+
+	c = kzalloc_obj(*c, GFP_KERNEL);
+	if (!c)
+		return ERR_PTR(-ENOMEM);
+
+	init_waitqueue_head(&c->waitq);
+	spin_lock_init(&c->lock);
+	refcount_set(&c->usage, 1);
+	c->flags = flags;
+
+	user_ns = runfd_create_user_ns();
+	if (IS_ERR(user_ns)) {
+		ret = PTR_ERR(user_ns);
+		goto err_put;
+	}
+	c->user_ns = user_ns;
+	ns_ref_active_get(user_ns);
+
+	if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
+		ret = -EPERM;
+		goto err_put;
+	}
+
+	ns = create_new_namespaces(clone_flags, current, user_ns, NULL);
+	if (IS_ERR(ns)) {
+		ret = PTR_ERR(ns);
+		goto err_put;
+	}
+
+	if (ns->time_ns != ns->time_ns_for_children) {
+		get_time_ns(ns->time_ns_for_children);
+		put_time_ns(ns->time_ns);
+		ns->time_ns = ns->time_ns_for_children;
+	}
+	c->ns = ns;
+	nsproxy_ns_active_get(ns);
+
+	return c;
+
+err_put:
+	runfd_put(c);
+	return ERR_PTR(ret);
+}
+
+/**
+ * sys_runfd - Create a run and return its file descriptor
+ * @flags: Combination of &enum runfd_flags values
+ *
+ * Allocate a run owning a fresh child user namespace (with the caller's
+ * effective UID and GID as owner and initially empty ID mappings) and dedicated
+ * empty mount, PID, UTS, IPC, network, cgroup, and time namespaces. Control
+ * operations authorize against capabilities in the run's owning user
+ * namespace.
+ *
+ * Return: Close-on-exec run file descriptor on success, negative error code
+ *         on failure.
+ */
+SYSCALL_DEFINE1(runfd, unsigned int, flags)
+{
+	struct run *c;
+	int fd;
+
+	if (flags & ~RUNFD_ALL_FLAGS)
+		return -EINVAL;
+
+	c = runfd_create(flags);
+	if (IS_ERR(c))
+		return PTR_ERR(c);
+
+	fd = anon_inode_getfd("runfd", &runfd_fops, c, O_RDWR | O_CLOEXEC);
+	if (fd < 0)
+		runfd_put(c);
+
+	return fd;
+}
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index c8be0abaa407..9c9ee50443fb 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -398,3 +398,6 @@ COND_SYSCALL(rseq_slice_yield);
 
 COND_SYSCALL(uretprobe);
 COND_SYSCALL(uprobe);
+
+/* kernel/runfd.c */
+COND_SYSCALL(runfd);
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 14/28] runfd: Add RUNFD_GET_NSFD ioctl
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (12 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 13/28] runfd: Add runfd() system call Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 15/28] runfd: Add RUNFD_SHARE_NSFD ioctl Jarkko Sakkinen
                   ` (13 subsequent siblings)
  27 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

Standalone namespace operations such as NS_SET_IDMAP and
move_mount(..., MOVE_MOUNT_T_MNTNS) operate on nsfs file descriptors,
requiring a way to obtain member namespace fds from a run file
descriptor before any process has entered it.

Add the RUNFD_GET_NSFD ioctl to open an O_CLOEXEC nsfs file
descriptor for a requested member namespace when the caller holds
CAP_SYS_ADMIN in the run's user namespace, additionally requiring
an ancestor active PID namespace and a running init process for
CLONE_NEWPID.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 fs/internal.h              |  1 -
 include/linux/nsfs.h       |  1 +
 include/uapi/linux/runfd.h | 19 ++++++++++
 kernel/runfd.c             | 76 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+), 1 deletion(-)

diff --git a/fs/internal.h b/fs/internal.h
index 3f2fbac40f8e..ee3f796241ac 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -250,7 +250,6 @@ extern void mnt_pin_kill(struct mount *m);
  * fs/nsfs.c
  */
 extern const struct dentry_operations ns_dentry_operations;
-int open_namespace(struct ns_common *ns);
 struct file *open_namespace_file(struct ns_common *ns);
 
 /*
diff --git a/include/linux/nsfs.h b/include/linux/nsfs.h
index 731b67fc2fec..40912c1eb5ff 100644
--- a/include/linux/nsfs.h
+++ b/include/linux/nsfs.h
@@ -23,6 +23,7 @@ bool ns_match(const struct ns_common *ns, dev_t dev, ino_t ino);
 int ns_get_name(char *buf, size_t size, struct task_struct *task,
 			const struct proc_ns_operations *ns_ops);
 void nsfs_init(void);
+int open_namespace(struct ns_common *ns);
 
 #define __current_namespace_from_type(__ns)				\
 	_Generic((__ns),						\
diff --git a/include/uapi/linux/runfd.h b/include/uapi/linux/runfd.h
index f46a757b1159..7c4ecc5e4f1c 100644
--- a/include/uapi/linux/runfd.h
+++ b/include/uapi/linux/runfd.h
@@ -7,6 +7,8 @@
 #ifndef _UAPI_LINUX_RUNFD_H
 #define _UAPI_LINUX_RUNFD_H
 
+#include <linux/ioctl.h>
+
 /**
  * enum runfd_flags - Flags for runfd()
  * @RUNFD_AUTOKILL:	Send %SIGKILL to run init on final fd release.
@@ -19,4 +21,21 @@ enum runfd_flags {
 	RUNFD_AUTOKILL	= 0x00000001,
 };
 
+#define RUNFD_IOCTL_MAGIC	0xB9
+
+/**
+ * DOC: RUNFD_GET_NSFD
+ *
+ * ``ioctl(run_fd, RUNFD_GET_NSFD, nstype)`` opens an ``nsfs`` file
+ * descriptor (with ``O_CLOEXEC``) for the member namespace identified by
+ * ``nstype`` (one of ``CLONE_NEWNS``, ``CLONE_NEWCGROUP``,
+ * ``CLONE_NEWUTS``, ``CLONE_NEWIPC``, ``CLONE_NEWUSER``, ``CLONE_NEWPID``,
+ * ``CLONE_NEWNET``, or ``CLONE_NEWTIME``).
+ *
+ * Requires ``CAP_SYS_ADMIN`` in the run's user namespace.
+ * Opening ``CLONE_NEWPID`` additionally requires running in an ancestor
+ * active PID namespace and that run init is running.
+ */
+#define RUNFD_GET_NSFD	_IO(RUNFD_IOCTL_MAGIC, 0x01)
+
 #endif /* _UAPI_LINUX_RUNFD_H */
diff --git a/kernel/runfd.c b/kernel/runfd.c
index 6b250796c24e..b0dd7666f5d7 100644
--- a/kernel/runfd.c
+++ b/kernel/runfd.c
@@ -25,6 +25,8 @@
 #include <linux/slab.h>
 #include <linux/syscalls.h>
 #include <linux/uaccess.h>
+#include <linux/cgroup_namespace.h>
+#include <linux/ipc_namespace.h>
 #include <linux/mnt_namespace.h>
 #include <linux/nsproxy.h>
 #include <linux/ns_common.h>
@@ -33,6 +35,8 @@
 #include <linux/pid_namespace.h>
 #include <linux/time_namespace.h>
 #include <linux/user_namespace.h>
+#include <linux/uts_namespace.h>
+#include <net/net_namespace.h>
 #include <linux/idr.h>
 #include <uapi/linux/runfd.h>
 
@@ -65,6 +69,76 @@ static __poll_t runfd_poll(struct file *file, poll_table *wait)
 	return mask;
 }
 
+static long runfd_get_nsfd(struct run *run, unsigned long nstype)
+{
+	struct ns_common *ns = NULL;
+
+	if (nstype > UINT_MAX)
+		return -EINVAL;
+	if (!ns_capable(run->user_ns, CAP_SYS_ADMIN))
+		return -EPERM;
+
+	if (nstype == CLONE_NEWPID) {
+		if (!pidns_is_ancestor(run->ns->pid_ns_for_children,
+				       task_active_pid_ns(current)))
+			return -EXDEV;
+		if (READ_ONCE(run->state) != RUNFD_RUNNING)
+			return -ESRCH;
+	}
+
+	scoped_guard(spinlock, &run->lock) {
+		switch (nstype) {
+		case CLONE_NEWNS:
+			ns = from_mnt_ns(run->ns->mnt_ns);
+			break;
+		case CLONE_NEWCGROUP:
+			ns = to_ns_common(run->ns->cgroup_ns);
+			break;
+		case CLONE_NEWUTS:
+			ns = to_ns_common(run->ns->uts_ns);
+			break;
+		case CLONE_NEWIPC:
+			ns = to_ns_common(run->ns->ipc_ns);
+			break;
+		case CLONE_NEWUSER:
+			ns = to_ns_common(run->user_ns);
+			break;
+		case CLONE_NEWPID:
+			ns = to_ns_common(run->ns->pid_ns_for_children);
+			break;
+		case CLONE_NEWNET:
+			ns = to_ns_common(run->ns->net_ns);
+			break;
+		case CLONE_NEWTIME:
+#ifdef CONFIG_TIME_NS
+			ns = to_ns_common(run->ns->time_ns);
+			break;
+#else
+			return -EOPNOTSUPP;
+#endif
+		default:
+			return -EINVAL;
+		}
+
+		if (!__ns_ref_get(ns))
+			return -ESRCH;
+	}
+
+	return open_namespace(ns);
+}
+
+static long runfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+	struct run *run = file->private_data;
+
+	switch (cmd) {
+	case RUNFD_GET_NSFD:
+		return runfd_get_nsfd(run, arg);
+	default:
+		return -ENOIOCTLCMD;
+	}
+}
+
 static int runfd_release(struct inode *inode, struct file *file)
 {
 	struct run *run = file->private_data;
@@ -87,6 +161,8 @@ static int runfd_release(struct inode *inode, struct file *file)
 
 static const struct file_operations runfd_fops = {
 	.poll		= runfd_poll,
+	.unlocked_ioctl	= runfd_ioctl,
+	.compat_ioctl	= runfd_ioctl,
 	.release	= runfd_release,
 };
 
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 15/28] runfd: Add RUNFD_SHARE_NSFD ioctl
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (13 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 14/28] runfd: Add RUNFD_GET_NSFD ioctl Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 16/28] exit: Support P_RUNFD in waitid() Jarkko Sakkinen
                   ` (12 subsequent siblings)
  27 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

runfd() isolates every namespace by default rather than relying
on unshare() deny-listing, which prevents workloads such as
host-networked sandboxes or sidecars sharing a network or IPC namespace
from opting into specific existing namespaces.

Add the build-phase RUNFD_SHARE_NSFD ioctl to replace the run's
cgroup, IPC, UTS, network, or time namespace with a supplied nsfs file
descriptor in-place under run->lock while the run is still in
RUNFD_INIT, rejecting calls with -EBUSY once CLONE_INTO_RUN
begins. Require CAP_SYS_ADMIN in the run's user namespace, and
require CAP_SYS_ADMIN in the target namespace's owning user namespace
when the caller is not already a member of that namespace.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 include/uapi/linux/runfd.h | 14 ++++++
 kernel/runfd.c             | 90 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+)

diff --git a/include/uapi/linux/runfd.h b/include/uapi/linux/runfd.h
index 7c4ecc5e4f1c..a97715a63617 100644
--- a/include/uapi/linux/runfd.h
+++ b/include/uapi/linux/runfd.h
@@ -38,4 +38,18 @@ enum runfd_flags {
  */
 #define RUNFD_GET_NSFD	_IO(RUNFD_IOCTL_MAGIC, 0x01)
 
+/**
+ * DOC: RUNFD_SHARE_NSFD
+ *
+ * ``ioctl(run_fd, RUNFD_SHARE_NSFD, ns_fd)`` replaces the corresponding
+ * member namespace of ``run_fd`` with ``ns_fd`` (``CLONE_NEWCGROUP``,
+ * ``CLONE_NEWIPC``, ``CLONE_NEWUTS``, ``CLONE_NEWNET``, or ``CLONE_NEWTIME``)
+ * while ``run_fd`` is in ``RUNFD_INIT``.
+ *
+ * Requires ``CAP_SYS_ADMIN`` in the run's user namespace, plus
+ * ``CAP_SYS_ADMIN`` in ``ns_fd``'s owning user namespace when the caller is
+ * not already a member of ``ns_fd``.
+ */
+#define RUNFD_SHARE_NSFD	_IO(RUNFD_IOCTL_MAGIC, 0x02)
+
 #endif /* _UAPI_LINUX_RUNFD_H */
diff --git a/kernel/runfd.c b/kernel/runfd.c
index b0dd7666f5d7..45e5709dbc0e 100644
--- a/kernel/runfd.c
+++ b/kernel/runfd.c
@@ -33,6 +33,8 @@
 #include <linux/nsfs.h>
 #include <linux/pid.h>
 #include <linux/pid_namespace.h>
+#include <linux/proc_fs.h>
+#include <linux/proc_ns.h>
 #include <linux/time_namespace.h>
 #include <linux/user_namespace.h>
 #include <linux/uts_namespace.h>
@@ -127,6 +129,92 @@ static long runfd_get_nsfd(struct run *run, unsigned long nstype)
 	return open_namespace(ns);
 }
 
+static long runfd_share_nsfd(struct run *c, unsigned long arg)
+{
+	struct ns_common *old_time_children = NULL;
+	struct ns_common *old_ns = NULL;
+	struct ns_common *ns;
+
+	if (arg > INT_MAX)
+		return -EBADF;
+
+	CLASS(fd, f)((int)arg);
+	if (fd_empty(f))
+		return -EBADF;
+	if (!proc_ns_file(fd_file(f)))
+		return -EINVAL;
+
+	ns = get_proc_ns(file_inode(fd_file(f)));
+	switch (ns->ns_type) {
+	case CLONE_NEWCGROUP:
+	case CLONE_NEWIPC:
+	case CLONE_NEWUTS:
+	case CLONE_NEWNET:
+		break;
+	case CLONE_NEWTIME:
+		if (!IS_ENABLED(CONFIG_TIME_NS))
+			return -EOPNOTSUPP;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	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;
+
+	scoped_guard(spinlock, &c->lock) {
+		if (c->state != RUNFD_INIT)
+			return -EBUSY;
+
+		__ns_ref_inc(ns);
+		__ns_ref_active_get(ns);
+
+		switch (ns->ns_type) {
+		case CLONE_NEWCGROUP:
+			old_ns = to_ns_common(c->ns->cgroup_ns);
+			c->ns->cgroup_ns = to_cg_ns(ns);
+			break;
+		case CLONE_NEWIPC:
+			old_ns = to_ns_common(c->ns->ipc_ns);
+			c->ns->ipc_ns = to_ipc_ns(ns);
+			break;
+		case CLONE_NEWUTS:
+			old_ns = to_ns_common(c->ns->uts_ns);
+			c->ns->uts_ns = to_uts_ns(ns);
+			break;
+		case CLONE_NEWNET:
+			old_ns = to_ns_common(c->ns->net_ns);
+			c->ns->net_ns = to_net_ns(ns);
+			break;
+#ifdef CONFIG_TIME_NS
+		case CLONE_NEWTIME:
+			__ns_ref_inc(ns);
+			__ns_ref_active_get(ns);
+			old_ns = to_ns_common(c->ns->time_ns);
+			old_time_children =
+				to_ns_common(c->ns->time_ns_for_children);
+			c->ns->time_ns = to_time_ns(ns);
+			c->ns->time_ns_for_children = to_time_ns(ns);
+			break;
+#endif
+		default:
+			WARN_ON_ONCE(1);
+			break;
+		}
+	}
+
+	__ns_ref_active_put(old_ns);
+	old_ns->ops->put(old_ns);
+	if (old_time_children) {
+		__ns_ref_active_put(old_time_children);
+		old_time_children->ops->put(old_time_children);
+	}
+	return 0;
+}
+
 static long runfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
 	struct run *run = file->private_data;
@@ -134,6 +222,8 @@ static long runfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 	switch (cmd) {
 	case RUNFD_GET_NSFD:
 		return runfd_get_nsfd(run, arg);
+	case RUNFD_SHARE_NSFD:
+		return runfd_share_nsfd(run, arg);
 	default:
 		return -ENOIOCTLCMD;
 	}
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 16/28] exit: Support P_RUNFD in waitid()
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (14 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 15/28] runfd: Add RUNFD_SHARE_NSFD ioctl Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05 13:48   ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 17/28] signal: Support run fds in pidfd_send_signal() Jarkko Sakkinen
                   ` (11 subsequent siblings)
  27 siblings, 1 reply; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

wait4() and waitid() only allow a parent or subreaper to collect exit
status, so an external manager holding a run file descriptor cannot
wait on a run init process forked by another process or observe
exit status multiple times across observers.

Add P_RUNFD to waitid() and wire kernel_waitid() to runfd_waitid()
to wait freezably and interruptibly on a run file descriptor until
the run reaches RUNFD_DEAD and populate siginfo_t with init's
caller-visible TGID, munged UID, and exit status without consuming it.

Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 include/linux/runfd.h     | 10 +++++
 include/uapi/linux/wait.h |  1 +
 kernel/exit.c             |  4 ++
 kernel/runfd.c            | 83 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 98 insertions(+)

diff --git a/include/linux/runfd.h b/include/linux/runfd.h
index 8f18afee7d5b..eb2e8db5844f 100644
--- a/include/linux/runfd.h
+++ b/include/linux/runfd.h
@@ -19,8 +19,10 @@ struct file;
 struct nsproxy;
 struct pid;
 struct pid_namespace;
+struct rusage;
 struct task_struct;
 struct user_namespace;
+struct waitid_info;
 
 /**
  * enum runfd_state - run lifecycle states
@@ -75,6 +77,8 @@ void runfd_put(struct run *c);
 bool runfd_is_file(struct file *file);
 void runfd_copy(struct pid *pid, struct run *run);
 void runfd_exit(struct pid_namespace *pid_ns, struct task_struct *tsk);
+long runfd_waitid(int upid, struct waitid_info *infop, int options,
+		  struct rusage *ru);
 #else
 static inline void runfd_put(struct run *c)
 {
@@ -93,6 +97,12 @@ static inline void runfd_exit(struct pid_namespace *pid_ns,
 			      struct task_struct *tsk)
 {
 }
+
+static inline long runfd_waitid(int upid, struct waitid_info *infop,
+				int options, struct rusage *ru)
+{
+	return -EINVAL;
+}
 #endif /* CONFIG_RUNFD */
 
 #endif /* _LINUX_RUNFD_H */
diff --git a/include/uapi/linux/wait.h b/include/uapi/linux/wait.h
index 85b809fc9f11..fc36f4e12d6e 100644
--- a/include/uapi/linux/wait.h
+++ b/include/uapi/linux/wait.h
@@ -18,6 +18,7 @@
 #define P_PID		1
 #define P_PGID		2
 #define P_PIDFD		3
+#define P_RUNFD	4
 
 
 #endif /* _UAPI_LINUX_WAIT_H */
diff --git a/kernel/exit.c b/kernel/exit.c
index d5e7bc2af804..e8ec67d307b4 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -71,6 +71,7 @@
 #include <linux/unwind_deferred.h>
 #include <linux/uaccess.h>
 #include <linux/pidfs.h>
+#include <linux/runfd.h>
 
 #include <uapi/linux/wait.h>
 
@@ -1803,6 +1804,9 @@ static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop,
 	struct wait_opts wo;
 	long ret;
 
+	if (which == P_RUNFD)
+		return runfd_waitid(upid, infop, options, ru);
+
 	ret = kernel_waitid_prepare(&wo, which, upid, infop, options, ru);
 	if (ret)
 		return ret;
diff --git a/kernel/runfd.c b/kernel/runfd.c
index 45e5709dbc0e..52a07a108705 100644
--- a/kernel/runfd.c
+++ b/kernel/runfd.c
@@ -17,6 +17,7 @@
 #include <linux/wait.h>
 #include <uapi/linux/wait.h>
 #include <linux/file.h>
+#include <linux/freezer.h>
 #include <linux/fs.h>
 #include <linux/anon_inodes.h>
 #include <linux/runfd.h>
@@ -42,6 +43,8 @@
 #include <linux/idr.h>
 #include <uapi/linux/runfd.h>
 
+#include "exit.h"
+
 void runfd_put(struct run *c)
 {
 	if (!c || !refcount_dec_and_test(&c->usage))
@@ -215,6 +218,86 @@ static long runfd_share_nsfd(struct run *c, unsigned long arg)
 	return 0;
 }
 
+/**
+ * DOC: P_RUNFD
+ *
+ * ``waitid(P_RUNFD, run_fd, infop, options, NULL)`` waits freezably until
+ * ``run_fd`` reaches ``RUNFD_DEAD`` (unless ``WNOHANG`` or ``O_NONBLOCK`` is
+ * set) and writes init's exit information into ``infop`` without consuming it.
+ * ``options`` must include ``WEXITED`` and may include ``WNOHANG`` and
+ * ``WNOWAIT``; ``rusage`` must be ``NULL``, and the caller must run in an
+ * ancestor active PID namespace.
+ */
+long runfd_waitid(int upid, struct waitid_info *infop, int options,
+		  struct rusage *ru)
+{
+	struct pid_namespace *pid_ns;
+	unsigned int f_flags;
+	struct run *run;
+	bool nonblock;
+	int status;
+	kuid_t uid;
+	long ret;
+
+	if (upid < 0 || ru)
+		return -EINVAL;
+	if (options & ~(WEXITED | WNOHANG | WNOWAIT))
+		return -EINVAL;
+	if (!(options & WEXITED))
+		return -EINVAL;
+
+	CLASS(fd, f)(upid);
+	if (fd_empty(f) || !runfd_is_file(fd_file(f)))
+		return -EBADF;
+
+	f_flags = READ_ONCE(fd_file(f)->f_flags);
+	nonblock = (options & WNOHANG) || (f_flags & O_NONBLOCK);
+	run = fd_file(f)->private_data;
+	pid_ns = task_active_pid_ns(current);
+
+	if (!pidns_is_ancestor(run->ns->pid_ns_for_children, pid_ns))
+		return -ECHILD;
+	for (;;) {
+		enum runfd_state state;
+
+		scoped_guard(spinlock, &run->lock) {
+			state = run->state;
+			if (state == RUNFD_INIT)
+				return -ECHILD;
+			if (state == RUNFD_DEAD) {
+				ret = pid_nr_ns(run->init_pid, pid_ns);
+				if (ret <= 0)
+					return -ECHILD;
+				status = run->exit_code;
+				uid = run->init_uid;
+			}
+		}
+		if (state == RUNFD_DEAD)
+			break;
+		if (nonblock)
+			return (options & WNOHANG) ? 0 : -EAGAIN;
+
+		ret = wait_event_freezable(run->waitq,
+					   READ_ONCE(run->state) ==
+					   RUNFD_DEAD ||
+					   READ_ONCE(run->state) ==
+					   RUNFD_INIT);
+		if (ret)
+			return ret;
+	}
+
+	if ((status & 0x7f) == 0) {
+		infop->cause = CLD_EXITED;
+		infop->status = status >> 8;
+	} else {
+		infop->cause = (status & 0x80) ? CLD_DUMPED : CLD_KILLED;
+		infop->status = status & 0x7f;
+	}
+	infop->pid = ret;
+	infop->uid = from_kuid_munged(current_user_ns(), uid);
+	return ret;
+}
+
 static long runfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
 	struct run *run = file->private_data;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 17/28] signal: Support run fds in pidfd_send_signal()
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (15 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 16/28] exit: Support P_RUNFD in waitid() Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  4:02   ` bot+bpf-ci
  2026-12-05  3:26 ` [RFC PATCH v10 18/28] fork: Support CLONE_INTO_RUN in clone3() Jarkko Sakkinen
                   ` (10 subsequent siblings)
  27 siblings, 1 reply; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

Signaling every process inside a run from userspace via /proc is
racy against concurrent fork() calls.

Teach pidfd_send_signal() to dispatch run file descriptors to
runfd_send_signal() when info is NULL and flags is 0. Require an
ancestor active PID namespace, walk the run's PID namespace IDR
under tasklist_lock, and deliver a validated signal once to each thread
group including in-flight forks by member processes, aggregating
per-process delivery results.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 include/linux/runfd.h | 10 ++++++++
 kernel/runfd.c        | 59 +++++++++++++++++++++++++++++++++++++++++++
 kernel/signal.c       |  4 +++
 3 files changed, 73 insertions(+)

diff --git a/include/linux/runfd.h b/include/linux/runfd.h
index eb2e8db5844f..b22790fdefd9 100644
--- a/include/linux/runfd.h
+++ b/include/linux/runfd.h
@@ -20,6 +20,7 @@ struct nsproxy;
 struct pid;
 struct pid_namespace;
 struct rusage;
+struct siginfo;
 struct task_struct;
 struct user_namespace;
 struct waitid_info;
@@ -79,6 +80,8 @@ void runfd_copy(struct pid *pid, struct run *run);
 void runfd_exit(struct pid_namespace *pid_ns, struct task_struct *tsk);
 long runfd_waitid(int upid, struct waitid_info *infop, int options,
 		  struct rusage *ru);
+int runfd_send_signal(struct file *file, int sig,
+		      struct siginfo __user *info, unsigned int flags);
 #else
 static inline void runfd_put(struct run *c)
 {
@@ -103,6 +106,13 @@ static inline long runfd_waitid(int upid, struct waitid_info *infop,
 {
 	return -EINVAL;
 }
+
+static inline int runfd_send_signal(struct file *file, int sig,
+				    struct siginfo __user *info,
+				    unsigned int flags)
+{
+	return -EBADF;
+}
 #endif /* CONFIG_RUNFD */
 
 #endif /* _LINUX_RUNFD_H */
diff --git a/kernel/runfd.c b/kernel/runfd.c
index 52a07a108705..81ce523c79c6 100644
--- a/kernel/runfd.c
+++ b/kernel/runfd.c
@@ -298,6 +298,65 @@ long runfd_waitid(int upid, struct waitid_info *infop, int options,
 	return ret;
 }
 
+/**
+ * DOC: pidfd_send_signal
+ *
+ * ``pidfd_send_signal(run_fd, sig, NULL, 0)`` delivers ``sig`` (or ``0`` for
+ * a permission and existence probe) once to each member thread group in a
+ * running run. ``info`` must be ``NULL``, ``flags`` must be ``0``, and the
+ * caller must run in an ancestor active PID namespace.
+ */
+int runfd_send_signal(struct file *file, int sig,
+		      struct siginfo __user *info, unsigned int flags)
+{
+	struct run *run = file->private_data;
+	struct pid_namespace *pid_ns = run->ns->pid_ns_for_children;
+	bool any_success = false;
+	bool any_other = false;
+	bool any_perm = false;
+	int other_err = 0;
+	struct pid *pid;
+	int nr;
+
+	if (info || flags || sig < 0 || !valid_signal(sig))
+		return -EINVAL;
+	if (!pidns_is_ancestor(pid_ns, task_active_pid_ns(current)))
+		return -EXDEV;
+	if (READ_ONCE(run->state) != RUNFD_RUNNING)
+		return -ESRCH;
+
+	scoped_guard(rcu) {
+		read_lock(&tasklist_lock);
+		idr_for_each_entry(&pid_ns->idr, pid, nr) {
+			struct task_struct *task = pid_task(pid, PIDTYPE_TGID);
+			int err;
+
+			if (!task)
+				continue;
+
+			err = group_send_sig_info(sig, SEND_SIG_NOINFO, task,
+						  PIDTYPE_MAX);
+			if (!err) {
+				any_success = true;
+			} else if (err == -EPERM) {
+				any_perm = true;
+			} else if (err != -ESRCH && !any_other) {
+				any_other = true;
+				other_err = err;
+			}
+		}
+		read_unlock(&tasklist_lock);
+	}
+
+	if (any_success)
+		return 0;
+	if (any_other)
+		return other_err;
+	if (any_perm)
+		return -EPERM;
+	return -ESRCH;
+}
+
 static long runfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
 	struct run *run = file->private_data;
diff --git a/kernel/signal.c b/kernel/signal.c
index dd770e68faee..edc72d870a3b 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -37,6 +37,7 @@
 #include <linux/capability.h>
 #include <linux/freezer.h>
 #include <linux/pid_namespace.h>
+#include <linux/runfd.h>
 #include <linux/nsproxy.h>
 #include <linux/user_namespace.h>
 #include <linux/uprobes.h>
@@ -4181,6 +4182,9 @@ SYSCALL_DEFINE4(pidfd_send_signal, int, pidfd, int, sig,
 		if (fd_empty(f))
 			return -EBADF;
 
+		if (runfd_is_file(fd_file(f)))
+			return runfd_send_signal(fd_file(f), sig, info, flags);
+
 		/* Is this a pidfd? */
 		pid = pidfd_to_pid(fd_file(f));
 		if (IS_ERR(pid))
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 18/28] fork: Support CLONE_INTO_RUN in clone3()
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (16 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 17/28] signal: Support run fds in pidfd_send_signal() Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  4:17   ` bot+bpf-ci
  2026-12-05  3:26 ` [RFC PATCH v10 19/28] fs: Support FSCONFIG_SET_RUN in fsconfig() Jarkko Sakkinen
                   ` (9 subsequent siblings)
  27 siblings, 1 reply; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

Multithreaded userspace daemons cannot call setns(CLONE_NEWUSER) or
safely mutate process-wide filesystem state in place before spawning a
child into a target namespace set.

Add CLONE_INTO_RUN and struct clone_args.runfd
(CLONE_ARGS_SIZE_VER3) to spawn a child process directly into a run
whose root mount has been installed. Transition the run from
RUNFD_INIT through RUNFD_FORKING to RUNFD_RUNNING for the first
process so it becomes PID 1, serialize concurrent entrants on waitq
until bootstrap resolves, and admit subsequent callers into the running
PID namespace until teardown begins.

Derive child credentials from current, require CAP_SYS_ADMIN and
CAP_SYS_CHROOT in the target user namespace and an ancestor active PID
namespace, preserve caller umask, reset dumpability when exec_state
originates outside the target user namespace, commit time namespace vvar
mappings after copy_process() succeeds, and look up the live mount
namespace root. Restrict companion flags to CLONE_VFORK, CLONE_PIDFD,
CLONE_PIDFD_AUTOKILL, CLONE_AUTOREAP, CLONE_CLEAR_SIGHAND,
CLONE_INTO_CGROUP, and CLONE_NNP.

Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 include/linux/cred.h       |   4 +-
 include/linux/nsproxy.h    |   4 +-
 include/linux/runfd.h      |  15 +++
 include/linux/sched/task.h |   6 ++
 include/uapi/linux/sched.h |   5 +
 kernel/cred.c              |  20 +++-
 kernel/fork.c              |  83 ++++++++++++++--
 kernel/nsproxy.c           |   9 +-
 kernel/runfd.c             | 188 ++++++++++++++++++++++++++++++++++++-
 9 files changed, 318 insertions(+), 16 deletions(-)

diff --git a/include/linux/cred.h b/include/linux/cred.h
index 49c26af37349..f22041306884 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -19,6 +19,7 @@
 
 struct cred;
 struct inode;
+struct run;
 
 extern struct task_struct init_task;
 
@@ -152,7 +153,8 @@ struct cred {
 
 extern void __put_cred(struct cred *);
 extern void exit_creds(struct task_struct *);
-extern int copy_creds(struct task_struct *, u64);
+int copy_creds(struct task_struct *tsk, u64 clone_flags,
+	       struct run *run);
 extern const struct cred *get_task_cred(struct task_struct *);
 extern struct cred *cred_alloc_blank(void);
 extern struct cred *prepare_creds(void);
diff --git a/include/linux/nsproxy.h b/include/linux/nsproxy.h
index d611c40cb4ce..7cee992e22ad 100644
--- a/include/linux/nsproxy.h
+++ b/include/linux/nsproxy.h
@@ -12,6 +12,7 @@ struct ipc_namespace;
 struct pid_namespace;
 struct cgroup_namespace;
 struct fs_struct;
+struct run;
 struct user_namespace;
 
 /*
@@ -96,7 +97,8 @@ static inline struct cred *nsset_cred(struct nsset *set)
 struct nsproxy *create_new_namespaces(u64 flags, struct task_struct *tsk,
 				      struct user_namespace *user_ns,
 				      struct fs_struct *new_fs);
-int copy_namespaces(u64 flags, struct task_struct *tsk);
+int copy_namespaces(u64 flags, struct task_struct *tsk,
+		    struct run *run);
 void switch_cred_namespaces(const struct cred *old, const struct cred *new);
 void exit_nsproxy_namespaces(struct task_struct *tsk);
 void get_cred_namespaces(struct task_struct *tsk);
diff --git a/include/linux/runfd.h b/include/linux/runfd.h
index b22790fdefd9..7ee0edf383b0 100644
--- a/include/linux/runfd.h
+++ b/include/linux/runfd.h
@@ -16,6 +16,7 @@
 #define RUNFD_ALL_FLAGS	RUNFD_AUTOKILL
 
 struct file;
+struct kernel_clone_args;
 struct nsproxy;
 struct pid;
 struct pid_namespace;
@@ -82,6 +83,9 @@ long runfd_waitid(int upid, struct waitid_info *infop, int options,
 		  struct rusage *ru);
 int runfd_send_signal(struct file *file, int sig,
 		      struct siginfo __user *info, unsigned int flags);
+int runfd_prepare_fork(struct kernel_clone_args *args);
+int runfd_finish_fork(struct kernel_clone_args *args,
+		      struct task_struct *p);
 #else
 static inline void runfd_put(struct run *c)
 {
@@ -113,6 +117,17 @@ static inline int runfd_send_signal(struct file *file, int sig,
 {
 	return -EBADF;
 }
+
+static inline int runfd_prepare_fork(struct kernel_clone_args *args)
+{
+	return -EINVAL;
+}
+
+static inline int runfd_finish_fork(struct kernel_clone_args *args,
+				    struct task_struct *p)
+{
+	return 0;
+}
 #endif /* CONFIG_RUNFD */
 
 #endif /* _LINUX_RUNFD_H */
diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h
index 90ed5bc3c7af..0c7bec5606cd 100644
--- a/include/linux/sched/task.h
+++ b/include/linux/sched/task.h
@@ -16,6 +16,8 @@ struct task_struct;
 struct rusage;
 union thread_union;
 struct css_set;
+struct file;
+struct run;
 
 /* All the bits taken by the old clone syscall. */
 #define CLONE_LEGACY_FLAGS 0xffffffffULL
@@ -39,11 +41,15 @@ struct kernel_clone_args {
 	/* Number of elements in *set_tid */
 	size_t set_tid_size;
 	int cgroup;
+	int run_fd;
 	int idle;
 	int (*fn)(void *);
 	void *fn_arg;
 	struct cgroup *cgrp;
 	struct css_set *cset;
+	struct file *run_file;
+	struct run *run;
+	bool run_bootstrapping;
 	unsigned int kill_seq;
 };
 
diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h
index 19ffeba89428..18046543baf1 100644
--- a/include/uapi/linux/sched.h
+++ b/include/uapi/linux/sched.h
@@ -40,6 +40,7 @@
 #define CLONE_NNP		(1ULL << 35) /* Set no_new_privs on child. */
 #define CLONE_PIDFD_AUTOKILL	(1ULL << 36) /* Kill child when clone pidfd closes. */
 #define CLONE_EMPTY_MNTNS	(1ULL << 37) /* Create an empty mount namespace. */
+#define CLONE_INTO_RUN		(1ULL << 38) /* Clone into a run. */
 
 /*
  * cloning flags intersect with CSIGNAL so can be used with unshare and clone3
@@ -94,6 +95,8 @@
  *                kernel's limit of nested PID namespaces.
  * @cgroup:       If CLONE_INTO_CGROUP is specified set this to
  *                a file descriptor for the cgroup.
+ * @runfd:        If CLONE_INTO_RUN is specified set this to
+ *                a file descriptor for the run.
  *
  * The structure is versioned by size and thus extensible.
  * New struct members must go at the end of the struct and
@@ -111,12 +114,14 @@ struct clone_args {
 	__aligned_u64 set_tid;
 	__aligned_u64 set_tid_size;
 	__aligned_u64 cgroup;
+	__aligned_u64 runfd;
 };
 #endif
 
 #define CLONE_ARGS_SIZE_VER0 64 /* sizeof first published struct */
 #define CLONE_ARGS_SIZE_VER1 80 /* sizeof second published struct */
 #define CLONE_ARGS_SIZE_VER2 88 /* sizeof third published struct */
+#define CLONE_ARGS_SIZE_VER3 96 /* sizeof fourth published struct */
 
 /*
  * Scheduling policies
diff --git a/kernel/cred.c b/kernel/cred.c
index d01df40a9a38..a5a17cab9a96 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -12,13 +12,16 @@
 #include <linux/slab.h>
 #include <linux/sched.h>
 #include <linux/sched/coredump.h>
+#include <linux/sched/exec_state.h>
 #include <linux/key.h>
 #include <linux/keyctl.h>
 #include <linux/init_task.h>
+#include <linux/runfd.h>
 #include <linux/security.h>
 #include <linux/binfmts.h>
 #include <linux/cn_proc.h>
 #include <linux/uidgid.h>
+#include <linux/user_namespace.h>
 
 #if 0
 #define kdebug(FMT, ...)						\
@@ -260,7 +263,8 @@ struct cred *prepare_exec_creds(void)
  * The new process gets the current process's subjective credentials as its
  * objective and subjective credentials
  */
-int copy_creds(struct task_struct *p, u64 clone_flags)
+int copy_creds(struct task_struct *p, u64 clone_flags,
+	       struct run *run)
 {
 	struct cred *new;
 	int ret;
@@ -287,6 +291,20 @@ int copy_creds(struct task_struct *p, u64 clone_flags)
 	if (!new)
 		return -ENOMEM;
 
+	if (run) {
+		struct task_exec_state *exec_state;
+
+		if (new->user_ns != run->user_ns) {
+			ret = install_user_ns_cred(new, run->user_ns);
+			if (ret < 0)
+				goto error_put;
+		}
+		exec_state = rcu_dereference_protected(p->exec_state, true);
+		if (exec_state->user_ns != run->user_ns)
+			WRITE_ONCE(exec_state->dumpable,
+				   READ_ONCE(suid_dumpable));
+	}
+
 	if (clone_flags & CLONE_NEWUSER) {
 		ret = create_user_ns(new);
 		if (ret < 0)
diff --git a/kernel/fork.c b/kernel/fork.c
index 46032e74e629..8298a3bdff73 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -65,6 +65,7 @@
 #include <linux/rcupdate.h>
 #include <linux/ptrace.h>
 #include <linux/mount.h>
+#include <linux/mnt_namespace.h>
 #include <linux/audit.h>
 #include <linux/memcontrol.h>
 #include <linux/ftrace.h>
@@ -1600,7 +1601,7 @@ static int copy_exec_state(u64 clone_flags, struct task_struct *tsk)
 	struct task_exec_state *exec_state;
 
 	/* CLONE_VM siblings refcount-share the parent's exec_state. */
-	if (clone_flags & CLONE_VM) {
+	if ((clone_flags & (CLONE_VM | CLONE_INTO_RUN)) == CLONE_VM) {
 		exec_state = rcu_dereference_protected(current->exec_state, true);
 		refcount_inc(&exec_state->count);
 		rcu_assign_pointer(tsk->exec_state, exec_state);
@@ -1617,7 +1618,7 @@ enum copy_fs_flags_t {
 };
 
 static int copy_fs(u64 clone_flags, struct task_struct *tsk,
-		   enum copy_fs_flags_t flags)
+		   enum copy_fs_flags_t flags, struct run *run)
 {
 	struct fs_struct *fs;
 
@@ -1633,7 +1634,7 @@ static int copy_fs(u64 clone_flags, struct task_struct *tsk,
 		if (current->nsproxy->mnt_ns != &init_mnt_ns)
 			return -EINVAL;
 		fs = userspace_init_fs;
-	} else if (flags & COPY_FS_IDLE) {
+	} else if (flags & COPY_FS_IDLE || run) {
 		fs = &init_fs;
 	} else {
 		fs = current->fs;
@@ -1655,6 +1656,21 @@ static int copy_fs(u64 clone_flags, struct task_struct *tsk,
 	tsk->real_fs = tsk->fs = copy_fs_struct(fs);
 	if (!tsk->fs)
 		return -ENOMEM;
+	if (run) {
+		struct path root __free(path_put) = {};
+		int err;
+
+		err = mnt_ns_get_root(run->ns->mnt_ns, &root);
+		if (err) {
+			free_fs_struct(tsk->fs);
+			tsk->real_fs = NULL;
+			tsk->fs = NULL;
+			return err;
+		}
+		tsk->fs->umask = READ_ONCE(current->fs->umask);
+		set_fs_root(tsk->fs, &root);
+		set_fs_pwd(tsk->fs, &root);
+	}
 	return 0;
 }
 
@@ -2003,6 +2019,17 @@ static bool need_futex_hash_allocate_default(u64 clone_flags)
 	return clone_flags & CLONE_VM;
 }
 
+static bool pid_ns_is_adding(const struct pid *pid)
+{
+	int i;
+
+	for (i = pid->level; i >= 0; i--) {
+		if (unlikely(!(pid->numbers[i].ns->pid_allocated & PIDNS_ADDING)))
+			return false;
+	}
+	return true;
+}
+
 /*
  * This creates a new process as a copy of the old one,
  * but does not actually start it yet.
@@ -2170,7 +2197,7 @@ __latent_entropy struct task_struct *copy_process(
 #ifdef CONFIG_PROVE_LOCKING
 	DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
 #endif
-	retval = copy_creds(p, clone_flags);
+	retval = copy_creds(p, clone_flags, args->run);
 	if (retval < 0)
 		goto bad_fork_free;
 
@@ -2301,7 +2328,7 @@ __latent_entropy struct task_struct *copy_process(
 		goto bad_fork_cleanup_semundo;
 	retval = copy_fs(clone_flags, p,
 			 (args->umh ? COPY_FS_UMH : 0) |
-			 (args->idle ? COPY_FS_IDLE : 0));
+			 (args->idle ? COPY_FS_IDLE : 0), args->run);
 	if (retval)
 		goto bad_fork_cleanup_semundo;
 	retval = copy_sighand(clone_flags, p);
@@ -2316,7 +2343,7 @@ __latent_entropy struct task_struct *copy_process(
 	retval = user_events_fork(p, clone_flags);
 	if (retval)
 		goto bad_fork_cleanup_mm;
-	retval = copy_namespaces(clone_flags, p);
+	retval = copy_namespaces(clone_flags, p, args->run);
 	if (retval)
 		goto bad_fork_cleanup_user_events;
 	retval = copy_io(clone_flags, p);
@@ -2492,11 +2519,16 @@ __latent_entropy struct task_struct *copy_process(
 	 * child missed SIGKILL.  If current is not in the same namespace,
 	 * we can't rely on fatal_signal_pending() below.
 	 */
-	if (unlikely(!(ns_of_pid(pid)->pid_allocated & PIDNS_ADDING))) {
+	if (unlikely(!pid_ns_is_adding(pid))) {
 		retval = -ENOMEM;
 		goto bad_fork_core_free;
 	}
 
+	if (unlikely(args->run_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;
@@ -2573,7 +2605,7 @@ __latent_entropy struct task_struct *copy_process(
 	write_unlock_irq(&tasklist_lock);
 
 	if (likely(p->pid) && thread_group_leader(p))
-		runfd_copy(pid, NULL);
+		runfd_copy(pid, args->run);
 
 	if (pidfile)
 		fd_install(pidfd, pidfile);
@@ -2780,6 +2812,13 @@ pid_t kernel_clone(struct kernel_clone_args *args)
 	if (!valid_signal(args->exit_signal))
 		return -EINVAL;
 
+	if (unlikely(clone_flags & CLONE_INTO_RUN)) {
+		int err = runfd_prepare_fork(args);
+
+		if (err)
+			return err;
+	}
+
 	/*
 	 * Determine whether and which event to report to ptracer.  When
 	 * called from kernel_thread or CLONE_UNTRACED is explicitly
@@ -2801,6 +2840,13 @@ pid_t kernel_clone(struct kernel_clone_args *args)
 	p = copy_process(NULL, trace, NUMA_NO_NODE, args);
 	add_latent_entropy();
 
+	if (unlikely(clone_flags & CLONE_INTO_RUN)) {
+		int err = runfd_finish_fork(args, p);
+
+		if (err)
+			return err;
+	}
+
 	if (IS_ERR(p))
 		return PTR_ERR(p);
 
@@ -2958,7 +3004,9 @@ static noinline int copy_clone_args_from_user(struct kernel_clone_args *kargs,
 		     CLONE_ARGS_SIZE_VER1);
 	BUILD_BUG_ON(offsetofend(struct clone_args, cgroup) !=
 		     CLONE_ARGS_SIZE_VER2);
-	BUILD_BUG_ON(sizeof(struct clone_args) != CLONE_ARGS_SIZE_VER2);
+	BUILD_BUG_ON(offsetofend(struct clone_args, runfd) !=
+		     CLONE_ARGS_SIZE_VER3);
+	BUILD_BUG_ON(sizeof(struct clone_args) != CLONE_ARGS_SIZE_VER3);
 
 	if (unlikely(usize > PAGE_SIZE))
 		return -E2BIG;
@@ -2988,6 +3036,10 @@ static noinline int copy_clone_args_from_user(struct kernel_clone_args *kargs,
 	    (args.cgroup > INT_MAX || usize < CLONE_ARGS_SIZE_VER2))
 		return -EINVAL;
 
+	if ((args.flags & CLONE_INTO_RUN) &&
+	    (args.runfd > INT_MAX || usize < CLONE_ARGS_SIZE_VER3))
+		return -EINVAL;
+
 	*kargs = (struct kernel_clone_args){
 		.flags		= args.flags,
 		.pidfd		= u64_to_user_ptr(args.pidfd),
@@ -2999,6 +3051,7 @@ static noinline int copy_clone_args_from_user(struct kernel_clone_args *kargs,
 		.tls		= args.tls,
 		.set_tid_size	= args.set_tid_size,
 		.cgroup		= args.cgroup,
+		.run_fd		= args.runfd,
 	};
 
 	if (args.set_tid &&
@@ -3039,13 +3092,19 @@ static inline bool clone3_stack_valid(struct kernel_clone_args *kargs)
 	return true;
 }
 
+#define CLONE_INTO_RUN_FLAGS \
+	(CLONE_INTO_RUN | CLONE_VFORK | CLONE_PIDFD | \
+	 CLONE_CLEAR_SIGHAND | CLONE_INTO_CGROUP | CLONE_AUTOREAP | \
+	 CLONE_NNP | CLONE_PIDFD_AUTOKILL)
+
 static bool clone3_args_valid(struct kernel_clone_args *kargs)
 {
 	/* Verify that no unknown flags are passed along. */
 	if (kargs->flags &
 	    ~(CLONE_LEGACY_FLAGS | CLONE_CLEAR_SIGHAND |
 	      CLONE_INTO_CGROUP | CLONE_AUTOREAP | CLONE_NNP |
-	      CLONE_PIDFD_AUTOKILL | CLONE_EMPTY_MNTNS))
+	      CLONE_PIDFD_AUTOKILL | CLONE_EMPTY_MNTNS |
+	      CLONE_INTO_RUN))
 		return false;
 
 	/*
@@ -3063,6 +3122,10 @@ static bool clone3_args_valid(struct kernel_clone_args *kargs)
 	    kargs->exit_signal)
 		return false;
 
+	if ((kargs->flags & CLONE_INTO_RUN) &&
+	    (kargs->flags & ~CLONE_INTO_RUN_FLAGS))
+		return false;
+
 	if (!clone3_stack_valid(kargs))
 		return false;
 
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index 3c4161515c3c..38679ba27cad 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -11,6 +11,7 @@
 
 #include <linux/slab.h>
 #include <linux/export.h>
+#include <linux/runfd.h>
 #include <linux/nsproxy.h>
 #include <linux/ns/ns_common_types.h>
 #include <linux/init_task.h>
@@ -166,12 +167,18 @@ struct nsproxy *create_new_namespaces(u64 flags, struct task_struct *tsk,
  * called from clone.  This now handles copy for nsproxy and all
  * namespaces therein.
  */
-int copy_namespaces(u64 flags, struct task_struct *tsk)
+int copy_namespaces(u64 flags, struct task_struct *tsk,
+		    struct run *run)
 {
 	struct nsproxy *old_ns = tsk->nsproxy;
 	struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
 	struct nsproxy *new_ns;
 
+	if (run) {
+		get_nsproxy(run->ns);
+		tsk->nsproxy = run->ns;
+		return 0;
+	}
 	if (likely(!(flags & (CLONE_NS_ALL & ~CLONE_NEWUSER)))) {
 		if ((flags & CLONE_VM) ||
 		    likely(old_ns->time_ns_for_children == old_ns->time_ns)) {
diff --git a/kernel/runfd.c b/kernel/runfd.c
index 81ce523c79c6..6296b2eab12f 100644
--- a/kernel/runfd.c
+++ b/kernel/runfd.c
@@ -19,6 +19,7 @@
 #include <linux/file.h>
 #include <linux/freezer.h>
 #include <linux/fs.h>
+#include <linux/fs_struct.h>
 #include <linux/anon_inodes.h>
 #include <linux/runfd.h>
 #include <linux/sched/signal.h>
@@ -132,6 +133,12 @@ static long runfd_get_nsfd(struct run *run, unsigned long nstype)
 	return open_namespace(ns);
 }
 
+static bool runfd_may_use_ns(struct ns_common *ns)
+{
+	return is_current_namespace(ns) ||
+	       ns_capable(ns->ops->owner(ns), CAP_SYS_ADMIN);
+}
+
 static long runfd_share_nsfd(struct run *c, unsigned long arg)
 {
 	struct ns_common *old_time_children = NULL;
@@ -164,8 +171,7 @@ static long runfd_share_nsfd(struct run *c, unsigned long arg)
 
 	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))
+	if (!runfd_may_use_ns(ns))
 		return -EPERM;
 
 	scoped_guard(spinlock, &c->lock) {
@@ -550,3 +556,181 @@ SYSCALL_DEFINE1(runfd, unsigned int, flags)
 
 	return fd;
 }
+
+/**
+ * DOC: CLONE_INTO_RUN
+ *
+ * Passing ``CLONE_INTO_RUN`` in ``struct clone_args.flags`` (with
+ * ``size >= CLONE_ARGS_SIZE_VER3``) spawns the child into the run identified
+ * by ``struct clone_args.runfd`` once ``"/"`` is mounted in its mount
+ * namespace. The first caller bootstraps PID 1 while concurrent bootstrap
+ * callers wait killably; subsequent callers join the running PID namespace
+ * until teardown begins.
+ *
+ * Requires ``CAP_SYS_ADMIN`` and ``CAP_SYS_CHROOT`` in the target user
+ * namespace (plus ``CAP_SYS_CHROOT`` in the caller's user namespace when
+ * chrooted), membership or ``CAP_SYS_ADMIN`` in the owning user namespace of
+ * any shared namespaces, and an ancestor active PID namespace. May be combined
+ * with ``CLONE_VFORK``, ``CLONE_PIDFD``, ``CLONE_PIDFD_AUTOKILL``,
+ * ``CLONE_AUTOREAP``, ``CLONE_CLEAR_SIGHAND``, ``CLONE_INTO_CGROUP``, and
+ * ``CLONE_NNP``.
+ *
+ * When ``current`` is outside the run's user namespace, the child's
+ * credentials are copied from ``current`` and installed into the run's
+ * user namespace with capabilities recomputed as in ``setns(CLONE_NEWUSER)``,
+ * retaining ``current``'s kernel UID, GID, and supplementary groups as mapped
+ * there.
+ *
+ * ``CLONE_VM``, ``CLONE_FILES``, ``CLONE_FS``, and ``CLONE_SIGHAND`` are
+ * rejected so the child never shares mutable task state with the caller.
+ * Whenever the caller's ``exec_state`` originates outside the run's user
+ * namespace, the child keeps ``exec_state->user_ns`` in that outer user
+ * namespace and resets dumpability to ``suid_dumpable``; until ``execve()``,
+ * ``ptrace_may_access()`` checks ``CAP_SYS_PTRACE`` against the outer user
+ * namespace, preventing processes already running inside the run from
+ * tracing the child or accessing ``/proc/<pid>/{exe,mem,fd}``.
+ */
+static bool runfd_pidns_alive(struct pid_namespace *pid_ns)
+{
+	for (; pid_ns != &init_pid_ns; pid_ns = pid_ns->parent) {
+		if (!(READ_ONCE(pid_ns->pid_allocated) & PIDNS_ADDING))
+			return false;
+	}
+	return true;
+}
+
+static int runfd_check_namespaces(struct run *run)
+{
+	struct nsproxy *ns = run->ns;
+
+	if (!runfd_may_use_ns(to_ns_common(ns->cgroup_ns)) ||
+	    !runfd_may_use_ns(to_ns_common(ns->ipc_ns)) ||
+	    !runfd_may_use_ns(to_ns_common(ns->uts_ns)) ||
+	    !runfd_may_use_ns(to_ns_common(ns->net_ns)))
+		return -EPERM;
+#ifdef CONFIG_TIME_NS
+	if (!runfd_may_use_ns(to_ns_common(ns->time_ns)))
+		return -EPERM;
+#endif
+	return 0;
+}
+
+int runfd_prepare_fork(struct kernel_clone_args *args)
+{
+	struct file *file __free(fput) = fget(args->run_fd);
+	struct path root __free(path_put) = {};
+	struct pid_namespace *pid_ns;
+	bool bootstrapping = false;
+	struct run *run;
+	int ret;
+
+	if (!file)
+		return -EBADF;
+	if (!runfd_is_file(file))
+		return -EINVAL;
+
+	run = file->private_data;
+	if (!ns_capable(run->user_ns, CAP_SYS_ADMIN) ||
+	    !ns_capable(run->user_ns, CAP_SYS_CHROOT))
+		return -EPERM;
+	if (current_chrooted() && !ns_capable(current_user_ns(), CAP_SYS_CHROOT))
+		return -EPERM;
+
+	pid_ns = run->ns->pid_ns_for_children;
+	if (!pidns_is_ancestor(pid_ns, task_active_pid_ns(current)))
+		return -EXDEV;
+
+	ret = mnt_ns_get_root(run->ns->mnt_ns, &root);
+	if (ret)
+		return ret;
+
+	for (;;) {
+		bool wait = false;
+
+		scoped_guard(spinlock, &run->lock) {
+			switch (run->state) {
+			case RUNFD_INIT:
+				if (!runfd_pidns_alive(pid_ns))
+					return -ESRCH;
+				if (READ_ONCE(pid_ns->child_reaper))
+					return -EBUSY;
+				WRITE_ONCE(run->state, RUNFD_FORKING);
+				bootstrapping = true;
+				break;
+			case RUNFD_FORKING:
+				wait = true;
+				break;
+			case RUNFD_RUNNING:
+				if (!runfd_pidns_alive(pid_ns))
+					return -ESRCH;
+				break;
+			case RUNFD_DEAD:
+				return -ESRCH;
+			}
+		}
+		if (!wait)
+			break;
+
+		ret = wait_event_killable(run->waitq,
+					  READ_ONCE(run->state) !=
+					  RUNFD_FORKING);
+		if (ret)
+			return ret;
+	}
+
+	ret = runfd_check_namespaces(run);
+	if (ret)
+		goto err_forking;
+
+	args->run_file = no_free_ptr(file);
+	args->run = run;
+	args->run_bootstrapping = bootstrapping;
+	return 0;
+
+err_forking:
+	if (bootstrapping) {
+		scoped_guard(spinlock, &run->lock) {
+			if (run->state == RUNFD_FORKING)
+				WRITE_ONCE(run->state, RUNFD_INIT);
+		}
+		wake_up_all(&run->waitq);
+	}
+	return ret;
+}
+
+int runfd_finish_fork(struct kernel_clone_args *args,
+		      struct task_struct *p)
+{
+	struct file *file __free(fput) = args->run_file;
+	struct run *run = args->run;
+	struct pid_namespace *pid_ns = run->ns->pid_ns_for_children;
+	int ret;
+
+	args->run_file = NULL;
+	args->run = NULL;
+	if (!IS_ERR(p)) {
+		if (args->run_bootstrapping)
+			wake_up_all(&run->waitq);
+		if (current->nsproxy->time_ns != run->ns->time_ns)
+			timens_commit(p, run->ns->time_ns);
+		return 0;
+	}
+
+	ret = PTR_ERR(p);
+	if (args->run_bootstrapping) {
+		scoped_guard(spinlock, &run->lock) {
+			if (run->state == RUNFD_FORKING)
+				WRITE_ONCE(run->state, RUNFD_INIT);
+		}
+		wake_up_all(&run->waitq);
+		if (ret == -EINVAL && !args->set_tid_size &&
+		    (READ_ONCE(pid_ns->child_reaper) ||
+		     (READ_ONCE(pid_ns->pid_allocated) & ~PIDNS_ADDING)))
+			ret = -EBUSY;
+	}
+	if ((ret == -ENOMEM || ret == -EBUSY) &&
+	    !runfd_pidns_alive(pid_ns))
+		return -ESRCH;
+
+	return ret;
+}
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 19/28] fs: Support FSCONFIG_SET_RUN in fsconfig()
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (17 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 18/28] fork: Support CLONE_INTO_RUN in clone3() Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  4:17   ` bot+bpf-ci
  2026-12-05  3:26 ` [RFC PATCH v10 20/28] proc: Implement ->set_run() fs_context operation Jarkko Sakkinen
                   ` (8 subsequent siblings)
  27 siblings, 1 reply; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

fsopen() and fsmount() gate on CAP_SYS_ADMIN in the caller's current
mount namespace and initialize filesystem contexts from current's user
and network namespaces, preventing an unprivileged external manager from
creating superblocks and detached mounts for an unentered run.

Add FSCONFIG_SET_RUN and the ->set_run() fs_context operation
so callers holding CAP_SYS_ADMIN in the target run's user namespace
can bind a newly opened fs_context to that run once before offering
parameters. Gate run context binding on explicit FS_RUN_MOUNT
opt-in (or FS_USERNS_DELEGATABLE), mark tmpfs, ramfs, and devpts with
FS_RUN_MOUNT, refresh fc->cred when FSCONFIG_SET_RUN
authorizes and initializes the context, and keep devpts pty_reserve
restricted to host mounts.

Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 Documentation/filesystems/mount_api.rst |  35 ++++++-
 fs/devpts/inode.c                       |   8 +-
 fs/filesystems.c                        |  15 +++
 fs/fs_context.c                         |  21 +++-
 fs/fsopen.c                             | 131 ++++++++++++++++++++++--
 fs/internal.h                           |   6 ++
 fs/namespace.c                          |  18 +++-
 fs/ramfs/inode.c                        |   2 +-
 include/linux/fs.h                      |   1 +
 include/linux/fs_context.h              |   6 ++
 include/uapi/linux/mount.h              |   1 +
 mm/shmem.c                              |   5 +-
 12 files changed, 230 insertions(+), 19 deletions(-)

diff --git a/Documentation/filesystems/mount_api.rst b/Documentation/filesystems/mount_api.rst
index e8b94357b4df..3b597f727d23 100644
--- a/Documentation/filesystems/mount_api.rst
+++ b/Documentation/filesystems/mount_api.rst
@@ -80,6 +80,7 @@ context.  This is represented by the fs_context structure::
 		unsigned int		sb_flags_mask;
 		unsigned int		s_iflags;
 		enum fs_context_purpose	purpose:8;
+		bool			run_bound:1;
 		...
 	};
 
@@ -123,7 +124,8 @@ The fs_context fields are as follows:
      There are a subset of the namespaces in use by the invoking process.  They
      retain references on each namespace.  The subscribed namespaces may be
      replaced by the filesystem to reflect other sources, such as the parent
-     mount superblock on an automount.
+     mount superblock on an automount, or to the target run's
+     namespaces when bound via FSCONFIG_SET_RUN.
 
    * ::
 
@@ -186,6 +188,15 @@ The fs_context fields are as follows:
 	FS_CONTEXT_FOR_RECONFIGURE	Change an existing mount
 	==========================	======================================
 
+   * ::
+
+       bool run_bound:1
+
+     Set when the filesystem context has been bound to a target run via
+     FSCONFIG_SET_RUN.  Filesystems may inspect this flag (for example in
+     ->init_fs_context() or ->parse_param()) to distinguish run-delegated
+     mounts from host mounts.
+
 The mount context is created by calling vfs_new_fs_context() or
 vfs_dup_fs_context() and is destroyed with put_fs_context().  Note that the
 structure is not refcounted.
@@ -214,6 +225,8 @@ The filesystem context points to a table of operations::
 		int (*parse_param)(struct fs_context *fc,
 				   struct fs_parameter *param);
 		int (*parse_monolithic)(struct fs_context *fc, void *data);
+		int (*set_run)(struct fs_context *fc,
+				   struct run *run);
 		int (*get_tree)(struct fs_context *fc);
 		int (*reconfigure)(struct fs_context *fc);
 	};
@@ -272,6 +285,26 @@ manage the filesystem context.  They are as follows:
      finds it's the standard key-val list then it may pass it off to
      generic_parse_monolithic().
 
+   * ::
+
+	int (*set_run)(struct fs_context *fc,
+			   struct run *run);
+
+     Called by FSCONFIG_SET_RUN after updating fc->user_ns, fc->net_ns,
+     and fc->cred, setting fc->run_bound, and re-running
+     ->init_fs_context().  Filesystems opting into FS_RUN_MOUNT (or
+     FS_USERNS_DELEGATABLE) that capture additional namespaces from current in
+     ->init_fs_context() (such as PID or IPC namespaces) can implement this
+     operation to rebind their private context to the target run's
+     namespaces.  It may update fc->user_ns (for example to a shared
+     namespace's owning user namespace), in which case the caller must hold
+     CAP_SYS_ADMIN in fc->user_ns or the bind fails with -EPERM.  When
+     ->set_run is NULL, fc->user_ns must equal run->user_ns after
+     ->init_fs_context() or the bind fails with -EOPNOTSUPP.
+
+     On success it should return 0.  In the case of an error, it should return
+     a negative error code and the context transitions to FS_CONTEXT_FAILED.
+
    * ::
 
 	int (*get_tree)(struct fs_context *fc);
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index bd1e8eb26edb..814eed794da7 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -231,10 +231,14 @@ static int devpts_parse_param(struct fs_context *fc, struct fs_parameter *param)
 
 	switch (opt) {
 	case Opt_uid:
+		if (!kuid_has_mapping(fc->user_ns, result.uid))
+			return invalf(fc, "Invalid uid");
 		opts->uid = result.uid;
 		opts->setuid = 1;
 		break;
 	case Opt_gid:
+		if (!kgid_has_mapping(fc->user_ns, result.gid))
+			return invalf(fc, "Invalid gid");
 		opts->gid = result.gid;
 		opts->setgid = 1;
 		break;
@@ -434,6 +438,8 @@ static int devpts_init_fs_context(struct fs_context *fc)
 	fsi->mount_opts.max     = NR_UNIX98_PTY_MAX;
 
 	if (fc->purpose == FS_CONTEXT_FOR_MOUNT &&
+	    !fc->run_bound &&
+	    fc->user_ns == &init_user_ns &&
 	    current->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns)
 		fsi->mount_opts.reserve = true;
 
@@ -457,7 +463,7 @@ static struct file_system_type devpts_fs_type = {
 	.init_fs_context = devpts_init_fs_context,
 	.parameters	= devpts_param_specs,
 	.kill_sb	= devpts_kill_sb,
-	.fs_flags	= FS_USERNS_MOUNT,
+	.fs_flags	= FS_USERNS_MOUNT | FS_RUN_MOUNT,
 };
 
 /*
diff --git a/fs/filesystems.c b/fs/filesystems.c
index 3083d904df9b..9429844bf6bf 100644
--- a/fs/filesystems.c
+++ b/fs/filesystems.c
@@ -18,6 +18,7 @@
 #include <linux/uaccess.h>
 #include <linux/fs_parser.h>
 #include <linux/rculist.h>
+#include "internal.h"
 
 /*
  * Read-mostly filesystem drivers list.
@@ -390,6 +391,20 @@ static struct file_system_type *__get_fs_type(const char *name, int len)
 	return fs;
 }
 
+struct file_system_type *get_fs_type_noload(const char *name)
+{
+	struct file_system_type *fs;
+	const char *dot = strchr(name, '.');
+	int len = dot ? dot - name : strlen(name);
+
+	fs = __get_fs_type(name, len);
+	if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
+		put_filesystem(fs);
+		fs = NULL;
+	}
+	return fs;
+}
+
 struct file_system_type *get_fs_type(const char *name)
 {
 	struct file_system_type *fs;
diff --git a/fs/fs_context.c b/fs/fs_context.c
index a50584df97be..cd004750b99c 100644
--- a/fs/fs_context.c
+++ b/fs/fs_context.c
@@ -249,6 +249,7 @@ EXPORT_SYMBOL(generic_parse_monolithic);
  * @sb_flags: Filesystem/superblock flags (SB_*)
  * @sb_flags_mask: Applicable members of @sb_flags
  * @purpose: The purpose that this configuration shall be used for.
+ * @init: Whether to initialise the filesystem context immediately.
  *
  * Open a filesystem and create a mount context.  The mount context is
  * initialised with the supplied flags and, if a submount/automount from
@@ -259,7 +260,8 @@ static struct fs_context *alloc_fs_context(struct file_system_type *fs_type,
 				      struct dentry *reference,
 				      unsigned int sb_flags,
 				      unsigned int sb_flags_mask,
-				      enum fs_context_purpose purpose)
+				      enum fs_context_purpose purpose,
+				      bool init)
 {
 	struct fs_context *fc;
 	int ret = -ENOMEM;
@@ -292,6 +294,9 @@ static struct fs_context *alloc_fs_context(struct file_system_type *fs_type,
 		break;
 	}
 
+	if (!init)
+		return fc;
+
 	ret = fc->fs_type->init_fs_context(fc);
 	if (ret < 0)
 		goto err_fc;
@@ -307,10 +312,16 @@ struct fs_context *fs_context_for_mount(struct file_system_type *fs_type,
 					unsigned int sb_flags)
 {
 	return alloc_fs_context(fs_type, NULL, sb_flags, 0,
-					FS_CONTEXT_FOR_MOUNT);
+				FS_CONTEXT_FOR_MOUNT, true);
 }
 EXPORT_SYMBOL(fs_context_for_mount);
 
+struct fs_context *fs_context_for_unpriv_mount(struct file_system_type *fs_type)
+{
+	return alloc_fs_context(fs_type, NULL, 0, 0,
+				FS_CONTEXT_FOR_MOUNT, false);
+}
+
 struct fs_context *fs_context_for_reconfigure(struct dentry *dentry,
 					unsigned int sb_flags,
 					unsigned int sb_flags_mask)
@@ -320,7 +331,8 @@ struct fs_context *fs_context_for_reconfigure(struct dentry *dentry,
 		return ERR_PTR(-EINVAL);
 
 	return alloc_fs_context(dentry->d_sb->s_type, dentry, sb_flags,
-				sb_flags_mask, FS_CONTEXT_FOR_RECONFIGURE);
+				sb_flags_mask, FS_CONTEXT_FOR_RECONFIGURE,
+				true);
 }
 
 /**
@@ -337,7 +349,8 @@ struct fs_context *fs_context_for_submount(struct file_system_type *type,
 	struct fs_context *fc;
 	int ret;
 
-	fc = alloc_fs_context(type, reference, 0, 0, FS_CONTEXT_FOR_SUBMOUNT);
+	fc = alloc_fs_context(type, reference, 0, 0, FS_CONTEXT_FOR_SUBMOUNT,
+			      true);
 	if (IS_ERR(fc))
 		return fc;
 
diff --git a/fs/fsopen.c b/fs/fsopen.c
index 70024870fefa..82351d6eabe0 100644
--- a/fs/fsopen.c
+++ b/fs/fsopen.c
@@ -13,9 +13,14 @@
 #include <linux/security.h>
 #include <linux/anon_inodes.h>
 #include <linux/namei.h>
+#include <linux/capability.h>
+#include <linux/runfd.h>
+#include <linux/nsproxy.h>
+#include <linux/user_namespace.h>
 #include <linux/file.h>
 #include <uapi/linux/mount.h>
 #include <linux/audit.h>
+#include <net/net_namespace.h>
 #include "internal.h"
 #include "mount.h"
 
@@ -41,6 +46,84 @@ static inline const char *fetch_message_locked(struct fc_log *log, size_t len,
 	return p;
 }
 
+/**
+ * DOC: FSCONFIG_SET_RUN
+ *
+ * ``fsconfig(fsfd, FSCONFIG_SET_RUN, NULL, NULL, run_fd)`` binds a newly
+ * opened ``FS_RUN_MOUNT`` or ``FS_USERNS_DELEGATABLE`` filesystem context
+ * to ``run_fd`` once before parameters are supplied. Requires
+ * ``CAP_SYS_ADMIN`` in the run's user namespace and binds the context to the
+ * run's user, network, PID (``proc``), and IPC (``mqueue``) namespaces.
+ */
+static int fsconfig_set_run(struct fs_context *fc, struct fs_parameter *param)
+{
+	struct user_namespace *user_ns;
+	struct net *net;
+	struct run *c;
+	int ret;
+
+	if (!runfd_is_file(param->file))
+		return -EINVAL;
+
+	c = param->file->private_data;
+	user_ns = c->user_ns;
+	if (!ns_capable(user_ns, CAP_SYS_ADMIN))
+		return -EPERM;
+	if (!(fc->fs_type->fs_flags &
+	      (FS_RUN_MOUNT | FS_USERNS_DELEGATABLE)))
+		return -EOPNOTSUPP;
+
+	if (fc->need_free && fc->ops && fc->ops->free)
+		fc->ops->free(fc);
+	fc->need_free = false;
+	fc->fs_private = NULL;
+	fc->s_fs_info = NULL;
+	fc->ops = NULL;
+	fc->sb_flags = 0;
+	fc->global = false;
+	security_free_mnt_opts(&fc->security);
+
+	scoped_guard(spinlock, &c->lock)
+		net = get_net(c->ns->net_ns);
+	put_cred(fc->cred);
+	fc->cred = get_current_cred();
+	put_net(fc->net_ns);
+	fc->net_ns = net;
+	put_user_ns(fc->user_ns);
+	fc->user_ns = get_user_ns(user_ns);
+
+	fc->run_bound = true;
+	fc->run_mnt_id = c->ns->mnt_ns->ns.ns_id;
+
+	ret = fc->fs_type->init_fs_context(fc);
+	if (ret < 0) {
+		fc->run_bound = false;
+		fc->phase = FS_CONTEXT_FAILED;
+		return ret;
+	}
+	fc->need_free = true;
+
+	if (fc->ops->set_run) {
+		ret = fc->ops->set_run(fc, c);
+		if (ret < 0) {
+			fc->run_bound = false;
+			fc->phase = FS_CONTEXT_FAILED;
+			return ret;
+		}
+		if (!ns_capable(fc->user_ns, CAP_SYS_ADMIN)) {
+			fc->run_bound = false;
+			fc->phase = FS_CONTEXT_FAILED;
+			return -EPERM;
+		}
+	} else if (fc->user_ns != user_ns) {
+		fc->run_bound = false;
+		fc->phase = FS_CONTEXT_FAILED;
+		return -EOPNOTSUPP;
+	}
+	fc->phase = FS_CONTEXT_CREATE_PARAMS;
+	return 0;
+}
+
 /*
  * Allow the user to read back any error, warning or informational messages.
  * Only one message is returned for each read(2) call.
@@ -123,9 +206,11 @@ SYSCALL_DEFINE2(fsopen, const char __user *, _fs_name, unsigned int, flags)
 	struct file_system_type *fs_type;
 	struct fs_context *fc;
 	const char *fs_name;
+	bool priv;
 	int ret;
 
-	if (!may_mount())
+	priv = may_mount();
+	if (!priv && !IS_ENABLED(CONFIG_RUNFD))
 		return -EPERM;
 
 	if (flags & ~FSOPEN_CLOEXEC)
@@ -137,17 +222,23 @@ SYSCALL_DEFINE2(fsopen, const char __user *, _fs_name, unsigned int, flags)
 
 	audit_log_fsopen(fs_name);
 
-	fs_type = get_fs_type(fs_name);
+	fs_type = priv ? get_fs_type(fs_name) : get_fs_type_noload(fs_name);
 	kfree(fs_name);
 	if (!fs_type)
-		return -ENODEV;
+		return priv ? -ENODEV : -EPERM;
 
-	fc = fs_context_for_mount(fs_type, 0);
+	if (!priv && !(fs_type->fs_flags & FS_RUN_MOUNT)) {
+		put_filesystem(fs_type);
+		return -EPERM;
+	}
+
+	fc = priv ? fs_context_for_mount(fs_type, 0) :
+		    fs_context_for_unpriv_mount(fs_type);
 	put_filesystem(fs_type);
 	if (IS_ERR(fc))
 		return PTR_ERR(fc);
 
-	fc->phase = FS_CONTEXT_CREATE_PARAMS;
+	fc->phase = priv ? FS_CONTEXT_CREATE_NS : FS_CONTEXT_AWAITING_NS;
 
 	ret = fscontext_alloc_log(fc);
 	if (ret < 0)
@@ -222,7 +313,8 @@ static int vfs_cmd_create(struct fs_context *fc, bool exclusive)
 	struct super_block *sb;
 	int ret;
 
-	if (fc->phase != FS_CONTEXT_CREATE_PARAMS)
+	if (fc->phase != FS_CONTEXT_CREATE_NS &&
+	    fc->phase != FS_CONTEXT_CREATE_PARAMS)
 		return -EBUSY;
 
 	if (!mount_capable(fc))
@@ -291,6 +383,8 @@ static int vfs_fsconfig_locked(struct fs_context *fc, int cmd,
 	ret = finish_clean_context(fc);
 	if (ret)
 		return ret;
+	if (fc->phase == FS_CONTEXT_AWAITING_NS && cmd != FSCONFIG_SET_RUN)
+		return -EPERM;
 	switch (cmd) {
 	case FSCONFIG_CMD_CREATE:
 		return vfs_cmd_create(fc, false);
@@ -298,9 +392,17 @@ static int vfs_fsconfig_locked(struct fs_context *fc, int cmd,
 		return vfs_cmd_create(fc, true);
 	case FSCONFIG_CMD_RECONFIGURE:
 		return vfs_cmd_reconfigure(fc);
+	case FSCONFIG_SET_RUN:
+		if (fc->phase != FS_CONTEXT_AWAITING_NS &&
+		    fc->phase != FS_CONTEXT_CREATE_NS)
+			return -EBUSY;
+		return fsconfig_set_run(fc, param);
+
 	default:
-		if (fc->phase != FS_CONTEXT_CREATE_PARAMS &&
-		    fc->phase != FS_CONTEXT_RECONF_PARAMS)
+		if (fc->phase == FS_CONTEXT_CREATE_NS)
+			fc->phase = FS_CONTEXT_CREATE_PARAMS;
+		else if (fc->phase != FS_CONTEXT_CREATE_PARAMS &&
+			 fc->phase != FS_CONTEXT_RECONF_PARAMS)
 			return -EBUSY;
 
 		return vfs_parse_fs_param(fc, param);
@@ -390,6 +492,12 @@ SYSCALL_DEFINE5(fsconfig,
 		if (!_key || _value || aux < 0)
 			return -EINVAL;
 		break;
+	case FSCONFIG_SET_RUN:
+		if (!IS_ENABLED(CONFIG_RUNFD))
+			return -EOPNOTSUPP;
+		if (_key || _value || aux < 0)
+			return -EINVAL;
+		break;
 	case FSCONFIG_CMD_CREATE:
 	case FSCONFIG_CMD_CREATE_EXCL:
 	case FSCONFIG_CMD_RECONFIGURE:
@@ -457,6 +565,12 @@ SYSCALL_DEFINE5(fsconfig,
 			goto out_key;
 		param.dirfd = aux;
 		break;
+	case FSCONFIG_SET_RUN:
+		ret = -EBADF;
+		param.file = fget(aux);
+		if (!param.file)
+			goto out_key;
+		break;
 	default:
 		break;
 	}
@@ -482,6 +596,7 @@ SYSCALL_DEFINE5(fsconfig,
 			putname(param.name);
 		break;
 	case FSCONFIG_SET_FD:
+	case FSCONFIG_SET_RUN:
 		if (param.file)
 			fput(param.file);
 		break;
diff --git a/fs/internal.h b/fs/internal.h
index ee3f796241ac..c7b57263ac83 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -40,12 +40,18 @@ int __block_write_begin_int(struct folio *folio, loff_t pos, unsigned len,
  */
 extern void __init chrdev_init(void);
 
+/*
+ * filesystems.c
+ */
+struct file_system_type *get_fs_type_noload(const char *name);
+
 /*
  * fs_context.c
  */
 extern int parse_monolithic_mount_data(struct fs_context *, void *);
 extern void vfs_clean_context(struct fs_context *fc);
 extern int finish_clean_context(struct fs_context *fc);
+struct fs_context *fs_context_for_unpriv_mount(struct file_system_type *fs_type);
 
 /*
  * namei.c
diff --git a/fs/namespace.c b/fs/namespace.c
index ced125eff59b..f91b15d56a2f 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -4722,7 +4722,8 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
 	    !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
 		return -EPERM;
 
-	if (!(flags & FSMOUNT_NAMESPACE) && !may_mount())
+	if (!(flags & FSMOUNT_NAMESPACE) && !IS_ENABLED(CONFIG_RUNFD) &&
+	    !may_mount())
 		return -EPERM;
 
 	if (attr_flags & ~FSMOUNT_VALID_FLAGS)
@@ -4757,6 +4758,16 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
 	if (ret)
 		return ret;
 
+	if (fc->run_bound) {
+		if (flags & FSMOUNT_NAMESPACE)
+			return -EINVAL;
+		if (!ns_capable(fc->user_ns, CAP_SYS_ADMIN))
+			return -EPERM;
+	} else if (!(flags & FSMOUNT_NAMESPACE) &&
+		   IS_ENABLED(CONFIG_RUNFD) && !may_mount()) {
+		return -EPERM;
+	}
+
 	/* There must be a valid superblock or we can't mount it */
 	ret = -EINVAL;
 	if (!fc->root)
@@ -4798,9 +4809,12 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
 		return FD_ADD((flags & FSMOUNT_CLOEXEC) ? O_CLOEXEC : 0,
 			      open_new_namespace(&new_path, MOUNT_COPY_NEW));
 
-	ns = alloc_mnt_ns(current->nsproxy->mnt_ns->user_ns, true);
+	ns = alloc_mnt_ns(fc->run_bound ? fc->user_ns :
+			  current->nsproxy->mnt_ns->user_ns, true);
 	if (IS_ERR(ns))
 		return PTR_ERR(ns);
+	if (fc->run_bound)
+		ns->seq_origin = fc->run_mnt_id;
 	mnt = real_mount(new_path.mnt);
 	ns->root = mnt;
 	ns->nr_mounts = 1;
diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index ef91b933d4e6..4a3801b501e5 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -319,7 +319,7 @@ static struct file_system_type ramfs_fs_type = {
 	.init_fs_context = ramfs_init_fs_context,
 	.parameters	= ramfs_fs_parameters,
 	.kill_sb	= ramfs_kill_sb,
-	.fs_flags	= FS_USERNS_MOUNT,
+	.fs_flags	= FS_USERNS_MOUNT | FS_RUN_MOUNT,
 };
 
 static int __init init_ramfs_fs(void)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 5b3a100aba77..91479495b49e 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2306,6 +2306,7 @@ struct file_system_type {
 #define FS_USERNS_MOUNT_RESTRICTED 512	/* Restrict mount in userns if not already visible */
 #define FS_USERNS_DELEGATABLE	1024	/* Can be mounted inside userns from outside */
 #define FS_DISALLOW_NOTIFY	2048	/* No fsnotify marks on its objects */
+#define FS_RUN_MOUNT	4096	/* Supports FSCONFIG_SET_RUN */
 #define FS_RENAME_DOES_D_MOVE	32768	/* FS will handle d_move() during rename() internally. */
 	int (*init_fs_context)(struct fs_context *);
 	const struct fs_parameter_spec *parameters;
diff --git a/include/linux/fs_context.h b/include/linux/fs_context.h
index d1727dffecc5..a015b0b24803 100644
--- a/include/linux/fs_context.h
+++ b/include/linux/fs_context.h
@@ -23,6 +23,7 @@ struct net;
 struct pid_namespace;
 struct super_block;
 struct user_namespace;
+struct run;
 struct vfsmount;
 struct path;
 
@@ -36,6 +37,8 @@ enum fs_context_purpose {
  * Userspace usage phase for fsopen/fspick.
  */
 enum fs_context_phase {
+	FS_CONTEXT_AWAITING_NS,		/* Unprivileged context awaiting target ns */
+	FS_CONTEXT_CREATE_NS,		/* Set namespaces for sb creation */
 	FS_CONTEXT_CREATE_PARAMS,	/* Loading params for sb creation */
 	FS_CONTEXT_CREATING,		/* A superblock is being created */
 	FS_CONTEXT_AWAITING_MOUNT,	/* Superblock created, awaiting fsmount() */
@@ -101,6 +104,7 @@ struct fs_context {
 	const char		*source;	/* The source name (eg. dev path) */
 	void			*security;	/* LSM options */
 	void			*s_fs_info;	/* Proposed s_fs_info */
+	u64			run_mnt_id;	/* Target run mnt_ns ID */
 	unsigned int		sb_flags;	/* Proposed superblock flags (SB_*) */
 	unsigned int		sb_flags_mask;	/* Superblock flags that were changed */
 	unsigned int		s_iflags;	/* OR'd with sb->s_iflags */
@@ -110,6 +114,7 @@ struct fs_context {
 	bool			global:1;	/* Goes into &init_user_ns */
 	bool			oldapi:1;	/* Coming from mount(2) */
 	bool			exclusive:1;    /* create new superblock, reject existing one */
+	bool			run_bound:1;	/* Bound via FSCONFIG_SET_RUN */
 };
 
 struct fs_context_operations {
@@ -117,6 +122,7 @@ struct fs_context_operations {
 	int (*dup)(struct fs_context *fc, struct fs_context *src_fc);
 	int (*parse_param)(struct fs_context *fc, struct fs_parameter *param);
 	int (*parse_monolithic)(struct fs_context *fc, void *data);
+	int (*set_run)(struct fs_context *fc, struct run *run);
 	int (*get_tree)(struct fs_context *fc);
 	int (*reconfigure)(struct fs_context *fc);
 };
diff --git a/include/uapi/linux/mount.h b/include/uapi/linux/mount.h
index cb4f7175db02..8818559939af 100644
--- a/include/uapi/linux/mount.h
+++ b/include/uapi/linux/mount.h
@@ -107,6 +107,7 @@ enum fsconfig_command {
 	FSCONFIG_CMD_CREATE	= 6,	/* Create new or reuse existing superblock */
 	FSCONFIG_CMD_RECONFIGURE = 7,	/* Invoke superblock reconfiguration */
 	FSCONFIG_CMD_CREATE_EXCL = 8,	/* Create new superblock, fail if reusing existing superblock */
+	FSCONFIG_SET_RUN	= 9,	/* Set target run, supplied by fd */
 };
 
 /*
diff --git a/mm/shmem.c b/mm/shmem.c
index a5713109c843..d511d0f35cc6 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -5632,7 +5632,8 @@ static struct file_system_type shmem_fs_type = {
 	.parameters	= shmem_fs_parameters,
 #endif
 	.kill_sb	= kill_anon_super,
-	.fs_flags	= FS_USERNS_MOUNT | FS_ALLOW_IDMAP | FS_MGTIME,
+	.fs_flags	= FS_USERNS_MOUNT | FS_RUN_MOUNT |
+			  FS_ALLOW_IDMAP | FS_MGTIME,
 };
 
 #if defined(CONFIG_SYSFS) && defined(CONFIG_TMPFS)
@@ -6061,7 +6062,7 @@ static struct file_system_type shmem_fs_type = {
 	.init_fs_context = ramfs_init_fs_context,
 	.parameters	= ramfs_fs_parameters,
 	.kill_sb	= ramfs_kill_sb,
-	.fs_flags	= FS_USERNS_MOUNT,
+	.fs_flags	= FS_USERNS_MOUNT | FS_RUN_MOUNT,
 };
 
 void __init shmem_init(void)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 20/28] proc: Implement ->set_run() fs_context operation
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (18 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 19/28] fs: Support FSCONFIG_SET_RUN in fsconfig() Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  4:02   ` bot+bpf-ci
  2026-12-05 13:48   ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 21/28] ipc/mqueue: " Jarkko Sakkinen
                   ` (7 subsequent siblings)
  27 siblings, 2 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

proc_init_fs_context() binds ctx->pid_ns to task_active_pid_ns(current)
and resets fc->user_ns to ctx->pid_ns->user_ns, overriding the user
namespace delegated by FSCONFIG_SET_RUN and leaving the context
attached to the caller's PID namespace.

Wire up proc_set_run() to verify that the target run's PID
namespace is a descendant of the caller's active PID namespace and
rebind ctx->pid_ns and fc->user_ns accordingly, and mark proc with
FS_RUN_MOUNT.

Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 fs/proc/root.c | 61 +++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 46 insertions(+), 15 deletions(-)

diff --git a/fs/proc/root.c b/fs/proc/root.c
index 7fbbe92bf73a..de14a7933ee5 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -15,6 +15,8 @@
 #include <linux/sched/stat.h>
 #include <linux/module.h>
 #include <linux/bitops.h>
+#include <linux/runfd.h>
+#include <linux/nsproxy.h>
 #include <linux/user_namespace.h>
 #include <linux/fs_context.h>
 #include <linux/mount.h>
@@ -30,7 +32,7 @@ struct proc_fs_context {
 	struct pid_namespace	*pid_ns;
 	unsigned int		mask;
 	enum proc_hidepid	hidepid;
-	int			gid;
+	kgid_t			gid;
 	enum proc_pidonly	pidonly;
 };
 
@@ -42,7 +44,7 @@ enum proc_param {
 };
 
 static const struct fs_parameter_spec proc_fs_parameters[] = {
-	fsparam_u32("gid",		Opt_gid),
+	fsparam_gid("gid",		Opt_gid),
 	fsparam_string("hidepid",	Opt_hidepid),
 	fsparam_string("subset",	Opt_subset),
 	fsparam_file_or_string("pidns",	Opt_pidns),
@@ -178,7 +180,9 @@ static int proc_parse_param(struct fs_context *fc, struct fs_parameter *param)
 
 	switch (opt) {
 	case Opt_gid:
-		ctx->gid = result.uint_32;
+		if (!kgid_has_mapping(fc->user_ns, result.gid))
+			return invalfc(fc, "Invalid gid");
+		ctx->gid = result.gid;
 		break;
 
 	case Opt_hidepid:
@@ -206,6 +210,10 @@ static int proc_parse_param(struct fs_context *fc, struct fs_parameter *param)
 			errorfc(fc, "cannot reconfigure pidns for existing procfs");
 			return -EBUSY;
 		}
+		if (fc->run_bound) {
+			errorfc(fc, "cannot override pidns on run-bound procfs");
+			return -EBUSY;
+		}
 		err = proc_parse_pidns_param(fc, param, &result);
 		if (err)
 			return err;
@@ -224,8 +232,7 @@ static int proc_parse_param(struct fs_context *fc, struct fs_parameter *param)
 }
 
 static int proc_apply_options(struct proc_fs_info *fs_info,
-			       struct fs_context *fc,
-			       struct user_namespace *user_ns)
+			      struct fs_context *fc)
 {
 	struct proc_fs_context *ctx = fc->fs_private;
 
@@ -234,8 +241,11 @@ static int proc_apply_options(struct proc_fs_info *fs_info,
 	    ctx->pidonly != fs_info->pidonly)
 		return invalf(fc, "proc: subset=pid cannot be changed\n");
 
-	if (ctx->mask & (1 << Opt_gid))
-		fs_info->pid_gid = make_kgid(user_ns, ctx->gid);
+	if (ctx->mask & (1 << Opt_gid)) {
+		if (!kgid_has_mapping(fc->user_ns, ctx->gid))
+			return invalfc(fc, "Invalid gid");
+		fs_info->pid_gid = ctx->gid;
+	}
 	if (ctx->mask & (1 << Opt_hidepid))
 		fs_info->hide_pid = ctx->hidepid;
 	if (ctx->mask & (1 << Opt_subset))
@@ -261,7 +271,8 @@ static int proc_fill_super(struct super_block *s, struct fs_context *fc)
 
 	fs_info->pid_ns = get_pid_ns(ctx->pid_ns);
 	fs_info->mounter_cred = get_cred(fc->cred);
-	ret = proc_apply_options(fs_info, fc, current_user_ns());
+	s->s_fs_info = fs_info;
+	ret = proc_apply_options(fs_info, fc);
 	if (ret)
 		return ret;
 
@@ -273,8 +284,6 @@ static int proc_fill_super(struct super_block *s, struct fs_context *fc)
 	s->s_magic = PROC_SUPER_MAGIC;
 	s->s_op = &proc_sops;
 	s->s_time_gran = 1;
-	s->s_fs_info = fs_info;
-
 	if (fs_info->pidonly == PROC_PIDONLY_ON)
 		s->s_iflags |= SB_I_RESTRICTED_VARIANT;
 
@@ -315,7 +324,7 @@ static int proc_reconfigure(struct fs_context *fc)
 
 	sync_filesystem(sb);
 
-	return proc_apply_options(fs_info, fc, current_user_ns());
+	return proc_apply_options(fs_info, fc);
 }
 
 static int proc_get_tree(struct fs_context *fc)
@@ -323,6 +332,21 @@ static int proc_get_tree(struct fs_context *fc)
 	return get_tree_nodev(fc, proc_fill_super);
 }
 
+static int proc_set_run(struct fs_context *fc, struct run *run)
+{
+	struct proc_fs_context *ctx = fc->fs_private;
+	struct pid_namespace *target = run->ns->pid_ns_for_children;
+
+	if (!pidns_is_ancestor(target, task_active_pid_ns(current)))
+		return invalfc(fc, "cannot set pidns to non-descendant pidns");
+
+	put_pid_ns(ctx->pid_ns);
+	ctx->pid_ns = get_pid_ns(target);
+	put_user_ns(fc->user_ns);
+	fc->user_ns = get_user_ns(ctx->pid_ns->user_ns);
+	return 0;
+}
+
 static void proc_fs_context_free(struct fs_context *fc)
 {
 	struct proc_fs_context *ctx = fc->fs_private;
@@ -334,6 +358,7 @@ static void proc_fs_context_free(struct fs_context *fc)
 static const struct fs_context_operations proc_fs_context_ops = {
 	.free		= proc_fs_context_free,
 	.parse_param	= proc_parse_param,
+	.set_run	= proc_set_run,
 	.get_tree	= proc_get_tree,
 	.reconfigure	= proc_reconfigure,
 };
@@ -346,9 +371,13 @@ static int proc_init_fs_context(struct fs_context *fc)
 	if (!ctx)
 		return -ENOMEM;
 
-	ctx->pid_ns = get_pid_ns(task_active_pid_ns(current));
-	put_user_ns(fc->user_ns);
-	fc->user_ns = get_user_ns(ctx->pid_ns->user_ns);
+	if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) {
+		ctx->pid_ns = get_pid_ns(proc_sb_info(fc->root->d_sb)->pid_ns);
+	} else {
+		ctx->pid_ns = get_pid_ns(task_active_pid_ns(current));
+		put_user_ns(fc->user_ns);
+		fc->user_ns = get_user_ns(ctx->pid_ns->user_ns);
+	}
 	fc->fs_private = ctx;
 	fc->ops = &proc_fs_context_ops;
 	return 0;
@@ -371,7 +400,9 @@ static struct file_system_type proc_fs_type = {
 	.init_fs_context	= proc_init_fs_context,
 	.parameters		= proc_fs_parameters,
 	.kill_sb		= proc_kill_sb,
-	.fs_flags		= FS_USERNS_MOUNT | FS_USERNS_MOUNT_RESTRICTED | FS_DISALLOW_NOTIFY_PERM,
+	.fs_flags		= FS_USERNS_MOUNT | FS_RUN_MOUNT |
+				  FS_USERNS_MOUNT_RESTRICTED |
+				  FS_DISALLOW_NOTIFY_PERM,
 };
 
 void __init proc_root_init(void)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 21/28] ipc/mqueue: Implement ->set_run() fs_context operation
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (19 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 20/28] proc: Implement ->set_run() fs_context operation Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  4:02   ` bot+bpf-ci
  2026-12-05  3:26 ` [RFC PATCH v10 22/28] security: Add run LSM hooks Jarkko Sakkinen
                   ` (6 subsequent siblings)
  27 siblings, 1 reply; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

mqueue_init_fs_context() captures current->nsproxy->ipc_ns and resets
fc->user_ns to ctx->ipc_ns->user_ns, overriding the user namespace
delegated by FSCONFIG_SET_RUN and leaving the context bound to the
caller's IPC namespace.

Wire up mqueue_set_run() to switch ctx->ipc_ns to the target
run's IPC namespace, update fc->user_ns to match, and mark mqueue
with FS_RUN_MOUNT.

Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 ipc/mqueue.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index 322c3dd98c44..f31df31c5053 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -30,6 +30,7 @@
 #include <linux/audit.h>
 #include <linux/signal.h>
 #include <linux/mutex.h>
+#include <linux/runfd.h>
 #include <linux/nsproxy.h>
 #include <linux/pid.h>
 #include <linux/ipc_namespace.h>
@@ -400,6 +401,20 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
 	return ERR_PTR(ret);
 }
 
+static int mqueue_set_run(struct fs_context *fc, struct run *run)
+{
+	struct mqueue_fs_context *ctx = fc->fs_private;
+	struct ipc_namespace *ipc_ns;
+
+	scoped_guard(spinlock, &run->lock)
+		ipc_ns = get_ipc_ns(run->ns->ipc_ns);
+	put_ipc_ns(ctx->ipc_ns);
+	ctx->ipc_ns = ipc_ns;
+	put_user_ns(fc->user_ns);
+	fc->user_ns = get_user_ns(ipc_ns->user_ns);
+	return 0;
+}
+
 static int mqueue_fill_super(struct super_block *sb, struct fs_context *fc)
 {
 	struct inode *inode;
@@ -453,9 +468,16 @@ static int mqueue_init_fs_context(struct fs_context *fc)
 	if (!ctx)
 		return -ENOMEM;
 
-	ctx->ipc_ns = get_ipc_ns(current->nsproxy->ipc_ns);
-	put_user_ns(fc->user_ns);
-	fc->user_ns = get_user_ns(ctx->ipc_ns->user_ns);
+	/*
+	 * Reconfiguration keeps the superblock's user namespace and does not
+	 * use ctx->ipc_ns, which put_ipc_ns() could be tearing down via
+	 * sb->s_fs_info.
+	 */
+	if (fc->purpose != FS_CONTEXT_FOR_RECONFIGURE) {
+		ctx->ipc_ns = get_ipc_ns(current->nsproxy->ipc_ns);
+		put_user_ns(fc->user_ns);
+		fc->user_ns = get_user_ns(ctx->ipc_ns->user_ns);
+	}
 	fc->fs_private = ctx;
 	fc->ops = &mqueue_fs_context_ops;
 	return 0;
@@ -1613,6 +1635,7 @@ static const struct super_operations mqueue_super_ops = {
 
 static const struct fs_context_operations mqueue_fs_context_ops = {
 	.free		= mqueue_fs_context_free,
+	.set_run	= mqueue_set_run,
 	.get_tree	= mqueue_get_tree,
 };
 
@@ -1620,7 +1643,7 @@ static struct file_system_type mqueue_fs_type = {
 	.name			= "mqueue",
 	.init_fs_context	= mqueue_init_fs_context,
 	.kill_sb		= kill_anon_super,
-	.fs_flags		= FS_USERNS_MOUNT,
+	.fs_flags		= FS_USERNS_MOUNT | FS_RUN_MOUNT,
 };
 
 int mq_init_ns(struct ipc_namespace *ns)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 22/28] security: Add run LSM hooks
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (20 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 21/28] ipc/mqueue: " Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  4:02   ` bot+bpf-ci
  2026-12-05  3:26 ` [RFC PATCH v10 23/28] landlock: Enforce namespace use restrictions on run Jarkko Sakkinen
                   ` (5 subsequent siblings)
  27 siblings, 1 reply; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

Security modules need visibility into run creation, teardown,
namespace sharing, process entry, and run-wide signal delivery so
policies can attach per-run security state and mediate operations
on run file descriptors.

Add lbs_runfd and run->security blob management alongside
security_runfd_alloc(), security_runfd_free(),
security_runfd_share(), security_runfd_clone(), and
security_runfd_kill().

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 include/linux/lsm_hook_defs.h |  8 ++++
 include/linux/lsm_hooks.h     |  3 ++
 include/linux/runfd.h         |  3 ++
 include/linux/security.h      | 37 ++++++++++++++++++
 kernel/runfd.c                | 43 ++++++++++++++++-----
 security/lsm_init.c           |  6 +++
 security/security.c           | 72 +++++++++++++++++++++++++++++++++++
 7 files changed, 163 insertions(+), 9 deletions(-)

diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 005a350681c3..e2ec29671269 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -480,3 +480,11 @@ LSM_HOOK(int, 0, bdev_alloc_security, struct block_device *bdev)
 LSM_HOOK(void, LSM_RET_VOID, bdev_free_security, struct block_device *bdev)
 LSM_HOOK(int, 0, bdev_setintegrity, struct block_device *bdev,
 	 enum lsm_integrity_type type, const void *value, size_t size)
+
+#ifdef CONFIG_RUNFD
+LSM_HOOK(int, 0, runfd_alloc, struct run *run, unsigned int flags)
+LSM_HOOK(void, LSM_RET_VOID, runfd_free, struct run *run)
+LSM_HOOK(int, 0, runfd_share, struct run *run, struct ns_common *ns)
+LSM_HOOK(int, 0, runfd_clone, struct run *run)
+LSM_HOOK(int, 0, runfd_kill, struct run *run, int sig)
+#endif /* CONFIG_RUNFD */
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
index 13621e9e233e..b4134b5a6ac7 100644
--- a/include/linux/lsm_hooks.h
+++ b/include/linux/lsm_hooks.h
@@ -121,6 +121,9 @@ struct lsm_blob_sizes {
 	unsigned int lbs_bpf_map;
 	unsigned int lbs_bpf_prog;
 	unsigned int lbs_bpf_token;
+#ifdef CONFIG_RUNFD
+	unsigned int lbs_runfd;
+#endif
 };
 
 /*
diff --git a/include/linux/runfd.h b/include/linux/runfd.h
index 7ee0edf383b0..82c498ee65f1 100644
--- a/include/linux/runfd.h
+++ b/include/linux/runfd.h
@@ -64,6 +64,9 @@ enum runfd_state {
 struct run {
 	refcount_t		usage;
 	int			exit_code;
+#ifdef CONFIG_SECURITY
+	void			*security;
+#endif
 	struct user_namespace	*user_ns;
 	struct nsproxy		*ns;
 	struct pid		*init_pid;
diff --git a/include/linux/security.h b/include/linux/security.h
index 9c8f8da83251..69d180c39c6a 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -84,6 +84,7 @@ struct audit_krule;
 struct ns_common;
 struct user_namespace;
 struct timezone;
+struct run;
 
 enum lsm_event {
 	LSM_POLICY_CHANGE,
@@ -2471,4 +2472,40 @@ static inline void security_initramfs_populated(void)
 }
 #endif /* CONFIG_SECURITY */
 
+#ifdef CONFIG_RUNFD
+#ifdef CONFIG_SECURITY
+int security_runfd_alloc(struct run *run, unsigned int flags);
+void security_runfd_free(struct run *run);
+int security_runfd_share(struct run *run, struct ns_common *ns);
+int security_runfd_clone(struct run *run);
+int security_runfd_kill(struct run *run, int sig);
+#else
+static inline int security_runfd_alloc(struct run *run,
+				       unsigned int flags)
+{
+	return 0;
+}
+
+static inline void security_runfd_free(struct run *run)
+{
+}
+
+static inline int security_runfd_share(struct run *run,
+				       struct ns_common *ns)
+{
+	return 0;
+}
+
+static inline int security_runfd_clone(struct run *run)
+{
+	return 0;
+}
+
+static inline int security_runfd_kill(struct run *run, int sig)
+{
+	return 0;
+}
+#endif /* CONFIG_SECURITY */
+#endif /* CONFIG_RUNFD */
+
 #endif /* ! __LINUX_SECURITY_H */
diff --git a/kernel/runfd.c b/kernel/runfd.c
index 6296b2eab12f..843f7f52fa95 100644
--- a/kernel/runfd.c
+++ b/kernel/runfd.c
@@ -42,15 +42,13 @@
 #include <linux/uts_namespace.h>
 #include <net/net_namespace.h>
 #include <linux/idr.h>
+#include <linux/security.h>
 #include <uapi/linux/runfd.h>
 
 #include "exit.h"
 
-void runfd_put(struct run *c)
+static void runfd_free(struct run *c)
 {
-	if (!c || !refcount_dec_and_test(&c->usage))
-		return;
-
 	if (c->ns)
 		put_nsproxy(c->ns);
 	if (c->init_pid)
@@ -62,6 +60,15 @@ void runfd_put(struct run *c)
 	kfree(c);
 }
 
+void runfd_put(struct run *c)
+{
+	if (!c || !refcount_dec_and_test(&c->usage))
+		return;
+
+	security_runfd_free(c);
+	runfd_free(c);
+}
+
 static __poll_t runfd_poll(struct file *file, poll_table *wait)
 {
 	struct run *run = file->private_data;
@@ -144,6 +151,7 @@ static long runfd_share_nsfd(struct run *c, unsigned long arg)
 	struct ns_common *old_time_children = NULL;
 	struct ns_common *old_ns = NULL;
 	struct ns_common *ns;
+	int ret;
 
 	if (arg > INT_MAX)
 		return -EBADF;
@@ -174,6 +182,10 @@ static long runfd_share_nsfd(struct run *c, unsigned long arg)
 	if (!runfd_may_use_ns(ns))
 		return -EPERM;
 
+	ret = security_runfd_share(c, ns);
+	if (ret)
+		return ret;
+
 	scoped_guard(spinlock, &c->lock) {
 		if (c->state != RUNFD_INIT)
 			return -EBUSY;
@@ -322,6 +334,7 @@ int runfd_send_signal(struct file *file, int sig,
 	bool any_perm = false;
 	int other_err = 0;
 	struct pid *pid;
+	int ret;
 	int nr;
 
 	if (info || flags || sig < 0 || !valid_signal(sig))
@@ -331,6 +344,10 @@ int runfd_send_signal(struct file *file, int sig,
 	if (READ_ONCE(run->state) != RUNFD_RUNNING)
 		return -ESRCH;
 
+	ret = security_runfd_kill(run, sig);
+	if (ret)
+		return ret;
+
 	scoped_guard(rcu) {
 		read_lock(&tasklist_lock);
 		idr_for_each_entry(&pid_ns->idr, pid, nr) {
@@ -494,20 +511,20 @@ static struct run *runfd_create(unsigned int flags)
 	user_ns = runfd_create_user_ns();
 	if (IS_ERR(user_ns)) {
 		ret = PTR_ERR(user_ns);
-		goto err_put;
+		goto err_free;
 	}
 	c->user_ns = user_ns;
 	ns_ref_active_get(user_ns);
 
 	if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
 		ret = -EPERM;
-		goto err_put;
+		goto err_free;
 	}
 
 	ns = create_new_namespaces(clone_flags, current, user_ns, NULL);
 	if (IS_ERR(ns)) {
 		ret = PTR_ERR(ns);
-		goto err_put;
+		goto err_free;
 	}
 
 	if (ns->time_ns != ns->time_ns_for_children) {
@@ -518,10 +535,14 @@ static struct run *runfd_create(unsigned int flags)
 	c->ns = ns;
 	nsproxy_ns_active_get(ns);
 
+	ret = security_runfd_alloc(c, flags);
+	if (ret < 0)
+		goto err_free;
+
 	return c;
 
-err_put:
-	runfd_put(c);
+err_free:
+	runfd_free(c);
 	return ERR_PTR(ret);
 }
 
@@ -682,6 +703,10 @@ int runfd_prepare_fork(struct kernel_clone_args *args)
 	if (ret)
 		goto err_forking;
 
+	ret = security_runfd_clone(run);
+	if (ret)
+		goto err_forking;
+
 	args->run_file = no_free_ptr(file);
 	args->run = run;
 	args->run_bootstrapping = bootstrapping;
diff --git a/security/lsm_init.c b/security/lsm_init.c
index 8d5ecea99c46..ec74af5c8652 100644
--- a/security/lsm_init.c
+++ b/security/lsm_init.c
@@ -316,6 +316,9 @@ static void __init lsm_prepare(struct lsm_info *lsm)
 	lsm_blob_size_update(&blobs->lbs_bpf_map, &blob_sizes.lbs_bpf_map);
 	lsm_blob_size_update(&blobs->lbs_bpf_prog, &blob_sizes.lbs_bpf_prog);
 	lsm_blob_size_update(&blobs->lbs_bpf_token, &blob_sizes.lbs_bpf_token);
+#ifdef CONFIG_RUNFD
+	lsm_blob_size_update(&blobs->lbs_runfd, &blob_sizes.lbs_runfd);
+#endif
 }
 
 /**
@@ -460,6 +463,9 @@ int __init security_init(void)
 		lsm_pr("blob(bpf_map) size %d\n", blob_sizes.lbs_bpf_map);
 		lsm_pr("blob(bpf_prog) size %d\n", blob_sizes.lbs_bpf_prog);
 		lsm_pr("blob(bpf_token) size %d\n", blob_sizes.lbs_bpf_token);
+#ifdef CONFIG_RUNFD
+		lsm_pr("blob(run) size %d\n", blob_sizes.lbs_runfd);
+#endif
 	}
 
 	if (blob_sizes.lbs_file)
diff --git a/security/security.c b/security/security.c
index c93c94103d2e..c8e47ac9ed39 100644
--- a/security/security.c
+++ b/security/security.c
@@ -30,6 +30,7 @@
 #include <linux/overflow.h>
 #include <linux/perf_event.h>
 #include <linux/fs.h>
+#include <linux/runfd.h>
 #include <net/flow.h>
 #include <net/sock.h>
 
@@ -5804,3 +5805,74 @@ void security_initramfs_populated(void)
 {
 	call_void_hook(initramfs_populated);
 }
+
+#ifdef CONFIG_RUNFD
+/**
+ * security_runfd_alloc() - Allocate LSM blob and check run creation
+ * @run: the new run
+ * @flags: creation flags passed to runfd()
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int security_runfd_alloc(struct run *run, unsigned int flags)
+{
+	int rc;
+
+	rc = lsm_blob_alloc(&run->security, blob_sizes.lbs_runfd,
+			    GFP_KERNEL);
+	if (unlikely(rc))
+		return rc;
+
+	rc = call_int_hook(runfd_alloc, run, flags);
+	if (unlikely(rc))
+		security_runfd_free(run);
+
+	return rc;
+}
+
+/**
+ * security_runfd_free() - Release LSM blob from @run
+ * @run: the run being freed
+ */
+void security_runfd_free(struct run *run)
+{
+	call_void_hook(runfd_free, run);
+	kfree(run->security);
+	run->security = NULL;
+}
+
+/**
+ * security_runfd_share() - Check permission to share @ns into @run
+ * @run: the target run
+ * @ns: the namespace being shared
+ *
+ * Return: 0 if permission is granted, negative error code on failure.
+ */
+int security_runfd_share(struct run *run, struct ns_common *ns)
+{
+	return call_int_hook(runfd_share, run, ns);
+}
+
+/**
+ * security_runfd_clone() - Check permission to spawn into @run
+ * @run: the target run
+ *
+ * Return: 0 if permission is granted, negative error code on failure.
+ */
+int security_runfd_clone(struct run *run)
+{
+	return call_int_hook(runfd_clone, run);
+}
+
+/**
+ * security_runfd_kill() - Check permission to signal @run
+ * @run: the target run
+ * @sig: signal number (or 0 for permission probe)
+ *
+ * Return: 0 if permission is granted, negative error code on failure.
+ */
+int security_runfd_kill(struct run *run, int sig)
+{
+	return call_int_hook(runfd_kill, run, sig);
+}
+#endif /* CONFIG_RUNFD */
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 23/28] landlock: Enforce namespace use restrictions on run
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (21 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 22/28] security: Add run LSM hooks Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  4:01   ` bot+bpf-ci
  2026-12-05  3:26 ` [RFC PATCH v10 24/28] bpf: Register run LSM hooks Jarkko Sakkinen
                   ` (4 subsequent siblings)
  27 siblings, 1 reply; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

When a Landlock-sandboxed task holds a pre-opened run file
descriptor, sharing namespaces via RUNFD_SHARE_NSFD or spawning a
child via clone3(CLONE_INTO_RUN) switches into existing namespaces
without passing through security_namespace_install().

Wire runfd_share and runfd_clone in Landlock's namespace hooks so
LANDLOCK_PERMISSION_NAMESPACE_USE mediates sharing a namespace into a
run and entering any run namespace that differs from the
caller's current namespaces.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 security/landlock/ns.c | 63 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 59 insertions(+), 4 deletions(-)

diff --git a/security/landlock/ns.c b/security/landlock/ns.c
index 3d443599b16f..5851195e31f0 100644
--- a/security/landlock/ns.c
+++ b/security/landlock/ns.c
@@ -13,6 +13,17 @@
 #include <linux/ns_common.h>
 #include <linux/nsproxy.h>
 #include <uapi/linux/landlock.h>
+#ifdef CONFIG_RUNFD
+#include <linux/cgroup_namespace.h>
+#include <linux/ipc_namespace.h>
+#include <linux/mnt_namespace.h>
+#include <linux/runfd.h>
+#include <linux/pid_namespace.h>
+#include <linux/time_namespace.h>
+#include <linux/user_namespace.h>
+#include <linux/uts_namespace.h>
+#include <net/net_namespace.h>
+#endif
 
 #include "cred.h"
 #include "domain.h"
@@ -93,10 +104,10 @@ static const struct access_masks ns_permission = {
  * @request_type: Namespace operation reported on denial.
  *
  * Shared check for namespace_init (creation via clone(2), unshare(2),
- * open_tree(2), or fsmount(2)) and namespace_install (use via setns(2)): denies
- * when the namespace type is not in the domain's allowed set.  At allocation
- * time @ns->ns_id is already set even though the namespace is not reachable
- * from user space yet.
+ * open_tree(2), fsmount(2), or run(2)), namespace_install (use via
+ * setns(2)), and runfd_share / runfd_clone: denies when the namespace
+ * type is not in the domain's allowed set.  At allocation time @ns->ns_id is
+ * already set even though the namespace is not reachable from user space yet.
  *
  * Return: 0 if allowed, -EPERM if denied.
  */
@@ -141,9 +152,53 @@ static int hook_namespace_install(const struct nsset *const nsset,
 	return check_ns_type(ns, LANDLOCK_REQUEST_NAMESPACE_ENTER);
 }
 
+#ifdef CONFIG_RUNFD
+static int check_runfd_ns(struct ns_common *const ns)
+{
+	if (is_current_namespace(ns))
+		return 0;
+	return check_ns_type(ns, LANDLOCK_REQUEST_NAMESPACE_ENTER);
+}
+
+static int hook_runfd_share(struct run *const run,
+			    struct ns_common *const ns)
+{
+	return check_ns_type(ns, LANDLOCK_REQUEST_NAMESPACE_ENTER);
+}
+
+static int hook_runfd_clone(struct run *const run)
+{
+	struct ns_common *const namespaces[] = {
+		to_ns_common(run->user_ns),
+		from_mnt_ns(run->ns->mnt_ns),
+		to_ns_common(run->ns->pid_ns_for_children),
+		to_ns_common(run->ns->cgroup_ns),
+		to_ns_common(run->ns->ipc_ns),
+		to_ns_common(run->ns->uts_ns),
+		to_ns_common(run->ns->net_ns),
+#ifdef CONFIG_TIME_NS
+		to_ns_common(run->ns->time_ns),
+#endif
+	};
+	size_t i;
+
+	for (i = 0; i < ARRAY_SIZE(namespaces); i++) {
+		int err = check_runfd_ns(namespaces[i]);
+
+		if (err)
+			return err;
+	}
+	return 0;
+}
+#endif /* CONFIG_RUNFD */
+
 static struct security_hook_list landlock_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(namespace_init, hook_namespace_init),
 	LSM_HOOK_INIT(namespace_install, hook_namespace_install),
+#ifdef CONFIG_RUNFD
+	LSM_HOOK_INIT(runfd_share, hook_runfd_share),
+	LSM_HOOK_INIT(runfd_clone, hook_runfd_clone),
+#endif
 };
 
 __init void landlock_add_ns_hooks(void)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 24/28] bpf: Register run LSM hooks
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (22 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 23/28] landlock: Enforce namespace use restrictions on run Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05 13:48   ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 25/28] arch: Wire up runfd() system call Jarkko Sakkinen
                   ` (3 subsequent siblings)
  27 siblings, 1 reply; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

BPF LSM programs need sleepable and untrusted hook classifications for
the run LSM hooks in order to attach policies to run
allocation, namespace sharing, cloning, signaling, and release.

Register bpf_lsm_runfd_alloc, bpf_lsm_runfd_share,
bpf_lsm_runfd_clone, and bpf_lsm_runfd_kill in
sleepable_lsm_hooks, and bpf_lsm_runfd_alloc and
bpf_lsm_runfd_free in untrusted_lsm_hooks under CONFIG_RUNFD.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 kernel/bpf/bpf_lsm.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c
index ae23511fd811..f41cebc1af4a 100644
--- a/kernel/bpf/bpf_lsm.c
+++ b/kernel/bpf/bpf_lsm.c
@@ -16,6 +16,7 @@
 #include <linux/btf_ids.h>
 #include <linux/ima.h>
 #include <linux/bpf-cgroup.h>
+#include <linux/runfd.h>
 
 /* For every LSM hook that allows attachment of BPF programs, declare a nop
  * function where a BPF program can be attached. Notably, we qualify each with
@@ -404,6 +405,12 @@ BTF_ID(func, bpf_lsm_task_setscheduler)
 BTF_ID(func, bpf_lsm_userns_create)
 BTF_ID(func, bpf_lsm_bdev_alloc_security)
 BTF_ID(func, bpf_lsm_bdev_setintegrity)
+#ifdef CONFIG_RUNFD
+BTF_ID(func, bpf_lsm_runfd_alloc)
+BTF_ID(func, bpf_lsm_runfd_share)
+BTF_ID(func, bpf_lsm_runfd_clone)
+BTF_ID(func, bpf_lsm_runfd_kill)
+#endif /* CONFIG_RUNFD */
 BTF_SET_END(sleepable_lsm_hooks)
 
 BTF_SET_START(untrusted_lsm_hooks)
@@ -422,6 +429,10 @@ BTF_ID(func, bpf_lsm_sk_free_security)
 BTF_ID(func, bpf_lsm_task_free)
 BTF_ID(func, bpf_lsm_bdev_alloc_security)
 BTF_ID(func, bpf_lsm_bdev_free_security)
+#ifdef CONFIG_RUNFD
+BTF_ID(func, bpf_lsm_runfd_alloc)
+BTF_ID(func, bpf_lsm_runfd_free)
+#endif /* CONFIG_RUNFD */
 BTF_SET_END(untrusted_lsm_hooks)
 
 bool bpf_lsm_is_sleepable_hook(u32 btf_id)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 25/28] arch: Wire up runfd() system call
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (23 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 24/28] bpf: Register run LSM hooks Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 26/28] ioctl: Register the runfd ioctl range Jarkko Sakkinen
                   ` (2 subsequent siblings)
  27 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

Now that run lifecycle and VFS mount-tree installation are in
place, expose runfd() (473, 583 on Alpha) across all
architecture system call tables, asm-generic unistd.h, and the mirrored
copies under tools/.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 arch/alpha/kernel/syscalls/syscall.tbl              | 1 +
 arch/arm/tools/syscall.tbl                          | 1 +
 arch/arm64/tools/syscall_32.tbl                     | 1 +
 arch/m68k/kernel/syscalls/syscall.tbl               | 1 +
 arch/microblaze/kernel/syscalls/syscall.tbl         | 1 +
 arch/mips/kernel/syscalls/syscall_n32.tbl           | 1 +
 arch/mips/kernel/syscalls/syscall_n64.tbl           | 1 +
 arch/mips/kernel/syscalls/syscall_o32.tbl           | 1 +
 arch/parisc/kernel/syscalls/syscall.tbl             | 1 +
 arch/powerpc/kernel/syscalls/syscall.tbl            | 1 +
 arch/s390/kernel/syscalls/syscall.tbl               | 1 +
 arch/sh/kernel/syscalls/syscall.tbl                 | 1 +
 arch/sparc/kernel/syscalls/syscall.tbl              | 1 +
 arch/x86/entry/syscalls/syscall_32.tbl              | 1 +
 arch/x86/entry/syscalls/syscall_64.tbl              | 1 +
 arch/xtensa/kernel/syscalls/syscall.tbl             | 1 +
 include/uapi/asm-generic/unistd.h                   | 6 +++++-
 scripts/syscall.tbl                                 | 1 +
 tools/include/uapi/asm-generic/unistd.h             | 6 +++++-
 tools/perf/arch/arm/entry/syscalls/syscall.tbl      | 1 +
 tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl | 1 +
 tools/perf/arch/powerpc/entry/syscalls/syscall.tbl  | 1 +
 tools/perf/arch/s390/entry/syscalls/syscall.tbl     | 1 +
 tools/perf/arch/sh/entry/syscalls/syscall.tbl       | 1 +
 tools/perf/arch/sparc/entry/syscalls/syscall.tbl    | 1 +
 tools/perf/arch/x86/entry/syscalls/syscall_32.tbl   | 1 +
 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl   | 1 +
 tools/perf/arch/xtensa/entry/syscalls/syscall.tbl   | 1 +
 tools/scripts/syscall.tbl                           | 1 +
 29 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/arch/alpha/kernel/syscalls/syscall.tbl b/arch/alpha/kernel/syscalls/syscall.tbl
index 52e3538cc7df..ff7cd33dff15 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -512,3 +512,4 @@
 580	common	listns				sys_listns
 581	common	rseq_slice_yield		sys_rseq_slice_yield
 582	common	fchroot				sys_fchroot
+583	common	runfd				sys_runfd
diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index 55717ed32c27..9ed325268843 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -487,3 +487,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/arch/arm64/tools/syscall_32.tbl b/arch/arm64/tools/syscall_32.tbl
index df2d1d82fb3c..9c4bf7000658 100644
--- a/arch/arm64/tools/syscall_32.tbl
+++ b/arch/arm64/tools/syscall_32.tbl
@@ -484,3 +484,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/arch/m68k/kernel/syscalls/syscall.tbl b/arch/m68k/kernel/syscalls/syscall.tbl
index ba7a4d8903d0..a5aa9abbde17 100644
--- a/arch/m68k/kernel/syscalls/syscall.tbl
+++ b/arch/m68k/kernel/syscalls/syscall.tbl
@@ -472,3 +472,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/arch/microblaze/kernel/syscalls/syscall.tbl b/arch/microblaze/kernel/syscalls/syscall.tbl
index 76d7cbe2a133..dafd96846faa 100644
--- a/arch/microblaze/kernel/syscalls/syscall.tbl
+++ b/arch/microblaze/kernel/syscalls/syscall.tbl
@@ -478,3 +478,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/arch/mips/kernel/syscalls/syscall_n32.tbl b/arch/mips/kernel/syscalls/syscall_n32.tbl
index 9ae88e4eac61..8dd8659744ef 100644
--- a/arch/mips/kernel/syscalls/syscall_n32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n32.tbl
@@ -411,3 +411,4 @@
 470	n32	listns				sys_listns
 471	n32	rseq_slice_yield		sys_rseq_slice_yield
 472	n32	fchroot				sys_fchroot
+473	n32	runfd				sys_runfd
diff --git a/arch/mips/kernel/syscalls/syscall_n64.tbl b/arch/mips/kernel/syscalls/syscall_n64.tbl
index 83dc93a0712f..912884b56767 100644
--- a/arch/mips/kernel/syscalls/syscall_n64.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n64.tbl
@@ -387,3 +387,4 @@
 470	n64	listns				sys_listns
 471	n64	rseq_slice_yield		sys_rseq_slice_yield
 472	n64	fchroot				sys_fchroot
+473	n64	runfd				sys_runfd
diff --git a/arch/mips/kernel/syscalls/syscall_o32.tbl b/arch/mips/kernel/syscalls/syscall_o32.tbl
index 9c62429c9b7b..28747fa27c53 100644
--- a/arch/mips/kernel/syscalls/syscall_o32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_o32.tbl
@@ -460,3 +460,4 @@
 470	o32	listns				sys_listns
 471	o32	rseq_slice_yield		sys_rseq_slice_yield
 472	o32	fchroot				sys_fchroot
+473	o32	runfd				sys_runfd
diff --git a/arch/parisc/kernel/syscalls/syscall.tbl b/arch/parisc/kernel/syscalls/syscall.tbl
index 88adc4016cce..90d728826d5b 100644
--- a/arch/parisc/kernel/syscalls/syscall.tbl
+++ b/arch/parisc/kernel/syscalls/syscall.tbl
@@ -471,3 +471,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/arch/powerpc/kernel/syscalls/syscall.tbl b/arch/powerpc/kernel/syscalls/syscall.tbl
index cfbb70039ff0..c54bdbad7fd2 100644
--- a/arch/powerpc/kernel/syscalls/syscall.tbl
+++ b/arch/powerpc/kernel/syscalls/syscall.tbl
@@ -563,3 +563,4 @@
 470	common	listns				sys_listns
 471	nospu	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	nospu	runfd				sys_runfd
diff --git a/arch/s390/kernel/syscalls/syscall.tbl b/arch/s390/kernel/syscalls/syscall.tbl
index 1b45e68a217b..d151b4194701 100644
--- a/arch/s390/kernel/syscalls/syscall.tbl
+++ b/arch/s390/kernel/syscalls/syscall.tbl
@@ -399,3 +399,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/arch/sh/kernel/syscalls/syscall.tbl b/arch/sh/kernel/syscalls/syscall.tbl
index ace068dff0de..bfdb1c3b0ffb 100644
--- a/arch/sh/kernel/syscalls/syscall.tbl
+++ b/arch/sh/kernel/syscalls/syscall.tbl
@@ -476,3 +476,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/arch/sparc/kernel/syscalls/syscall.tbl b/arch/sparc/kernel/syscalls/syscall.tbl
index 5b9fe0e8140f..d6285e223698 100644
--- a/arch/sparc/kernel/syscalls/syscall.tbl
+++ b/arch/sparc/kernel/syscalls/syscall.tbl
@@ -518,3 +518,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl
index 2c172ef48dfd..48bf4d1c87fd 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -478,3 +478,4 @@
 470	i386	listns			sys_listns
 471	i386	rseq_slice_yield	sys_rseq_slice_yield
 472	i386	fchroot			sys_fchroot
+473	i386	runfd			sys_runfd
diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl
index d5b6045b0090..be371f958850 100644
--- a/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/arch/x86/entry/syscalls/syscall_64.tbl
@@ -397,6 +397,7 @@
 470	common	listns			sys_listns
 471	common	rseq_slice_yield	sys_rseq_slice_yield
 472	common	fchroot			sys_fchroot
+473	common	runfd			sys_runfd
 
 #
 # Due to a historical design error, certain syscalls are numbered differently
diff --git a/arch/xtensa/kernel/syscalls/syscall.tbl b/arch/xtensa/kernel/syscalls/syscall.tbl
index d354bb231796..161b868fa478 100644
--- a/arch/xtensa/kernel/syscalls/syscall.tbl
+++ b/arch/xtensa/kernel/syscalls/syscall.tbl
@@ -443,3 +443,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h
index 5b7e77a7c736..5800afe963c0 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -867,8 +867,12 @@ __SYSCALL(__NR_rseq_slice_yield, sys_rseq_slice_yield)
 #define __NR_fchroot 472
 __SYSCALL(__NR_fchroot, sys_fchroot)
 
+/* kernel/runfd.c */
+#define __NR_runfd 473
+__SYSCALL(__NR_runfd, sys_runfd)
+
 #undef __NR_syscalls
-#define __NR_syscalls 473
+#define __NR_syscalls 474
 
 /*
  * 32 bit systems traditionally used different
diff --git a/scripts/syscall.tbl b/scripts/syscall.tbl
index 0ab531605120..a36bbed7670f 100644
--- a/scripts/syscall.tbl
+++ b/scripts/syscall.tbl
@@ -413,3 +413,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/tools/include/uapi/asm-generic/unistd.h b/tools/include/uapi/asm-generic/unistd.h
index 5b7e77a7c736..5800afe963c0 100644
--- a/tools/include/uapi/asm-generic/unistd.h
+++ b/tools/include/uapi/asm-generic/unistd.h
@@ -867,8 +867,12 @@ __SYSCALL(__NR_rseq_slice_yield, sys_rseq_slice_yield)
 #define __NR_fchroot 472
 __SYSCALL(__NR_fchroot, sys_fchroot)
 
+/* kernel/runfd.c */
+#define __NR_runfd 473
+__SYSCALL(__NR_runfd, sys_runfd)
+
 #undef __NR_syscalls
-#define __NR_syscalls 473
+#define __NR_syscalls 474
 
 /*
  * 32 bit systems traditionally used different
diff --git a/tools/perf/arch/arm/entry/syscalls/syscall.tbl b/tools/perf/arch/arm/entry/syscalls/syscall.tbl
index 55717ed32c27..9ed325268843 100644
--- a/tools/perf/arch/arm/entry/syscalls/syscall.tbl
+++ b/tools/perf/arch/arm/entry/syscalls/syscall.tbl
@@ -487,3 +487,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl b/tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl
index 83dc93a0712f..912884b56767 100644
--- a/tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl
+++ b/tools/perf/arch/mips/entry/syscalls/syscall_n64.tbl
@@ -387,3 +387,4 @@
 470	n64	listns				sys_listns
 471	n64	rseq_slice_yield		sys_rseq_slice_yield
 472	n64	fchroot				sys_fchroot
+473	n64	runfd				sys_runfd
diff --git a/tools/perf/arch/powerpc/entry/syscalls/syscall.tbl b/tools/perf/arch/powerpc/entry/syscalls/syscall.tbl
index cfbb70039ff0..c54bdbad7fd2 100644
--- a/tools/perf/arch/powerpc/entry/syscalls/syscall.tbl
+++ b/tools/perf/arch/powerpc/entry/syscalls/syscall.tbl
@@ -563,3 +563,4 @@
 470	common	listns				sys_listns
 471	nospu	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	nospu	runfd				sys_runfd
diff --git a/tools/perf/arch/s390/entry/syscalls/syscall.tbl b/tools/perf/arch/s390/entry/syscalls/syscall.tbl
index 1b45e68a217b..d151b4194701 100644
--- a/tools/perf/arch/s390/entry/syscalls/syscall.tbl
+++ b/tools/perf/arch/s390/entry/syscalls/syscall.tbl
@@ -399,3 +399,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/tools/perf/arch/sh/entry/syscalls/syscall.tbl b/tools/perf/arch/sh/entry/syscalls/syscall.tbl
index ace068dff0de..bfdb1c3b0ffb 100644
--- a/tools/perf/arch/sh/entry/syscalls/syscall.tbl
+++ b/tools/perf/arch/sh/entry/syscalls/syscall.tbl
@@ -476,3 +476,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/tools/perf/arch/sparc/entry/syscalls/syscall.tbl b/tools/perf/arch/sparc/entry/syscalls/syscall.tbl
index 5b9fe0e8140f..d6285e223698 100644
--- a/tools/perf/arch/sparc/entry/syscalls/syscall.tbl
+++ b/tools/perf/arch/sparc/entry/syscalls/syscall.tbl
@@ -518,3 +518,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/tools/perf/arch/x86/entry/syscalls/syscall_32.tbl b/tools/perf/arch/x86/entry/syscalls/syscall_32.tbl
index 2c172ef48dfd..48bf4d1c87fd 100644
--- a/tools/perf/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/tools/perf/arch/x86/entry/syscalls/syscall_32.tbl
@@ -478,3 +478,4 @@
 470	i386	listns			sys_listns
 471	i386	rseq_slice_yield	sys_rseq_slice_yield
 472	i386	fchroot			sys_fchroot
+473	i386	runfd			sys_runfd
diff --git a/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl b/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
index d5b6045b0090..be371f958850 100644
--- a/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
@@ -397,6 +397,7 @@
 470	common	listns			sys_listns
 471	common	rseq_slice_yield	sys_rseq_slice_yield
 472	common	fchroot			sys_fchroot
+473	common	runfd			sys_runfd
 
 #
 # Due to a historical design error, certain syscalls are numbered differently
diff --git a/tools/perf/arch/xtensa/entry/syscalls/syscall.tbl b/tools/perf/arch/xtensa/entry/syscalls/syscall.tbl
index d354bb231796..161b868fa478 100644
--- a/tools/perf/arch/xtensa/entry/syscalls/syscall.tbl
+++ b/tools/perf/arch/xtensa/entry/syscalls/syscall.tbl
@@ -443,3 +443,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
diff --git a/tools/scripts/syscall.tbl b/tools/scripts/syscall.tbl
index 0ab531605120..a36bbed7670f 100644
--- a/tools/scripts/syscall.tbl
+++ b/tools/scripts/syscall.tbl
@@ -413,3 +413,4 @@
 470	common	listns				sys_listns
 471	common	rseq_slice_yield		sys_rseq_slice_yield
 472	common	fchroot				sys_fchroot
+473	common	runfd				sys_runfd
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 26/28] ioctl: Register the runfd ioctl range
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (24 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 25/28] arch: Wire up runfd() system call Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  3:52   ` bot+bpf-ci
  2026-12-05 13:49   ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 27/28] docs: Include runfd kernel-doc in the userspace API manual Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 28/28] MAINTAINERS: Add entry for RUNFD Jarkko Sakkinen
  27 siblings, 2 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

Reserve ioctl magic 0xB9, sequence numbers 0x00 through 0x0F, for
RUNFS_GET_NFSD and RUNFS_SHARE_NFSD.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 Documentation/userspace-api/ioctl/ioctl-number.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst
index dbe462040999..ee1f8cd048c2 100644
--- a/Documentation/userspace-api/ioctl/ioctl-number.rst
+++ b/Documentation/userspace-api/ioctl/ioctl-number.rst
@@ -385,6 +385,7 @@ Code  Seq#    Include File                                             Comments
 0xB8  01-02  uapi/misc/mrvl_cn10k_dpi.h                                Marvell CN10K DPI driver
 0xB8  all    uapi/linux/mshv.h                                         Microsoft Hyper-V /dev/mshv driver
                                                                        <mailto:linux-hyperv@vger.kernel.org>
+0xB9  00-0F  uapi/linux/runfd.h                                       runfd uAPI
 0xBA  00-0F  uapi/linux/liveupdate.h                                   Pasha Tatashin
                                                                        <mailto:pasha.tatashin@soleen.com>
 0xC0  00-0F  linux/usb/iowarrior.h
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 27/28] docs: Include runfd kernel-doc in the userspace API manual
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (25 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 26/28] ioctl: Register the runfd ioctl range Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  2026-12-05  3:26 ` [RFC PATCH v10 28/28] MAINTAINERS: Add entry for RUNFD Jarkko Sakkinen
  27 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

Add a page that pulls in existing kernel-doc and link it from the
userspace API index.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 Documentation/userspace-api/index.rst |  1 +
 Documentation/userspace-api/runfd.rst | 77 +++++++++++++++++++++++++++
 2 files changed, 78 insertions(+)
 create mode 100644 Documentation/userspace-api/runfd.rst

diff --git a/Documentation/userspace-api/index.rst b/Documentation/userspace-api/index.rst
index a68b1bea57a8..01972f764ffc 100644
--- a/Documentation/userspace-api/index.rst
+++ b/Documentation/userspace-api/index.rst
@@ -17,6 +17,7 @@ System calls
    :maxdepth: 1
 
    unshare
+   runfd
    futex2
    ebpf/index
    ioctl/index
diff --git a/Documentation/userspace-api/runfd.rst b/Documentation/userspace-api/runfd.rst
new file mode 100644
index 000000000000..db6f2631d97a
--- /dev/null
+++ b/Documentation/userspace-api/runfd.rst
@@ -0,0 +1,77 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+===========
+runfd uAPI
+===========
+
+Overview
+========
+
+.. kernel-doc:: kernel/runfd.c
+   :doc: Overview
+
+Lifecycle
+=========
+
+.. kernel-doc:: include/linux/runfd.h
+   :identifiers: runfd_state
+
+Flags
+=====
+
+.. kernel-doc:: include/uapi/linux/runfd.h
+   :identifiers: runfd_flags
+
+Ioctls
+======
+
+.. kernel-doc:: include/uapi/linux/runfd.h
+   :doc: RUNFD_GET_NSFD
+
+.. kernel-doc:: include/uapi/linux/runfd.h
+   :doc: RUNFD_SHARE_NSFD
+
+System calls
+============
+
+.. kernel-doc:: kernel/runfd.c
+   :identifiers: sys_runfd
+
+Process creation
+================
+
+.. kernel-doc:: kernel/runfd.c
+   :doc: CLONE_INTO_RUN
+
+Process waiting
+===============
+
+.. kernel-doc:: kernel/runfd.c
+   :doc: P_RUNFD
+
+Signal delivery
+===============
+
+.. kernel-doc:: kernel/runfd.c
+   :doc: pidfd_send_signal
+
+Filesystem configuration
+========================
+
+.. kernel-doc:: fs/fsopen.c
+   :doc: FSCONFIG_SET_RUN
+
+Mount tree installation
+=======================
+
+.. kernel-doc:: fs/namespace.c
+   :doc: MOVE_MOUNT_T_MNTNS
+
+User namespace ID mapping
+=========================
+
+.. kernel-doc:: include/uapi/linux/nsfs.h
+   :identifiers: userns_idmap_extent userns_flags userns_idmap
+
+.. kernel-doc:: kernel/user_namespace.c
+   :identifiers: userns_set_idmap
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [RFC PATCH v10 28/28] MAINTAINERS: Add entry for RUNFD
  2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
                   ` (26 preceding siblings ...)
  2026-12-05  3:26 ` [RFC PATCH v10 27/28] docs: Include runfd kernel-doc in the userspace API manual Jarkko Sakkinen
@ 2026-12-05  3:26 ` Jarkko Sakkinen
  27 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05  3:26 UTC (permalink / raw)
  To: fsdevel
  Cc: Jarkko Sakkinen, bpf, containers, linux-api, linux-arch,
	linux-doc, linux-fsdevel, linux-integrity, linux-kernel,
	linux-kselftest, linux-mm, linux-security-module, Aleksa Sarai,
	Alexander Mikhalitsyn, Alexander Viro, Alexei Starovoitov,
	Andrew Morton, Andrii Nakryiko, Andy Lutomirski, Arnd Bergmann,
	Baolin Wang, Ben Segall, Christian Brauner, Daniel Borkmann,
	David Hildenbrand, David Howells, David Woodhouse,
	Davidlohr Bueso, Dietmar Eggemann, Eduard Zingerman,
	Emil Tsalapatis, Eric Biggers, Georgia Garcia, Giuseppe Scrivano,
	Günther Noack, Hugh Dickins, Ihor Solodrai, Ingo Molnar,
	James Morris, Jan Kara, Jason Gunthorpe, Jeff Layton, Jiri Olsa,
	John Johansen, Jonathan Corbet, Josef Bacik, Juri Lelli,
	Kees Cook, K Prateek Nayak, KP Singh, Kumar Kartikeya Dwivedi,
	Lennart Poettering, Liam R. Howlett, Manfred Spraul,
	Martin KaFai Lau, Matt Bobrowski, Mel Gorman, Michal Hocko,
	Mickaël Salaün, Mike Rapoport, Neal Gompa,
	Oleg Nesterov, Paul Moore, Pavel Tikhomirov, Peter Zijlstra,
	Randy Dunlap, Serge E. Hallyn, Serge Hallyn, Shuah Khan, Song Liu,
	Stephen Smalley, Steven Rostedt, Valentin Schneider,
	Vincent Guittot, Yonghong Song, Zygmunt Krynicki

Record maintainership and mailing list routing for runs across
their uAPI headers, core implementation, and documentation.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 MAINTAINERS | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 0308f4f17cd8..9076380f04e7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -24597,6 +24597,16 @@ L:	linux-rdma@vger.kernel.org
 S:	Maintained
 F:	drivers/infiniband/ulp/rtrs/
 
+RUNFD (CONTAINER RUN DESCRIPTORS)
+M:	David Howells <dhowells@redhat.com>
+M:	Jarkko Sakkinen <jarkko@kernel.org>
+L:	linux-fsdevel@vger.kernel.org
+S:	Maintained
+F:	Documentation/userspace-api/runfd.rst
+F:	include/linux/runfd.h
+F:	include/uapi/linux/runfd.h
+F:	kernel/runfd.c
+
 RUNTIME VERIFICATION (RV)
 M:	Steven Rostedt <rostedt@goodmis.org>
 M:	Gabriele Monaco <gmonaco@redhat.com>
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 26/28] ioctl: Register the runfd ioctl range
  2026-12-05  3:26 ` [RFC PATCH v10 26/28] ioctl: Register the runfd ioctl range Jarkko Sakkinen
@ 2026-12-05  3:52   ` bot+bpf-ci
  2026-12-05 13:49   ` Jarkko Sakkinen
  1 sibling, 0 replies; 49+ messages in thread
From: bot+bpf-ci @ 2026-12-05  3:52 UTC (permalink / raw)
  To: jarkko, fsdevel
  Cc: jarkko, bpf, containers, linux-api, linux-arch, linux-doc,
	linux-fsdevel, linux-integrity, linux-kernel, linux-kselftest,
	linux-mm, linux-security-module, aleksa, alex, viro, ast, akpm,
	andrii, luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef

[-- Attachment #1: Type: text/plain, Size: 2296 bytes --]

> ioctl: Register the runfd ioctl range

TL;DR:
- Possible misaligned ioctl-number.rst row may trigger a Sphinx docs build
  warning or error
- Commit message ioctl names don't match the header (RUNFS_GET_NFSD vs
  RUNFD_GET_NSFD)

>     ioctl: Register the runfd ioctl range
>
>     Reserve ioctl magic 0xB9, sequence numbers 0x00 through 0x0F, for
>     RUNFS_GET_NFSD and RUNFS_SHARE_NFSD.
>
>     Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>

This isn't a bug, but the ioctl names look wrong here.
include/uapi/linux/runfd.h defines RUNFD_GET_NSFD and RUNFD_SHARE_NSFD, not
RUNFS_GET_NFSD and RUNFS_SHARE_NFSD.  Could the commit message use the
names from the header?

> diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst
> --- a/Documentation/userspace-api/ioctl/ioctl-number.rst
> +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst

[ ... ]

> @@ -385,6 +385,7 @@ Code  Seq#    Include File                                             Comments
>  0xB8  01-02  uapi/misc/mrvl_cn10k_dpi.h                                Marvell CN10K DPI driver
>  0xB8  all    uapi/linux/mshv.h                                         Microsoft Hyper-V /dev/mshv driver
>                                                                         <mailto:linux-hyperv@vger.kernel.org>
> +0xB9  00-0F  uapi/linux/runfd.h                                       runfd uAPI

Is the Comments column aligned here?  "runfd uAPI" starts one column to the
left of the Comments text in the neighbouring rows, which puts it in the
blank margin between the columns of this simple table.

docutils can report "Text in column margin" for such a row, which would
turn into a warning or error in the Sphinx documentation build.

Could one space be added before "runfd uAPI" so it lines up with the
other rows?

>  0xBA  00-0F  uapi/linux/liveupdate.h                                   Pasha Tatashin
>                                                                         <mailto:pasha.tatashin@soleen.com>


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47474652355

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 23/28] landlock: Enforce namespace use restrictions on run
  2026-12-05  3:26 ` [RFC PATCH v10 23/28] landlock: Enforce namespace use restrictions on run Jarkko Sakkinen
@ 2026-12-05  4:01   ` bot+bpf-ci
  0 siblings, 0 replies; 49+ messages in thread
From: bot+bpf-ci @ 2026-12-05  4:01 UTC (permalink / raw)
  To: jarkko, fsdevel
  Cc: jarkko, bpf, containers, linux-api, linux-arch, linux-doc,
	linux-fsdevel, linux-integrity, linux-kernel, linux-kselftest,
	linux-mm, linux-security-module, aleksa, alex, viro, ast, akpm,
	andrii, luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef

[-- Attachment #1: Type: text/plain, Size: 1635 bytes --]

> landlock: Enforce namespace use restrictions on run

TL;DR: Nit only: a comment in landlock ns.c refers to a run(2) syscall, but
the series defines runfd(); it probably should say runfd(2).

> diff --git a/security/landlock/ns.c b/security/landlock/ns.c
> --- a/security/landlock/ns.c
> +++ b/security/landlock/ns.c

[ ... ]

> @@ -93,10 +104,10 @@ static const struct access_masks ns_permission = {
>   * @request_type: Namespace operation reported on denial.
>   *
>   * Shared check for namespace_init (creation via clone(2), unshare(2),
> - * open_tree(2), or fsmount(2)) and namespace_install (use via setns(2)): denies
> - * when the namespace type is not in the domain's allowed set.  At allocation
> - * time @ns->ns_id is already set even though the namespace is not reachable
> - * from user space yet.
> + * open_tree(2), fsmount(2), or run(2)), namespace_install (use via
> + * setns(2)), and runfd_share / runfd_clone: denies when the namespace
> + * type is not in the domain's allowed set.  At allocation time @ns->ns_id is
> + * already set even though the namespace is not reachable from user space yet.
>   *
>   * Return: 0 if allowed, -EPERM if denied.
>   */

This isn't a bug, but there is no run(2) system call in this series.  The
syscall is runfd():

kernel/runfd.c:
    SYSCALL_DEFINE1(runfd, unsigned int, flags)

Should the comment say runfd(2) instead of run(2)?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47474652355

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 01/28] userns: Factor out idmap validation and commit helpers
  2026-12-05  3:26 ` [RFC PATCH v10 01/28] userns: Factor out idmap validation and commit helpers Jarkko Sakkinen
@ 2026-12-05  4:01   ` bot+bpf-ci
  2026-12-05 14:13     ` Jarkko Sakkinen
  0 siblings, 1 reply; 49+ messages in thread
From: bot+bpf-ci @ 2026-12-05  4:01 UTC (permalink / raw)
  To: jarkko, fsdevel
  Cc: jarkko, bpf, containers, linux-api, linux-arch, linux-doc,
	linux-fsdevel, linux-integrity, linux-kernel, linux-kselftest,
	linux-mm, linux-security-module, aleksa, alex, viro, ast, akpm,
	andrii, luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef

[-- Attachment #1: Type: text/plain, Size: 1675 bytes --]

> userns: Factor out idmap validation and commit helpers

TL;DR: Commit message only: it claims "no functional change", but the
extent-limit check and the map_write() error-path cleanup were rewritten. It
asks the author to say so and explain why they are equivalent.

>     userns: Factor out idmap validation and commit helpers
>
>     map_write() and its permission helpers validate extent ranges, check
>     root and unprivileged self-mappings, translate parent ID ranges, sort
>     extents, and install the resulting map inline for procfs text writes,
>     preventing non-procfs callers from reusing the same validation and
>     commit path.
>
>     Extract idmap_maps_root(), unpriv_idmap_permitted(),
>     validate_and_insert_extent(), free_new_idmap(), resolve_new_idmap(), and
>     commit_new_idmap() with no functional change.
>
>     Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>

This isn't a bug, but the changelog says "no functional change" while two
spots are rewritten rather than moved.

The extent-limit check went from:

    (new_map.nr_extents + 1) == UID_GID_MAP_MAX_EXTENTS && (next_line != NULL)

to:

    new_map->nr_extents >= UID_GID_MAP_MAX_EXTENTS

so it no longer depends on next_line.  The error path in map_write() also
no longer resets map->forward, map->reverse and map->nr_extents.

Could the changelog say briefly that these two were changed, and why each
is equivalent to the old code?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47474652355

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 22/28] security: Add run LSM hooks
  2026-12-05  3:26 ` [RFC PATCH v10 22/28] security: Add run LSM hooks Jarkko Sakkinen
@ 2026-12-05  4:02   ` bot+bpf-ci
  0 siblings, 0 replies; 49+ messages in thread
From: bot+bpf-ci @ 2026-12-05  4:02 UTC (permalink / raw)
  To: jarkko, fsdevel
  Cc: jarkko, bpf, containers, linux-api, linux-arch, linux-doc,
	linux-fsdevel, linux-integrity, linux-kernel, linux-kselftest,
	linux-mm, linux-security-module, aleksa, alex, viro, ast, akpm,
	andrii, luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef

[-- Attachment #1: Type: text/plain, Size: 1187 bytes --]

> security: Add run LSM hooks

TL;DR: Design question only: no LSM in the series sets lbs_runfd, so the
per-run security blob handling (alloc/free) looks unused. Could it wait until
a module needs it?

> diff --git a/security/security.c b/security/security.c
> --- a/security/security.c
> +++ b/security/security.c

[ ... ]

> +int security_runfd_alloc(struct run *run, unsigned int flags)
> +{
> +	int rc;
> +
> +	rc = lsm_blob_alloc(&run->security, blob_sizes.lbs_runfd,
> +			    GFP_KERNEL);
> +	if (unlikely(rc))
> +		return rc;
> +

This isn't a bug, but is there an LSM that will set .lbs_runfd?

No LSM in this series sets it (Landlock only registers runfd_share and
runfd_clone, and BPF LSM does not use composite blobs), so
blob_sizes.lbs_runfd stays 0 and run->security stays NULL.

Could the run->security blob handling (lbs_runfd, lsm_blob_alloc() here,
the kfree() in security_runfd_free()) wait until a module needs per-run
state?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47474652355

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 17/28] signal: Support run fds in pidfd_send_signal()
  2026-12-05  3:26 ` [RFC PATCH v10 17/28] signal: Support run fds in pidfd_send_signal() Jarkko Sakkinen
@ 2026-12-05  4:02   ` bot+bpf-ci
  0 siblings, 0 replies; 49+ messages in thread
From: bot+bpf-ci @ 2026-12-05  4:02 UTC (permalink / raw)
  To: jarkko, fsdevel
  Cc: jarkko, bpf, containers, linux-api, linux-arch, linux-doc,
	linux-fsdevel, linux-integrity, linux-kernel, linux-kselftest,
	linux-mm, linux-security-module, aleksa, alex, viro, ast, akpm,
	andrii, luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef

[-- Attachment #1: Type: text/plain, Size: 1578 bytes --]

> signal: Support run fds in pidfd_send_signal()

TL;DR: Nits only in runfd_send_signal(): the sig < 0 check is redundant with
valid_signal(), and the any_other flag duplicates other_err.

> diff --git a/kernel/runfd.c b/kernel/runfd.c
> --- a/kernel/runfd.c
> +++ b/kernel/runfd.c

[ ... ]

> +int runfd_send_signal(struct file *file, int sig,
> +		      struct siginfo __user *info, unsigned int flags)
> +{
> +	struct run *run = file->private_data;
> +	struct pid_namespace *pid_ns = run->ns->pid_ns_for_children;
> +	bool any_success = false;
> +	bool any_other = false;
> +	bool any_perm = false;
> +	int other_err = 0;
> +	struct pid *pid;
> +	int nr;
> +
> +	if (info || flags || sig < 0 || !valid_signal(sig))
> +		return -EINVAL;

This isn't a bug, but is the sig < 0 test needed here?  valid_signal() takes
an unsigned long, so it already rejects negative values.

[ ... ]

> +			} else if (err != -ESRCH && !any_other) {
> +				any_other = true;
> +				other_err = err;
> +			}
> +		}
> +		read_unlock(&tasklist_lock);
> +	}
> +
> +	if (any_success)
> +		return 0;
> +	if (any_other)
> +		return other_err;

This isn't a bug, but could other_err stand on its own here (!other_err in
the loop and if (other_err) return other_err;)?  any_other is only set
together with a non-zero other_err, so it carries the same information.


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47474652355

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 21/28] ipc/mqueue: Implement ->set_run() fs_context operation
  2026-12-05  3:26 ` [RFC PATCH v10 21/28] ipc/mqueue: " Jarkko Sakkinen
@ 2026-12-05  4:02   ` bot+bpf-ci
  0 siblings, 0 replies; 49+ messages in thread
From: bot+bpf-ci @ 2026-12-05  4:02 UTC (permalink / raw)
  To: jarkko, fsdevel
  Cc: jarkko, bpf, containers, linux-api, linux-arch, linux-doc,
	linux-fsdevel, linux-integrity, linux-kernel, linux-kselftest,
	linux-mm, linux-security-module, aleksa, alex, viro, ast, akpm,
	andrii, luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef

[-- Attachment #1: Type: text/plain, Size: 2921 bytes --]

> ipc/mqueue: Implement ->set_run() fs_context operation

TL;DR: Commit message only: mqueue_init_fs_context() now skips IPC namespace
capture on reconfigure (fspick, remount) without saying so, and the new
comment is confusing. Not a bug.

>     ipc/mqueue: Implement ->set_run() fs_context operation
>
>     mqueue_init_fs_context() captures current->nsproxy->ipc_ns and resets
>     fc->user_ns to ctx->ipc_ns->user_ns, overriding the user namespace
>     delegated by FSCONFIG_SET_RUN and leaving the context bound to the
>     caller's IPC namespace.
>     Wire up mqueue_set_run() to switch ctx->ipc_ns to the target
>     run's IPC namespace, update fc->user_ns to match, and mark mqueue
>     with FS_RUN_MOUNT.
>     Co-developed-by: David Howells <dhowells@redhat.com>
>     Signed-off-by: David Howells <dhowells@redhat.com>
>     Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>

> diff --git a/ipc/mqueue.c b/ipc/mqueue.c
> --- a/ipc/mqueue.c
> +++ b/ipc/mqueue.c

[ ... ]

> @@ -453,9 +468,16 @@ static int mqueue_init_fs_context(struct fs_context *fc)
>  	if (!ctx)
>  		return -ENOMEM;
>  
> -	ctx->ipc_ns = get_ipc_ns(current->nsproxy->ipc_ns);
> -	put_user_ns(fc->user_ns);
> -	fc->user_ns = get_user_ns(ctx->ipc_ns->user_ns);
> +	/*
> +	 * Reconfiguration keeps the superblock's user namespace and does not
> +	 * use ctx->ipc_ns, which put_ipc_ns() could be tearing down via
> +	 * sb->s_fs_info.
> +	 */
> +	if (fc->purpose != FS_CONTEXT_FOR_RECONFIGURE) {
> +		ctx->ipc_ns = get_ipc_ns(current->nsproxy->ipc_ns);
> +		put_user_ns(fc->user_ns);
> +		fc->user_ns = get_user_ns(ctx->ipc_ns->user_ns);
> +	}
>  	fc->fs_private = ctx;
>  	fc->ops = &mqueue_fs_context_ops;
>  	return 0;

This isn't a bug, but the changelog only describes the new ->set_run()
operation and the FS_RUN_MOUNT flag.  It doesn't mention that
mqueue_init_fs_context() now skips capturing the IPC namespace and
overriding fc->user_ns when fc->purpose == FS_CONTEXT_FOR_RECONFIGURE.

That change applies to every fspick() and remount of mqueue, and to the
re-initialisation done after fsmount(), not only to run-bound contexts.
For those paths ctx->ipc_ns is now NULL, and fc->user_ns stays as the
superblock's user namespace.

The new comment is also hard to follow.  It says ctx->ipc_ns is something
put_ipc_ns() "could be tearing down via sb->s_fs_info", but neither the old
nor the new code reads sb->s_fs_info here.

Could the changelog say why the FS_CONTEXT_FOR_RECONFIGURE case is now
skipped, and could the comment be reworded to say that, unlike proc, mqueue
does not take the superblock's IPC namespace from sb->s_fs_info?  Or would
this hunk be better as a separate patch?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47474652355

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 20/28] proc: Implement ->set_run() fs_context operation
  2026-12-05  3:26 ` [RFC PATCH v10 20/28] proc: Implement ->set_run() fs_context operation Jarkko Sakkinen
@ 2026-12-05  4:02   ` bot+bpf-ci
  2026-12-05 13:48   ` Jarkko Sakkinen
  1 sibling, 0 replies; 49+ messages in thread
From: bot+bpf-ci @ 2026-12-05  4:02 UTC (permalink / raw)
  To: jarkko, fsdevel
  Cc: jarkko, bpf, containers, linux-api, linux-arch, linux-doc,
	linux-fsdevel, linux-integrity, linux-kernel, linux-kselftest,
	linux-mm, linux-security-module, aleksa, alex, viro, ast, akpm,
	andrii, luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef

[-- Attachment #1: Type: text/plain, Size: 3384 bytes --]

> proc: Implement ->set_run() fs_context operation

TL;DR: The procfs gid= change may be an unintended user-visible behaviour
change: mounts and remounts that worked before (e.g. with pidns= or from an
ancestor userns) may now fail with -EINVAL. Should it be a separate patch?

> diff --git a/fs/proc/root.c b/fs/proc/root.c
> --- a/fs/proc/root.c
> +++ b/fs/proc/root.c

[ ... ]

> @@ -178,7 +180,9 @@ static int proc_parse_param(struct fs_context *fc, struct fs_parameter *param)
>  
>  	switch (opt) {
>  	case Opt_gid:
> -		ctx->gid = result.uint_32;
> +		if (!kgid_has_mapping(fc->user_ns, result.gid))
> +			return invalfc(fc, "Invalid gid");
> +		ctx->gid = result.gid;
>  		break;

[ ... ]

> @@ -234,8 +241,11 @@ static int proc_apply_options(struct proc_fs_info *fs_info,
>  	    ctx->pidonly != fs_info->pidonly)
>  		return invalf(fc, "proc: subset=pid cannot be changed\n");
>  
> -	if (ctx->mask & (1 << Opt_gid))
> -		fs_info->pid_gid = make_kgid(user_ns, ctx->gid);
> +	if (ctx->mask & (1 << Opt_gid)) {
> +		if (!kgid_has_mapping(fc->user_ns, ctx->gid))
> +			return invalfc(fc, "Invalid gid");
> +		fs_info->pid_gid = ctx->gid;
> +	}

Is it intended to change how gid= is handled for every procfs mount and
remount, rather than only run-bound ones?  The changelog only describes
->set_run().

The option used to be a u32 converted with make_kgid(current_user_ns(), ...)
when applied.  It is now converted at parse time by fs_param_is_gid(), and
the resulting kgid must also be mapped in fc->user_ns, both in
proc_parse_param() and in proc_apply_options().

Mounts that worked before can now fail with -EINVAL when the caller's user
namespace is an ancestor of the procfs owner and the group is not mapped
into that owner.  For example, host root runs:

    mount -t proc -o pidns=/proc/<ctr>/ns/pid,gid=<host gid> proc /mnt

against a user-namespaced container.  proc_parse_pidns_param() sets:

    fc->user_ns = get_user_ns(ctx->pid_ns->user_ns);

to the container's user namespace.  If gid= comes after pidns=,
proc_parse_param() rejects it immediately with "Invalid gid".  If gid= comes
first, proc_fill_super() -> proc_apply_options() rejects it.  Before the
patch both orders succeeded and pid_gid was set to the host kgid.

The same happens when host root enters only the container's pid and mount
namespaces (nsenter -p -m, without -U) and mounts or remounts proc with
gid=.  For a remount, fc->user_ns is s_user_ns, which is now kept by the new
FS_CONTEXT_FOR_RECONFIGURE branch in proc_init_fs_context().

Also, gid=4294967295 is now refused by fs_param_is_gid()'s gid_valid()
check, where before it was silently stored as INVALID_GID.

The stricter rule matches tmpfs, devpts and bpffs and may well be intended,
but it is a user-visible restriction on an existing mount option, and
Documentation/filesystems/proc.rst does not mention it.  The s_fs_info move
in proc_fill_super() and the reconfigure branch in proc_init_fs_context()
exist only to support this new check.

Should the gid change be a separate patch, with its own rationale and a note
on the compatibility impact for pidns= and remount users?

[ ... ]


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47474652355

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 02/28] userns: Add NS_SET_IDMAP ioctl
  2026-12-05  3:26 ` [RFC PATCH v10 02/28] userns: Add NS_SET_IDMAP ioctl Jarkko Sakkinen
@ 2026-12-05  4:02   ` bot+bpf-ci
  2026-12-05 13:47   ` Jarkko Sakkinen
  1 sibling, 0 replies; 49+ messages in thread
From: bot+bpf-ci @ 2026-12-05  4:02 UTC (permalink / raw)
  To: jarkko, fsdevel
  Cc: jarkko, bpf, containers, linux-api, linux-arch, linux-doc,
	linux-fsdevel, linux-integrity, linux-kernel, linux-kselftest,
	linux-mm, linux-security-module, aleksa, alex, viro, ast, akpm,
	andrii, luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef

[-- Attachment #1: Type: text/plain, Size: 2427 bytes --]

> userns: Add NS_SET_IDMAP ioctl

TL;DR: NS_SET_IDMAP in userns_set_idmap() runs both caller and opener
capability checks eagerly, so successful calls may log spurious audited
LSM/SELinux denials; the review suggests a noaudit check first.

> diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
> --- a/kernel/user_namespace.c
> +++ b/kernel/user_namespace.c

[ ... ]

> +long userns_set_idmap(struct file *filp, struct user_namespace *ns,
> +		      const struct userns_idmap __user *map, size_t size)
> +{

[ ... ]

> +	if (!ns->parent)
> +		return -EPERM;
> +	if (current_user_ns() != ns && current_user_ns() != ns->parent)
> +		return -EPERM;
> +
> +	file_ok = (filp->f_cred->user_ns == ns ||
> +		   filp->f_cred->user_ns == ns->parent) &&
> +		  file_ns_capable(filp, ns, CAP_SYS_ADMIN);
> +	if (!ns_capable(ns, CAP_SYS_ADMIN) && !file_ok)
> +		return -EPERM;

Is it intended that both capability checks always run here?  file_ok is
computed eagerly through file_ns_capable(), and ns_capable() is then
evaluated as well.  Both are audited checks, so every NS_SET_IDMAP call
produces two LSM capability decisions.

In the main use case from the commit message, an unprivileged owner opens
its user namespace and passes the fd to a privileged mapping helper.  The
helper's ns_capable() check is sufficient, but the opener check still runs
and SELinux checks cap_userns { sys_admin } for the opener's domain.  If
policy denies that, an AVC denial is logged for an ioctl that then
succeeds.

The reverse case behaves the same way: a caller without the capability,
whose fd opener had it, gets an audited ns_capable() failure before
file_ok allows the ioctl.

Other code that accepts either of two capability checks uses the noaudit
variant for the first one, for example checkpoint_restore_ns_capable_noaudit()
in include/linux/capability.h and pid_table_root_permissions() in
kernel/pid.c.

Could the caller be checked first with ns_capable_noaudit(ns,
CAP_SYS_ADMIN), consulting the opener through file_ns_capable() only when
that fails?

This does not appear to be addressed later in the series; the capability
check in userns_set_idmap() is unchanged at the end of it.


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47474652355

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 18/28] fork: Support CLONE_INTO_RUN in clone3()
  2026-12-05  3:26 ` [RFC PATCH v10 18/28] fork: Support CLONE_INTO_RUN in clone3() Jarkko Sakkinen
@ 2026-12-05  4:17   ` bot+bpf-ci
  0 siblings, 0 replies; 49+ messages in thread
From: bot+bpf-ci @ 2026-12-05  4:17 UTC (permalink / raw)
  To: jarkko, fsdevel
  Cc: jarkko, bpf, containers, linux-api, linux-arch, linux-doc,
	linux-fsdevel, linux-integrity, linux-kernel, linux-kselftest,
	linux-mm, linux-security-module, aleksa, alex, viro, ast, akpm,
	andrii, luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef

[-- Attachment #1: Type: text/plain, Size: 1520 bytes --]

> fork: Support CLONE_INTO_RUN in clone3()

TL;DR: Design/cleanup question, not a bug: new pid_ns_is_adding() in fork.c
duplicates runfd_pidns_alive() and the loop in alloc_pid(), differing in
READ_ONCE() and init_pid_ns handling. Could they share one helper?

> diff --git a/kernel/fork.c b/kernel/fork.c
> --- a/kernel/fork.c
> +++ b/kernel/fork.c

[ ... ]

> @@ -2019,6 +2035,17 @@ static bool need_futex_hash_allocate_default(u64 clone_flags)
>  	return clone_flags & CLONE_VM;
>  }
>  
> +static bool pid_ns_is_adding(const struct pid *pid)
> +{
> +	int i;
> +
> +	for (i = pid->level; i >= 0; i--) {
> +		if (unlikely(!(pid->numbers[i].ns->pid_allocated & PIDNS_ADDING)))
> +			return false;
> +	}
> +	return true;
> +}
> +

This isn't a bug, but this helper answers the same question as
runfd_pidns_alive() in kernel/runfd.c, which walks pid_ns->parent using
READ_ONCE() and stops before init_pid_ns.  alloc_pid() in kernel/pid.c also
has an open-coded copy of the same loop:

    for (upid = pid->numbers + ns->level; upid >= pid->numbers; --upid)
        if (unlikely(!(upid->ns->pid_allocated & PIDNS_ADDING)))

Could these share one helper in kernel/pid.c or pid_namespace.h?  Or is
there a reason they differ in READ_ONCE() use and in whether init_pid_ns is
checked?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47474652355

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 19/28] fs: Support FSCONFIG_SET_RUN in fsconfig()
  2026-12-05  3:26 ` [RFC PATCH v10 19/28] fs: Support FSCONFIG_SET_RUN in fsconfig() Jarkko Sakkinen
@ 2026-12-05  4:17   ` bot+bpf-ci
  0 siblings, 0 replies; 49+ messages in thread
From: bot+bpf-ci @ 2026-12-05  4:17 UTC (permalink / raw)
  To: jarkko, fsdevel
  Cc: jarkko, bpf, containers, linux-api, linux-arch, linux-doc,
	linux-fsdevel, linux-integrity, linux-kernel, linux-kselftest,
	linux-mm, linux-security-module, aleksa, alex, viro, ast, akpm,
	andrii, luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef

[-- Attachment #1: Type: text/plain, Size: 4390 bytes --]

> fs: Support FSCONFIG_SET_RUN in fsconfig()

TL;DR:
- devpts ptmx may be owned by an unmapped host uid for run-bound mounts,
  possibly making /dev/pts/ptmx unusable in the run
- FS_RUN_MOUNT comment omits that it allows fsopen() by callers failing
  may_mount()

> diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
> index bd1e8eb26edb..814eed794da7 100644
> --- a/fs/devpts/inode.c
> +++ b/fs/devpts/inode.c

[ ... ]

> @@ -457,7 +463,7 @@ static struct file_system_type devpts_fs_type = {
>  	.init_fs_context = devpts_init_fs_context,
>  	.parameters	= devpts_param_specs,
>  	.kill_sb	= devpts_kill_sb,
> -	.fs_flags	= FS_USERNS_MOUNT,
> +	.fs_flags	= FS_USERNS_MOUNT | FS_RUN_MOUNT,
>  };

With FS_RUN_MOUNT set here, a manager outside the run's user namespace can
now reach devpts_fill_super() and mknod_ptmx() for a run-bound context:

fsconfig(FSCONFIG_SET_RUN)
fsconfig(FSCONFIG_CMD_CREATE)
  vfs_get_tree()
    devpts_get_tree()
      get_tree_nodev()
        devpts_fill_super()
          mknod_ptmx()

In mknod_ptmx() the owner of the ptmx inode comes from the current task:

	kuid_t ptmx_uid = current_fsuid();
	kgid_t ptmx_gid = current_fsgid();
	...
	inode->i_uid = ptmx_uid;
	inode->i_gid = ptmx_gid;

Here current is the manager, not a task inside fc->user_ns.  If the manager
is host root (kuid 0) and the run maps 0..65535 to 100000..165535, the ptmx
node of a superblock with s_user_ns set to the run's user namespace ends up
owned by kuid 0 / kgid 0, which is not mapped in s_user_ns.

With the default DEVPTS_DEFAULT_PTMX_MODE (0000), can any task in the run
still open /dev/pts/ptmx?  generic_permission() denies by mode, and
capable_wrt_inode_uidgid(CAP_DAC_OVERRIDE) should fail because
privileged_wrt_inode_uidgid() requires the inode uid/gid to be mapped in the
caller's namespace.  chmod looks like it fails the same way, since
inode_owner_or_capable() needs the mapping for CAP_FOWNER.  Only a remount
with ptmxmode= appears to recover it.

This also seems inconsistent with the kuid_has_mapping(fc->user_ns, ...) and
kgid_has_mapping(fc->user_ns, ...) checks this patch adds to
devpts_parse_param(), which keep explicit uid=/gid= options from giving the
instance an owner that is unmapped in fc->user_ns.  The implicit owner taken
from current is neither checked nor remapped.

The commit message says fc->cred is refreshed for the run binding, but
mknod_ptmx() does not use fc->cred.

Should the owner be derived from fc->user_ns when fc->run_bound is set, for
example make_kuid(fc->user_ns, 0) and make_kgid(fc->user_ns, 0), or should
an unmapped owner be rejected?

[ ... ]

> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 5b3a100aba77..91479495b49e 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -2306,6 +2306,7 @@ struct file_system_type {
>  #define FS_USERNS_MOUNT_RESTRICTED 512	/* Restrict mount in userns if not already visible */
>  #define FS_USERNS_DELEGATABLE	1024	/* Can be mounted inside userns from outside */
>  #define FS_DISALLOW_NOTIFY	2048	/* No fsnotify marks on its objects */
> +#define FS_RUN_MOUNT	4096	/* Supports FSCONFIG_SET_RUN */
>  #define FS_RENAME_DOES_D_MOVE	32768	/* FS will handle d_move() during rename() internally. */

Does this comment describe the whole effect of the flag?  In sys_fsopen() it
is what lets a caller that fails may_mount() open the filesystem at all:

	priv = may_mount();
	if (!priv && !IS_ENABLED(CONFIG_RUNFD))
		return -EPERM;
	...
	if (!priv && !(fs_type->fs_flags & FS_RUN_MOUNT)) {
		put_filesystem(fs_type);
		return -EPERM;
	}

The flag is also not required for FSCONFIG_SET_RUN itself, since
fsconfig_set_run() accepts either flag:

	if (!(fc->fs_type->fs_flags &
	      (FS_RUN_MOUNT | FS_USERNS_DELEGATABLE)))
		return -EOPNOTSUPP;

A filesystem with only FS_USERNS_DELEGATABLE (bpf, nfs, nfs4) therefore
supports FSCONFIG_SET_RUN without FS_RUN_MOUNT, while a filesystem that sets
FS_RUN_MOUNT because it "supports FSCONFIG_SET_RUN" also lets any user
fsopen() it when CONFIG_RUNFD=y.

Could the comment (and the new mount_api.rst text) say that FS_RUN_MOUNT
permits fsopen() by callers that fail may_mount()?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47474652355

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 02/28] userns: Add NS_SET_IDMAP ioctl
  2026-12-05  3:26 ` [RFC PATCH v10 02/28] userns: Add NS_SET_IDMAP ioctl Jarkko Sakkinen
  2026-12-05  4:02   ` bot+bpf-ci
@ 2026-12-05 13:47   ` Jarkko Sakkinen
  1 sibling, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05 13:47 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: bpf, containers, linux-api, linux-arch, linux-doc,
	linux-integrity, linux-kernel, linux-kselftest, linux-mm,
	linux-security-module, aleksa, alex, viro, ast, akpm, andrii,
	luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef,
	juri.lelli, kees, kprateek.nayak, kpsingh, memxor, lennart, liam,
	manfred, martin.lau, matt, mgorman, mhocko, mic, rppt, neal, oleg,
	paul, ptikhomirov, peterz, rdunlap, serge, sergeh, skhan, song,
	stephen.smalley.work, rostedt, vschneid, vincent.guittot,
	yonghong.song, zygmunt.krynicki

diff --git a/fs/nsfs.c b/fs/nsfs.c
index c3c511133d80..f246930c9fa3 100644
--- a/fs/nsfs.c
+++ b/fs/nsfs.c
@@ -366,7 +366,7 @@ static long ns_ioctl(struct file *filp, unsigned int ioctl,
 		if (ns->ns_type != CLONE_NEWUSER)
 			return -EINVAL;
 
-		return userns_set_idmap(filp, to_user_ns(ns),
+		return userns_set_idmap(to_user_ns(ns),
 					(const struct userns_idmap __user *)arg,
 					_IOC_SIZE(ioctl));
 	default:
diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
index 7181c6011b44..079c66cbfa1c 100644
--- a/include/linux/user_namespace.h
+++ b/include/linux/user_namespace.h
@@ -35,7 +35,8 @@ struct uid_gid_map { /* 64 bytes -- 1 cache line */
 	};
 };
 
-#define USERNS_INIT_FLAGS USERNS_SETGROUPS_ALLOWED
+#define USERNS_STATE_SETGROUPS_ALLOWED 1UL
+#define USERNS_INIT_FLAGS USERNS_STATE_SETGROUPS_ALLOWED
 
 struct ucounts;
 struct userns_idmap;
@@ -207,7 +208,7 @@ extern bool in_userns(const struct user_namespace *ancestor,
 		       const struct user_namespace *child);
 extern bool current_in_userns(const struct user_namespace *target_ns);
 struct ns_common *ns_get_owner(struct ns_common *ns);
-long userns_set_idmap(struct file *file, struct user_namespace *ns,
+long userns_set_idmap(struct user_namespace *ns,
 		      const struct userns_idmap __user *map, size_t size);
 
 #if IS_ENABLED(CONFIG_KUNIT)
@@ -267,8 +268,7 @@ static inline struct ns_common *ns_get_owner(struct ns_common *ns)
 	return ERR_PTR(-EPERM);
 }
 
-static inline long userns_set_idmap(struct file *file,
-				    struct user_namespace *ns,
+static inline long userns_set_idmap(struct user_namespace *ns,
 				    const struct userns_idmap __user *map,
 				    size_t size)
 {
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 0a6d77b57798..1ab18f621980 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -150,7 +150,7 @@ int create_user_ns(struct cred *new)
 	set_userns_rlimit_max(ns, UCOUNT_RLIMIT_MEMLOCK, rlimit(RLIMIT_MEMLOCK));
 	ns->ucounts = ucounts;
 
-	/* Inherit USERNS_SETGROUPS_ALLOWED from our parent */
+	/* Inherit the setgroups policy from our parent. */
 	mutex_lock(&userns_state_mutex);
 	ns->flags = parent_ns->flags;
 	mutex_unlock(&userns_state_mutex);
@@ -1034,7 +1034,7 @@ static bool unpriv_idmap_permitted(const struct user_namespace *ns,
 	if (cap_setid == CAP_SETUID)
 		return uid_eq(make_kuid(ns->parent, id), cred->euid);
 	if (cap_setid == CAP_SETGID)
-		return !(ns_flags & USERNS_SETGROUPS_ALLOWED) &&
+		return !(ns_flags & USERNS_STATE_SETGROUPS_ALLOWED) &&
 		       gid_eq(make_kgid(ns->parent, id), cred->egid);
 	return false;
 }
@@ -1246,27 +1246,24 @@ static int parse_user_idmap_extents(__u64 uptr, __u32 nr_extents,
 
 /**
  * userns_set_idmap - Handle %NS_SET_IDMAP on a user namespace nsfs file
- * @filp: ``nsfs`` file referencing @ns
  * @ns: Target user namespace
  * @map: User pointer to &struct userns_idmap configuration
  * @size: Size of @map in bytes, encoded in the ioctl number
  *
  * Atomically configure UID, GID, and project ID mappings (and, when
- * @map->nr_gid_extents is non-zero, the %USERNS_SETGROUPS_ALLOWED policy) of
- * @ns. Requires ``CAP_SYS_ADMIN`` over @ns in the caller's or @filp opener's
- * credentials, with parent ID ranges authorized against the caller's
- * credentials.
+ * @map->nr_gid_extents is non-zero, the setgroups policy) of @ns. The
+ * caller must have ``CAP_SYS_ADMIN`` over @ns; the descriptor does not
+ * confer authority. Parent ID ranges are authorized against the caller.
  *
  * Return: 0 on success, negative error code on failure.
  */
-long userns_set_idmap(struct file *filp, struct user_namespace *ns,
+long userns_set_idmap(struct user_namespace *ns,
 		      const struct userns_idmap __user *map, size_t size)
 {
 	struct uid_gid_map new_uid = {}, new_gid = {}, new_projid = {};
 	struct userns_idmap req = {};
 	unsigned long new_flags;
 	unsigned int flags;
-	bool file_ok;
 	int ret;
 
 	BUILD_BUG_ON(sizeof(struct userns_idmap) != USERNS_IDMAP_SIZE_VER0);
@@ -1292,10 +1289,7 @@ long userns_set_idmap(struct file *filp, struct user_namespace *ns,
 	if (current_user_ns() != ns && current_user_ns() != ns->parent)
 		return -EPERM;
 
-	file_ok = (filp->f_cred->user_ns == ns ||
-		   filp->f_cred->user_ns == ns->parent) &&
-		  file_ns_capable(filp, ns, CAP_SYS_ADMIN);
-	if (!ns_capable(ns, CAP_SYS_ADMIN) && !file_ok)
+	if (!ns_capable(ns, CAP_SYS_ADMIN))
 		return -EPERM;
 
 	if (req.nr_uid_extents) {
@@ -1331,10 +1325,10 @@ long userns_set_idmap(struct file *filp, struct user_namespace *ns,
 
 	if (req.nr_gid_extents) {
 		if ((flags & USERNS_SETGROUPS_ALLOWED) &&
-		    !(new_flags & USERNS_SETGROUPS_ALLOWED))
+		    !(new_flags & USERNS_STATE_SETGROUPS_ALLOWED))
 			goto out_unlock;
 		if (!(flags & USERNS_SETGROUPS_ALLOWED))
-			new_flags &= ~USERNS_SETGROUPS_ALLOWED;
+			new_flags &= ~USERNS_STATE_SETGROUPS_ALLOWED;
 	}
 
 	if (req.nr_uid_extents) {
@@ -1465,7 +1459,7 @@ int proc_setgroups_show(struct seq_file *seq, void *v)
 	unsigned long userns_flags = READ_ONCE(ns->flags);
 
 	seq_printf(seq, "%s\n",
-		   (userns_flags & USERNS_SETGROUPS_ALLOWED) ?
+		   (userns_flags & USERNS_STATE_SETGROUPS_ALLOWED) ?
 		   "allow" : "deny");
 	return 0;
 }
@@ -1515,7 +1509,7 @@ ssize_t proc_setgroups_write(struct file *file, const char __user *buf,
 		/* Enabling setgroups after setgroups has been disabled
 		 * is not allowed.
 		 */
-		if (!(ns->flags & USERNS_SETGROUPS_ALLOWED))
+		if (!(ns->flags & USERNS_STATE_SETGROUPS_ALLOWED))
 			goto out_unlock;
 	} else {
 		/* Permanently disabling setgroups after setgroups has
@@ -1523,7 +1517,7 @@ ssize_t proc_setgroups_write(struct file *file, const char __user *buf,
 		 */
 		if (ns->gid_map.nr_extents != 0)
 			goto out_unlock;
-		ns->flags &= ~USERNS_SETGROUPS_ALLOWED;
+		ns->flags &= ~USERNS_STATE_SETGROUPS_ALLOWED;
 	}
 	mutex_unlock(&userns_state_mutex);
 
@@ -1547,7 +1541,7 @@ bool userns_may_setgroups(const struct user_namespace *ns)
 	 */
 	allowed = ns->gid_map.nr_extents != 0;
 	/* Is setgroups allowed? */
-	allowed = allowed && (ns->flags & USERNS_SETGROUPS_ALLOWED);
+	allowed = allowed && (ns->flags & USERNS_STATE_SETGROUPS_ALLOWED);
 	mutex_unlock(&userns_state_mutex);
 
 	return allowed;

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 03/28] mount: Add mnt_ns_get_root()
  2026-12-05  3:26 ` [RFC PATCH v10 03/28] mount: Add mnt_ns_get_root() Jarkko Sakkinen
@ 2026-12-05 13:47   ` Jarkko Sakkinen
  0 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05 13:47 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: bpf, containers, linux-api, linux-arch, linux-doc,
	linux-integrity, linux-kernel, linux-kselftest, linux-mm,
	linux-security-module, aleksa, alex, viro, ast, akpm, andrii,
	luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef,
	juri.lelli, kees, kprateek.nayak, kpsingh, memxor, lennart, liam,
	manfred, martin.lau, matt, mgorman, mhocko, mic, rppt, neal, oleg,
	paul, ptikhomirov, peterz, rdunlap, serge, sergeh, skhan, song,
	stephen.smalley.work, rostedt, vschneid, vincent.guittot,
	yonghong.song, zygmunt.krynicki

diff --git a/fs/namespace.c b/fs/namespace.c
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -6949,6 +6949,18 @@ static void mntns_put(struct ns_common *ns)
 	put_mnt_ns(to_mnt_ns(ns));
 }
 
+/**
+ * mnt_ns_get_root - Get the live root of a mount namespace
+ * @mnt_ns: Non-anonymous mount namespace with an active reference held
+ * @root: Storage for the referenced root path
+ *
+ * On success the caller must release @root with path_put(). If no filesystem
+ * covers the initial root, clear @root and return -ENOENT. On lookup failure,
+ * leave @root unchanged.
+ *
+ * Context: Sleepable, without namespace_sem or mount_lock held.
+ * Return: 0 on success or a negative error code.
+ */
 int mnt_ns_get_root(struct mnt_namespace *mnt_ns, struct path *root)
 {
 	int err;

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 04/28] mount: Enforce mount_too_revealing() for foreign mntns
  2026-12-05  3:26 ` [RFC PATCH v10 04/28] mount: Enforce mount_too_revealing() for foreign mntns Jarkko Sakkinen
@ 2026-12-05 13:47   ` Jarkko Sakkinen
  0 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05 13:47 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: bpf, containers, linux-api, linux-arch, linux-doc,
	linux-integrity, linux-kernel, linux-kselftest, linux-mm,
	linux-security-module, aleksa, alex, viro, ast, akpm, andrii,
	luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef,
	juri.lelli, kees, kprateek.nayak, kpsingh, memxor, lennart, liam,
	manfred, martin.lau, matt, mgorman, mhocko, mic, rppt, neal, oleg,
	paul, ptikhomirov, peterz, rdunlap, serge, sergeh, skhan, song,
	stephen.smalley.work, rostedt, vschneid, vincent.guittot,
	yonghong.song, zygmunt.krynicki

diff --git a/fs/namespace.c b/fs/namespace.c
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -6821,6 +6821,7 @@ static bool mnt_already_visible(struct mnt_namespace *ns,
 		return false;
 
 	guard(namespace_shared)();
+	guard(mount_locked_reader)();
 	hlist_for_each_entry(mnt, &ns->mnt_visible_mounts, mnt_ns_visible) {
 		const struct super_block *sb_visible = mnt->mnt.mnt_sb;
 		struct mount *child;
@@ -6836,8 +6837,7 @@ static bool mnt_already_visible(struct mnt_namespace *ns,
 		if (sb_visible->s_iflags & SB_I_RESTRICTED_VARIANT)
 			continue;
 
-		/* A local view of the mount flags */
-		mnt_flags = READ_ONCE(mnt->mnt.mnt_flags);
+		mnt_flags = mnt->mnt.mnt_flags;
 
 		/* Don't miss readonly hidden in the superblock flags */
 		if (sb_rdonly(mnt->mnt.mnt_sb))
@@ -6865,7 +6865,7 @@ static bool mnt_already_visible(struct mnt_namespace *ns,
 		list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) {
 			struct inode *inode = child->mnt_mountpoint->d_inode;
 			/* Only worry about locked mounts */
-			if (!foreign_ns && !(READ_ONCE(child->mnt.mnt_flags) & MNT_LOCKED))
+			if (!foreign_ns && !(child->mnt.mnt_flags & MNT_LOCKED))
 				continue;
 			/* Is the directory permanently empty? */
 			if (!is_empty_dir_inode(inode))

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 08/28] apparmor: Mediate MOVE_MOUNT_CLONE as recursive bind
  2026-12-05  3:26 ` [RFC PATCH v10 08/28] apparmor: Mediate MOVE_MOUNT_CLONE as recursive bind Jarkko Sakkinen
@ 2026-12-05 13:48   ` Jarkko Sakkinen
  0 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05 13:48 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: bpf, containers, linux-api, linux-arch, linux-doc,
	linux-integrity, linux-kernel, linux-kselftest, linux-mm,
	linux-security-module, aleksa, alex, viro, ast, akpm, andrii,
	luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef,
	juri.lelli, kees, kprateek.nayak, kpsingh, memxor, lennart, liam,
	manfred, martin.lau, matt, mgorman, mhocko, mic, rppt, neal, oleg,
	paul, ptikhomirov, peterz, rdunlap, serge, sergeh, skhan, song,
	stephen.smalley.work, rostedt, vschneid, vincent.guittot,
	yonghong.song, zygmunt.krynicki

diff --git a/security/apparmor/include/path.h b/security/apparmor/include/path.h
index 22f420d54950..250812a77e11 100644
--- a/security/apparmor/include/path.h
+++ b/security/apparmor/include/path.h
@@ -23,7 +23,6 @@ enum path_flags {
 
 	PATH_DELEGATE_DELETED = 0x10000, /* delegate deleted files */
 	PATH_MEDIATE_DELETED = 0x20000,	 /* mediate deleted paths */
-	PATH_TARGET_MNTNS = 0x40000,	 /* resolve path in target mntns */
 };
 
 int aa_path_name(const struct path *path, int flags, char *buffer,
diff --git a/security/apparmor/mount.c b/security/apparmor/mount.c
index 2dfe26e99fc1..d246491bf293 100644
--- a/security/apparmor/mount.c
+++ b/security/apparmor/mount.c
@@ -231,7 +231,6 @@ static int path_flags(const struct aa_profile *profile, const struct path *path)
  * @data: fs mount data (MAYBE NULL)
  * @binary: whether @data is binary
  * @devinfo: error str if (IS_ERR(@devname))
- * @pflags: extra path lookup flags for @mntpath
  * @ad: apparmor audit data structure
  *
  * Returns: 0 on success else error
@@ -240,7 +239,7 @@ static int match_mnt_path_str(struct aa_profile *profile,
 			      const struct path *mntpath, char *buffer,
 			      const char *devname, const char *type,
 			      unsigned long flags, void *data, bool binary,
-			      const char *devinfo, int pflags,
+			      const char *devinfo,
 			      struct apparmor_audit_data *ad)
 {
 	struct aa_perms perms = { };
@@ -257,8 +256,8 @@ static int match_mnt_path_str(struct aa_profile *profile,
 
 	ad->mnt.type = type;
 
-	error = aa_path_name(mntpath, path_flags(profile, mntpath) | pflags,
-			     buffer, &mntpnt, &ad->info, profile->disconnected);
+	error = aa_path_name(mntpath, path_flags(profile, mntpath), buffer,
+			     &mntpnt, &ad->info, profile->disconnected);
 	if (error)
 		return aa_audit_perm_error(&profile->label, AA_MAY_MOUNT,
 					   error, ad, audit_cb);
@@ -295,7 +294,6 @@ static int match_mnt_path_str(struct aa_profile *profile,
  * @flags: mount flags to match
  * @data: fs mount data (MAYBE NULL)
  * @binary: whether @data is binary
- * @pflags: extra path lookup flags for @path
  * @ad: apparmor audit data structure
  *
  * Returns: 0 on success else error
@@ -303,8 +301,7 @@ static int match_mnt_path_str(struct aa_profile *profile,
 static int match_mnt(struct aa_profile *profile, const struct path *path,
 		     char *buffer, const struct path *devpath, char *devbuffer,
 		     const char *type, unsigned long flags, void *data,
-		     bool binary, int pflags,
-		     struct apparmor_audit_data *ad)
+		     bool binary, struct apparmor_audit_data *ad)
 {
 	const char *devname = NULL, *info = NULL;
 	struct aa_ruleset *rules = profile->label.rules[0];
@@ -325,8 +322,7 @@ static int match_mnt(struct aa_profile *profile, const struct path *path,
 	}
 
 	return match_mnt_path_str(profile, path, buffer, devname,
-				  type, flags, data, binary, info,
-				  pflags, ad);
+				  type, flags, data, binary, info, ad);
 }
 
 int aa_remount(const struct cred *subj_cred,
@@ -350,7 +346,7 @@ int aa_remount(const struct cred *subj_cred,
 		return -ENOMEM;
 	error = fn_for_each(label, profile,
 			match_mnt(profile, path, buffer, NULL, NULL, NULL,
-				  flags, data, binary, 0, &ad));
+				  flags, data, binary, &ad));
 	aa_put_buffer(buffer);
 
 	return error;
@@ -388,8 +384,7 @@ int aa_bind_mount(const struct cred *subj_cred,
 
 	error = fn_for_each(label, profile,
 			match_mnt(profile, path, buffer, &old_path,
-				  old_buffer, NULL, flags, NULL, false, 0,
-				  &ad));
+				  old_buffer, NULL, flags, NULL, false, &ad));
 out:
 	aa_put_buffer(buffer);
 	aa_put_buffer(old_buffer);
@@ -420,7 +415,7 @@ int aa_mount_change_type(const struct cred *subj_cred,
 		return -ENOMEM;
 	error = fn_for_each(label, profile,
 			match_mnt(profile, path, buffer, NULL, NULL, NULL,
-				  flags, NULL, false, 0, &ad));
+				  flags, NULL, false, &ad));
 	aa_put_buffer(buffer);
 
 	return error;
@@ -434,7 +429,6 @@ int aa_move_mount(const struct cred *subj_cred,
 	char *to_buffer = NULL, *from_buffer = NULL;
 	unsigned long mnt_flags = (flags & MOVE_MOUNT_CLONE) ?
 				  (MS_BIND | MS_REC) : MS_MOVE;
-	int pflags = 0;
 	int error;
 	DEFINE_AUDIT_MOUNT(ad, OP_MOUNT, subj_cred);
 	ad.mnt.flags = mnt_flags;
@@ -456,12 +450,10 @@ int aa_move_mount(const struct cred *subj_cred,
 	if (!to_buffer || !from_buffer)
 		goto out;
 
-	if ((flags & MOVE_MOUNT_T_MNTNS) && !our_mnt(to_path->mnt))
-		pflags = PATH_TARGET_MNTNS;
 	error = fn_for_each(label, profile,
 			match_mnt(profile, to_path, to_buffer, from_path,
 				  from_buffer, NULL, mnt_flags, NULL, false,
-				  pflags, &ad));
+				  &ad));
 out:
 	aa_put_buffer(to_buffer);
 	aa_put_buffer(from_buffer);
@@ -538,12 +530,12 @@ int aa_new_mount(const struct cred *subj_cred, struct aa_label *label,
 		error = fn_for_each(label, profile,
 				match_mnt(profile, path, buffer, dev_path,
 					  dev_buffer, type, flags, data,
-					  binary, 0, &ad));
+					  binary, &ad));
 	} else {
 		error = fn_for_each(label, profile,
 				match_mnt_path_str(profile, path, buffer,
 						   dev_name, type, flags, data,
-						   binary, NULL, 0, &ad));
+						   binary, NULL, &ad));
 	}
 
 out:
diff --git a/security/apparmor/path.c b/security/apparmor/path.c
index 3443f5a86871..2494e8101538 100644
--- a/security/apparmor/path.c
+++ b/security/apparmor/path.c
@@ -116,14 +116,14 @@ static int d_namespace_path(const struct path *path, char *buf, char **name,
 	}
 
 	/* resolve paths relative to chroot?*/
-	if ((flags & PATH_CHROOT_REL) && !(flags & PATH_TARGET_MNTNS)) {
+	if (flags & PATH_CHROOT_REL) {
 		struct path root;
 		get_fs_root(current->fs, &root);
 		res = __d_path(path, &root, buf, buflen);
 		path_put(&root);
 	} else {
 		res = d_absolute_path(path, buf, buflen);
-		if (!(flags & PATH_TARGET_MNTNS) && !our_mnt(path->mnt))
+		if (!our_mnt(path->mnt))
 			connected = 0;
 	}
 
@@ -143,7 +143,7 @@ static int d_namespace_path(const struct path *path, char *buf, char **name,
 			*name = buf;
 			goto out;
 		}
-	} else if (!(flags & PATH_TARGET_MNTNS) && !our_mnt(path->mnt))
+	} else if (!our_mnt(path->mnt))
 		connected = 0;
 
 	*name = res;
diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c
index 0965e2f65509..24fbce2e4322 100644
--- a/security/apparmor/policy_unpack.c
+++ b/security/apparmor/policy_unpack.c
@@ -1244,14 +1244,12 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
 		goto fail;
 
 	/* path_flags is optional */
-	if (aa_unpack_u32(e, &profile->path_flags, "path_flags")) {
-		profile->path_flags &= ~PATH_TARGET_MNTNS;
+	if (aa_unpack_u32(e, &profile->path_flags, "path_flags"))
 		profile->path_flags |= profile->label.flags &
 			PATH_MEDIATE_DELETED;
-	} else {
+	else
 		/* set a default value if path_flags field is not present */
 		profile->path_flags = PATH_MEDIATE_DELETED;
-	}
 
 	info = "failed to unpack profile capabilities";
 	if (!aa_unpack_cap_low(e, &rules->caps.allow, NULL))

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 16/28] exit: Support P_RUNFD in waitid()
  2026-12-05  3:26 ` [RFC PATCH v10 16/28] exit: Support P_RUNFD in waitid() Jarkko Sakkinen
@ 2026-12-05 13:48   ` Jarkko Sakkinen
  0 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05 13:48 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: bpf, containers, linux-api, linux-arch, linux-doc,
	linux-integrity, linux-kernel, linux-kselftest, linux-mm,
	linux-security-module, aleksa, alex, viro, ast, akpm, andrii,
	luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef,
	juri.lelli, kees, kprateek.nayak, kpsingh, memxor, lennart, liam,
	manfred, martin.lau, matt, mgorman, mhocko, mic, rppt, neal, oleg,
	paul, ptikhomirov, peterz, rdunlap, serge, sergeh, skhan, song,
	stephen.smalley.work, rostedt, vschneid, vincent.guittot,
	yonghong.song, zygmunt.krynicki

diff --git a/kernel/runfd.c b/kernel/runfd.c
index 843f7f52fa95..56149dd3b4be 100644
--- a/kernel/runfd.c
+++ b/kernel/runfd.c
@@ -69,6 +69,8 @@ void runfd_put(struct run *c)
 	runfd_free(c);
 }
 
+DEFINE_FREE(runfd_put, struct run *, runfd_put(_T))
+
 static __poll_t runfd_poll(struct file *file, poll_table *wait)
 {
 	struct run *run = file->private_data;
@@ -241,17 +243,21 @@ static long runfd_share_nsfd(struct run *c, unsigned long arg)
  *
  * ``waitid(P_RUNFD, run_fd, infop, options, NULL)`` waits freezably until
  * ``run_fd`` reaches ``RUNFD_DEAD`` (unless ``WNOHANG`` or ``O_NONBLOCK`` is
- * set) and writes init's exit information into ``infop`` without consuming it.
+ * set) and writes init's exit information into ``infop``. The information
+ * remains available to other waiters. Init's parent reaps the process
+ * separately once it becomes waitable.
+ *
  * ``options`` must include ``WEXITED`` and may include ``WNOHANG`` and
- * ``WNOWAIT``; ``rusage`` must be ``NULL``, and the caller must run in an
- * ancestor active PID namespace.
+ * ``WNOWAIT``. ``WNOWAIT`` leaves the behavior unchanged. ``rusage`` must be
+ * ``NULL``, and the caller must run in an ancestor active PID namespace.
+ * ``IORING_OP_WAITID`` does not support ``P_RUNFD``.
  */
 long runfd_waitid(int upid, struct waitid_info *infop, int options,
 		  struct rusage *ru)
 {
 	struct pid_namespace *pid_ns;
 	unsigned int f_flags;
-	struct run *run;
+	struct run *run __free(runfd_put) = NULL;
 	bool nonblock;
 	int status;
 	kuid_t uid;
@@ -264,13 +270,19 @@ long runfd_waitid(int upid, struct waitid_info *infop, int options,
 	if (!(options & WEXITED))
 		return -EINVAL;
 
-	CLASS(fd, f)(upid);
-	if (fd_empty(f) || !runfd_is_file(fd_file(f)))
-		return -EBADF;
+	{
+		CLASS(fd, f)(upid);
+
+		if (fd_empty(f) || !runfd_is_file(fd_file(f)))
+			return -EBADF;
+
+		f_flags = READ_ONCE(fd_file(f)->f_flags);
+		run = fd_file(f)->private_data;
+		refcount_inc(&run->usage);
+		/* Don't pin the file across the wait: release may kill init. */
+	}
 
-	f_flags = READ_ONCE(fd_file(f)->f_flags);
 	nonblock = (options & WNOHANG) || (f_flags & O_NONBLOCK);
-	run = fd_file(f)->private_data;
 	pid_ns = task_active_pid_ns(current);
 
 	if (!pidns_is_ancestor(run->ns->pid_ns_for_children, pid_ns))

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 20/28] proc: Implement ->set_run() fs_context operation
  2026-12-05  3:26 ` [RFC PATCH v10 20/28] proc: Implement ->set_run() fs_context operation Jarkko Sakkinen
  2026-12-05  4:02   ` bot+bpf-ci
@ 2026-12-05 13:48   ` Jarkko Sakkinen
  1 sibling, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05 13:48 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: bpf, containers, linux-api, linux-arch, linux-doc,
	linux-integrity, linux-kernel, linux-kselftest, linux-mm,
	linux-security-module, aleksa, alex, viro, ast, akpm, andrii,
	luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef,
	juri.lelli, kees, kprateek.nayak, kpsingh, memxor, lennart, liam,
	manfred, martin.lau, matt, mgorman, mhocko, mic, rppt, neal, oleg,
	paul, ptikhomirov, peterz, rdunlap, serge, sergeh, skhan, song,
	stephen.smalley.work, rostedt, vschneid, vincent.guittot,
	yonghong.song, zygmunt.krynicki

diff --git a/fs/proc/root.c b/fs/proc/root.c
index de14a7933ee5..8e64572937db 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -180,8 +180,6 @@ static int proc_parse_param(struct fs_context *fc, struct fs_parameter *param)
 
 	switch (opt) {
 	case Opt_gid:
-		if (!kgid_has_mapping(fc->user_ns, result.gid))
-			return invalfc(fc, "Invalid gid");
 		ctx->gid = result.gid;
 		break;
 
@@ -241,11 +239,8 @@ static int proc_apply_options(struct proc_fs_info *fs_info,
 	    ctx->pidonly != fs_info->pidonly)
 		return invalf(fc, "proc: subset=pid cannot be changed\n");
 
-	if (ctx->mask & (1 << Opt_gid)) {
-		if (!kgid_has_mapping(fc->user_ns, ctx->gid))
-			return invalfc(fc, "Invalid gid");
+	if (ctx->mask & (1 << Opt_gid))
 		fs_info->pid_gid = ctx->gid;
-	}
 	if (ctx->mask & (1 << Opt_hidepid))
 		fs_info->hide_pid = ctx->hidepid;
 	if (ctx->mask & (1 << Opt_subset))

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 24/28] bpf: Register run LSM hooks
  2026-12-05  3:26 ` [RFC PATCH v10 24/28] bpf: Register run LSM hooks Jarkko Sakkinen
@ 2026-12-05 13:48   ` Jarkko Sakkinen
  0 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05 13:48 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: bpf, containers, linux-api, linux-arch, linux-doc,
	linux-integrity, linux-kernel, linux-kselftest, linux-mm,
	linux-security-module, aleksa, alex, viro, ast, akpm, andrii,
	luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef,
	juri.lelli, kees, kprateek.nayak, kpsingh, memxor, lennart, liam,
	manfred, martin.lau, matt, mgorman, mhocko, mic, rppt, neal, oleg,
	paul, ptikhomirov, peterz, rdunlap, serge, sergeh, skhan, song,
	stephen.smalley.work, rostedt, vschneid, vincent.guittot,
	yonghong.song, zygmunt.krynicki

diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c
index f41cebc1af4a..00358940e21f 100644
--- a/kernel/bpf/bpf_lsm.c
+++ b/kernel/bpf/bpf_lsm.c
@@ -16,7 +16,6 @@
 #include <linux/btf_ids.h>
 #include <linux/ima.h>
 #include <linux/bpf-cgroup.h>
-#include <linux/runfd.h>
 
 /* For every LSM hook that allows attachment of BPF programs, declare a nop
  * function where a BPF program can be attached. Notably, we qualify each with

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 26/28] ioctl: Register the runfd ioctl range
  2026-12-05  3:26 ` [RFC PATCH v10 26/28] ioctl: Register the runfd ioctl range Jarkko Sakkinen
  2026-12-05  3:52   ` bot+bpf-ci
@ 2026-12-05 13:49   ` Jarkko Sakkinen
  1 sibling, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05 13:49 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: bpf, containers, linux-api, linux-arch, linux-doc,
	linux-integrity, linux-kernel, linux-kselftest, linux-mm,
	linux-security-module, aleksa, alex, viro, ast, akpm, andrii,
	luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef,
	juri.lelli, kees, kprateek.nayak, kpsingh, memxor, lennart, liam,
	manfred, martin.lau, matt, mgorman, mhocko, mic, rppt, neal, oleg,
	paul, ptikhomirov, peterz, rdunlap, serge, sergeh, skhan, song,
	stephen.smalley.work, rostedt, vschneid, vincent.guittot,
	yonghong.song, zygmunt.krynicki

diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst
index ee1f8cd048c2..c82674453d79 100644
--- a/Documentation/userspace-api/ioctl/ioctl-number.rst
+++ b/Documentation/userspace-api/ioctl/ioctl-number.rst
@@ -385,7 +385,7 @@ Code  Seq#    Include File                                             Comments
 0xB8  01-02  uapi/misc/mrvl_cn10k_dpi.h                                Marvell CN10K DPI driver
 0xB8  all    uapi/linux/mshv.h                                         Microsoft Hyper-V /dev/mshv driver
                                                                        <mailto:linux-hyperv@vger.kernel.org>
-0xB9  00-0F  uapi/linux/runfd.h                                       runfd uAPI
+0xB9  00-0F  uapi/linux/runfd.h                                        runfd uAPI
 0xBA  00-0F  uapi/linux/liveupdate.h                                   Pasha Tatashin
                                                                        <mailto:pasha.tatashin@soleen.com>
 0xC0  00-0F  linux/usb/iowarrior.h

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 01/28] userns: Factor out idmap validation and commit helpers
  2026-12-05  4:01   ` bot+bpf-ci
@ 2026-12-05 14:13     ` Jarkko Sakkinen
  2026-12-05 14:22       ` Jarkko Sakkinen
  0 siblings, 1 reply; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05 14:13 UTC (permalink / raw)
  To: bot+bpf-ci
  Cc: fsdevel, bpf, containers, linux-api, linux-arch, linux-doc,
	linux-fsdevel, linux-integrity, linux-kernel, linux-kselftest,
	linux-mm, linux-security-module, aleksa, alex, viro, ast, akpm,
	andrii, luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef,
	a.com, juri.lelli, kees, kprateek.nayak, kpsingh, memxor, lennart,
	liam, manfred, martin.lau, matt, mgorman, mhocko, mic, rppt, neal,
	oleg, paul, ptikhomirov, peterz, rdunlap, serge, sergeh, skhan,
	song, stephen.smalley.work, rostedt, vschneid, vincent.guittot,
	yonghong.song, zygmunt.krynicki, martin.lau, mason

On Sat, Dec 05, 2026 at 04:01:58AM +0000, bot+bpf-ci@kernel.org wrote:
> > userns: Factor out idmap validation and commit helpers
> 
> TL;DR: Commit message only: it claims "no functional change", but the
> extent-limit check and the map_write() error-path cleanup were rewritten. It
> asks the author to say so and explain why they are equivalent.

This, and other commit message issues reported by Sashiko have been
addressed at

	https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git/log/?h=runfd

Other Sashiko and BPF bot issues have been addressed too, and fixup
diffs have been sent as responses to the corresponding patches.

Ucells is a Cells v3 ABI written in C:

	https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/ucells.git/about/?h=main

The gist:

- Ucells uses seccomp user notification to intercept Cells v3 syscalls
  and handle them in a userspace supervisor.
- The supervisor uses runfd to stage each cell’s namespaces,
  launch its init process, and track its exit.
- BPF programs enforce per-cell isolation rules at runfd and
  other kernel security hooks.

It's much more realistic than the Python daemon I had.

BPF LSM is still relatively fresh kernel feature that already exist in
the mainline, and  would really need more use cases so that we can make
it better.

I was wondering a while ago how I would practically use BPF LSM. Now it
found its use case :-) I'm glad it exists; otherwise this would not be
as conclusive as it is now.

Br, Jarkko

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [RFC PATCH v10 01/28] userns: Factor out idmap validation and commit helpers
  2026-12-05 14:13     ` Jarkko Sakkinen
@ 2026-12-05 14:22       ` Jarkko Sakkinen
  0 siblings, 0 replies; 49+ messages in thread
From: Jarkko Sakkinen @ 2026-12-05 14:22 UTC (permalink / raw)
  To: bot+bpf-ci
  Cc: fsdevel, bpf, containers, linux-api, linux-arch, linux-doc,
	linux-fsdevel, linux-integrity, linux-kernel, linux-kselftest,
	linux-mm, linux-security-module, aleksa, alex, viro, ast, akpm,
	andrii, luto, arnd, baolin.wang, bsegall, brauner, daniel, david,
	dhowells, dwmw2, dave, dietmar.eggemann, eddyz87, emil, ebiggers,
	georgia.garcia, giuseppe, gnoack, hughd, ihor.solodrai, mingo,
	jmorris, jack, jgg, jlayton, jolsa, john.johansen, corbet, josef,
	a.com, juri.lelli, kees, kprateek.nayak, kpsingh, memxor, lennart,
	liam, manfred, martin.lau, matt, mgorman, mhocko, mic, rppt, neal,
	oleg, paul, ptikhomirov, peterz, rdunlap, serge, sergeh, skhan,
	song, stephen.smalley.work, rostedt, vschneid, vincent.guittot,
	yonghong.song, zygmunt.krynicki, martin.lau, mason

On Sat, Dec 05, 2026 at 04:13:38PM +0200, Jarkko Sakkinen wrote:
> On Sat, Dec 05, 2026 at 04:01:58AM +0000, bot+bpf-ci@kernel.org wrote:
> > > userns: Factor out idmap validation and commit helpers
> > 
> > TL;DR: Commit message only: it claims "no functional change", but the
> > extent-limit check and the map_write() error-path cleanup were rewritten. It
> > asks the author to say so and explain why they are equivalent.
> 
> This, and other commit message issues reported by Sashiko have been
> addressed at
> 
> 	https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git/log/?h=runfd
> 
> Other Sashiko and BPF bot issues have been addressed too, and fixup
> diffs have been sent as responses to the corresponding patches.
> 
> Ucells is a Cells v3 ABI written in C:
> 
> 	https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/ucells.git/about/?h=main
> 
> The gist:
> 
> - Ucells uses seccomp user notification to intercept Cells v3 syscalls
>   and handle them in a userspace supervisor.
> - The supervisor uses runfd to stage each cell’s namespaces,
>   launch its init process, and track its exit.
> - BPF programs enforce per-cell isolation rules at runfd and
>   other kernel security hooks.
> 
> It's much more realistic than the Python daemon I had.
> 
> BPF LSM is still relatively fresh kernel feature that already exist in
> the mainline, and  would really need more use cases so that we can make
> it better.
> 
> I was wondering a while ago how I would practically use BPF LSM. Now it
> found its use case :-) I'm glad it exists; otherwise this would not be
> as conclusive as it is now.

With this, I guess reached singularity, and the rest is recursive
self-improvement.

Br, Jarkko

^ permalink raw reply	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2026-12-05 14:22 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05  3:26 [RFC PATCH v10 00/28] runfd: Staged namespace execution Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 01/28] userns: Factor out idmap validation and commit helpers Jarkko Sakkinen
2026-12-05  4:01   ` bot+bpf-ci
2026-12-05 14:13     ` Jarkko Sakkinen
2026-12-05 14:22       ` Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 02/28] userns: Add NS_SET_IDMAP ioctl Jarkko Sakkinen
2026-12-05  4:02   ` bot+bpf-ci
2026-12-05 13:47   ` Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 03/28] mount: Add mnt_ns_get_root() Jarkko Sakkinen
2026-12-05 13:47   ` Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 04/28] mount: Enforce mount_too_revealing() for foreign mntns Jarkko Sakkinen
2026-12-05 13:47   ` Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 05/28] mount: Support MOVE_MOUNT_T_MNTNS in move_mount() Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 06/28] security: Pass flags to security_move_mount() Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 07/28] mount: Support MOVE_MOUNT_CLONE with MOVE_MOUNT_T_MNTNS Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 08/28] apparmor: Mediate MOVE_MOUNT_CLONE as recursive bind Jarkko Sakkinen
2026-12-05 13:48   ` Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 09/28] userns: Factor out install_user_ns_cred() Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 10/28] nsproxy: Expose create_new_namespaces() Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 11/28] runfd: Add core infrastructure Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 12/28] runfd: Track init lifecycle via copy_process() and pid_namespace Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 13/28] runfd: Add runfd() system call Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 14/28] runfd: Add RUNFD_GET_NSFD ioctl Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 15/28] runfd: Add RUNFD_SHARE_NSFD ioctl Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 16/28] exit: Support P_RUNFD in waitid() Jarkko Sakkinen
2026-12-05 13:48   ` Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 17/28] signal: Support run fds in pidfd_send_signal() Jarkko Sakkinen
2026-12-05  4:02   ` bot+bpf-ci
2026-12-05  3:26 ` [RFC PATCH v10 18/28] fork: Support CLONE_INTO_RUN in clone3() Jarkko Sakkinen
2026-12-05  4:17   ` bot+bpf-ci
2026-12-05  3:26 ` [RFC PATCH v10 19/28] fs: Support FSCONFIG_SET_RUN in fsconfig() Jarkko Sakkinen
2026-12-05  4:17   ` bot+bpf-ci
2026-12-05  3:26 ` [RFC PATCH v10 20/28] proc: Implement ->set_run() fs_context operation Jarkko Sakkinen
2026-12-05  4:02   ` bot+bpf-ci
2026-12-05 13:48   ` Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 21/28] ipc/mqueue: " Jarkko Sakkinen
2026-12-05  4:02   ` bot+bpf-ci
2026-12-05  3:26 ` [RFC PATCH v10 22/28] security: Add run LSM hooks Jarkko Sakkinen
2026-12-05  4:02   ` bot+bpf-ci
2026-12-05  3:26 ` [RFC PATCH v10 23/28] landlock: Enforce namespace use restrictions on run Jarkko Sakkinen
2026-12-05  4:01   ` bot+bpf-ci
2026-12-05  3:26 ` [RFC PATCH v10 24/28] bpf: Register run LSM hooks Jarkko Sakkinen
2026-12-05 13:48   ` Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 25/28] arch: Wire up runfd() system call Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 26/28] ioctl: Register the runfd ioctl range Jarkko Sakkinen
2026-12-05  3:52   ` bot+bpf-ci
2026-12-05 13:49   ` Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 27/28] docs: Include runfd kernel-doc in the userspace API manual Jarkko Sakkinen
2026-12-05  3:26 ` [RFC PATCH v10 28/28] MAINTAINERS: Add entry for RUNFD Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox