* [RFC PATCH v2 00/13] Namespace for namespace roots
@ 2026-11-17 23:13 Jarkko Sakkinen
2026-11-17 23:13 ` [RFC PATCH v2 01/13] nsproxy: Pass nsproxy to create_new_namespaces() Jarkko Sakkinen
` (14 more replies)
0 siblings, 15 replies; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17 23:13 UTC (permalink / raw)
To: linux-fsdevel
Cc: Jarkko Sakkinen, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
OVERVIEW
========
A root namespace (rootns) is a kernel object backed by a file descriptor
that binds together:
1. A full or partial set of detached namespaces.
2. A dedicated PID namespace for spawning processes into, signaling
members, and polling or waiting on PID 1 exit.
3. An initially empty mount namespace (CLONE_EMPTY_MNTNS) that must be
populated before going live, without inheriting host mount-tree
ancestors.
Work on this feature started in 2025 from David Howells' container object
patch set [1], which I turned into a namespace for namespace roots and
rebuilt around that premise.
While the patch set is manually written, the original motivation came
from isolating LLM agents. Running untrusted agent workloads made it
clear that OCI runtimes need to minimize their live configuration
surface.
Assembling mounts, credentials, and namespaces inside helper processes
with a half-configured container is what I see as the main challenge,
and the existential debate around namespaces and container objects is an
unfocused discussion topic.
[1] https://lore.kernel.org/all/155059610368.17079.2220554006494174417.stgit@warthog.procyon.org.uk/
IMPLEMENTATION
==============
rootns_create() allocates a rootns instance backed by a pollable
anonymous inode fd, pinning dedicated empty mount (CLONE_EMPTY_MNTNS) and
PID namespaces along with any optional namespaces selected in flags.
Before entry, userspace populates the mount tree through the control fd:
FSCONFIG_SET_ROOTNS binds a newly opened fs_context to the target rootns,
and move_mount(..., MOVE_MOUNT_T_ROOTNS_ROOT) installs "/" onto the
nullfs root once (transitioning the rootns to ROOTNS_READY) and attaches
relative submounts beneath it.
Processes are spawned into a ready rootns via clone3() with
CLONE_INTO_ROOTNS and struct clone_args.rootns, without mutating the
caller in place. Pairing CLONE_INTO_ROOTNS with CLONE_VM | CLONE_VFORK
and opening the target binary via openat2(..., RESOLVE_IN_ROOT) on the
retained "/" mount fd allows spawning with execveat() without copying
page tables.
The first entrant becomes PID 1; once it exits and
zap_pid_ns_processes() reaps all members, poll() reports EPOLLHUP and
rootns_wait() returns init's exit status and rusage. rootns_kill() walks
pid_ns->idr under RCU to signal member thread groups.
CHANGES
=======
v2:
- Drop rootns provenance tracking (rootns_id and rootns_may_setns()) and
rely on user_namespace ownership for setns() isolation (Andy
Lutomirski).
- Replace the rootns_enter() system call with clone3(CLONE_INTO_ROOTNS)
and struct clone_args.rootns (CLONE_ARGS_SIZE_VER3), allowing
CLONE_VM | CLONE_VFORK and compatible per-child clone3() flags (Andy
Lutomirski).
- Drop the spurious task_no_new_privs() check in may_enter_rootns_creds()
(Andy Lutomirski).
- Update documentation, Kconfig, syscall tables, and kselftests for
CLONE_INTO_ROOTNS.
VERSIONS
========
v1: https://lore.kernel.org/linux-fsdevel/20261117050841.3289652-1-jarkko@kernel.org/
Cc: linux-api@vger.kernel.org
Cc: linux-doc@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: linux-security-module@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Ben Segall <bsegall@google.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: John Johansen <john.johansen@canonical.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Kees Cook <kees@kernel.org>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: "Liam R. Howlett" <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Manfred Spraul <manfred@colorfullife.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Neal Gompa <neal@gompa.dev>
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 Hallyn <sergeh@kernel.org>
Cc: Shuah Khan <skhan@linuxfoundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Jarkko Sakkinen (13):
nsproxy: Pass nsproxy to create_new_namespaces()
rootns: Add core infrastructure for root namespaces
rootns: Track init lifecycle via copy_process() and pid_namespace
rootns: Add rootns_create() system call
rootns: Add rootns_wait() system call
rootns: Add rootns_kill() system call
fork: Support CLONE_INTO_ROOTNS in clone3()
fs: Support FSCONFIG_SET_ROOTNS in fsconfig()
fs: Support installing rootns mount trees via move_mount()
arch: Wire up rootns system calls
docs: Document root namespace uAPI
selftests/rootns: Add root namespace test suite
MAINTAINERS: Add entry for ROOT NAMESPACE
Documentation/userspace-api/index.rst | 1 +
Documentation/userspace-api/rootns.rst | 40 +
MAINTAINERS | 11 +
arch/alpha/kernel/syscalls/syscall.tbl | 3 +
arch/arm/tools/syscall.tbl | 3 +
arch/arm64/tools/syscall_32.tbl | 3 +
arch/m68k/kernel/syscalls/syscall.tbl | 3 +
arch/microblaze/kernel/syscalls/syscall.tbl | 3 +
arch/mips/kernel/syscalls/syscall_n32.tbl | 3 +
arch/mips/kernel/syscalls/syscall_n64.tbl | 3 +
arch/mips/kernel/syscalls/syscall_o32.tbl | 3 +
arch/parisc/kernel/syscalls/syscall.tbl | 3 +
arch/powerpc/kernel/syscalls/syscall.tbl | 3 +
arch/s390/kernel/syscalls/syscall.tbl | 3 +
arch/sh/kernel/syscalls/syscall.tbl | 3 +
arch/sparc/kernel/syscalls/syscall.tbl | 3 +
arch/x86/entry/syscalls/syscall_32.tbl | 3 +
arch/x86/entry/syscalls/syscall_64.tbl | 3 +
arch/xtensa/kernel/syscalls/syscall.tbl | 3 +
fs/fsopen.c | 76 +-
fs/namespace.c | 178 ++-
fs/proc/root.c | 13 +
include/linux/compat.h | 4 +
include/linux/cred.h | 4 +-
include/linux/fs_context.h | 3 +
include/linux/nsproxy.h | 9 +-
include/linux/pid_namespace.h | 4 +
include/linux/rootns.h | 92 ++
include/linux/sched/task.h | 8 +
include/linux/syscalls.h | 4 +
include/uapi/asm-generic/unistd.h | 10 +-
include/uapi/linux/mount.h | 4 +-
include/uapi/linux/rootns.h | 38 +
include/uapi/linux/sched.h | 5 +
init/Kconfig | 9 +
ipc/mqueue.c | 12 +
kernel/Makefile | 2 +
kernel/cred.c | 70 +-
kernel/fork.c | 67 +-
kernel/nsproxy.c | 41 +-
kernel/pid_namespace.c | 2 +
kernel/rootns.c | 593 ++++++++
kernel/sys_ni.c | 6 +
scripts/syscall.tbl | 3 +
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/rootns/.gitignore | 2 +
tools/testing/selftests/rootns/Makefile | 5 +
tools/testing/selftests/rootns/config | 9 +
tools/testing/selftests/rootns/smoke.c | 1381 +++++++++++++++++++
49 files changed, 2680 insertions(+), 75 deletions(-)
create mode 100644 Documentation/userspace-api/rootns.rst
create mode 100644 include/linux/rootns.h
create mode 100644 include/uapi/linux/rootns.h
create mode 100644 kernel/rootns.c
create mode 100644 tools/testing/selftests/rootns/.gitignore
create mode 100644 tools/testing/selftests/rootns/Makefile
create mode 100644 tools/testing/selftests/rootns/config
create mode 100644 tools/testing/selftests/rootns/smoke.c
--
2.47.3
^ permalink raw reply [flat|nested] 36+ messages in thread
* [RFC PATCH v2 01/13] nsproxy: Pass nsproxy to create_new_namespaces()
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
@ 2026-11-17 23:13 ` Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 02/13] rootns: Add core infrastructure for root namespaces Jarkko Sakkinen
` (13 subsequent siblings)
14 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17 23:13 UTC (permalink / raw)
To: linux-fsdevel
Cc: Jarkko Sakkinen, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
create_new_namespaces() takes a struct task_struct pointer even though
it only reads tsk->nsproxy, preventing callers outside kernel/nsproxy.c
from constructing a child nsproxy without mutating a task.
Expose create_new_namespaces() and pass the source struct nsproxy
pointer directly so root namespace creation can allocate a detached
namespace set from current->nsproxy.
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 | 5 +++++
kernel/nsproxy.c | 32 ++++++++++++++++----------------
2 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/include/linux/nsproxy.h b/include/linux/nsproxy.h
index dc2447f5f092..cacbbbe3f1ce 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,10 @@ static inline struct cred *nsset_cred(struct nsset *set)
*
*/
+struct nsproxy *create_new_namespaces(u64 flags,
+ struct nsproxy *ns,
+ 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..8a3c6d4e94e2 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -85,9 +85,10 @@ 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 nsproxy *ns,
+ struct user_namespace *user_ns,
+ struct fs_struct *new_fs)
{
struct nsproxy *new_nsp;
int err;
@@ -96,52 +97,51 @@ static struct nsproxy *create_new_namespaces(u64 flags,
if (!new_nsp)
return ERR_PTR(-ENOMEM);
- new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns,
- user_ns, new_fs);
+ new_nsp->mnt_ns = copy_mnt_ns(flags, ns->mnt_ns, user_ns, new_fs);
if (IS_ERR(new_nsp->mnt_ns)) {
err = PTR_ERR(new_nsp->mnt_ns);
goto out_ns;
}
- new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
+ new_nsp->uts_ns = copy_utsname(flags, user_ns, ns->uts_ns);
if (IS_ERR(new_nsp->uts_ns)) {
err = PTR_ERR(new_nsp->uts_ns);
goto out_uts;
}
- new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
+ new_nsp->ipc_ns = copy_ipcs(flags, user_ns, ns->ipc_ns);
if (IS_ERR(new_nsp->ipc_ns)) {
err = PTR_ERR(new_nsp->ipc_ns);
goto out_ipc;
}
new_nsp->pid_ns_for_children =
- copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children);
+ copy_pid_ns(flags, user_ns, ns->pid_ns_for_children);
if (IS_ERR(new_nsp->pid_ns_for_children)) {
err = PTR_ERR(new_nsp->pid_ns_for_children);
goto out_pid;
}
new_nsp->cgroup_ns = copy_cgroup_ns(flags, user_ns,
- tsk->nsproxy->cgroup_ns);
+ ns->cgroup_ns);
if (IS_ERR(new_nsp->cgroup_ns)) {
err = PTR_ERR(new_nsp->cgroup_ns);
goto out_cgroup;
}
- new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
+ new_nsp->net_ns = copy_net_ns(flags, user_ns, ns->net_ns);
if (IS_ERR(new_nsp->net_ns)) {
err = PTR_ERR(new_nsp->net_ns);
goto out_net;
}
new_nsp->time_ns_for_children = copy_time_ns(flags, user_ns,
- tsk->nsproxy->time_ns_for_children);
+ ns->time_ns_for_children);
if (IS_ERR(new_nsp->time_ns_for_children)) {
err = PTR_ERR(new_nsp->time_ns_for_children);
goto out_time;
}
- new_nsp->time_ns = get_time_ns(tsk->nsproxy->time_ns);
+ new_nsp->time_ns = get_time_ns(ns->time_ns);
return new_nsp;
@@ -192,7 +192,7 @@ int copy_namespaces(u64 flags, struct task_struct *tsk)
(CLONE_NEWIPC | CLONE_SYSVSEM))
return -EINVAL;
- new_ns = create_new_namespaces(flags, tsk, user_ns, tsk->fs);
+ new_ns = create_new_namespaces(flags, tsk->nsproxy, user_ns, tsk->fs);
if (IS_ERR(new_ns))
return PTR_ERR(new_ns);
@@ -231,7 +231,7 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,
flags |= CLONE_EMPTY_MNTNS;
}
- *new_nsp = create_new_namespaces(flags, current, user_ns,
+ *new_nsp = create_new_namespaces(flags, current->nsproxy, user_ns,
new_fs ? new_fs : current->fs);
if (IS_ERR(*new_nsp)) {
err = PTR_ERR(*new_nsp);
@@ -289,7 +289,7 @@ int exec_task_namespaces(void)
if (tsk->nsproxy->time_ns_for_children == tsk->nsproxy->time_ns)
return 0;
- new = create_new_namespaces(0, tsk, current_user_ns(), tsk->fs);
+ new = create_new_namespaces(0, tsk->nsproxy, current_user_ns(), tsk->fs);
if (IS_ERR(new))
return PTR_ERR(new);
@@ -356,7 +356,7 @@ static int prepare_nsset(unsigned flags, struct nsset *nsset)
struct task_struct *me = current;
nsset->flags = flags;
- nsset->nsproxy = create_new_namespaces(0, me, current_user_ns(), me->fs);
+ nsset->nsproxy = create_new_namespaces(0, me->nsproxy, current_user_ns(), me->fs);
if (IS_ERR(nsset->nsproxy))
return PTR_ERR(nsset->nsproxy);
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [RFC PATCH v2 02/13] rootns: Add core infrastructure for root namespaces
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
2026-11-17 23:13 ` [RFC PATCH v2 01/13] nsproxy: Pass nsproxy to create_new_namespaces() Jarkko Sakkinen
@ 2026-11-17 23:13 ` Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 03/13] rootns: Track init lifecycle via copy_process() and pid_namespace Jarkko Sakkinen
` (12 subsequent siblings)
14 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17 23:13 UTC (permalink / raw)
To: linux-fsdevel
Cc: Jarkko Sakkinen, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
Linux namespaces can be created and entered individually, but userspace
orchestrators lack a single kernel object that binds a namespace set, a
root mount, and an init process behind a pollable file descriptor.
Add struct rootns, its lifecycle states, reference counting, uAPI
creation flags, and anonymous inode file operations under CONFIG_ROOTNS.
Drop active and passive namespace references on final release, send
SIGKILL to the rootns init thread group on close when
ROOTNS_KILL_ON_CLOSE is set, and report EPOLLHUP from poll() once the
rootns reaches ROOTNS_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/rootns.h | 66 ++++++++++++++++++++++
include/uapi/linux/rootns.h | 38 +++++++++++++
init/Kconfig | 9 +++
kernel/Makefile | 2 +
kernel/rootns.c | 107 ++++++++++++++++++++++++++++++++++++
5 files changed, 222 insertions(+)
create mode 100644 include/linux/rootns.h
create mode 100644 include/uapi/linux/rootns.h
create mode 100644 kernel/rootns.c
diff --git a/include/linux/rootns.h b/include/linux/rootns.h
new file mode 100644
index 000000000000..8464c90863ac
--- /dev/null
+++ b/include/linux/rootns.h
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2019 Red Hat, Inc. All Rights Reserved.
+ */
+
+#ifndef _LINUX_ROOTNS_H
+#define _LINUX_ROOTNS_H
+
+#include <linux/refcount.h>
+#include <linux/resource.h>
+#include <linux/spinlock.h>
+#include <linux/wait.h>
+#include <linux/path.h>
+
+struct cred;
+struct file;
+struct nsproxy;
+struct pid;
+struct task_struct;
+
+enum rootns_state {
+ ROOTNS_EMPTY = 0,
+ ROOTNS_READY = 1,
+ ROOTNS_FORKING = 2,
+ ROOTNS_RUNNING = 3,
+ ROOTNS_DEAD = 4,
+};
+
+/*
+ * The rootns object.
+ */
+struct rootns {
+ refcount_t usage;
+ int exit_code; /* The exit code of 'init' */
+ struct rusage rusage; /* Resource usage of 'init' */
+ const struct cred *cred; /* Creds for this rootns, including userns */
+ struct nsproxy *ns; /* This rootns's namespaces */
+ struct path root; /* The root of the rootns's fs namespace */
+ struct pid *init_pid; /* The 'init' task's TGID (pid ref) */
+ spinlock_t lock; /* Guards rootns lifecycle state */
+ wait_queue_head_t waitq; /* Someone waiting for init to exit waits here */
+ unsigned int flags; /* Validated rootns_create() flags */
+ enum rootns_state state; /* Root namespace lifecycle state */
+};
+
+#ifdef CONFIG_ROOTNS
+struct rootns *get_rootns(struct rootns *c);
+void put_rootns(struct rootns *c);
+bool is_rootns_file(struct file *file);
+#else
+static inline struct rootns *get_rootns(struct rootns *c)
+{
+ return NULL;
+}
+
+static inline void put_rootns(struct rootns *c)
+{
+}
+
+static inline bool is_rootns_file(struct file *file)
+{
+ return false;
+}
+#endif /* CONFIG_ROOTNS */
+
+#endif /* _LINUX_ROOTNS_H */
diff --git a/include/uapi/linux/rootns.h b/include/uapi/linux/rootns.h
new file mode 100644
index 000000000000..bde89d183578
--- /dev/null
+++ b/include/uapi/linux/rootns.h
@@ -0,0 +1,38 @@
+/* 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_ROOTNS_H
+#define _UAPI_LINUX_ROOTNS_H
+
+/**
+ * enum rootns_flags - Flags for rootns_create()
+ * @ROOTNS_CGROUP: Create a fresh cgroup namespace instead of inheriting.
+ * @ROOTNS_UTS: Create a fresh UTS namespace instead of inheriting.
+ * @ROOTNS_IPC: Create a fresh IPC namespace instead of inheriting.
+ * @ROOTNS_USER: Create a fresh user namespace owned by the caller.
+ * @ROOTNS_NET: Create a fresh network namespace instead of inheriting.
+ * @ROOTNS_KILL_ON_CLOSE: Send %SIGKILL to rootns init on final fd release.
+ * @ROOTNS_CLOSE_ON_EXEC: Set %O_CLOEXEC on the returned control fd.
+ * @ROOTNS_ALL_NAMESPACES: Mask of all optional namespace selection flags.
+ * @ROOTNS_ALL_FLAGS: Mask of all valid flags accepted by rootns_create().
+ *
+ * Every root namespace unconditionally owns dedicated mount and PID
+ * namespaces. Optional namespace flags allocate fresh instances of the
+ * remaining namespaces instead of inheriting them from the caller.
+ */
+enum rootns_flags {
+ ROOTNS_CGROUP = 0x00000001,
+ ROOTNS_UTS = 0x00000002,
+ ROOTNS_IPC = 0x00000004,
+ ROOTNS_USER = 0x00000008,
+ ROOTNS_NET = 0x00000010,
+ ROOTNS_KILL_ON_CLOSE = 0x00000100,
+ ROOTNS_CLOSE_ON_EXEC = 0x00000200,
+ ROOTNS_ALL_NAMESPACES = 0x0000001f,
+ ROOTNS_ALL_FLAGS = 0x0000031f,
+};
+
+#endif /* _UAPI_LINUX_ROOTNS_H */
diff --git a/init/Kconfig b/init/Kconfig
index c8a7cfa60a6e..4e9483d3b0a9 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1281,6 +1281,15 @@ config NET_NS
Allow user space to create what appear to be multiple instances
of the network stack.
+config ROOTNS
+ bool "Root namespace"
+ depends on USER_NS && PID_NS && UTS_NS && IPC_NS && NET_NS && CGROUPS
+ help
+ Allow user space to create and manage isolated root namespaces
+ with their own mount tree, credentials, namespace set, and init
+ process lifecycle via rootns_create(), rootns_wait(),
+ rootns_kill(), and clone3() with CLONE_INTO_ROOTNS.
+
endif # NAMESPACES
config CHECKPOINT_RESTORE
diff --git a/kernel/Makefile b/kernel/Makefile
index 4ff92e24680c..7074d2664ce7 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_ROOTNS) += rootns.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/rootns.c b/kernel/rootns.c
new file mode 100644
index 000000000000..e75d918b93ec
--- /dev/null
+++ b/kernel/rootns.c
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2017-2019 Red Hat, Inc. All Rights Reserved.
+ */
+
+#include <linux/poll.h>
+#include <linux/wait.h>
+#include <linux/fs.h>
+#include <linux/anon_inodes.h>
+#include <linux/rootns.h>
+#include <linux/sched/signal.h>
+#include <linux/slab.h>
+#include <linux/syscalls.h>
+#include <linux/uaccess.h>
+#include <linux/nsproxy.h>
+#include <linux/ns_common.h>
+#include <linux/nsfs.h>
+#include <linux/pid.h>
+#include <linux/user_namespace.h>
+#include <linux/compat.h>
+#include <uapi/linux/rootns.h>
+
+/*
+ * Get a reference to a rootns.
+ */
+struct rootns *get_rootns(struct rootns *c)
+{
+ refcount_inc(&c->usage);
+ return c;
+}
+
+/*
+ * Drop a reference on a rootns and clear it if it is no longer in use.
+ */
+void put_rootns(struct rootns *c)
+{
+ if (!c || !refcount_dec_and_test(&c->usage))
+ return;
+
+ if (c->ns)
+ put_nsproxy(c->ns);
+ path_put(&c->root);
+
+ if (c->init_pid)
+ put_pid(c->init_pid);
+ if (c->cred) {
+ ns_ref_active_put(c->cred->user_ns);
+ put_cred(c->cred);
+ }
+ kfree(c);
+}
+
+/*
+ * Allow the user to poll for the rootns dying.
+ */
+static __poll_t rootns_poll(struct file *file, poll_table *wait)
+{
+ struct rootns *rootns = file->private_data;
+ __poll_t mask = 0;
+
+ poll_wait(file, &rootns->waitq, wait);
+
+ if (READ_ONCE(rootns->state) == ROOTNS_DEAD)
+ mask |= EPOLLHUP;
+
+ return mask;
+}
+
+static int __rootns_kill(struct rootns *rootns, int sig, bool priv)
+{
+ struct pid *pid = NULL;
+ int ret;
+
+ scoped_guard(spinlock, &rootns->lock) {
+ if (rootns->state == ROOTNS_RUNNING)
+ pid = get_pid(rootns->init_pid);
+ }
+ if (!pid)
+ return -ESRCH;
+
+ ret = kill_pid(pid, sig, priv);
+ put_pid(pid);
+ return ret;
+}
+
+static int rootns_release(struct inode *inode, struct file *file)
+{
+ struct rootns *rootns = file->private_data;
+
+ if (rootns->flags & ROOTNS_KILL_ON_CLOSE)
+ __rootns_kill(rootns, SIGKILL, true);
+ put_rootns(rootns);
+ return 0;
+}
+
+static const struct file_operations rootns_fops = {
+ .poll = rootns_poll,
+ .release = rootns_release,
+};
+
+/*
+ * Returns true if the file is a rootns.
+ */
+bool is_rootns_file(struct file *file)
+{
+ return file->f_op == &rootns_fops;
+}
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [RFC PATCH v2 03/13] rootns: Track init lifecycle via copy_process() and pid_namespace
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
2026-11-17 23:13 ` [RFC PATCH v2 01/13] nsproxy: Pass nsproxy to create_new_namespaces() Jarkko Sakkinen
2026-11-17 23:13 ` [RFC PATCH v2 02/13] rootns: Add core infrastructure for root namespaces Jarkko Sakkinen
@ 2026-11-17 23:13 ` Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 04/13] rootns: Add rootns_create() system call Jarkko Sakkinen
` (11 subsequent siblings)
14 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17 23:13 UTC (permalink / raw)
To: linux-fsdevel
Cc: Jarkko Sakkinen, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
A root namespace needs to record its init thread group's PID when
bootstrapped and capture its exit status and resource usage once all
processes in the root namespace have terminated, without serializing
normal fork() and exit() paths inside the container.
Commit the bootstrap init PID and wake waiters in copy_rootns(), and
invoke exit_rootns() from zap_pid_ns_processes() after the root
namespace'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/rootns.h | 12 +++++++++++
kernel/fork.c | 2 ++
kernel/pid_namespace.c | 2 ++
kernel/rootns.c | 40 +++++++++++++++++++++++++++++++++++
5 files changed, 60 insertions(+)
diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
index b20baaa7e62b..6fd959f4d0d4 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 rootns;
#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_ROOTNS
+ struct rootns *rootns;
+#endif
struct ns_common ns;
struct work_struct work;
} __randomize_layout;
diff --git a/include/linux/rootns.h b/include/linux/rootns.h
index 8464c90863ac..b8437bf21830 100644
--- a/include/linux/rootns.h
+++ b/include/linux/rootns.h
@@ -16,6 +16,7 @@ struct cred;
struct file;
struct nsproxy;
struct pid;
+struct pid_namespace;
struct task_struct;
enum rootns_state {
@@ -47,6 +48,8 @@ struct rootns {
struct rootns *get_rootns(struct rootns *c);
void put_rootns(struct rootns *c);
bool is_rootns_file(struct file *file);
+void copy_rootns(struct task_struct *tsk, struct rootns *rootns);
+void exit_rootns(struct pid_namespace *pid_ns, struct task_struct *tsk);
#else
static inline struct rootns *get_rootns(struct rootns *c)
{
@@ -61,6 +64,15 @@ static inline bool is_rootns_file(struct file *file)
{
return false;
}
+
+static inline void copy_rootns(struct task_struct *tsk, struct rootns *rootns)
+{
+}
+
+static inline void exit_rootns(struct pid_namespace *pid_ns,
+ struct task_struct *tsk)
+{
+}
#endif /* CONFIG_ROOTNS */
#endif /* _LINUX_ROOTNS_H */
diff --git a/kernel/fork.c b/kernel/fork.c
index 5efceb8d58a7..99e22b3cd213 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/rootns.h>
#include <linux/posix-timers.h>
#include <linux/user-return-notifier.h>
#include <linux/oom.h>
@@ -2565,6 +2566,7 @@ __latent_entropy struct task_struct *copy_process(
attach_pid(p, PIDTYPE_TGID);
attach_pid(p, PIDTYPE_PGID);
attach_pid(p, PIDTYPE_SID);
+ copy_rootns(p, NULL);
__this_cpu_inc(process_counts);
} else {
current->signal->nr_threads++;
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 127a5fd23e70..081c27aa85bd 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/rootns.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);
+ exit_rootns(pid_ns, me);
return;
}
diff --git a/kernel/rootns.c b/kernel/rootns.c
index e75d918b93ec..e3b203322ae2 100644
--- a/kernel/rootns.c
+++ b/kernel/rootns.c
@@ -16,6 +16,7 @@
#include <linux/ns_common.h>
#include <linux/nsfs.h>
#include <linux/pid.h>
+#include <linux/pid_namespace.h>
#include <linux/user_namespace.h>
#include <linux/compat.h>
#include <uapi/linux/rootns.h>
@@ -105,3 +106,42 @@ bool is_rootns_file(struct file *file)
{
return file->f_op == &rootns_fops;
}
+
+void copy_rootns(struct task_struct *tsk, struct rootns *c)
+{
+ if (likely(!c || READ_ONCE(c->state) != ROOTNS_FORKING))
+ return;
+
+ scoped_guard(spinlock, &c->lock) {
+ get_rootns(c);
+ WRITE_ONCE(c->init_pid, get_task_pid(tsk, PIDTYPE_TGID));
+ WRITE_ONCE(c->state, ROOTNS_RUNNING);
+ }
+ wake_up_all(&c->waitq);
+}
+
+void exit_rootns(struct pid_namespace *pid_ns, struct task_struct *tsk)
+{
+ struct rootns *c = pid_ns->rootns;
+ struct task_struct *leader;
+ struct rusage rusage;
+ int status;
+
+ if (!c)
+ return;
+
+ leader = tsk->group_leader;
+ status = (tsk->signal->flags & SIGNAL_GROUP_EXIT) ?
+ tsk->signal->group_exit_code : leader->exit_code;
+ getrusage(leader, RUSAGE_BOTH, &rusage);
+
+ scoped_guard(spinlock, &c->lock) {
+ c->exit_code = status;
+ c->rusage = rusage;
+ WRITE_ONCE(c->state, ROOTNS_DEAD);
+ }
+
+ pid_ns->rootns = NULL;
+ wake_up_poll(&c->waitq, EPOLLHUP);
+ put_rootns(c);
+}
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [RFC PATCH v2 04/13] rootns: Add rootns_create() system call
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
` (2 preceding siblings ...)
2026-11-17 23:13 ` [RFC PATCH v2 03/13] rootns: Track init lifecycle via copy_process() and pid_namespace Jarkko Sakkinen
@ 2026-11-17 23:13 ` Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 05/13] rootns: Add rootns_wait() " Jarkko Sakkinen
` (10 subsequent siblings)
14 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17 23:13 UTC (permalink / raw)
To: linux-fsdevel
Cc: Jarkko Sakkinen, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
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 rootns_create() system call to allocate a detached rootns
instance with dedicated empty mount (CLONE_EMPTY_MNTNS) and PID
namespaces and return its control file descriptor. Create fresh optional
namespaces selected in flags while inheriting unset ones from the
caller, and pin active references for the lifetime of the rootns. Leave
the newly created rootns in ROOTNS_EMPTY until userspace installs a root
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>
---
include/linux/syscalls.h | 1 +
kernel/rootns.c | 139 +++++++++++++++++++++++++++++++++++++++
kernel/sys_ni.c | 3 +
3 files changed, 143 insertions(+)
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 552d9710a0d5..272d54bddbe2 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_rootns_create(unsigned int flags);
/*
* Architecture-specific system calls
diff --git a/kernel/rootns.c b/kernel/rootns.c
index e3b203322ae2..caa810b65d0d 100644
--- a/kernel/rootns.c
+++ b/kernel/rootns.c
@@ -145,3 +145,142 @@ void exit_rootns(struct pid_namespace *pid_ns, struct task_struct *tsk)
wake_up_poll(&c->waitq, EPOLLHUP);
put_rootns(c);
}
+
+/*
+ * Create credentials for a rootns. Drop keyrings from the new credential to
+ * avoid unnecessary pinning.
+ */
+static const struct cred *create_rootns_creds(unsigned int flags)
+{
+ struct cred *new;
+ int ret;
+
+ new = prepare_creds();
+ if (!new)
+ return ERR_PTR(-ENOMEM);
+
+#ifdef CONFIG_KEYS
+ key_put(new->thread_keyring);
+ new->thread_keyring = NULL;
+ key_put(new->process_keyring);
+ new->process_keyring = NULL;
+ key_put(new->session_keyring);
+ new->session_keyring = NULL;
+ key_put(new->request_key_auth);
+ new->request_key_auth = NULL;
+#endif
+ if (!(flags & ROOTNS_USER))
+ return new;
+
+ ret = create_user_ns(new);
+ if (ret < 0)
+ goto err;
+ new->euid = new->user_ns->owner;
+ new->egid = new->user_ns->group;
+
+ new->uid = new->euid;
+ new->suid = new->euid;
+ new->fsuid = new->euid;
+ new->gid = new->egid;
+ new->sgid = new->egid;
+ new->fsgid = new->egid;
+ ret = set_cred_ucounts(new);
+ if (ret < 0)
+ goto err;
+ return new;
+
+err:
+ abort_creds(new);
+ return ERR_PTR(ret);
+}
+
+/*
+ * Create a new rootns.
+ */
+static struct rootns *create_rootns(unsigned int flags)
+{
+ u64 clone_flags = CLONE_NEWNS | CLONE_EMPTY_MNTNS | CLONE_NEWPID;
+ const struct cred *cred;
+ struct nsproxy *ns;
+ struct rootns *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;
+
+ cred = create_rootns_creds(flags);
+ if (IS_ERR(cred)) {
+ ret = PTR_ERR(cred);
+ goto err_put;
+ }
+ c->cred = cred;
+ ns_ref_active_get(cred->user_ns);
+
+ if (!ns_capable(cred->user_ns, CAP_SYS_ADMIN)) {
+ ret = -EPERM;
+ goto err_put;
+ }
+
+ if (flags & ROOTNS_CGROUP)
+ clone_flags |= CLONE_NEWCGROUP;
+ if (flags & ROOTNS_UTS)
+ clone_flags |= CLONE_NEWUTS;
+ if (flags & ROOTNS_IPC)
+ clone_flags |= CLONE_NEWIPC;
+ if (flags & ROOTNS_NET)
+ clone_flags |= CLONE_NEWNET;
+
+ ns = create_new_namespaces(clone_flags, current->nsproxy, cred->user_ns,
+ NULL);
+ if (IS_ERR(ns)) {
+ ret = PTR_ERR(ns);
+ goto err_put;
+ }
+
+ c->ns = ns;
+ ns->pid_ns_for_children->rootns = c;
+ nsproxy_ns_active_get(ns);
+
+ return c;
+
+err_put:
+ put_rootns(c);
+ return ERR_PTR(ret);
+}
+
+/**
+ * sys_rootns_create - Create a detached root namespace
+ * @flags: Combination of &enum rootns_flags values
+ *
+ * Allocate a detached root namespace with dedicated empty mount and PID
+ * namespaces plus any optional namespaces requested in @flags.
+ *
+ * Return: Control file descriptor on success, negative error code on failure.
+ */
+SYSCALL_DEFINE1(rootns_create, unsigned int, flags)
+{
+ struct rootns *c;
+ int fd;
+
+ if (flags & ~ROOTNS_ALL_FLAGS)
+ return -EINVAL;
+ if (unlikely(!current->nsproxy))
+ return -EOPNOTSUPP;
+
+ c = create_rootns(flags);
+ if (IS_ERR(c))
+ return PTR_ERR(c);
+
+ fd = anon_inode_getfd("rootns", &rootns_fops, c,
+ O_RDWR | (flags & ROOTNS_CLOSE_ON_EXEC ? O_CLOEXEC : 0));
+ if (fd < 0)
+ put_rootns(c);
+
+ return fd;
+}
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index c8be0abaa407..4a6c4337cc74 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/rootns.c */
+COND_SYSCALL(rootns_create);
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [RFC PATCH v2 05/13] rootns: Add rootns_wait() system call
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
` (3 preceding siblings ...)
2026-11-17 23:13 ` [RFC PATCH v2 04/13] rootns: Add rootns_create() system call Jarkko Sakkinen
@ 2026-11-17 23:13 ` Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 06/13] rootns: Add rootns_kill() " Jarkko Sakkinen
` (9 subsequent siblings)
14 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17 23:13 UTC (permalink / raw)
To: linux-fsdevel
Cc: Jarkko Sakkinen, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
wait4() and waitid() only allow a parent or subreaper to collect exit
status, so an external manager holding a rootns file descriptor cannot
wait on a rootns init process forked by another process or observe exit
status multiple times across observers.
Add the rootns_wait() system call and its compat entry point to wait on
a rootns file descriptor until its init thread group exits and report
the recorded wait status and rusage. Return the init TGID translated
into the caller's active PID namespace, 0 for WNOHANG while still
running, or -ECHILD when the PID is not visible to the caller.
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/compat.h | 4 ++
include/linux/syscalls.h | 2 +
kernel/rootns.c | 105 +++++++++++++++++++++++++++++++++++++++
kernel/sys_ni.c | 2 +
4 files changed, 113 insertions(+)
diff --git a/include/linux/compat.h b/include/linux/compat.h
index ad37ca617e65..3a9ac9dbb24c 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -779,6 +779,10 @@ asmlinkage long compat_sys_recvmmsg_time32(int fd, struct compat_mmsghdr __user
asmlinkage long compat_sys_wait4(compat_pid_t pid,
compat_uint_t __user *stat_addr, int options,
struct compat_rusage __user *ru);
+asmlinkage long compat_sys_rootns_wait(int rootnsfd,
+ compat_int_t __user *status,
+ unsigned int options,
+ struct compat_rusage __user *ru);
asmlinkage long compat_sys_fanotify_mark(int, unsigned int, __u32, __u32,
int, const char __user *);
asmlinkage long compat_sys_open_by_handle_at(int mountdirfd,
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 272d54bddbe2..60e9c4ff71e7 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -1007,6 +1007,8 @@ asmlinkage long sys_lsm_set_self_attr(unsigned int attr, struct lsm_ctx __user *
u32 size, u32 flags);
asmlinkage long sys_lsm_list_modules(u64 __user *ids, u32 __user *size, u32 flags);
asmlinkage long sys_rootns_create(unsigned int flags);
+asmlinkage long sys_rootns_wait(int rootnsfd, int __user *status,
+ unsigned int options, struct rusage __user *ru);
/*
* Architecture-specific system calls
diff --git a/kernel/rootns.c b/kernel/rootns.c
index caa810b65d0d..83ab759a31ec 100644
--- a/kernel/rootns.c
+++ b/kernel/rootns.c
@@ -5,6 +5,8 @@
#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/rootns.h>
@@ -284,3 +286,106 @@ SYSCALL_DEFINE1(rootns_create, unsigned int, flags)
return fd;
}
+
+/*
+ * Wait for rootns init to exit and report results for the caller.
+ *
+ * Returns caller-visible init TGID on success, 0 for WNOHANG when still
+ * running, and -ECHILD when init pid is not visible in caller pidns.
+ */
+static long rootns_wait_common(int rootnsfd, unsigned int options,
+ int *status, struct rusage *ru)
+{
+ CLASS(fd, f)(rootnsfd);
+ struct pid_namespace *pid_ns = task_active_pid_ns(current);
+ struct rootns *rootns;
+ long ret;
+
+ if (fd_empty(f))
+ return -EBADF;
+ if (!is_rootns_file(fd_file(f)) || (options & ~WNOHANG))
+ return -EINVAL;
+
+ rootns = fd_file(f)->private_data;
+ if (!(options & WNOHANG)) {
+ ret = wait_event_killable(rootns->waitq,
+ READ_ONCE(rootns->state) == ROOTNS_DEAD);
+ if (ret)
+ return ret;
+ }
+
+ scoped_guard(spinlock, &rootns->lock) {
+ if (rootns->state != ROOTNS_DEAD)
+ return 0;
+ if (!rootns->init_pid)
+ return -ECHILD;
+ ret = pid_nr_ns(rootns->init_pid, pid_ns);
+ if (ret <= 0)
+ return -ECHILD;
+ if (status)
+ *status = rootns->exit_code;
+ if (ru)
+ *ru = rootns->rusage;
+ }
+
+ return ret;
+}
+
+/**
+ * sys_rootns_wait - Wait for root namespace termination and collect init status
+ * @rootnsfd: Root namespace control file descriptor
+ * @status: Optional user pointer to receive wait status of init
+ * @options: Wait options (0 or %WNOHANG)
+ * @ru: Optional user pointer to receive resource usage of init
+ *
+ * Wait killably (unless %WNOHANG is set in @options) until @rootnsfd reaches
+ * %ROOTNS_DEAD, then copy out the recorded exit status and resource usage of
+ * the rootns init thread group.
+ *
+ * Return: Caller-visible init TGID on success, 0 if %WNOHANG is set and the
+ * rootns has not terminated, %-ECHILD if init was never started or is not
+ * visible in the caller's active PID namespace, or negative error code.
+ */
+SYSCALL_DEFINE4(rootns_wait, int, rootnsfd, int __user *, status,
+ unsigned int, options, struct rusage __user *, ru)
+{
+ int code;
+ long ret;
+ struct rusage rusage;
+
+ ret = rootns_wait_common(rootnsfd, options,
+ status ? &code : NULL,
+ ru ? &rusage : NULL);
+ if (ret <= 0)
+ return ret;
+
+ if (status && put_user(code, status))
+ return -EFAULT;
+ if (ru && copy_to_user(ru, &rusage, sizeof(rusage)))
+ return -EFAULT;
+ return ret;
+}
+
+#ifdef CONFIG_COMPAT
+COMPAT_SYSCALL_DEFINE4(rootns_wait, int, rootnsfd,
+ compat_int_t __user *, status,
+ unsigned int, options,
+ struct compat_rusage __user *, ru)
+{
+ int code;
+ long ret;
+ struct rusage rusage;
+
+ ret = rootns_wait_common(rootnsfd, options,
+ status ? &code : NULL,
+ ru ? &rusage : NULL);
+ if (ret <= 0)
+ return ret;
+
+ if (status && put_user(code, status))
+ return -EFAULT;
+ if (ru && put_compat_rusage(&rusage, ru))
+ return -EFAULT;
+ return ret;
+}
+#endif
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index 4a6c4337cc74..f9918d38107b 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -401,3 +401,5 @@ COND_SYSCALL(uprobe);
/* kernel/rootns.c */
COND_SYSCALL(rootns_create);
+COND_SYSCALL(rootns_wait);
+COND_SYSCALL_COMPAT(rootns_wait);
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [RFC PATCH v2 06/13] rootns: Add rootns_kill() system call
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
` (4 preceding siblings ...)
2026-11-17 23:13 ` [RFC PATCH v2 05/13] rootns: Add rootns_wait() " Jarkko Sakkinen
@ 2026-11-17 23:13 ` Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 07/13] fork: Support CLONE_INTO_ROOTNS in clone3() Jarkko Sakkinen
` (8 subsequent siblings)
14 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17 23:13 UTC (permalink / raw)
To: linux-fsdevel
Cc: Jarkko Sakkinen, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
Signaling every process inside a container from userspace via /proc is
racy against concurrent fork() calls.
Add the rootns_kill() system call to walk the root namespace's PID
namespace IDR under RCU and deliver a validated signal once to each
thread group, aggregating per-process delivery results.
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
include/linux/syscalls.h | 1 +
kernel/rootns.c | 65 ++++++++++++++++++++++++++++++++++++++++
kernel/sys_ni.c | 1 +
3 files changed, 67 insertions(+)
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 60e9c4ff71e7..a854d248c8a3 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -1009,6 +1009,7 @@ asmlinkage long sys_lsm_list_modules(u64 __user *ids, u32 __user *size, u32 flag
asmlinkage long sys_rootns_create(unsigned int flags);
asmlinkage long sys_rootns_wait(int rootnsfd, int __user *status,
unsigned int options, struct rusage __user *ru);
+asmlinkage long sys_rootns_kill(int rootnsfd, int sig);
/*
* Architecture-specific system calls
diff --git a/kernel/rootns.c b/kernel/rootns.c
index 83ab759a31ec..90a070dbf4a8 100644
--- a/kernel/rootns.c
+++ b/kernel/rootns.c
@@ -21,6 +21,7 @@
#include <linux/pid_namespace.h>
#include <linux/user_namespace.h>
#include <linux/compat.h>
+#include <linux/idr.h>
#include <uapi/linux/rootns.h>
/*
@@ -389,3 +390,67 @@ COMPAT_SYSCALL_DEFINE4(rootns_wait, int, rootnsfd,
return ret;
}
#endif
+
+static int rootns_kill_members(struct rootns *rootns, int sig)
+{
+ struct pid_namespace *pid_ns = rootns->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 (READ_ONCE(rootns->state) != ROOTNS_RUNNING)
+ return -ESRCH;
+
+ scoped_guard(rcu) {
+ idr_for_each_entry(&pid_ns->idr, pid, nr) {
+ int err;
+
+ if (!pid_task(pid, PIDTYPE_TGID))
+ continue;
+
+ err = kill_pid(pid, sig, 0);
+ if (!err) {
+ any_success = true;
+ } else if (err == -EPERM) {
+ any_perm = true;
+ } else if (err != -ESRCH && !any_other) {
+ any_other = true;
+ other_err = err;
+ }
+ }
+ }
+
+ if (any_success)
+ return 0;
+ if (any_other)
+ return other_err;
+ if (any_perm)
+ return -EPERM;
+ return -ESRCH;
+}
+
+/**
+ * sys_rootns_kill - Send a signal to all thread groups in a root namespace
+ * @rootnsfd: Root namespace control file descriptor
+ * @sig: Signal number to deliver (or 0 for permission check)
+ *
+ * Walk the target root namespace's PID namespace IDR under RCU and deliver
+ * @sig once to each member thread group.
+ *
+ * Return: 0 if at least one thread group was signaled, %-ESRCH if the rootns
+ * is not running or has no members, or negative error code on failure.
+ */
+SYSCALL_DEFINE2(rootns_kill, int, rootnsfd, int, sig)
+{
+ CLASS(fd, f)(rootnsfd);
+
+ if (fd_empty(f))
+ return -EBADF;
+ if (!is_rootns_file(fd_file(f)) || !valid_signal(sig))
+ return -EINVAL;
+
+ return rootns_kill_members(fd_file(f)->private_data, sig);
+}
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index f9918d38107b..fba44c49ddbb 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -403,3 +403,4 @@ COND_SYSCALL(uprobe);
COND_SYSCALL(rootns_create);
COND_SYSCALL(rootns_wait);
COND_SYSCALL_COMPAT(rootns_wait);
+COND_SYSCALL(rootns_kill);
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [RFC PATCH v2 07/13] fork: Support CLONE_INTO_ROOTNS in clone3()
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
` (5 preceding siblings ...)
2026-11-17 23:13 ` [RFC PATCH v2 06/13] rootns: Add rootns_kill() " Jarkko Sakkinen
@ 2026-11-17 23:13 ` Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 08/13] fs: Support FSCONFIG_SET_ROOTNS in fsconfig() Jarkko Sakkinen
` (7 subsequent siblings)
14 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17 23:13 UTC (permalink / raw)
To: linux-fsdevel
Cc: Jarkko Sakkinen, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
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_ROOTNS and struct clone_args.rootns (CLONE_ARGS_SIZE_VER3)
to spawn a child process directly into a rootns whose root mount has
been installed. Transition the rootns from ROOTNS_READY through
ROOTNS_FORKING to ROOTNS_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.
Require CAP_SYS_ADMIN in the target user namespace, forbid credential
privilege escalation, and require an ancestor active PID namespace so
the caller receives a valid child PID. Restrict companion flags to
CLONE_VFORK, CLONE_VM (with 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/rootns.h | 14 ++++
include/linux/sched/task.h | 8 +++
include/uapi/linux/sched.h | 5 ++
kernel/cred.c | 70 +++++++++++++------
kernel/fork.c | 67 +++++++++++++++---
kernel/nsproxy.c | 11 ++-
kernel/rootns.c | 137 +++++++++++++++++++++++++++++++++++++
9 files changed, 288 insertions(+), 32 deletions(-)
diff --git a/include/linux/cred.h b/include/linux/cred.h
index 49c26af37349..9849366fd44b 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -19,6 +19,7 @@
struct cred;
struct inode;
+struct rootns;
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 rootns *rootns);
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 cacbbbe3f1ce..26b3b788cc90 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 rootns;
struct user_namespace;
/*
@@ -97,7 +98,8 @@ struct nsproxy *create_new_namespaces(u64 flags,
struct nsproxy *ns,
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 rootns *rootns);
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/rootns.h b/include/linux/rootns.h
index b8437bf21830..2077b28e39c7 100644
--- a/include/linux/rootns.h
+++ b/include/linux/rootns.h
@@ -14,6 +14,7 @@
struct cred;
struct file;
+struct kernel_clone_args;
struct nsproxy;
struct pid;
struct pid_namespace;
@@ -50,6 +51,8 @@ void put_rootns(struct rootns *c);
bool is_rootns_file(struct file *file);
void copy_rootns(struct task_struct *tsk, struct rootns *rootns);
void exit_rootns(struct pid_namespace *pid_ns, struct task_struct *tsk);
+int rootns_prepare_fork(struct kernel_clone_args *args);
+int rootns_finish_fork(struct kernel_clone_args *args, struct task_struct *p);
#else
static inline struct rootns *get_rootns(struct rootns *c)
{
@@ -73,6 +76,17 @@ static inline void exit_rootns(struct pid_namespace *pid_ns,
struct task_struct *tsk)
{
}
+
+static inline int rootns_prepare_fork(struct kernel_clone_args *args)
+{
+ return -EINVAL;
+}
+
+static inline int rootns_finish_fork(struct kernel_clone_args *args,
+ struct task_struct *p)
+{
+ return 0;
+}
#endif /* CONFIG_ROOTNS */
#endif /* _LINUX_ROOTNS_H */
diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h
index 90ed5bc3c7af..e0c4e8ab02f1 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 rootns;
/* All the bits taken by the old clone syscall. */
#define CLONE_LEGACY_FLAGS 0xffffffffULL
@@ -39,11 +41,17 @@ struct kernel_clone_args {
/* Number of elements in *set_tid */
size_t set_tid_size;
int cgroup;
+ int rootns_fd;
int idle;
int (*fn)(void *);
void *fn_arg;
struct cgroup *cgrp;
struct css_set *cset;
+#ifdef CONFIG_ROOTNS
+ struct file *rootns_file;
+ struct rootns *rootns;
+ bool rootns_bootstrapping;
+#endif
unsigned int kill_seq;
};
diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h
index 19ffeba89428..405cfc954ae1 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_ROOTNS (1ULL << 38) /* Clone into a specific root namespace. */
/*
* 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.
+ * @rootns: If CLONE_INTO_ROOTNS is specified set this to
+ * a file descriptor for the root namespace.
*
* 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 rootns;
};
#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..afc91eed2656 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -15,10 +15,12 @@
#include <linux/key.h>
#include <linux/keyctl.h>
#include <linux/init_task.h>
+#include <linux/rootns.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, ...) \
@@ -162,24 +164,8 @@ struct cred *cred_alloc_blank(void)
return NULL;
}
-/**
- * prepare_creds - Prepare a new set of credentials for modification
- *
- * Prepare a new set of task credentials for modification. A task's creds
- * shouldn't generally be modified directly, therefore this function is used to
- * prepare a new copy, which the caller then modifies and then commits by
- * calling commit_creds().
- *
- * Preparation involves making a copy of the objective creds for modification.
- *
- * Returns a pointer to the new creds-to-be if successful, NULL otherwise.
- *
- * Call commit_creds() or abort_creds() to clean up.
- */
-struct cred *prepare_creds(void)
+static struct cred *dup_creds(const struct cred *old)
{
- struct task_struct *task = current;
- const struct cred *old;
struct cred *new;
new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
@@ -188,7 +174,6 @@ struct cred *prepare_creds(void)
kdebug("prepare_creds() alloc %p", new);
- old = task->cred;
memcpy(new, old, sizeof(struct cred));
new->non_rcu = 0;
@@ -221,6 +206,25 @@ struct cred *prepare_creds(void)
abort_creds(new);
return NULL;
}
+
+/**
+ * prepare_creds - Prepare a new set of credentials for modification
+ *
+ * Prepare a new set of task credentials for modification. A task's creds
+ * shouldn't generally be modified directly, therefore this function is used to
+ * prepare a new copy, which the caller then modifies and then commits by
+ * calling commit_creds().
+ *
+ * Preparation involves making a copy of the objective creds for modification.
+ *
+ * Returns a pointer to the new creds-to-be if successful, NULL otherwise.
+ *
+ * Call commit_creds() or abort_creds() to clean up.
+ */
+struct cred *prepare_creds(void)
+{
+ return dup_creds(current->cred);
+}
EXPORT_SYMBOL(prepare_creds);
/*
@@ -251,6 +255,25 @@ struct cred *prepare_exec_creds(void)
return new;
}
+static bool cred_cap_issubset(const struct cred *set,
+ const struct cred *subset);
+
+static bool may_enter_rootns_creds(const struct cred *old,
+ const struct cred *target)
+{
+ if (cred_cap_issubset(old, target) &&
+ uid_eq(old->euid, target->euid) &&
+ gid_eq(old->egid, target->egid))
+ return true;
+
+ if (old->user_ns == target->user_ns)
+ return false;
+
+ return ns_capable(target->user_ns->parent, CAP_SYS_ADMIN) &&
+ ns_capable(target->user_ns->parent, CAP_SETUID) &&
+ ns_capable(target->user_ns->parent, CAP_SETGID);
+}
+
/*
* Copy credentials for the new process created by fork()
*
@@ -260,7 +283,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 rootns *rootns)
{
struct cred *new;
int ret;
@@ -283,7 +307,13 @@ int copy_creds(struct task_struct *p, u64 clone_flags)
return 0;
}
- new = prepare_creds();
+ if (rootns) {
+ if (!may_enter_rootns_creds(current_cred(), rootns->cred))
+ return -EPERM;
+ new = dup_creds(rootns->cred);
+ } else {
+ new = prepare_creds();
+ }
if (!new)
return -ENOMEM;
diff --git a/kernel/fork.c b/kernel/fork.c
index 99e22b3cd213..978605de8428 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1632,8 +1632,20 @@ enum copy_fs_flags_t {
COPY_FS_IDLE = (1 << 1),
};
+#ifdef CONFIG_ROOTNS
+static inline struct rootns *clone_args_rootns(const struct kernel_clone_args *args)
+{
+ return args->rootns;
+}
+#else
+static inline struct rootns *clone_args_rootns(const struct kernel_clone_args *args)
+{
+ return NULL;
+}
+#endif
+
static int copy_fs(u64 clone_flags, struct task_struct *tsk,
- enum copy_fs_flags_t flags)
+ enum copy_fs_flags_t flags, struct rootns *rootns)
{
struct fs_struct *fs;
@@ -1649,7 +1661,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 || rootns) {
fs = &init_fs;
} else {
fs = current->fs;
@@ -1671,6 +1683,10 @@ 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 (rootns) {
+ set_fs_root(tsk->fs, &rootns->root);
+ set_fs_pwd(tsk->fs, &rootns->root);
+ }
return 0;
}
@@ -2186,7 +2202,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, clone_args_rootns(args));
if (retval < 0)
goto bad_fork_free;
@@ -2317,7 +2333,8 @@ __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),
+ clone_args_rootns(args));
if (retval)
goto bad_fork_cleanup_semundo;
retval = copy_sighand(clone_flags, p);
@@ -2329,7 +2346,7 @@ __latent_entropy struct task_struct *copy_process(
retval = copy_mm(clone_flags, p);
if (retval)
goto bad_fork_cleanup_signal;
- retval = copy_namespaces(clone_flags, p);
+ retval = copy_namespaces(clone_flags, p, clone_args_rootns(args));
if (retval)
goto bad_fork_cleanup_mm;
retval = copy_io(clone_flags, p);
@@ -2566,7 +2583,7 @@ __latent_entropy struct task_struct *copy_process(
attach_pid(p, PIDTYPE_TGID);
attach_pid(p, PIDTYPE_PGID);
attach_pid(p, PIDTYPE_SID);
- copy_rootns(p, NULL);
+ copy_rootns(p, clone_args_rootns(args));
__this_cpu_inc(process_counts);
} else {
current->signal->nr_threads++;
@@ -2779,6 +2796,13 @@ pid_t kernel_clone(struct kernel_clone_args *args)
if (!valid_signal(args->exit_signal))
return -EINVAL;
+ if (unlikely(clone_flags & CLONE_INTO_ROOTNS)) {
+ int err = rootns_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
@@ -2800,6 +2824,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_ROOTNS)) {
+ int err = rootns_finish_fork(args, p);
+
+ if (err)
+ return err;
+ }
+
if (IS_ERR(p))
return PTR_ERR(p);
@@ -2957,7 +2988,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, rootns) !=
+ CLONE_ARGS_SIZE_VER3);
+ BUILD_BUG_ON(sizeof(struct clone_args) != CLONE_ARGS_SIZE_VER3);
if (unlikely(usize > PAGE_SIZE))
return -E2BIG;
@@ -2987,6 +3020,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_ROOTNS) &&
+ (args.rootns > INT_MAX || usize < CLONE_ARGS_SIZE_VER3))
+ return -EINVAL;
+
*kargs = (struct kernel_clone_args){
.flags = args.flags,
.pidfd = u64_to_user_ptr(args.pidfd),
@@ -2998,6 +3035,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,
+ .rootns_fd = args.rootns,
};
if (args.set_tid &&
@@ -3038,13 +3076,19 @@ static inline bool clone3_stack_valid(struct kernel_clone_args *kargs)
return true;
}
+#define CLONE_INTO_ROOTNS_FLAGS \
+ (CLONE_INTO_ROOTNS | CLONE_VM | 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_ROOTNS))
return false;
/*
@@ -3062,6 +3106,13 @@ static bool clone3_args_valid(struct kernel_clone_args *kargs)
kargs->exit_signal)
return false;
+ if (kargs->flags & CLONE_INTO_ROOTNS) {
+ if (kargs->flags & ~CLONE_INTO_ROOTNS_FLAGS)
+ return false;
+ if ((kargs->flags & CLONE_VM) && !(kargs->flags & CLONE_VFORK))
+ return false;
+ }
+
if (!clone3_stack_valid(kargs))
return false;
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index 8a3c6d4e94e2..78a1e1fb2cfd 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -13,6 +13,7 @@
#include <linux/export.h>
#include <linux/nsproxy.h>
#include <linux/ns/ns_common_types.h>
+#include <linux/rootns.h>
#include <linux/init_task.h>
#include <linux/mnt_namespace.h>
#include <linux/utsname.h>
@@ -166,12 +167,18 @@ struct nsproxy *create_new_namespaces(u64 flags,
* 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 rootns *rootns)
{
struct nsproxy *old_ns = tsk->nsproxy;
struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
struct nsproxy *new_ns;
+ if (rootns) {
+ get_nsproxy(rootns->ns);
+ tsk->nsproxy = rootns->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)) {
@@ -192,7 +199,7 @@ int copy_namespaces(u64 flags, struct task_struct *tsk)
(CLONE_NEWIPC | CLONE_SYSVSEM))
return -EINVAL;
- new_ns = create_new_namespaces(flags, tsk->nsproxy, user_ns, tsk->fs);
+ new_ns = create_new_namespaces(flags, old_ns, user_ns, tsk->fs);
if (IS_ERR(new_ns))
return PTR_ERR(new_ns);
diff --git a/kernel/rootns.c b/kernel/rootns.c
index 90a070dbf4a8..edf373093496 100644
--- a/kernel/rootns.c
+++ b/kernel/rootns.c
@@ -3,6 +3,27 @@
* Copyright (C) 2017-2019 Red Hat, Inc. All Rights Reserved.
*/
+/**
+ * DOC: Overview
+ *
+ * A root namespace binds an isolated namespace set, a root mount tree, owner
+ * credentials, and an init process behind a pollable control file descriptor:
+ *
+ * 1. ``rootns_create()`` allocates a detached ``rootns`` with dedicated empty
+ * mount and PID namespaces and returns its control fd.
+ *
+ * 2. Userspace configures and installs ``"/"`` via ``FSCONFIG_SET_ROOTNS``
+ * and ``MOVE_MOUNT_T_ROOTNS_ROOT``, then attaches relative submounts.
+ *
+ * 3. ``clone3()`` with ``CLONE_INTO_ROOTNS`` spawns processes into the
+ * ``rootns``; the first call commits PID 1 while concurrent bootstrap
+ * callers wait killably.
+ *
+ * 4. When PID 1 exits, the PID namespace zaps and reaps all remaining tasks,
+ * ``poll()`` reports ``EPOLLHUP``, and ``rootns_wait()`` returns the exit
+ * status and ``rusage``.
+ */
+
#include <linux/poll.h>
#include <linux/wait.h>
#include <uapi/linux/wait.h>
@@ -11,6 +32,7 @@
#include <linux/anon_inodes.h>
#include <linux/rootns.h>
#include <linux/sched/signal.h>
+#include <linux/sched/task.h>
#include <linux/slab.h>
#include <linux/syscalls.h>
#include <linux/uaccess.h>
@@ -454,3 +476,118 @@ SYSCALL_DEFINE2(rootns_kill, int, rootnsfd, int, sig)
return rootns_kill_members(fd_file(f)->private_data, sig);
}
+
+/**
+ * DOC: CLONE_INTO_ROOTNS
+ *
+ * Passing ``CLONE_INTO_ROOTNS`` in ``struct clone_args.flags`` (with
+ * ``size >= CLONE_ARGS_SIZE_VER3``) spawns the child process into the root
+ * namespace identified by ``struct clone_args.rootns``.
+ *
+ * The first caller transitions the ``rootns`` from ``ROOTNS_READY`` through
+ * ``ROOTNS_FORKING`` to ``ROOTNS_RUNNING`` as PID 1 of its PID namespace
+ * while concurrent bootstrap callers wait killably. Subsequent callers join
+ * the running PID namespace until teardown begins.
+ *
+ * The caller must hold ``CAP_SYS_ADMIN`` in the target user namespace, run in
+ * an ancestor active PID namespace, and not escalate credentials relative to
+ * the ``rootns`` owner credentials.
+ *
+ * ``CLONE_INTO_ROOTNS`` may be combined with the following ``CLONE_*`` flags:
+ *
+ * - ``CLONE_VFORK``
+ * - ``CLONE_VM`` (requires ``CLONE_VFORK``)
+ * - ``CLONE_PIDFD``
+ * - ``CLONE_PIDFD_AUTOKILL``
+ * - ``CLONE_AUTOREAP``
+ * - ``CLONE_CLEAR_SIGHAND``
+ * - ``CLONE_INTO_CGROUP``
+ * - ``CLONE_NNP``
+ *
+ * Returns ``-EBADF`` if ``rootns`` is not an open file descriptor, ``-EINVAL``
+ * for unsupported flags, invalid argument size, or non-``rootns`` file
+ * descriptors, ``-ENOENT`` before ``"/"`` is installed, ``-EXDEV`` if the
+ * caller's active PID namespace is not an ancestor, ``-EPERM`` on disallowed
+ * credentials, and ``-ESRCH`` once teardown has started.
+ */
+int rootns_prepare_fork(struct kernel_clone_args *args)
+{
+ struct file *file __free(fput) = fget(args->rootns_fd);
+ struct pid_namespace *pid_ns;
+ bool bootstrapping = false;
+ struct rootns *rootns;
+ int ret;
+
+ if (!file)
+ return -EBADF;
+ if (!is_rootns_file(file))
+ return -EINVAL;
+
+ rootns = file->private_data;
+ if (!ns_capable(rootns->cred->user_ns, CAP_SYS_ADMIN))
+ return -EPERM;
+
+ pid_ns = rootns->ns->pid_ns_for_children;
+ if (!pidns_is_ancestor(pid_ns, task_active_pid_ns(current)))
+ return -EXDEV;
+
+ for (;;) {
+ scoped_guard(spinlock, &rootns->lock) {
+ switch (rootns->state) {
+ case ROOTNS_EMPTY:
+ return -ENOENT;
+ case ROOTNS_READY:
+ WRITE_ONCE(rootns->state, ROOTNS_FORKING);
+ bootstrapping = true;
+ break;
+ case ROOTNS_FORKING:
+ break;
+ case ROOTNS_RUNNING:
+ if (!(READ_ONCE(pid_ns->pid_allocated) & PIDNS_ADDING))
+ return -ESRCH;
+ break;
+ case ROOTNS_DEAD:
+ return -ESRCH;
+ }
+ if (rootns->state != ROOTNS_FORKING || bootstrapping)
+ break;
+ }
+
+ ret = wait_event_killable(rootns->waitq,
+ READ_ONCE(rootns->state) != ROOTNS_FORKING);
+ if (ret)
+ return ret;
+ }
+
+ args->rootns_file = no_free_ptr(file);
+ args->rootns = rootns;
+ args->rootns_bootstrapping = bootstrapping;
+ return 0;
+}
+
+int rootns_finish_fork(struct kernel_clone_args *args, struct task_struct *p)
+{
+ struct file *file __free(fput) = args->rootns_file;
+ struct rootns *rootns = args->rootns;
+ struct pid_namespace *pid_ns = rootns->ns->pid_ns_for_children;
+ int ret;
+
+ args->rootns_file = NULL;
+ args->rootns = NULL;
+ if (!IS_ERR(p))
+ return 0;
+
+ ret = PTR_ERR(p);
+ if (args->rootns_bootstrapping) {
+ scoped_guard(spinlock, &rootns->lock) {
+ if (rootns->state == ROOTNS_FORKING)
+ WRITE_ONCE(rootns->state, ROOTNS_READY);
+ }
+ wake_up_all(&rootns->waitq);
+ } else if (ret == -ENOMEM &&
+ !(READ_ONCE(pid_ns->pid_allocated) & PIDNS_ADDING)) {
+ return -ESRCH;
+ }
+
+ return ret;
+}
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [RFC PATCH v2 08/13] fs: Support FSCONFIG_SET_ROOTNS in fsconfig()
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
` (6 preceding siblings ...)
2026-11-17 23:13 ` [RFC PATCH v2 07/13] fork: Support CLONE_INTO_ROOTNS in clone3() Jarkko Sakkinen
@ 2026-11-17 23:13 ` Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 09/13] fs: Support installing rootns mount trees via move_mount() Jarkko Sakkinen
` (6 subsequent siblings)
14 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17 23:13 UTC (permalink / raw)
To: linux-fsdevel
Cc: Jarkko Sakkinen, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
fsopen() initializes a filesystem context from current's user, network,
PID, and IPC namespaces, preventing an external manager from creating
proc, mqueue, or userns-owned superblocks bound to an unentered root
namespace.
Add FSCONFIG_SET_ROOTNS so callers holding CAP_SYS_ADMIN in the target
rootns user namespace can bind a newly opened fs_context to that rootns
once before offering parameters. Update fc->net_ns, switch fc->user_ns
for non-global FS_USERNS_MOUNT or FS_USERNS_DELEGATABLE filesystems
whose mounter fsuid/fsgid map into the rootns user namespace, and pass
the rootns to ->set_rootns() for proc and mqueue.
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/fsopen.c | 76 ++++++++++++++++++++++++++++++++++++--
fs/proc/root.c | 13 +++++++
include/linux/fs_context.h | 3 ++
include/uapi/linux/mount.h | 1 +
ipc/mqueue.c | 12 ++++++
5 files changed, 101 insertions(+), 4 deletions(-)
diff --git a/fs/fsopen.c b/fs/fsopen.c
index 70024870fefa..ca3234c8c4e4 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/nsproxy.h>
+#include <linux/rootns.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,50 @@ static inline const char *fetch_message_locked(struct fc_log *log, size_t len,
return p;
}
+/**
+ * DOC: FSCONFIG_SET_ROOTNS
+ *
+ * ``fsconfig(fsfd, FSCONFIG_SET_ROOTNS, NULL, NULL, rootnsfd)`` binds a newly
+ * opened filesystem context to ``rootnsfd`` once before any parameters are
+ * supplied (subsequent calls fail with ``-EBUSY``).
+ *
+ * The caller must hold ``CAP_SYS_ADMIN`` in the target ``rootns`` user
+ * namespace.
+ *
+ * ``fc->net_ns`` is switched to the ``rootns`` network namespace,
+ * ``fc->user_ns`` is delegated for non-global ``FS_USERNS_MOUNT`` or
+ * ``FS_USERNS_DELEGATABLE`` filesystems when the mounter ``fsuid``/``fsgid``
+ * map into the target user namespace, and ``proc`` and ``mqueue`` contexts
+ * bind to the target ``rootns`` PID and IPC namespaces.
+ */
+static int fsconfig_set_rootns(struct fs_context *fc, struct fs_parameter *param)
+{
+ struct user_namespace *user_ns;
+ struct rootns *c;
+
+ if (!is_rootns_file(param->file))
+ return -EINVAL;
+
+ c = param->file->private_data;
+ user_ns = c->cred->user_ns;
+ if (!ns_capable(user_ns, CAP_SYS_ADMIN))
+ return -EPERM;
+
+ put_net(fc->net_ns);
+ fc->net_ns = get_net(c->ns->net_ns);
+ if (!fc->global &&
+ (fc->fs_type->fs_flags & (FS_USERNS_MOUNT | FS_USERNS_DELEGATABLE)) &&
+ kuid_has_mapping(user_ns, fc->cred->fsuid) &&
+ kgid_has_mapping(user_ns, fc->cred->fsgid)) {
+ put_user_ns(fc->user_ns);
+ fc->user_ns = get_user_ns(user_ns);
+ }
+ if (fc->ops->set_rootns)
+ fc->ops->set_rootns(fc, c);
+ 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.
@@ -147,7 +196,7 @@ SYSCALL_DEFINE2(fsopen, const char __user *, _fs_name, unsigned int, flags)
if (IS_ERR(fc))
return PTR_ERR(fc);
- fc->phase = FS_CONTEXT_CREATE_PARAMS;
+ fc->phase = FS_CONTEXT_CREATE_NS;
ret = fscontext_alloc_log(fc);
if (ret < 0)
@@ -222,7 +271,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))
@@ -298,9 +348,16 @@ 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_ROOTNS:
+ if (fc->phase != FS_CONTEXT_CREATE_NS)
+ return -EBUSY;
+ return fsconfig_set_rootns(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 +447,10 @@ SYSCALL_DEFINE5(fsconfig,
if (!_key || _value || aux < 0)
return -EINVAL;
break;
+ case FSCONFIG_SET_ROOTNS:
+ if (_key || _value || aux < 0)
+ return -EINVAL;
+ break;
case FSCONFIG_CMD_CREATE:
case FSCONFIG_CMD_CREATE_EXCL:
case FSCONFIG_CMD_RECONFIGURE:
@@ -457,6 +518,12 @@ SYSCALL_DEFINE5(fsconfig,
goto out_key;
param.dirfd = aux;
break;
+ case FSCONFIG_SET_ROOTNS:
+ ret = -EBADF;
+ param.file = fget(aux);
+ if (!param.file)
+ goto out_key;
+ break;
default:
break;
}
@@ -482,6 +549,7 @@ SYSCALL_DEFINE5(fsconfig,
putname(param.name);
break;
case FSCONFIG_SET_FD:
+ case FSCONFIG_SET_ROOTNS:
if (param.file)
fput(param.file);
break;
diff --git a/fs/proc/root.c b/fs/proc/root.c
index 7fbbe92bf73a..5976029ad3f8 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/nsproxy.h>
+#include <linux/rootns.h>
#include <linux/user_namespace.h>
#include <linux/fs_context.h>
#include <linux/mount.h>
@@ -323,6 +325,16 @@ static int proc_get_tree(struct fs_context *fc)
return get_tree_nodev(fc, proc_fill_super);
}
+static void proc_set_rootns(struct fs_context *fc, struct rootns *rootns)
+{
+ struct proc_fs_context *ctx = fc->fs_private;
+
+ put_pid_ns(ctx->pid_ns);
+ ctx->pid_ns = get_pid_ns(rootns->ns->pid_ns_for_children);
+ put_user_ns(fc->user_ns);
+ fc->user_ns = get_user_ns(ctx->pid_ns->user_ns);
+}
+
static void proc_fs_context_free(struct fs_context *fc)
{
struct proc_fs_context *ctx = fc->fs_private;
@@ -334,6 +346,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_rootns = proc_set_rootns,
.get_tree = proc_get_tree,
.reconfigure = proc_reconfigure,
};
diff --git a/include/linux/fs_context.h b/include/linux/fs_context.h
index d1727dffecc5..cb978273c8bc 100644
--- a/include/linux/fs_context.h
+++ b/include/linux/fs_context.h
@@ -21,6 +21,7 @@ struct file_system_type;
struct mnt_namespace;
struct net;
struct pid_namespace;
+struct rootns;
struct super_block;
struct user_namespace;
struct vfsmount;
@@ -36,6 +37,7 @@ enum fs_context_purpose {
* Userspace usage phase for fsopen/fspick.
*/
enum fs_context_phase {
+ 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() */
@@ -117,6 +119,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);
+ void (*set_rootns)(struct fs_context *fc, struct rootns *rootns);
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 ac865edac517..cb55cfcfc92e 100644
--- a/include/uapi/linux/mount.h
+++ b/include/uapi/linux/mount.h
@@ -105,6 +105,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_ROOTNS = 9, /* Set a rootns, supplied by fd */
};
/*
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index 322c3dd98c44..a85ca188d370 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -32,6 +32,7 @@
#include <linux/mutex.h>
#include <linux/nsproxy.h>
#include <linux/pid.h>
+#include <linux/rootns.h>
#include <linux/ipc_namespace.h>
#include <linux/user_namespace.h>
#include <linux/slab.h>
@@ -400,6 +401,16 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
return ERR_PTR(ret);
}
+static void mqueue_set_rootns(struct fs_context *fc, struct rootns *rootns)
+{
+ struct mqueue_fs_context *ctx = fc->fs_private;
+
+ put_ipc_ns(ctx->ipc_ns);
+ ctx->ipc_ns = get_ipc_ns(rootns->ns->ipc_ns);
+ put_user_ns(fc->user_ns);
+ fc->user_ns = get_user_ns(ctx->ipc_ns->user_ns);
+}
+
static int mqueue_fill_super(struct super_block *sb, struct fs_context *fc)
{
struct inode *inode;
@@ -1613,6 +1624,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_rootns = mqueue_set_rootns,
.get_tree = mqueue_get_tree,
};
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [RFC PATCH v2 09/13] fs: Support installing rootns mount trees via move_mount()
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
` (7 preceding siblings ...)
2026-11-17 23:13 ` [RFC PATCH v2 08/13] fs: Support FSCONFIG_SET_ROOTNS in fsconfig() Jarkko Sakkinen
@ 2026-11-17 23:13 ` Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 10/13] arch: Wire up rootns system calls Jarkko Sakkinen
` (5 subsequent siblings)
14 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17 23:13 UTC (permalink / raw)
To: linux-fsdevel
Cc: Jarkko Sakkinen, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
A newly created rootns starts with an empty nullfs-rooted mount
namespace, and move_mount() only resolves target paths against the
caller's own filesystem view.
Add MOVE_MOUNT_T_ROOTNS_ROOT to populate a rootns mount tree through its
file descriptor before or after entry. Installing "/" attaches a
detached anonymous mount tree onto the nullfs root of the rootns mount
namespace once and transitions the rootns to ROOTNS_READY; relative
target paths attach anonymous mounts underneath the installed rootns
root while verifying the destination mount namespace.
Allocate fsmount() anonymous namespaces in fc->user_ns, check target
user namespace CAP_SYS_ADMIN for MOVE_MOUNT_T_ROOTNS_ROOT instead of
caller may_mount(), and lock moved mount trees 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 | 178 ++++++++++++++++++++++++++++++++-----
include/uapi/linux/mount.h | 3 +-
2 files changed, 157 insertions(+), 24 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index aecd05ac0170..f8c96e4d13ee 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -34,6 +34,7 @@
#include <linux/mnt_idmapping.h>
#include <linux/pidfs.h>
#include <linux/nstree.h>
+#include <linux/rootns.h>
#include "pnode.h"
#include "internal.h"
@@ -2564,6 +2565,8 @@ 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_ROOTNS = BIT(2),
+ MNT_TREE_ROOTNS_INIT = BIT(3),
};
/**
@@ -3781,6 +3784,7 @@ static int do_move_mount(const struct path *old_path,
struct mount *old = real_mount(old_path->mnt);
int err;
bool beneath = flags & MNT_TREE_BENEATH;
+ bool lock_tree;
if (!path_mounted(old_path))
return -EINVAL;
@@ -3792,7 +3796,13 @@ 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_ROOTNS) {
+ if (!anon_ns_root(old) || old->mnt_ns == mp.parent->mnt_ns)
+ return -EINVAL;
+ if ((flags & MNT_TREE_ROOTNS_INIT) &&
+ mp.parent != real_mount(new_path->mnt))
+ return -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))
@@ -3845,7 +3855,16 @@ static int do_move_mount(const struct path *old_path,
if (mount_is_ancestor(old, mp.parent))
return -ELOOP;
- return attach_recursive_mnt(old, &mp);
+ lock_tree = (flags & MNT_TREE_ROOTNS) &&
+ old->mnt_ns->user_ns != mp.parent->mnt_ns->user_ns;
+ err = attach_recursive_mnt(old, &mp);
+ if (!err && lock_tree) {
+ scoped_guard(mount_writer) {
+ lock_mnt_tree(old);
+ old->mnt.mnt_flags |= MNT_LOCKED;
+ }
+ }
+ return err;
}
static int do_move_mount_old(const struct path *path, const char *old_name)
@@ -4699,7 +4718,7 @@ 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->user_ns, true);
if (IS_ERR(ns))
return PTR_ERR(ns);
mnt = real_mount(new_path.mnt);
@@ -4739,6 +4758,129 @@ static inline int vfs_move_mount(const struct path *from_path,
return do_move_mount(from_path, to_path, mflags);
}
+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_ROOTNS_ROOT
+ *
+ * ``MOVE_MOUNT_T_ROOTNS_ROOT`` installs detached anonymous mount trees into a
+ * target ``rootns`` control fd supplied as ``to_dfd``:
+ *
+ * 1. ``to_pathname`` of ``"/"`` attaches the initial root mount onto the
+ * ``nullfs`` root of the ``rootns`` mount namespace at most once and
+ * transitions the ``rootns`` to ``ROOTNS_READY``.
+ *
+ * 2. Relative ``to_pathname`` values resolve beneath the installed ``rootns``
+ * root inside the ``rootns`` mount namespace.
+ *
+ * Capability is checked against ``CAP_SYS_ADMIN`` in the target ``rootns``
+ * user namespace, and source trees crossing user namespace boundaries are
+ * locked with ``MNT_LOCKED`` and locked mount flags.
+ */
+static int move_mount_rootns(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 *rootns_mnt_ns;
+ unsigned int lflags;
+ struct rootns *rootns;
+ 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_rootns)(to_dfd);
+ if (fd_empty(f_rootns))
+ return -EBADF;
+ if (!is_rootns_file(fd_file(f_rootns)))
+ return -EINVAL;
+
+ rootns = fd_file(f_rootns)->private_data;
+ if (!ns_capable(rootns->cred->user_ns, CAP_SYS_ADMIN))
+ return -EPERM;
+
+ rootns_mnt_ns = rootns->ns->mnt_ns;
+ is_root = to_name->name[0] == '/' && to_name->name[1] == '\0';
+ if (is_root) {
+ if (flags & MOVE_MOUNT_BENEATH)
+ return -EINVAL;
+ if (READ_ONCE(rootns->state) != ROOTNS_EMPTY)
+ return -EBUSY;
+
+ to_path.mnt = mntget(&rootns_mnt_ns->root->mnt);
+ to_path.dentry = dget(rootns_mnt_ns->root->mnt.mnt_root);
+ mflags |= MNT_TREE_ROOTNS_INIT;
+ } else {
+ if (to_name->name[0] == '/')
+ return -EINVAL;
+
+ scoped_guard(spinlock, &rootns->lock) {
+ if (rootns->state == ROOTNS_EMPTY)
+ return -ENOENT;
+ }
+
+ lflags = 0;
+ 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,
+ &rootns->root);
+ if (ret)
+ return ret;
+ if (real_mount(to_path.mnt)->mnt_ns != rootns_mnt_ns)
+ return -EINVAL;
+ }
+
+ ret = lookup_move_mount_from(from_dfd, from_pathname, flags,
+ &from_path);
+ if (ret)
+ return ret;
+
+ ret = vfs_move_mount(&from_path, &to_path, mflags | MNT_TREE_ROOTNS);
+ if (!ret && is_root) {
+ scoped_guard(spinlock, &rootns->lock) {
+ path_get(&from_path);
+ rootns->root = from_path;
+ WRITE_ONCE(rootns->state, ROOTNS_READY);
+ }
+ }
+
+ return ret;
+}
+
/*
* Move a mount from one place to another. In combination with
* fsopen()/fsmount() this is used to install a new mount and in combination
@@ -4758,7 +4900,7 @@ SYSCALL_DEFINE5(move_mount,
enum mnt_tree_flags_t mflags = 0;
int ret = 0;
- if (!may_mount())
+ if (!(flags & MOVE_MOUNT_T_ROOTNS_ROOT) && !may_mount())
return -EPERM;
if (flags & ~MOVE_MOUNT__MASK)
@@ -4771,6 +4913,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_ROOTNS_ROOT)) {
+ if (flags & (MOVE_MOUNT_T_EMPTY_PATH | MOVE_MOUNT_SET_GROUP))
+ return -EINVAL;
+ return move_mount_rootns(from_dfd, from_pathname,
+ to_dfd, to_pathname, flags, mflags);
+ }
+
uflags = 0;
if (flags & MOVE_MOUNT_T_EMPTY_PATH)
uflags = AT_EMPTY_PATH;
@@ -4794,25 +4943,8 @@ 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;
diff --git a/include/uapi/linux/mount.h b/include/uapi/linux/mount.h
index cb55cfcfc92e..7224a43af51d 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_ROOTNS_ROOT 0x00000080 /* Set as rootns root */
#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] 36+ messages in thread
* [RFC PATCH v2 10/13] arch: Wire up rootns system calls
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
` (8 preceding siblings ...)
2026-11-17 23:13 ` [RFC PATCH v2 09/13] fs: Support installing rootns mount trees via move_mount() Jarkko Sakkinen
@ 2026-11-17 23:13 ` Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 11/13] docs: Document root namespace uAPI Jarkko Sakkinen
` (4 subsequent siblings)
14 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17 23:13 UTC (permalink / raw)
To: linux-fsdevel
Cc: Jarkko Sakkinen, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
Now that the core root namespace lifecycle and VFS mount-tree
installation are in place, expose rootns_create() (473), rootns_wait()
(474), and rootns_kill() (475) across all architecture system call
tables and asm-generic unistd.h.
Co-developed-by: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
arch/alpha/kernel/syscalls/syscall.tbl | 3 +++
arch/arm/tools/syscall.tbl | 3 +++
arch/arm64/tools/syscall_32.tbl | 3 +++
arch/m68k/kernel/syscalls/syscall.tbl | 3 +++
arch/microblaze/kernel/syscalls/syscall.tbl | 3 +++
arch/mips/kernel/syscalls/syscall_n32.tbl | 3 +++
arch/mips/kernel/syscalls/syscall_n64.tbl | 3 +++
arch/mips/kernel/syscalls/syscall_o32.tbl | 3 +++
arch/parisc/kernel/syscalls/syscall.tbl | 3 +++
arch/powerpc/kernel/syscalls/syscall.tbl | 3 +++
arch/s390/kernel/syscalls/syscall.tbl | 3 +++
arch/sh/kernel/syscalls/syscall.tbl | 3 +++
arch/sparc/kernel/syscalls/syscall.tbl | 3 +++
arch/x86/entry/syscalls/syscall_32.tbl | 3 +++
arch/x86/entry/syscalls/syscall_64.tbl | 3 +++
arch/xtensa/kernel/syscalls/syscall.tbl | 3 +++
include/uapi/asm-generic/unistd.h | 10 +++++++++-
scripts/syscall.tbl | 3 +++
18 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/arch/alpha/kernel/syscalls/syscall.tbl b/arch/alpha/kernel/syscalls/syscall.tbl
index 52e3538cc7df..c7bec286deff 100644
--- a/arch/alpha/kernel/syscalls/syscall.tbl
+++ b/arch/alpha/kernel/syscalls/syscall.tbl
@@ -512,3 +512,6 @@
580 common listns sys_listns
581 common rseq_slice_yield sys_rseq_slice_yield
582 common fchroot sys_fchroot
+583 common rootns_create sys_rootns_create
+584 common rootns_wait sys_rootns_wait
+585 common rootns_kill sys_rootns_kill
diff --git a/arch/arm/tools/syscall.tbl b/arch/arm/tools/syscall.tbl
index 55717ed32c27..59f78bf991c9 100644
--- a/arch/arm/tools/syscall.tbl
+++ b/arch/arm/tools/syscall.tbl
@@ -487,3 +487,6 @@
470 common listns sys_listns
471 common rseq_slice_yield sys_rseq_slice_yield
472 common fchroot sys_fchroot
+473 common rootns_create sys_rootns_create
+474 common rootns_wait sys_rootns_wait
+475 common rootns_kill sys_rootns_kill
diff --git a/arch/arm64/tools/syscall_32.tbl b/arch/arm64/tools/syscall_32.tbl
index df2d1d82fb3c..8ef57696c6a8 100644
--- a/arch/arm64/tools/syscall_32.tbl
+++ b/arch/arm64/tools/syscall_32.tbl
@@ -484,3 +484,6 @@
470 common listns sys_listns
471 common rseq_slice_yield sys_rseq_slice_yield
472 common fchroot sys_fchroot
+473 common rootns_create sys_rootns_create
+474 common rootns_wait sys_rootns_wait compat_sys_rootns_wait
+475 common rootns_kill sys_rootns_kill
diff --git a/arch/m68k/kernel/syscalls/syscall.tbl b/arch/m68k/kernel/syscalls/syscall.tbl
index ba7a4d8903d0..36eb16ae659f 100644
--- a/arch/m68k/kernel/syscalls/syscall.tbl
+++ b/arch/m68k/kernel/syscalls/syscall.tbl
@@ -472,3 +472,6 @@
470 common listns sys_listns
471 common rseq_slice_yield sys_rseq_slice_yield
472 common fchroot sys_fchroot
+473 common rootns_create sys_rootns_create
+474 common rootns_wait sys_rootns_wait
+475 common rootns_kill sys_rootns_kill
diff --git a/arch/microblaze/kernel/syscalls/syscall.tbl b/arch/microblaze/kernel/syscalls/syscall.tbl
index 76d7cbe2a133..54739d61a9ee 100644
--- a/arch/microblaze/kernel/syscalls/syscall.tbl
+++ b/arch/microblaze/kernel/syscalls/syscall.tbl
@@ -478,3 +478,6 @@
470 common listns sys_listns
471 common rseq_slice_yield sys_rseq_slice_yield
472 common fchroot sys_fchroot
+473 common rootns_create sys_rootns_create
+474 common rootns_wait sys_rootns_wait
+475 common rootns_kill sys_rootns_kill
diff --git a/arch/mips/kernel/syscalls/syscall_n32.tbl b/arch/mips/kernel/syscalls/syscall_n32.tbl
index 9ae88e4eac61..f0a58c6b4516 100644
--- a/arch/mips/kernel/syscalls/syscall_n32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n32.tbl
@@ -411,3 +411,6 @@
470 n32 listns sys_listns
471 n32 rseq_slice_yield sys_rseq_slice_yield
472 n32 fchroot sys_fchroot
+473 n32 rootns_create sys_rootns_create
+474 n32 rootns_wait compat_sys_rootns_wait
+475 n32 rootns_kill sys_rootns_kill
diff --git a/arch/mips/kernel/syscalls/syscall_n64.tbl b/arch/mips/kernel/syscalls/syscall_n64.tbl
index 83dc93a0712f..c1d2774c6283 100644
--- a/arch/mips/kernel/syscalls/syscall_n64.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n64.tbl
@@ -387,3 +387,6 @@
470 n64 listns sys_listns
471 n64 rseq_slice_yield sys_rseq_slice_yield
472 n64 fchroot sys_fchroot
+473 n64 rootns_create sys_rootns_create
+474 n64 rootns_wait sys_rootns_wait
+475 n64 rootns_kill sys_rootns_kill
diff --git a/arch/mips/kernel/syscalls/syscall_o32.tbl b/arch/mips/kernel/syscalls/syscall_o32.tbl
index 9c62429c9b7b..99a753234dbf 100644
--- a/arch/mips/kernel/syscalls/syscall_o32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_o32.tbl
@@ -460,3 +460,6 @@
470 o32 listns sys_listns
471 o32 rseq_slice_yield sys_rseq_slice_yield
472 o32 fchroot sys_fchroot
+473 o32 rootns_create sys_rootns_create
+474 o32 rootns_wait sys_rootns_wait compat_sys_rootns_wait
+475 o32 rootns_kill sys_rootns_kill
diff --git a/arch/parisc/kernel/syscalls/syscall.tbl b/arch/parisc/kernel/syscalls/syscall.tbl
index 88adc4016cce..f3bac8085491 100644
--- a/arch/parisc/kernel/syscalls/syscall.tbl
+++ b/arch/parisc/kernel/syscalls/syscall.tbl
@@ -471,3 +471,6 @@
470 common listns sys_listns
471 common rseq_slice_yield sys_rseq_slice_yield
472 common fchroot sys_fchroot
+473 common rootns_create sys_rootns_create
+474 common rootns_wait sys_rootns_wait compat_sys_rootns_wait
+475 common rootns_kill sys_rootns_kill
diff --git a/arch/powerpc/kernel/syscalls/syscall.tbl b/arch/powerpc/kernel/syscalls/syscall.tbl
index cfbb70039ff0..4cac51e4d370 100644
--- a/arch/powerpc/kernel/syscalls/syscall.tbl
+++ b/arch/powerpc/kernel/syscalls/syscall.tbl
@@ -563,3 +563,6 @@
470 common listns sys_listns
471 nospu rseq_slice_yield sys_rseq_slice_yield
472 common fchroot sys_fchroot
+473 common rootns_create sys_rootns_create
+474 common rootns_wait sys_rootns_wait compat_sys_rootns_wait
+475 common rootns_kill sys_rootns_kill
diff --git a/arch/s390/kernel/syscalls/syscall.tbl b/arch/s390/kernel/syscalls/syscall.tbl
index 1b45e68a217b..7f8cd4147860 100644
--- a/arch/s390/kernel/syscalls/syscall.tbl
+++ b/arch/s390/kernel/syscalls/syscall.tbl
@@ -399,3 +399,6 @@
470 common listns sys_listns
471 common rseq_slice_yield sys_rseq_slice_yield
472 common fchroot sys_fchroot
+473 common rootns_create sys_rootns_create
+474 common rootns_wait sys_rootns_wait
+475 common rootns_kill sys_rootns_kill
diff --git a/arch/sh/kernel/syscalls/syscall.tbl b/arch/sh/kernel/syscalls/syscall.tbl
index ace068dff0de..9bfcb96dcdeb 100644
--- a/arch/sh/kernel/syscalls/syscall.tbl
+++ b/arch/sh/kernel/syscalls/syscall.tbl
@@ -476,3 +476,6 @@
470 common listns sys_listns
471 common rseq_slice_yield sys_rseq_slice_yield
472 common fchroot sys_fchroot
+473 common rootns_create sys_rootns_create
+474 common rootns_wait sys_rootns_wait
+475 common rootns_kill sys_rootns_kill
diff --git a/arch/sparc/kernel/syscalls/syscall.tbl b/arch/sparc/kernel/syscalls/syscall.tbl
index 5b9fe0e8140f..a847f4cbea3a 100644
--- a/arch/sparc/kernel/syscalls/syscall.tbl
+++ b/arch/sparc/kernel/syscalls/syscall.tbl
@@ -518,3 +518,6 @@
470 common listns sys_listns
471 common rseq_slice_yield sys_rseq_slice_yield
472 common fchroot sys_fchroot
+473 common rootns_create sys_rootns_create
+474 common rootns_wait sys_rootns_wait compat_sys_rootns_wait
+475 common rootns_kill sys_rootns_kill
diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl
index 2c172ef48dfd..e49c96692038 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -478,3 +478,6 @@
470 i386 listns sys_listns
471 i386 rseq_slice_yield sys_rseq_slice_yield
472 i386 fchroot sys_fchroot
+473 i386 rootns_create sys_rootns_create
+474 i386 rootns_wait sys_rootns_wait compat_sys_rootns_wait
+475 i386 rootns_kill sys_rootns_kill
diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl
index d5b6045b0090..d6f7fb7be172 100644
--- a/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/arch/x86/entry/syscalls/syscall_64.tbl
@@ -397,6 +397,9 @@
470 common listns sys_listns
471 common rseq_slice_yield sys_rseq_slice_yield
472 common fchroot sys_fchroot
+473 common rootns_create sys_rootns_create
+474 common rootns_wait sys_rootns_wait
+475 common rootns_kill sys_rootns_kill
#
# 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..268c0d577788 100644
--- a/arch/xtensa/kernel/syscalls/syscall.tbl
+++ b/arch/xtensa/kernel/syscalls/syscall.tbl
@@ -443,3 +443,6 @@
470 common listns sys_listns
471 common rseq_slice_yield sys_rseq_slice_yield
472 common fchroot sys_fchroot
+473 common rootns_create sys_rootns_create
+474 common rootns_wait sys_rootns_wait
+475 common rootns_kill sys_rootns_kill
diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h
index 5b7e77a7c736..571db09eb571 100644
--- a/include/uapi/asm-generic/unistd.h
+++ b/include/uapi/asm-generic/unistd.h
@@ -867,8 +867,16 @@ __SYSCALL(__NR_rseq_slice_yield, sys_rseq_slice_yield)
#define __NR_fchroot 472
__SYSCALL(__NR_fchroot, sys_fchroot)
+/* kernel/rootns.c */
+#define __NR_rootns_create 473
+__SYSCALL(__NR_rootns_create, sys_rootns_create)
+#define __NR_rootns_wait 474
+__SC_COMP(__NR_rootns_wait, sys_rootns_wait, compat_sys_rootns_wait)
+#define __NR_rootns_kill 475
+__SYSCALL(__NR_rootns_kill, sys_rootns_kill)
+
#undef __NR_syscalls
-#define __NR_syscalls 473
+#define __NR_syscalls 476
/*
* 32 bit systems traditionally used different
diff --git a/scripts/syscall.tbl b/scripts/syscall.tbl
index 0ab531605120..e9ff99c03b2b 100644
--- a/scripts/syscall.tbl
+++ b/scripts/syscall.tbl
@@ -413,3 +413,6 @@
470 common listns sys_listns
471 common rseq_slice_yield sys_rseq_slice_yield
472 common fchroot sys_fchroot
+473 common rootns_create sys_rootns_create
+474 common rootns_wait sys_rootns_wait compat_sys_rootns_wait
+475 common rootns_kill sys_rootns_kill
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [RFC PATCH v2 11/13] docs: Document root namespace uAPI
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
` (9 preceding siblings ...)
2026-11-17 23:13 ` [RFC PATCH v2 10/13] arch: Wire up rootns system calls Jarkko Sakkinen
@ 2026-11-17 23:13 ` Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 12/13] selftests/rootns: Add root namespace test suite Jarkko Sakkinen
` (3 subsequent siblings)
14 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17 23:13 UTC (permalink / raw)
To: linux-fsdevel
Cc: Jarkko Sakkinen, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
Userspace container managers need a clear specification of rootns state
transitions, mount-tree construction, credential rules, and process
creation semantics.
Add Documentation/userspace-api/rootns.rst to include the kernel-doc
sections and system call reference from kernel/rootns.c,
include/uapi/linux/rootns.h, fs/fsopen.c, and fs/namespace.c.
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/userspace-api/index.rst | 1 +
Documentation/userspace-api/rootns.rst | 40 ++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
create mode 100644 Documentation/userspace-api/rootns.rst
diff --git a/Documentation/userspace-api/index.rst b/Documentation/userspace-api/index.rst
index a68b1bea57a8..56d0ac4eb087 100644
--- a/Documentation/userspace-api/index.rst
+++ b/Documentation/userspace-api/index.rst
@@ -17,6 +17,7 @@ System calls
:maxdepth: 1
unshare
+ rootns
futex2
ebpf/index
ioctl/index
diff --git a/Documentation/userspace-api/rootns.rst b/Documentation/userspace-api/rootns.rst
new file mode 100644
index 000000000000..46b40f5fb29b
--- /dev/null
+++ b/Documentation/userspace-api/rootns.rst
@@ -0,0 +1,40 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+===================
+Root namespace uAPI
+===================
+
+Overview
+========
+
+.. kernel-doc:: kernel/rootns.c
+ :doc: Overview
+
+Flags
+=====
+
+.. kernel-doc:: include/uapi/linux/rootns.h
+
+System calls
+============
+
+.. kernel-doc:: kernel/rootns.c
+ :identifiers: sys_rootns_create sys_rootns_wait sys_rootns_kill
+
+Process creation
+================
+
+.. kernel-doc:: kernel/rootns.c
+ :doc: CLONE_INTO_ROOTNS
+
+Filesystem configuration
+========================
+
+.. kernel-doc:: fs/fsopen.c
+ :doc: FSCONFIG_SET_ROOTNS
+
+Mount tree installation
+=======================
+
+.. kernel-doc:: fs/namespace.c
+ :doc: MOVE_MOUNT_T_ROOTNS_ROOT
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [RFC PATCH v2 12/13] selftests/rootns: Add root namespace test suite
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
` (10 preceding siblings ...)
2026-11-17 23:13 ` [RFC PATCH v2 11/13] docs: Document root namespace uAPI Jarkko Sakkinen
@ 2026-11-17 23:13 ` Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 13/13] MAINTAINERS: Add entry for ROOT NAMESPACE Jarkko Sakkinen
` (2 subsequent siblings)
14 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17 23:13 UTC (permalink / raw)
To: linux-fsdevel
Cc: Jarkko Sakkinen, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
Verify the root namespace uAPI and security invariants across
privileged, unprivileged, and edge-case scenarios.
Add a kselftest harness suite under tools/testing/selftests/rootns
exercising rootns creation, clone3(CLONE_INTO_ROOTNS) init and
concurrent bootstrap lifecycle, poll(EPOLLHUP) and WNOHANG/rusage
reporting, FSCONFIG_SET_ROOTNS and mount-tree installation, pivot_root()
and OPEN_TREE_NAMESPACE inside a rootns, and entry and setns()
permission enforcement.
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
tools/testing/selftests/Makefile | 1 +
tools/testing/selftests/rootns/.gitignore | 2 +
tools/testing/selftests/rootns/Makefile | 5 +
tools/testing/selftests/rootns/config | 9 +
tools/testing/selftests/rootns/smoke.c | 1381 +++++++++++++++++++++
5 files changed, 1398 insertions(+)
create mode 100644 tools/testing/selftests/rootns/.gitignore
create mode 100644 tools/testing/selftests/rootns/Makefile
create mode 100644 tools/testing/selftests/rootns/config
create mode 100644 tools/testing/selftests/rootns/smoke.c
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile
index 07c3719f8b04..7c44f93e57a4 100644
--- a/tools/testing/selftests/Makefile
+++ b/tools/testing/selftests/Makefile
@@ -117,6 +117,7 @@ TARGETS += rdma
TARGETS += resctrl
TARGETS += riscv
TARGETS += rlimits
+TARGETS += rootns
TARGETS += rseq
TARGETS += rtc
TARGETS += rust
diff --git a/tools/testing/selftests/rootns/.gitignore b/tools/testing/selftests/rootns/.gitignore
new file mode 100644
index 000000000000..9a018c20d310
--- /dev/null
+++ b/tools/testing/selftests/rootns/.gitignore
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+/smoke
diff --git a/tools/testing/selftests/rootns/Makefile b/tools/testing/selftests/rootns/Makefile
new file mode 100644
index 000000000000..79162fba3c2b
--- /dev/null
+++ b/tools/testing/selftests/rootns/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+CFLAGS += -Wall -Wextra -O2 -g $(KHDR_INCLUDES)
+TEST_GEN_PROGS := smoke
+include ../lib.mk
diff --git a/tools/testing/selftests/rootns/config b/tools/testing/selftests/rootns/config
new file mode 100644
index 000000000000..715b0a1cf6a8
--- /dev/null
+++ b/tools/testing/selftests/rootns/config
@@ -0,0 +1,9 @@
+CONFIG_CGROUPS=y
+CONFIG_IPC_NS=y
+CONFIG_NET_NS=y
+CONFIG_PID_NS=y
+CONFIG_PROC_FS=y
+CONFIG_ROOTNS=y
+CONFIG_TMPFS=y
+CONFIG_USER_NS=y
+CONFIG_UTS_NS=y
diff --git a/tools/testing/selftests/rootns/smoke.c b/tools/testing/selftests/rootns/smoke.c
new file mode 100644
index 000000000000..350e6e8e2523
--- /dev/null
+++ b/tools/testing/selftests/rootns/smoke.c
@@ -0,0 +1,1381 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Opinsys Oy
+ */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <sched.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/prctl.h>
+#include <sys/resource.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <sys/vfs.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <linux/magic.h>
+#include <linux/mount.h>
+#include <linux/rootns.h>
+#include <linux/sched.h>
+#include "kselftest_harness.h"
+
+#ifndef __NR_pidfd_open
+#define __NR_pidfd_open 434
+#endif
+
+#ifndef __NR_clone3
+#define __NR_clone3 435
+#endif
+
+#ifndef __NR_rootns_create
+#ifdef __alpha__
+#define __NR_rootns_create 583
+#define __NR_rootns_wait 584
+#define __NR_rootns_kill 585
+#else
+#define __NR_rootns_create 473
+#define __NR_rootns_wait 474
+#define __NR_rootns_kill 475
+#endif
+#endif
+
+static int sys_open_tree(int dfd, const char *path, unsigned int flags)
+{
+ return syscall(__NR_open_tree, dfd, path, flags);
+}
+
+static int sys_move_mount(int from_dfd, const char *from_path, int to_dfd,
+ const char *to_path, unsigned int flags)
+{
+ return syscall(__NR_move_mount, from_dfd, from_path, to_dfd, to_path,
+ flags);
+}
+
+static int sys_fsopen(const char *fsname, unsigned int flags)
+{
+ return syscall(__NR_fsopen, fsname, flags);
+}
+
+static int sys_fsconfig(int fsfd, unsigned int cmd, const char *key,
+ const void *value, int aux)
+{
+ return syscall(__NR_fsconfig, fsfd, cmd, key, value, aux);
+}
+
+static int sys_fsmount(int fsfd, unsigned int flags, unsigned int attr_flags)
+{
+ return syscall(__NR_fsmount, fsfd, flags, attr_flags);
+}
+
+static int sys_pidfd_open(pid_t pid, unsigned int flags)
+{
+ return syscall(__NR_pidfd_open, pid, flags);
+}
+
+static int sys_pivot_root(const char *new_root, const char *put_old)
+{
+ return syscall(__NR_pivot_root, new_root, put_old);
+}
+
+static int sys_rootns_create(unsigned int flags)
+{
+ return syscall(__NR_rootns_create, flags);
+}
+
+static pid_t sys_clone3(struct clone_args *args, size_t size)
+{
+ fflush(stdout);
+ fflush(stderr);
+ return syscall(__NR_clone3, args, size);
+}
+
+static pid_t clone_into_rootns(int cfd, __u64 extra_flags)
+{
+ struct clone_args args = {
+ .flags = CLONE_INTO_ROOTNS | extra_flags,
+ .exit_signal = SIGCHLD,
+ .rootns = (__u64)(unsigned int)cfd,
+ };
+
+ return sys_clone3(&args, sizeof(args));
+}
+
+static int sys_rootns_wait(int cfd, int *status, unsigned int options,
+ struct rusage *ru)
+{
+ return syscall(__NR_rootns_wait, cfd, status, options, ru);
+}
+
+static int sys_rootns_kill(int cfd, int sig)
+{
+ return syscall(__NR_rootns_kill, cfd, sig);
+}
+
+static int wait_for_pid_exit(pid_t pid, int *status, int timeout_ms)
+{
+ struct pollfd pfd;
+ int pidfd;
+ int ret;
+
+ pidfd = sys_pidfd_open(pid, 0);
+ if (pidfd >= 0) {
+ pfd.fd = pidfd;
+ pfd.events = POLLIN;
+ do {
+ ret = poll(&pfd, 1, timeout_ms);
+ } while (ret < 0 && errno == EINTR);
+ close(pidfd);
+
+ if (ret == 0) {
+ errno = ETIMEDOUT;
+ return -1;
+ }
+ if (ret < 0)
+ return -1;
+ } else if (errno != ESRCH) {
+ return -1;
+ }
+
+ do {
+ ret = waitpid(pid, status, 0);
+ } while (ret < 0 && errno == EINTR);
+
+ return (ret == pid) ? 0 : -1;
+}
+
+static void kill_and_reap_pid(pid_t pid)
+{
+ int status;
+
+ if (pid <= 0)
+ return;
+ if (kill(pid, SIGKILL) < 0 && errno != ESRCH)
+ return;
+ (void)waitpid(pid, &status, 0);
+}
+
+static int reap_child_exit_code(pid_t pid)
+{
+ int status = 0;
+
+ if (wait_for_pid_exit(pid, &status, 5000) < 0) {
+ kill_and_reap_pid(pid);
+ return -1;
+ }
+ if (!WIFEXITED(status))
+ return -2;
+ return WEXITSTATUS(status);
+}
+
+static int clone_exit(void *arg)
+{
+ (void)arg;
+ return 0;
+}
+
+static int clone_with_flags(int flags)
+{
+ const size_t stack_size = 64 * 1024;
+ void *stack;
+ pid_t pid;
+ int status;
+ int ret;
+
+ stack = malloc(stack_size);
+ if (!stack)
+ return -ENOMEM;
+
+ pid = clone(clone_exit, (char *)stack + stack_size,
+ SIGCHLD | flags, NULL);
+ if (pid < 0)
+ ret = -errno;
+ else if (waitpid(pid, &status, 0) < 0)
+ ret = -errno;
+ else if (!WIFEXITED(status) || WEXITSTATUS(status))
+ ret = -EIO;
+ else
+ ret = 0;
+
+ free(stack);
+ return ret;
+}
+
+static int send_fd(int sockfd, int fd)
+{
+ char control[CMSG_SPACE(sizeof(fd))];
+ char marker = 'R';
+ struct iovec iov = {
+ .iov_base = &marker,
+ .iov_len = sizeof(marker),
+ };
+ struct msghdr msg = {
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_control = control,
+ .msg_controllen = sizeof(control),
+ };
+ struct cmsghdr *cmsg;
+
+ memset(control, 0, sizeof(control));
+ cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
+ memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd));
+
+ return (sendmsg(sockfd, &msg, 0) < 0) ? -1 : 0;
+}
+
+static int recv_fd(int sockfd)
+{
+ char control[CMSG_SPACE(sizeof(int))];
+ char marker;
+ int fd;
+ struct iovec iov = {
+ .iov_base = &marker,
+ .iov_len = sizeof(marker),
+ };
+ struct msghdr msg = {
+ .msg_iov = &iov,
+ .msg_iovlen = 1,
+ .msg_control = control,
+ .msg_controllen = sizeof(control),
+ };
+ struct cmsghdr *cmsg;
+
+ memset(control, 0, sizeof(control));
+ if (recvmsg(sockfd, &msg, 0) < 0)
+ return -1;
+
+ cmsg = CMSG_FIRSTHDR(&msg);
+ if (!cmsg ||
+ cmsg->cmsg_level != SOL_SOCKET ||
+ cmsg->cmsg_type != SCM_RIGHTS ||
+ cmsg->cmsg_len < CMSG_LEN(sizeof(fd))) {
+ errno = EPROTO;
+ return -1;
+ }
+
+ memcpy(&fd, CMSG_DATA(cmsg), sizeof(fd));
+ return fd;
+}
+
+static int send_unshared_mntns_and_wait(int sockfd)
+{
+ ssize_t nread;
+ char ch;
+ int nsfd;
+ int ret;
+
+ if (unshare(CLONE_NEWNS) < 0)
+ return 1;
+
+ nsfd = open("/proc/self/ns/mnt", O_RDONLY | O_CLOEXEC);
+ if (nsfd < 0)
+ return 2;
+
+ ret = send_fd(sockfd, nsfd);
+ close(nsfd);
+ if (ret < 0)
+ return 3;
+
+ nread = read(sockfd, &ch, sizeof(ch));
+ if (nread != (ssize_t)sizeof(ch))
+ return 4;
+
+ return 0;
+}
+
+static int create_rootns_as_uid(uid_t uid, unsigned int flags, int *cfd)
+{
+ int pipefd[2];
+ ssize_t nread;
+ int err = 0;
+ int status;
+ int sv[2];
+ pid_t pid;
+
+ if (socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0, sv) < 0)
+ return -errno;
+
+ if (pipe2(pipefd, O_CLOEXEC) < 0) {
+ err = -errno;
+ close(sv[0]);
+ close(sv[1]);
+ return err;
+ }
+
+ pid = fork();
+ if (pid < 0) {
+ err = -errno;
+ close(pipefd[0]);
+ close(pipefd[1]);
+ close(sv[0]);
+ close(sv[1]);
+ return err;
+ }
+
+ if (pid == 0) {
+ int child_fd = -1;
+
+ close(pipefd[0]);
+ close(sv[0]);
+
+ if (setresuid(uid, uid, uid) < 0) {
+ err = errno;
+ goto out_child;
+ }
+
+ child_fd = sys_rootns_create(flags);
+ if (child_fd < 0) {
+ err = errno;
+ goto out_child;
+ }
+
+ if (send_fd(sv[1], child_fd) < 0)
+ err = errno;
+
+out_child:
+ if (child_fd >= 0)
+ close(child_fd);
+ (void)write(pipefd[1], &err, sizeof(err));
+ close(pipefd[1]);
+ close(sv[1]);
+ _exit(err ? 1 : 0);
+ }
+
+ close(pipefd[1]);
+ close(sv[1]);
+
+ nread = read(pipefd[0], &err, sizeof(err));
+ close(pipefd[0]);
+ if (nread != (ssize_t)sizeof(err))
+ err = (nread < 0) ? errno : EPROTO;
+
+ if (!err) {
+ *cfd = recv_fd(sv[0]);
+ if (*cfd < 0)
+ err = errno;
+ }
+ close(sv[0]);
+
+ if (waitpid(pid, &status, 0) != pid && !err)
+ err = errno;
+ if (!err && (!WIFEXITED(status) || WEXITSTATUS(status)))
+ err = ECHILD;
+
+ return err ? -err : 0;
+}
+
+static int mount_root(int cfd)
+{
+ static const char *const dirs[] = { "proc", "mnt", "tmp" };
+ int saved_errno;
+ int rootfd;
+ int fsfd;
+ size_t i;
+
+ fsfd = sys_fsopen("tmpfs", 0);
+ if (fsfd < 0)
+ return -1;
+
+ if (sys_fsconfig(fsfd, FSCONFIG_SET_ROOTNS, NULL, NULL, cfd) < 0)
+ goto err_fsfd;
+ if (sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) < 0)
+ goto err_fsfd;
+
+ rootfd = sys_fsmount(fsfd, 0, 0);
+ if (rootfd < 0)
+ goto err_fsfd;
+
+ for (i = 0; i < ARRAY_SIZE(dirs); i++) {
+ if (mkdirat(rootfd, dirs[i], 0755) < 0 && errno != EEXIST)
+ goto err_rootfd;
+ }
+
+ if (sys_move_mount(rootfd, "", cfd, "/",
+ MOVE_MOUNT_F_EMPTY_PATH |
+ MOVE_MOUNT_T_ROOTNS_ROOT) < 0)
+ goto err_rootfd;
+
+ close(rootfd);
+ close(fsfd);
+ return 0;
+
+err_rootfd:
+ saved_errno = errno;
+ close(rootfd);
+ errno = saved_errno;
+err_fsfd:
+ saved_errno = errno;
+ close(fsfd);
+ errno = saved_errno;
+ return -1;
+}
+
+static int mount_proc(int cfd, bool need_proc)
+{
+ const char *fstype = need_proc ? "proc" : "tmpfs";
+ int saved_errno;
+ int fsfd;
+ int mfd;
+
+ fsfd = sys_fsopen(fstype, 0);
+ if (fsfd < 0)
+ return -1;
+
+ if (sys_fsconfig(fsfd, FSCONFIG_SET_ROOTNS, NULL, NULL, cfd) < 0)
+ goto err_fsfd;
+ if (sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) < 0)
+ goto err_fsfd;
+
+ mfd = sys_fsmount(fsfd, 0, 0);
+ if (mfd < 0)
+ goto err_fsfd;
+
+ if (sys_move_mount(mfd, "", cfd, "proc",
+ MOVE_MOUNT_F_EMPTY_PATH |
+ MOVE_MOUNT_T_ROOTNS_ROOT) < 0) {
+ saved_errno = errno;
+ close(mfd);
+ errno = saved_errno;
+ goto err_fsfd;
+ }
+
+ close(mfd);
+ close(fsfd);
+ return 0;
+
+err_fsfd:
+ saved_errno = errno;
+ close(fsfd);
+ errno = saved_errno;
+ return -1;
+}
+
+static int create_test_rootns(bool need_proc, unsigned int flags)
+{
+ int saved_errno;
+ int cfd;
+
+ cfd = sys_rootns_create(flags);
+ if (cfd < 0)
+ return -1;
+
+ if (mount_root(cfd) < 0 || mount_proc(cfd, need_proc) < 0) {
+ saved_errno = errno;
+ close(cfd);
+ errno = saved_errno;
+ return -1;
+ }
+
+ return cfd;
+}
+
+FIXTURE(rootns) {
+ int cfd;
+};
+
+FIXTURE_SETUP(rootns) {
+ self->cfd = create_test_rootns(false, ROOTNS_ALL_NAMESPACES |
+ ROOTNS_KILL_ON_CLOSE |
+ ROOTNS_CLOSE_ON_EXEC);
+ ASSERT_GE(self->cfd, 0);
+}
+
+FIXTURE_TEARDOWN(rootns) {
+ if (self->cfd >= 0)
+ close(self->cfd);
+}
+
+TEST_F(rootns, create) {
+ ASSERT_GE(self->cfd, 0);
+}
+
+TEST_F(rootns, kill) {
+ int ready_pipe[2];
+ int hold_pipe[2];
+ char ch;
+ int status;
+ pid_t pid1;
+ pid_t pid2;
+ int ret;
+
+ ASSERT_EQ(pipe2(ready_pipe, O_CLOEXEC), 0);
+ ASSERT_EQ(pipe2(hold_pipe, O_CLOEXEC), 0);
+
+ pid1 = clone_into_rootns(self->cfd, 0);
+ ASSERT_GE(pid1, 0);
+ if (pid1 == 0) {
+ close(self->cfd);
+ close(ready_pipe[0]);
+ close(ready_pipe[1]);
+ close(hold_pipe[0]);
+ close(hold_pipe[1]);
+ for (;;)
+ pause();
+ }
+
+ pid2 = clone_into_rootns(self->cfd, 0);
+ ASSERT_GE(pid2, 0);
+ if (pid2 == 0) {
+ pid_t child;
+
+ close(self->cfd);
+ close(ready_pipe[0]);
+ close(hold_pipe[0]);
+ child = fork();
+ if (child < 0)
+ _exit(1);
+ if (child == 0) {
+ ch = 'r';
+ (void)write(ready_pipe[1], &ch, 1);
+ close(ready_pipe[1]);
+ for (;;)
+ pause();
+ }
+ close(ready_pipe[1]);
+ close(hold_pipe[1]);
+ for (;;)
+ pause();
+ }
+ close(ready_pipe[1]);
+ close(hold_pipe[1]);
+
+ ASSERT_EQ(read(ready_pipe[0], &ch, 1), 1);
+ close(ready_pipe[0]);
+
+ ASSERT_EQ(sys_rootns_kill(self->cfd, SIGKILL), 0);
+ ASSERT_EQ(read(hold_pipe[0], &ch, 1), 0);
+ close(hold_pipe[0]);
+
+ ret = wait_for_pid_exit(pid2, &status, 5000);
+ if (ret < 0) {
+ kill_and_reap_pid(pid2);
+ kill_and_reap_pid(pid1);
+ ASSERT_EQ(ret, 0);
+ }
+ ASSERT_TRUE(WIFSIGNALED(status));
+ ASSERT_EQ(WTERMSIG(status), SIGKILL);
+
+ ret = wait_for_pid_exit(pid1, &status, 5000);
+ if (ret < 0) {
+ kill_and_reap_pid(pid1);
+ ASSERT_EQ(ret, 0);
+ }
+ ASSERT_TRUE(WIFSIGNALED(status));
+ ASSERT_EQ(WTERMSIG(status), SIGKILL);
+}
+
+TEST_F(rootns, wait) {
+ int status = 0;
+ pid_t pid;
+
+ pid = clone_into_rootns(self->cfd, 0);
+ ASSERT_GE(pid, 0);
+ if (pid == 0)
+ _exit(123);
+
+ ASSERT_EQ(sys_rootns_wait(self->cfd, &status, 0, NULL), pid);
+ ASSERT_TRUE(WIFEXITED(status));
+ ASSERT_EQ(WEXITSTATUS(status), 123);
+ ASSERT_EQ(reap_child_exit_code(pid), 123);
+}
+
+TEST_F(rootns, poll) {
+ struct pollfd pfd;
+ struct rusage ru;
+ int status = 0;
+ int pipefd[2];
+ pid_t pid;
+
+ ASSERT_EQ(pipe2(pipefd, O_CLOEXEC), 0);
+
+ pid = clone_into_rootns(self->cfd, 0);
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ char ch;
+
+ close(self->cfd);
+ close(pipefd[1]);
+ (void)read(pipefd[0], &ch, 1);
+ close(pipefd[0]);
+ _exit(42);
+ }
+ close(pipefd[0]);
+
+ ASSERT_EQ(sys_rootns_wait(self->cfd, &status, WNOHANG, NULL), 0);
+
+ pfd.fd = self->cfd;
+ pfd.events = POLLIN;
+ pfd.revents = 0;
+ ASSERT_EQ(poll(&pfd, 1, 0), 0);
+
+ close(pipefd[1]);
+
+ ASSERT_EQ(poll(&pfd, 1, 5000), 1);
+ ASSERT_NE(pfd.revents & POLLHUP, 0);
+
+ memset(&ru, 0xff, sizeof(ru));
+ ASSERT_EQ(sys_rootns_wait(self->cfd, &status, WNOHANG, &ru), pid);
+ ASSERT_TRUE(WIFEXITED(status));
+ ASSERT_EQ(WEXITSTATUS(status), 42);
+ ASSERT_GE(ru.ru_utime.tv_sec, 0);
+ ASSERT_GE(ru.ru_maxrss, 0);
+ ASSERT_EQ(reap_child_exit_code(pid), 42);
+}
+
+TEST_F(rootns, clone_dead) {
+ int status = 0;
+ pid_t pid;
+
+ pid = clone_into_rootns(self->cfd, 0);
+ ASSERT_GE(pid, 0);
+ if (pid == 0)
+ _exit(0);
+
+ ASSERT_EQ(sys_rootns_wait(self->cfd, &status, 0, NULL), pid);
+ ASSERT_TRUE(WIFEXITED(status));
+ ASSERT_EQ(reap_child_exit_code(pid), 0);
+
+ ASSERT_EQ(clone_into_rootns(self->cfd, 0), -1);
+ ASSERT_EQ(errno, ESRCH);
+}
+
+TEST_F(rootns, nested_ns) {
+ pid_t pid;
+ int nsfd;
+
+ nsfd = open("/proc/self/ns/mnt", O_RDONLY | O_CLOEXEC);
+ ASSERT_GE(nsfd, 0);
+
+ pid = clone_into_rootns(self->cfd, 0);
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ close(self->cfd);
+
+ if (unshare(CLONE_NEWNS))
+ _exit(1);
+ if (clone_with_flags(CLONE_NEWNS))
+ _exit(2);
+ if (unshare(CLONE_NEWUSER))
+ _exit(3);
+ if (clone_with_flags(CLONE_NEWUSER))
+ _exit(4);
+ if (setns(nsfd, CLONE_NEWNS) != -1 || errno != EPERM)
+ _exit(5);
+
+ close(nsfd);
+ _exit(0);
+ }
+
+ close(nsfd);
+ ASSERT_EQ(reap_child_exit_code(pid), 0);
+}
+
+TEST_F(rootns, setns_same) {
+ ssize_t nwritten;
+ pid_t pid1;
+ pid_t pid2;
+ char ch;
+ int nsfd;
+ int sv[2];
+
+ ASSERT_EQ(socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0, sv), 0);
+
+ pid1 = clone_into_rootns(self->cfd, 0);
+ ASSERT_GE(pid1, 0);
+ if (pid1 == 0) {
+ int ret;
+
+ close(self->cfd);
+ close(sv[0]);
+ ret = send_unshared_mntns_and_wait(sv[1]);
+ close(sv[1]);
+ _exit(ret);
+ }
+ close(sv[1]);
+
+ nsfd = recv_fd(sv[0]);
+ ASSERT_GE(nsfd, 0);
+
+ pid2 = clone_into_rootns(self->cfd, 0);
+ ASSERT_GE(pid2, 0);
+ if (pid2 == 0) {
+ int ret;
+
+ close(self->cfd);
+ close(sv[0]);
+ ret = setns(nsfd, CLONE_NEWNS);
+ close(nsfd);
+ _exit(ret ? 1 : 0);
+ }
+ close(nsfd);
+
+ ASSERT_EQ(reap_child_exit_code(pid2), 0);
+
+ ch = 'x';
+ nwritten = write(sv[0], &ch, sizeof(ch));
+ ASSERT_EQ(nwritten, (ssize_t)sizeof(ch));
+ close(sv[0]);
+
+ ASSERT_EQ(reap_child_exit_code(pid1), 0);
+}
+
+TEST_F(rootns, setns_foreign) {
+ unsigned int flags = ROOTNS_ALL_NAMESPACES |
+ ROOTNS_KILL_ON_CLOSE | ROOTNS_CLOSE_ON_EXEC;
+ ssize_t nwritten;
+ int alpha_cfd;
+ int beta_cfd;
+ pid_t alpha_pid;
+ pid_t beta_pid;
+ char ch;
+ int nsfd;
+ int sv[2];
+
+ alpha_cfd = create_test_rootns(false, flags);
+ ASSERT_GE(alpha_cfd, 0);
+
+ beta_cfd = create_test_rootns(false, flags);
+ ASSERT_GE(beta_cfd, 0);
+
+ ASSERT_EQ(socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0, sv), 0);
+
+ beta_pid = clone_into_rootns(beta_cfd, 0);
+ ASSERT_GE(beta_pid, 0);
+ if (beta_pid == 0) {
+ int ret;
+
+ close(alpha_cfd);
+ close(beta_cfd);
+ close(sv[0]);
+ ret = send_unshared_mntns_and_wait(sv[1]);
+ close(sv[1]);
+ _exit(ret);
+ }
+ close(sv[1]);
+
+ nsfd = recv_fd(sv[0]);
+ ASSERT_GE(nsfd, 0);
+
+ alpha_pid = clone_into_rootns(alpha_cfd, 0);
+ ASSERT_GE(alpha_pid, 0);
+ if (alpha_pid == 0) {
+ int ret;
+
+ close(alpha_cfd);
+ close(beta_cfd);
+ close(sv[0]);
+ ret = setns(nsfd, CLONE_NEWNS);
+ close(nsfd);
+ if (ret != -1 || errno != EPERM)
+ _exit(1);
+ _exit(0);
+ }
+ close(nsfd);
+
+ ASSERT_EQ(reap_child_exit_code(alpha_pid), 0);
+
+ ch = 'x';
+ nwritten = write(sv[0], &ch, sizeof(ch));
+ ASSERT_EQ(nwritten, (ssize_t)sizeof(ch));
+ close(sv[0]);
+
+ ASSERT_EQ(reap_child_exit_code(beta_pid), 0);
+
+ close(alpha_cfd);
+ close(beta_cfd);
+}
+
+TEST_F(rootns, submount) {
+ pid_t pid;
+
+ pid = clone_into_rootns(self->cfd, 0);
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ struct statfs st;
+
+ close(self->cfd);
+ if (statfs("/proc", &st) < 0)
+ _exit(1);
+ if ((unsigned long)st.f_type != (unsigned long)TMPFS_MAGIC)
+ _exit(2);
+ _exit(0);
+ }
+
+ ASSERT_EQ(reap_child_exit_code(pid), 0);
+}
+
+TEST_F(rootns, proc) {
+ int cfd;
+ pid_t pid;
+
+ cfd = create_test_rootns(true, ROOTNS_ALL_NAMESPACES |
+ ROOTNS_KILL_ON_CLOSE |
+ ROOTNS_CLOSE_ON_EXEC);
+ ASSERT_GE(cfd, 0);
+
+ pid = clone_into_rootns(cfd, 0);
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ struct statfs st;
+ char target[32];
+ ssize_t len;
+
+ close(cfd);
+ if (getpid() != 1)
+ _exit(1);
+ if (statfs("/proc", &st) < 0)
+ _exit(2);
+ if ((unsigned long)st.f_type != (unsigned long)PROC_SUPER_MAGIC)
+ _exit(3);
+ len = readlink("/proc/self", target, sizeof(target) - 1);
+ if (len <= 0)
+ _exit(4);
+ target[len] = '\0';
+ if (strcmp(target, "1") != 0)
+ _exit(5);
+ _exit(0);
+ }
+
+ ASSERT_EQ(reap_child_exit_code(pid), 0);
+ close(cfd);
+}
+
+TEST_F(rootns, pivot_root) {
+ unsigned int flags = (ROOTNS_ALL_NAMESPACES & ~ROOTNS_USER) |
+ ROOTNS_KILL_ON_CLOSE | ROOTNS_CLOSE_ON_EXEC;
+ int cfd;
+ pid_t pid;
+
+ cfd = create_test_rootns(false, flags);
+ ASSERT_GE(cfd, 0);
+
+ pid = clone_into_rootns(cfd, 0);
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ int fsfd;
+ int mfd;
+ int nsfd;
+
+ close(cfd);
+ fsfd = sys_fsopen("tmpfs", 0);
+ if (fsfd < 0)
+ _exit(1);
+ if (sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) < 0)
+ _exit(2);
+ mfd = sys_fsmount(fsfd, 0, 0);
+ close(fsfd);
+ if (mfd < 0)
+ _exit(3);
+ if (mkdirat(mfd, "old", 0755) < 0)
+ _exit(4);
+ if (sys_move_mount(mfd, "", AT_FDCWD, "/mnt",
+ MOVE_MOUNT_F_EMPTY_PATH) < 0)
+ _exit(5);
+ close(mfd);
+
+ if (chdir("/mnt") < 0)
+ _exit(6);
+ if (sys_pivot_root(".", "old") < 0)
+ _exit(7);
+
+ nsfd = sys_open_tree(AT_FDCWD, "/",
+ OPEN_TREE_NAMESPACE | OPEN_TREE_CLOEXEC);
+ if (nsfd < 0)
+ _exit(8);
+ if (setns(nsfd, CLONE_NEWNS) < 0)
+ _exit(9);
+ close(nsfd);
+ _exit(0);
+ }
+
+ ASSERT_EQ(reap_child_exit_code(pid), 0);
+ close(cfd);
+}
+
+TEST_F(rootns, kill_on_close) {
+ int status;
+ pid_t pid;
+ int cfd;
+ int ret;
+
+ cfd = create_test_rootns(false, ROOTNS_ALL_NAMESPACES | ROOTNS_KILL_ON_CLOSE);
+ ASSERT_GE(cfd, 0);
+
+ pid = clone_into_rootns(cfd, 0);
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ close(cfd);
+ for (;;)
+ pause();
+ }
+
+ close(cfd);
+
+ ret = wait_for_pid_exit(pid, &status, 5000);
+ if (ret < 0) {
+ kill_and_reap_pid(pid);
+ ASSERT_EQ(ret, 0);
+ }
+ ASSERT_TRUE(WIFSIGNALED(status));
+ ASSERT_EQ(WTERMSIG(status), SIGKILL);
+}
+
+static int enter_unpriv_user_mntns(uid_t drop_uid)
+{
+ char map[32];
+ uid_t uid;
+ gid_t gid;
+ int fd;
+ int len;
+
+ if (geteuid() == 0 &&
+ (setresgid(drop_uid, drop_uid, drop_uid) < 0 ||
+ setresuid(drop_uid, drop_uid, drop_uid) < 0))
+ return -errno;
+
+ uid = geteuid();
+ gid = getegid();
+ if (unshare(CLONE_NEWUSER | CLONE_NEWNS) < 0)
+ return -errno;
+
+ fd = open("/proc/self/setgroups", O_WRONLY | O_CLOEXEC);
+ if (fd >= 0) {
+ (void)write(fd, "deny\n", 5);
+ close(fd);
+ }
+
+ fd = open("/proc/self/uid_map", O_WRONLY | O_CLOEXEC);
+ if (fd < 0)
+ return -errno;
+ len = snprintf(map, sizeof(map), "0 %u 1\n", (unsigned int)uid);
+ if (write(fd, map, (size_t)len) != len) {
+ close(fd);
+ return -EIO;
+ }
+ close(fd);
+
+ fd = open("/proc/self/gid_map", O_WRONLY | O_CLOEXEC);
+ if (fd < 0)
+ return -errno;
+ len = snprintf(map, sizeof(map), "0 %u 1\n", (unsigned int)gid);
+ if (write(fd, map, (size_t)len) != len) {
+ close(fd);
+ return -EIO;
+ }
+ close(fd);
+
+ return 0;
+}
+
+TEST_F(rootns, mount_perms) {
+ int cfd = -1;
+ int rootfsfd;
+ pid_t pid;
+ int mfd;
+ int ret;
+
+ ret = create_rootns_as_uid(1000, ROOTNS_ALL_NAMESPACES | ROOTNS_USER,
+ &cfd);
+ if (ret == -EPERM || ret == -EACCES || ret == -EINVAL)
+ SKIP(return, "unprivileged ROOTNS_USER creation is unavailable");
+ ASSERT_EQ(ret, 0);
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ int u_fsfd;
+ int u_mfd;
+
+ ret = enter_unpriv_user_mntns(2000);
+ if (ret == -EPERM || ret == -EACCES || ret == -EINVAL ||
+ ret == -ENOSPC)
+ _exit(0);
+ if (ret < 0)
+ _exit(1);
+
+ u_fsfd = sys_fsopen("tmpfs", 0);
+ if (u_fsfd < 0)
+ _exit(2);
+ if (sys_fsconfig(u_fsfd, FSCONFIG_SET_ROOTNS, NULL, NULL,
+ cfd) != -1 || errno != EPERM)
+ _exit(3);
+ if (sys_fsconfig(u_fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) < 0)
+ _exit(4);
+
+ u_mfd = sys_fsmount(u_fsfd, 0, 0);
+ if (u_mfd < 0)
+ _exit(5);
+ if (sys_move_mount(u_mfd, "", cfd, "/",
+ MOVE_MOUNT_F_EMPTY_PATH |
+ MOVE_MOUNT_T_ROOTNS_ROOT) != -1 ||
+ errno != EPERM)
+ _exit(6);
+
+ close(u_mfd);
+ close(u_fsfd);
+ close(cfd);
+ _exit(0);
+ }
+ ASSERT_EQ(reap_child_exit_code(pid), 0);
+
+ if (geteuid() == 0) {
+ rootfsfd = sys_fsopen("tmpfs", 0);
+ ASSERT_GE(rootfsfd, 0);
+ ASSERT_EQ(sys_fsconfig(rootfsfd, FSCONFIG_SET_ROOTNS, NULL,
+ NULL, cfd), 0);
+ ASSERT_EQ(sys_fsconfig(rootfsfd, FSCONFIG_CMD_CREATE, NULL,
+ NULL, 0), 0);
+ mfd = sys_fsmount(rootfsfd, 0, 0);
+ ASSERT_GE(mfd, 0);
+ close(rootfsfd);
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ if (setresgid(1000, 1000, 1000) < 0 ||
+ setresuid(1000, 1000, 1000) < 0)
+ _exit(1);
+ if (sys_move_mount(mfd, "", cfd, "/",
+ MOVE_MOUNT_F_EMPTY_PATH |
+ MOVE_MOUNT_T_ROOTNS_ROOT) < 0)
+ _exit(2);
+ close(mfd);
+ close(cfd);
+ _exit(0);
+ }
+ close(mfd);
+ ASSERT_EQ(reap_child_exit_code(pid), 0);
+ }
+
+ close(cfd);
+}
+
+TEST_F(rootns, mount_attached) {
+ int cfd;
+
+ cfd = sys_rootns_create(ROOTNS_ALL_NAMESPACES |
+ ROOTNS_KILL_ON_CLOSE |
+ ROOTNS_CLOSE_ON_EXEC);
+ ASSERT_GE(cfd, 0);
+
+ ASSERT_EQ(sys_move_mount(AT_FDCWD, "/", cfd, "/",
+ MOVE_MOUNT_T_ROOTNS_ROOT), -1);
+ ASSERT_EQ(errno, EINVAL);
+
+ close(cfd);
+}
+
+TEST_F(rootns, mount_empty_path) {
+ int cfd;
+ int mfd;
+
+ cfd = sys_rootns_create(ROOTNS_ALL_NAMESPACES |
+ ROOTNS_KILL_ON_CLOSE |
+ ROOTNS_CLOSE_ON_EXEC);
+ ASSERT_GE(cfd, 0);
+
+ mfd = sys_open_tree(AT_FDCWD, "/", OPEN_TREE_CLONE);
+ ASSERT_GE(mfd, 0);
+
+ ASSERT_EQ(sys_move_mount(mfd, "", cfd, "",
+ MOVE_MOUNT_F_EMPTY_PATH |
+ MOVE_MOUNT_T_ROOTNS_ROOT), -1);
+ ASSERT_EQ(errno, EINVAL);
+
+ close(mfd);
+ close(cfd);
+}
+
+TEST_F(rootns, clone_perms) {
+ pid_t pid;
+ int cfd;
+
+ cfd = sys_rootns_create(ROOTNS_ALL_NAMESPACES |
+ ROOTNS_KILL_ON_CLOSE |
+ ROOTNS_CLOSE_ON_EXEC);
+ ASSERT_GE(cfd, 0);
+
+ ASSERT_EQ(clone_into_rootns(cfd, 0), -1);
+ ASSERT_EQ(errno, ENOENT);
+
+ ASSERT_EQ(mount_root(cfd), 0);
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ int ret = enter_unpriv_user_mntns(2000);
+
+ if (ret == -EPERM || ret == -EACCES || ret == -EINVAL ||
+ ret == -ENOSPC) {
+ close(cfd);
+ _exit(0);
+ }
+ if (ret < 0)
+ _exit(1);
+ if (clone_into_rootns(cfd, 0) != -1 || errno != EPERM)
+ _exit(2);
+ close(cfd);
+ _exit(0);
+ }
+ ASSERT_EQ(reap_child_exit_code(pid), 0);
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ pid_t ent_pid;
+
+ if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0)
+ _exit(1);
+ ent_pid = clone_into_rootns(cfd, 0);
+ if (ent_pid < 0)
+ _exit(2);
+ if (ent_pid == 0) {
+ close(cfd);
+ if (getpid() != 1)
+ _exit(3);
+ if (prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0) != 1)
+ _exit(4);
+ _exit(0);
+ }
+ close(cfd);
+ _exit(reap_child_exit_code(ent_pid) == 0 ? 0 : 5);
+ }
+ ASSERT_EQ(reap_child_exit_code(pid), 0);
+
+ close(cfd);
+}
+
+TEST_F(rootns, clone_flags) {
+ static const __u64 bad_flags[] = {
+ CLONE_NEWNS,
+ CLONE_NEWPID,
+ CLONE_NEWUSER,
+ CLONE_EMPTY_MNTNS,
+ CLONE_FS,
+ CLONE_THREAD | CLONE_SIGHAND | CLONE_VM,
+ CLONE_PARENT,
+ CLONE_SYSVSEM,
+ CLONE_VM,
+ };
+ struct clone_args args;
+ int pipefd[2];
+ int pidfd = -1;
+ int bad_fd;
+ pid_t pid;
+ size_t i;
+ int cfd;
+
+ memset(&args, 0, sizeof(args));
+ args.flags = CLONE_INTO_ROOTNS;
+ args.exit_signal = SIGCHLD;
+ args.rootns = (__u64)self->cfd;
+ ASSERT_EQ(sys_clone3(&args, CLONE_ARGS_SIZE_VER2), -1);
+ ASSERT_EQ(errno, EINVAL);
+
+ args.rootns = (__u64)-1;
+ ASSERT_EQ(sys_clone3(&args, sizeof(args)), -1);
+ ASSERT_EQ(errno, EINVAL);
+
+ ASSERT_EQ(pipe2(pipefd, O_CLOEXEC), 0);
+ ASSERT_EQ(clone_into_rootns(pipefd[0], 0), -1);
+ ASSERT_EQ(errno, EINVAL);
+ bad_fd = pipefd[0];
+ close(pipefd[0]);
+ close(pipefd[1]);
+
+ ASSERT_EQ(clone_into_rootns(bad_fd, 0), -1);
+ ASSERT_EQ(errno, EBADF);
+
+ for (i = 0; i < ARRAY_SIZE(bad_flags); i++) {
+ memset(&args, 0, sizeof(args));
+ args.flags = CLONE_INTO_ROOTNS | bad_flags[i];
+ args.rootns = (__u64)self->cfd;
+ if (!(bad_flags[i] & (CLONE_THREAD | CLONE_PARENT)))
+ args.exit_signal = SIGCHLD;
+ ASSERT_EQ(sys_clone3(&args, sizeof(args)), -1);
+ ASSERT_EQ(errno, EINVAL);
+ }
+
+ cfd = sys_rootns_create(ROOTNS_ALL_NAMESPACES |
+ ROOTNS_KILL_ON_CLOSE |
+ ROOTNS_CLOSE_ON_EXEC);
+ ASSERT_GE(cfd, 0);
+ ASSERT_EQ(clone_into_rootns(cfd, CLONE_VM | CLONE_VFORK), -1);
+ ASSERT_EQ(errno, ENOENT);
+ close(cfd);
+
+ memset(&args, 0, sizeof(args));
+ args.flags = CLONE_INTO_ROOTNS | CLONE_VFORK | CLONE_PIDFD |
+ CLONE_CLEAR_SIGHAND | CLONE_NNP;
+ args.pidfd = (__u64)(uintptr_t)&pidfd;
+ args.exit_signal = SIGCHLD;
+ args.rootns = (__u64)self->cfd;
+ pid = sys_clone3(&args, sizeof(args));
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ close(self->cfd);
+ if (getpid() != 1)
+ _exit(1);
+ if (prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0) != 1)
+ _exit(2);
+ _exit(0);
+ }
+ ASSERT_GE(pidfd, 0);
+ close(pidfd);
+ ASSERT_EQ(reap_child_exit_code(pid), 0);
+}
+
+TEST_F(rootns, fsconfig) {
+ pid_t pid;
+ int fsfd;
+ int cfd;
+
+ cfd = sys_rootns_create(ROOTNS_ALL_NAMESPACES |
+ ROOTNS_KILL_ON_CLOSE |
+ ROOTNS_CLOSE_ON_EXEC);
+ ASSERT_GE(cfd, 0);
+
+ fsfd = sys_fsopen("tmpfs", 0);
+ ASSERT_GE(fsfd, 0);
+ ASSERT_EQ(sys_fsconfig(fsfd, FSCONFIG_SET_ROOTNS, NULL, NULL, cfd), 0);
+ ASSERT_EQ(sys_fsconfig(fsfd, FSCONFIG_SET_ROOTNS, NULL, NULL, cfd), -1);
+ ASSERT_EQ(errno, EBUSY);
+ close(fsfd);
+ close(cfd);
+
+ pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ int ucfd;
+ int ret;
+ int sfd;
+
+ ret = enter_unpriv_user_mntns(1000);
+ if (ret == -EPERM || ret == -EACCES || ret == -EINVAL ||
+ ret == -ENOSPC)
+ _exit(0);
+ if (ret < 0)
+ _exit(1);
+
+ ucfd = sys_rootns_create(ROOTNS_USER | ROOTNS_CLOSE_ON_EXEC);
+ if (ucfd < 0) {
+ if (errno == EPERM || errno == EACCES ||
+ errno == EINVAL || errno == ENOSPC)
+ _exit(0);
+ _exit(2);
+ }
+
+ sfd = sys_fsopen("sysfs", 0);
+ if (sfd < 0) {
+ if (errno == ENODEV) {
+ close(ucfd);
+ _exit(0);
+ }
+ _exit(3);
+ }
+
+ if (sys_fsconfig(sfd, FSCONFIG_SET_ROOTNS, NULL, NULL, ucfd) < 0)
+ _exit(4);
+ if (sys_fsconfig(sfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) != -1 ||
+ errno != EPERM)
+ _exit(5);
+
+ close(sfd);
+ close(ucfd);
+ _exit(0);
+ }
+
+ ASSERT_EQ(reap_child_exit_code(pid), 0);
+}
+
+TEST_F(rootns, clone_concurrent) {
+ unsigned int seen_mask = 0;
+ int start_pipe[2];
+ int ready_pipe[2];
+ int hold_pipe[2];
+ pid_t workers[4];
+ int status = 0;
+ int i;
+
+ ASSERT_EQ(pipe2(start_pipe, O_CLOEXEC), 0);
+ ASSERT_EQ(pipe2(ready_pipe, O_CLOEXEC), 0);
+ ASSERT_EQ(pipe2(hold_pipe, O_CLOEXEC), 0);
+
+ for (i = 0; i < 4; i++) {
+ workers[i] = fork();
+ ASSERT_GE(workers[i], 0);
+ if (workers[i] == 0) {
+ pid_t ent_pid;
+ char ch;
+
+ close(start_pipe[1]);
+ close(ready_pipe[0]);
+ close(hold_pipe[1]);
+
+ (void)read(start_pipe[0], &ch, 1);
+ close(start_pipe[0]);
+
+ ent_pid = clone_into_rootns(self->cfd, 0);
+ if (ent_pid < 0)
+ _exit(1);
+ if (ent_pid == 0) {
+ unsigned char my_pid = (unsigned char)getpid();
+
+ if (write(ready_pipe[1], &my_pid, 1) != 1)
+ _exit(2);
+ close(ready_pipe[1]);
+ (void)read(hold_pipe[0], &ch, 1);
+ close(hold_pipe[0]);
+ _exit(0);
+ }
+
+ close(ready_pipe[1]);
+ close(hold_pipe[0]);
+ close(self->cfd);
+ _exit(reap_child_exit_code(ent_pid) == 0 ? 0 : 3);
+ }
+ }
+
+ close(start_pipe[0]);
+ close(ready_pipe[1]);
+ close(hold_pipe[0]);
+ close(start_pipe[1]);
+
+ for (i = 0; i < 4; i++) {
+ unsigned char pid_byte = 0;
+
+ ASSERT_EQ(read(ready_pipe[0], &pid_byte, 1), 1);
+ ASSERT_GE(pid_byte, 1);
+ ASSERT_LE(pid_byte, 4);
+ seen_mask |= 1U << pid_byte;
+ }
+ close(ready_pipe[0]);
+ close(hold_pipe[1]);
+
+ ASSERT_EQ(seen_mask, 0x1eU);
+
+ for (i = 0; i < 4; i++)
+ ASSERT_EQ(reap_child_exit_code(workers[i]), 0);
+
+ ASSERT_GT(sys_rootns_wait(self->cfd, &status, 0, NULL), 0);
+ ASSERT_TRUE(WIFEXITED(status));
+ ASSERT_EQ(WEXITSTATUS(status), 0);
+}
+
+TEST_HARNESS_MAIN
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [RFC PATCH v2 13/13] MAINTAINERS: Add entry for ROOT NAMESPACE
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
` (11 preceding siblings ...)
2026-11-17 23:13 ` [RFC PATCH v2 12/13] selftests/rootns: Add root namespace test suite Jarkko Sakkinen
@ 2026-11-17 23:13 ` Jarkko Sakkinen
2026-11-18 14:47 ` [RFC PATCH v2 00/13] Namespace for namespace roots Josef Bacik
2026-11-18 16:59 ` Andy Lutomirski
14 siblings, 0 replies; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17 23:13 UTC (permalink / raw)
To: linux-fsdevel
Cc: Jarkko Sakkinen, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
Record maintainership and mailing list routing for the root namespace
subsystem across its uAPI headers, core implementation, documentation,
and selftests.
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
MAINTAINERS | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 7cbce21ba45a..072be5ec7fd8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -24533,6 +24533,17 @@ F: include/linux/mfd/rohm-bd96802.h
F: include/linux/mfd/rohm-generic.h
F: include/linux/mfd/rohm-shared.h
+ROOT NAMESPACE
+M: David Howells <dhowells@redhat.com>
+M: Jarkko Sakkinen <jarkko@kernel.org>
+L: linux-fsdevel@vger.kernel.org
+S: Maintained
+F: Documentation/userspace-api/rootns.rst
+F: include/linux/rootns.h
+F: include/uapi/linux/rootns.h
+F: kernel/rootns.c
+F: tools/testing/selftests/rootns/
+
ROTATION DRIVER FOR ALLWINNER A83T
M: Jernej Skrabec <jernej.skrabec@gmail.com>
L: linux-media@vger.kernel.org
--
2.47.3
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 00/13] Namespace for namespace roots
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
` (12 preceding siblings ...)
2026-11-17 23:13 ` [RFC PATCH v2 13/13] MAINTAINERS: Add entry for ROOT NAMESPACE Jarkko Sakkinen
@ 2026-11-18 14:47 ` Josef Bacik
2026-11-18 15:28 ` Jarkko Sakkinen
2026-11-18 16:59 ` Andy Lutomirski
14 siblings, 1 reply; 36+ messages in thread
From: Josef Bacik @ 2026-11-18 14:47 UTC (permalink / raw)
To: Jarkko Sakkinen
Cc: linux-fsdevel, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki, alex
On Wed, Nov 18, 2026 at 01:13:39AM +0200, Jarkko Sakkinen wrote:
> OVERVIEW
> ========
>
> A root namespace (rootns) is a kernel object backed by a file descriptor
> that binds together:
>
> 1. A full or partial set of detached namespaces.
> 2. A dedicated PID namespace for spawning processes into, signaling
> members, and polling or waiting on PID 1 exit.
> 3. An initially empty mount namespace (CLONE_EMPTY_MNTNS) that must be
> populated before going live, without inheriting host mount-tree
> ancestors.
This is what cells is doing https://lwn.net/Articles/1102593/, you may
want to take a look at that work. Christian, Lennart, Alex, myself
and others are working towards this in a more wholistic way. There's a
lot more that goes into this outside of just the object itself. I've got
my version deployed inside Anthropic for securing containers and I've
tripped over a lot of pre-work that needs to come because we can tackle
this. Alex has my rough outline for kuid64 for example, which is
necessary for making sure we don't overlap UID's on the system and
create holes this way. The cells work/anything that wants to have clear
security boundaries is going to require that as a pre-requisite. If
you'd like I can include you in our planning so we can get something
that will solve all of our problems. Thanks,
Josef
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 00/13] Namespace for namespace roots
2026-11-18 14:47 ` [RFC PATCH v2 00/13] Namespace for namespace roots Josef Bacik
@ 2026-11-18 15:28 ` Jarkko Sakkinen
2026-11-18 15:39 ` Jarkko Sakkinen
0 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-18 15:28 UTC (permalink / raw)
To: Josef Bacik
Cc: linux-fsdevel, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki, alex
On Wed, Nov 18, 2026 at 02:47:34PM +0000, Josef Bacik wrote:
> On Wed, Nov 18, 2026 at 01:13:39AM +0200, Jarkko Sakkinen wrote:
> > OVERVIEW
> > ========
> >
> > A root namespace (rootns) is a kernel object backed by a file descriptor
> > that binds together:
> >
> > 1. A full or partial set of detached namespaces.
> > 2. A dedicated PID namespace for spawning processes into, signaling
> > members, and polling or waiting on PID 1 exit.
> > 3. An initially empty mount namespace (CLONE_EMPTY_MNTNS) that must be
> > populated before going live, without inheriting host mount-tree
> > ancestors.
>
> This is what cells is doing https://lwn.net/Articles/1102593/, you may
> want to take a look at that work. Christian, Lennart, Alex, myself
> and others are working towards this in a more wholistic way. There's a
> lot more that goes into this outside of just the object itself. I've got
> my version deployed inside Anthropic for securing containers and I've
> tripped over a lot of pre-work that needs to come because we can tackle
> this. Alex has my rough outline for kuid64 for example, which is
> necessary for making sure we don't overlap UID's on the system and
> create holes this way. The cells work/anything that wants to have clear
> security boundaries is going to require that as a pre-requisite. If
> you'd like I can include you in our planning so we can get something
> that will solve all of our problems. Thanks,
>
> Josef
No it's not doing the same, and this why I sent the patch set.
I don't see cells fighting with rootns and given that rootns has a small
surface and it leverages already battle-tested code, instead of
reinventing the wheel, it also has benefits. It neither doubles the
number of container frameworks in kernel.
What I'm not claiming is that this is better. I just wanted to fact
correct "this is what cells is doing". It is not true. It could be
better solution but still that statement is untrue.
Br, Jarkko
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 00/13] Namespace for namespace roots
2026-11-18 15:28 ` Jarkko Sakkinen
@ 2026-11-18 15:39 ` Jarkko Sakkinen
2026-11-18 15:46 ` Jarkko Sakkinen
0 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-18 15:39 UTC (permalink / raw)
To: Josef Bacik
Cc: linux-fsdevel, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki, alex
On Wed, Nov 18, 2026 at 05:28:10PM +0200, Jarkko Sakkinen wrote:
> On Wed, Nov 18, 2026 at 02:47:34PM +0000, Josef Bacik wrote:
> > On Wed, Nov 18, 2026 at 01:13:39AM +0200, Jarkko Sakkinen wrote:
> > > OVERVIEW
> > > ========
> > >
> > > A root namespace (rootns) is a kernel object backed by a file descriptor
> > > that binds together:
> > >
> > > 1. A full or partial set of detached namespaces.
> > > 2. A dedicated PID namespace for spawning processes into, signaling
> > > members, and polling or waiting on PID 1 exit.
> > > 3. An initially empty mount namespace (CLONE_EMPTY_MNTNS) that must be
> > > populated before going live, without inheriting host mount-tree
> > > ancestors.
> >
> > This is what cells is doing https://lwn.net/Articles/1102593/, you may
> > want to take a look at that work. Christian, Lennart, Alex, myself
> > and others are working towards this in a more wholistic way. There's a
> > lot more that goes into this outside of just the object itself. I've got
> > my version deployed inside Anthropic for securing containers and I've
> > tripped over a lot of pre-work that needs to come because we can tackle
> > this. Alex has my rough outline for kuid64 for example, which is
> > necessary for making sure we don't overlap UID's on the system and
> > create holes this way. The cells work/anything that wants to have clear
> > security boundaries is going to require that as a pre-requisite. If
> > you'd like I can include you in our planning so we can get something
> > that will solve all of our problems. Thanks,
> >
> > Josef
>
> No it's not doing the same, and this why I sent the patch set.
>
> I don't see cells fighting with rootns and given that rootns has a small
> surface and it leverages already battle-tested code, instead of
> reinventing the wheel, it also has benefits. It neither doubles the
> number of container frameworks in kernel.
>
> What I'm not claiming is that this is better. I just wanted to fact
> correct "this is what cells is doing". It is not true. It could be
> better solution but still that statement is untrue.
For better or worse, cells does a lot more; just looking at the patch set
size.
For rootns one can point out with a finger its possible problems BUT here's
the thing: it does not haven unknown unknowns. Even if cells had less
of known problems; we have zero idea what will come up if that ever
lands. The possible consequence have less predictability.
Also, as per integration, they actually are not fighting features, as
they are in different layers. There's no same thing at all.
Br, Jarkko
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 00/13] Namespace for namespace roots
2026-11-18 15:39 ` Jarkko Sakkinen
@ 2026-11-18 15:46 ` Jarkko Sakkinen
0 siblings, 0 replies; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-18 15:46 UTC (permalink / raw)
To: Josef Bacik
Cc: linux-fsdevel, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Andy Lutomirski, Ben Segall, Christian Brauner,
David Hildenbrand, David Howells, Davidlohr Bueso,
Dietmar Eggemann, Ingo Molnar, Jan Kara, Jonathan Corbet,
John Johansen, Juri Lelli, Kees Cook, K Prateek Nayak,
Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul, Mel Gorman,
Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki, alex
On Wed, Nov 18, 2026 at 05:39:47PM +0200, Jarkko Sakkinen wrote:
> On Wed, Nov 18, 2026 at 05:28:10PM +0200, Jarkko Sakkinen wrote:
> > On Wed, Nov 18, 2026 at 02:47:34PM +0000, Josef Bacik wrote:
> > > On Wed, Nov 18, 2026 at 01:13:39AM +0200, Jarkko Sakkinen wrote:
> > > > OVERVIEW
> > > > ========
> > > >
> > > > A root namespace (rootns) is a kernel object backed by a file descriptor
> > > > that binds together:
> > > >
> > > > 1. A full or partial set of detached namespaces.
> > > > 2. A dedicated PID namespace for spawning processes into, signaling
> > > > members, and polling or waiting on PID 1 exit.
> > > > 3. An initially empty mount namespace (CLONE_EMPTY_MNTNS) that must be
> > > > populated before going live, without inheriting host mount-tree
> > > > ancestors.
> > >
> > > This is what cells is doing https://lwn.net/Articles/1102593/, you may
> > > want to take a look at that work. Christian, Lennart, Alex, myself
> > > and others are working towards this in a more wholistic way. There's a
> > > lot more that goes into this outside of just the object itself. I've got
> > > my version deployed inside Anthropic for securing containers and I've
> > > tripped over a lot of pre-work that needs to come because we can tackle
> > > this. Alex has my rough outline for kuid64 for example, which is
> > > necessary for making sure we don't overlap UID's on the system and
> > > create holes this way. The cells work/anything that wants to have clear
> > > security boundaries is going to require that as a pre-requisite. If
> > > you'd like I can include you in our planning so we can get something
> > > that will solve all of our problems. Thanks,
> > >
> > > Josef
> >
> > No it's not doing the same, and this why I sent the patch set.
> >
> > I don't see cells fighting with rootns and given that rootns has a small
> > surface and it leverages already battle-tested code, instead of
> > reinventing the wheel, it also has benefits. It neither doubles the
> > number of container frameworks in kernel.
> >
> > What I'm not claiming is that this is better. I just wanted to fact
> > correct "this is what cells is doing". It is not true. It could be
> > better solution but still that statement is untrue.
>
> For better or worse, cells does a lot more; just looking at the patch set
> size.
>
> For rootns one can point out with a finger its possible problems BUT here's
> the thing: it does not haven unknown unknowns. Even if cells had less
> of known problems; we have zero idea what will come up if that ever
> lands. The possible consequence have less predictability.
>
> Also, as per integration, they actually are not fighting features, as
> they are in different layers. There's no same thing at all.
>
Yeah, and there is no obvious causality either that would result a
zero sum game. Rootns is something OCI runtime, any of them, can
quickly adapt to the existing framework. Cells takes longer, but
could be very worth of price. It's called "defense in depth".
Br, Jarkko
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 00/13] Namespace for namespace roots
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
` (13 preceding siblings ...)
2026-11-18 14:47 ` [RFC PATCH v2 00/13] Namespace for namespace roots Josef Bacik
@ 2026-11-18 16:59 ` Andy Lutomirski
2026-11-18 17:04 ` Jarkko Sakkinen
14 siblings, 1 reply; 36+ messages in thread
From: Andy Lutomirski @ 2026-11-18 16:59 UTC (permalink / raw)
To: Jarkko Sakkinen, josef
Cc: linux-fsdevel, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Ben Segall, Christian Brauner, David Hildenbrand,
David Howells, Davidlohr Bueso, Dietmar Eggemann, Ingo Molnar,
Jan Kara, Jonathan Corbet, John Johansen, Juri Lelli, Kees Cook,
K Prateek Nayak, Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul,
Mel Gorman, Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
On Tue, Nov 17, 2026 at 3:14 PM Jarkko Sakkinen <jarkko@kernel.org> wrote:
>
> OVERVIEW
> ========
>
> A root namespace (rootns) is a kernel object backed by a file descriptor
> that binds together:
>
> 1. A full or partial set of detached namespaces.
> 2. A dedicated PID namespace for spawning processes into, signaling
> members, and polling or waiting on PID 1 exit.
> 3. An initially empty mount namespace (CLONE_EMPTY_MNTNS) that must be
> populated before going live, without inheriting host mount-tree
> ancestors.
>
> Work on this feature started in 2025 from David Howells' container object
> patch set [1], which I turned into a namespace for namespace roots and
> rebuilt around that premise.
>
> While the patch set is manually written, the original motivation came
> from isolating LLM agents. Running untrusted agent workloads made it
> clear that OCI runtimes need to minimize their live configuration
> surface.
>
> Assembling mounts, credentials, and namespaces inside helper processes
> with a half-configured container is what I see as the main challenge,
> and the existential debate around namespaces and container objects is an
> unfocused discussion topic.
I've skimmed some of the series, and I see a bunch of good ideas that
involve using an fd to manage a thing. But I'm wondering how much of
the value is added by that and how much is added by having a new
*type* of thing: the "rootns".
How much of the value comes from the rootns vs the new APIs to
configure namespaces without entering them first?
For that matter, the cells series also seems to contain a (possibly
very similar) variant of the same thing.
Would it make sense to come up with a patchset that does *just* the
configure-a-namespace-by-fd part? It seems to me that this should be
an easier thing to agree on, and it's a big part of the complexity of
all of this, and it solves a real problem even without
cells/rootnses/jails/whatever.
--Andy
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 00/13] Namespace for namespace roots
2026-11-18 16:59 ` Andy Lutomirski
@ 2026-11-18 17:04 ` Jarkko Sakkinen
2026-11-18 17:08 ` Jarkko Sakkinen
0 siblings, 1 reply; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-18 17:04 UTC (permalink / raw)
To: Andy Lutomirski
Cc: josef, linux-fsdevel, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Ben Segall, Christian Brauner, David Hildenbrand,
David Howells, Davidlohr Bueso, Dietmar Eggemann, Ingo Molnar,
Jan Kara, Jonathan Corbet, John Johansen, Juri Lelli, Kees Cook,
K Prateek Nayak, Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul,
Mel Gorman, Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
On Wed, Nov 18, 2026 at 08:59:39AM -0800, Andy Lutomirski wrote:
> On Tue, Nov 17, 2026 at 3:14 PM Jarkko Sakkinen <jarkko@kernel.org> wrote:
> >
> > OVERVIEW
> > ========
> >
> > A root namespace (rootns) is a kernel object backed by a file descriptor
> > that binds together:
> >
> > 1. A full or partial set of detached namespaces.
> > 2. A dedicated PID namespace for spawning processes into, signaling
> > members, and polling or waiting on PID 1 exit.
> > 3. An initially empty mount namespace (CLONE_EMPTY_MNTNS) that must be
> > populated before going live, without inheriting host mount-tree
> > ancestors.
> >
> > Work on this feature started in 2025 from David Howells' container object
> > patch set [1], which I turned into a namespace for namespace roots and
> > rebuilt around that premise.
> >
> > While the patch set is manually written, the original motivation came
> > from isolating LLM agents. Running untrusted agent workloads made it
> > clear that OCI runtimes need to minimize their live configuration
> > surface.
> >
> > Assembling mounts, credentials, and namespaces inside helper processes
> > with a half-configured container is what I see as the main challenge,
> > and the existential debate around namespaces and container objects is an
> > unfocused discussion topic.
>
>
> I've skimmed some of the series, and I see a bunch of good ideas that
> involve using an fd to manage a thing. But I'm wondering how much of
> the value is added by that and how much is added by having a new
> *type* of thing: the "rootns".
>
> How much of the value comes from the rootns vs the new APIs to
> configure namespaces without entering them first?
>
> For that matter, the cells series also seems to contain a (possibly
> very similar) variant of the same thing.
>
> Would it make sense to come up with a patchset that does *just* the
> configure-a-namespace-by-fd part? It seems to me that this should be
> an easier thing to agree on, and it's a big part of the complexity of
> all of this, and it solves a real problem even without
> cells/rootnses/jails/whatever.
Is it more accurately scope the part that is "just the fd-part" and
what you consider as "extra cruft"?
I.e., where do you draw the border?
>
> --Andy
Br, Jarkko
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 00/13] Namespace for namespace roots
2026-11-18 17:04 ` Jarkko Sakkinen
@ 2026-11-18 17:08 ` Jarkko Sakkinen
2026-11-18 17:30 ` Jarkko Sakkinen
2026-11-18 17:46 ` Andy Lutomirski
0 siblings, 2 replies; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-18 17:08 UTC (permalink / raw)
To: Andy Lutomirski
Cc: josef, linux-fsdevel, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Ben Segall, Christian Brauner, David Hildenbrand,
David Howells, Davidlohr Bueso, Dietmar Eggemann, Ingo Molnar,
Jan Kara, Jonathan Corbet, John Johansen, Juri Lelli, Kees Cook,
K Prateek Nayak, Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul,
Mel Gorman, Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
On Wed, Nov 18, 2026 at 07:04:21PM +0200, Jarkko Sakkinen wrote:
> On Wed, Nov 18, 2026 at 08:59:39AM -0800, Andy Lutomirski wrote:
> > On Tue, Nov 17, 2026 at 3:14 PM Jarkko Sakkinen <jarkko@kernel.org> wrote:
> > >
> > > OVERVIEW
> > > ========
> > >
> > > A root namespace (rootns) is a kernel object backed by a file descriptor
> > > that binds together:
> > >
> > > 1. A full or partial set of detached namespaces.
> > > 2. A dedicated PID namespace for spawning processes into, signaling
> > > members, and polling or waiting on PID 1 exit.
> > > 3. An initially empty mount namespace (CLONE_EMPTY_MNTNS) that must be
> > > populated before going live, without inheriting host mount-tree
> > > ancestors.
> > >
> > > Work on this feature started in 2025 from David Howells' container object
> > > patch set [1], which I turned into a namespace for namespace roots and
> > > rebuilt around that premise.
> > >
> > > While the patch set is manually written, the original motivation came
> > > from isolating LLM agents. Running untrusted agent workloads made it
> > > clear that OCI runtimes need to minimize their live configuration
> > > surface.
> > >
> > > Assembling mounts, credentials, and namespaces inside helper processes
> > > with a half-configured container is what I see as the main challenge,
> > > and the existential debate around namespaces and container objects is an
> > > unfocused discussion topic.
> >
> >
> > I've skimmed some of the series, and I see a bunch of good ideas that
> > involve using an fd to manage a thing. But I'm wondering how much of
> > the value is added by that and how much is added by having a new
> > *type* of thing: the "rootns".
> >
> > How much of the value comes from the rootns vs the new APIs to
> > configure namespaces without entering them first?
> >
> > For that matter, the cells series also seems to contain a (possibly
> > very similar) variant of the same thing.
> >
> > Would it make sense to come up with a patchset that does *just* the
> > configure-a-namespace-by-fd part? It seems to me that this should be
> > an easier thing to agree on, and it's a big part of the complexity of
> > all of this, and it solves a real problem even without
> > cells/rootnses/jails/whatever.
>
> Is it more accurately scope the part that is "just the fd-part" and
> what you consider as "extra cruft"?
>
> I.e., where do you draw the border?
I'm asking this because I had similar thoughts when I started this back
in 2025. David had some good ideas but it did more than having a fd
that does not go live before everything is set up properly.
Then I thought that, I guess people who proactively on the topic do
something more lean and compact, and never sent roonts patches.
I'm not seeing anything more lean and compact.
>
> >
> > --Andy
>
> Br, Jarkko
Br, Jarkko
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 00/13] Namespace for namespace roots
2026-11-18 17:08 ` Jarkko Sakkinen
@ 2026-11-18 17:30 ` Jarkko Sakkinen
2026-11-18 17:46 ` Andy Lutomirski
1 sibling, 0 replies; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-18 17:30 UTC (permalink / raw)
To: Andy Lutomirski
Cc: josef, linux-fsdevel, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Ben Segall, Christian Brauner, David Hildenbrand,
David Howells, Davidlohr Bueso, Dietmar Eggemann, Ingo Molnar,
Jan Kara, Jonathan Corbet, John Johansen, Juri Lelli, Kees Cook,
K Prateek Nayak, Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul,
Mel Gorman, Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
On Wed, Nov 18, 2026 at 07:08:36PM +0200, Jarkko Sakkinen wrote:
> On Wed, Nov 18, 2026 at 07:04:21PM +0200, Jarkko Sakkinen wrote:
> > On Wed, Nov 18, 2026 at 08:59:39AM -0800, Andy Lutomirski wrote:
> > > On Tue, Nov 17, 2026 at 3:14 PM Jarkko Sakkinen <jarkko@kernel.org> wrote:
> > > Would it make sense to come up with a patchset that does *just* the
> > > configure-a-namespace-by-fd part? It seems to me that this should be
> > > an easier thing to agree on, and it's a big part of the complexity of
> > > all of this, and it solves a real problem even without
> > > cells/rootnses/jails/whatever.
> >
> > Is it more accurately scope the part that is "just the fd-part" and
> > what you consider as "extra cruft"?
> >
> > I.e., where do you draw the border?
>
> I'm asking this because I had similar thoughts when I started this back
> in 2025. David had some good ideas but it did more than having a fd
> that does not go live before everything is set up properly.
>
> Then I thought that, I guess people who proactively on the topic do
> something more lean and compact, and never sent roonts patches.
> I'm not seeing anything more lean and compact.
What if "A full or partial set of detached namespaces" would be changed
into "full set of detached namespaces"?
That would simplify the patch set a lot.
By pratical means we would take this:
enum rootns_flags {
ROOTNS_CGROUP = 0x00000001,
ROOTNS_UTS = 0x00000002,
ROOTNS_IPC = 0x00000004,
ROOTNS_USER = 0x00000008,
ROOTNS_NET = 0x00000010,
ROOTNS_KILL_ON_CLOSE = 0x00000100,
ROOTNS_CLOSE_ON_EXEC = 0x00000200,
ROOTNS_ALL_NAMESPACES = 0x0000001f,
ROOTNS_ALL_FLAGS = 0x0000031f,
};
And outcome would be:
enum rootns_flags {
ROOTNS_KILL_ON_CLOSE = 0x00000001,
ROOTNS_CLOSE_ON_EXEC = 0x00000002,
ROOTNS_ALL_FLAGS = 0x00000003,
};
If I was using this I would at any time just take em all. "Partial" is
just something that I've been just carrying since probably David's
original patches i.e., it simply has not been considered that much.
Br, Jarkko
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 00/13] Namespace for namespace roots
2026-11-18 17:08 ` Jarkko Sakkinen
2026-11-18 17:30 ` Jarkko Sakkinen
@ 2026-11-18 17:46 ` Andy Lutomirski
2026-11-18 18:23 ` Jarkko Sakkinen
1 sibling, 1 reply; 36+ messages in thread
From: Andy Lutomirski @ 2026-11-18 17:46 UTC (permalink / raw)
To: Jarkko Sakkinen
Cc: josef, linux-fsdevel, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Ben Segall, Christian Brauner, David Hildenbrand,
David Howells, Davidlohr Bueso, Dietmar Eggemann, Ingo Molnar,
Jan Kara, Jonathan Corbet, John Johansen, Juri Lelli, Kees Cook,
K Prateek Nayak, Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul,
Mel Gorman, Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
On Wed, Nov 18, 2026 at 9:08 AM Jarkko Sakkinen <jarkko@kernel.org> wrote:
>
> On Wed, Nov 18, 2026 at 07:04:21PM +0200, Jarkko Sakkinen wrote:
> > On Wed, Nov 18, 2026 at 08:59:39AM -0800, Andy Lutomirski wrote:
> > > On Tue, Nov 17, 2026 at 3:14 PM Jarkko Sakkinen <jarkko@kernel.org> wrote:
> > > >
> > > > OVERVIEW
> > > > ========
> > > >
> > > > A root namespace (rootns) is a kernel object backed by a file descriptor
> > > > that binds together:
> > > >
> > > > 1. A full or partial set of detached namespaces.
> > > > 2. A dedicated PID namespace for spawning processes into, signaling
> > > > members, and polling or waiting on PID 1 exit.
> > > > 3. An initially empty mount namespace (CLONE_EMPTY_MNTNS) that must be
> > > > populated before going live, without inheriting host mount-tree
> > > > ancestors.
> > > >
> > > > Work on this feature started in 2025 from David Howells' container object
> > > > patch set [1], which I turned into a namespace for namespace roots and
> > > > rebuilt around that premise.
> > > >
> > > > While the patch set is manually written, the original motivation came
> > > > from isolating LLM agents. Running untrusted agent workloads made it
> > > > clear that OCI runtimes need to minimize their live configuration
> > > > surface.
> > > >
> > > > Assembling mounts, credentials, and namespaces inside helper processes
> > > > with a half-configured container is what I see as the main challenge,
> > > > and the existential debate around namespaces and container objects is an
> > > > unfocused discussion topic.
> > >
> > >
> > > I've skimmed some of the series, and I see a bunch of good ideas that
> > > involve using an fd to manage a thing. But I'm wondering how much of
> > > the value is added by that and how much is added by having a new
> > > *type* of thing: the "rootns".
> > >
> > > How much of the value comes from the rootns vs the new APIs to
> > > configure namespaces without entering them first?
> > >
> > > For that matter, the cells series also seems to contain a (possibly
> > > very similar) variant of the same thing.
> > >
> > > Would it make sense to come up with a patchset that does *just* the
> > > configure-a-namespace-by-fd part? It seems to me that this should be
> > > an easier thing to agree on, and it's a big part of the complexity of
> > > all of this, and it solves a real problem even without
> > > cells/rootnses/jails/whatever.
> >
> > Is it more accurately scope the part that is "just the fd-part" and
> > what you consider as "extra cruft"?
I'm not actually trying to say that anything is "extra cruft". What I
mean is: there seems to be somewhat of a core that is pretty similar
between the two patchsets, and that core seems independently useful.
> >
> > I.e., where do you draw the border?
>
> I'm asking this because I had similar thoughts when I started this back
> in 2025. David had some good ideas but it did more than having a fd
> that does not go live before everything is set up properly.
I don't know that I have a very clear border, but here's an example:
rootns has MOVE_MOUNT_T_ROOTNS_ROOT.
cells has:
+What else goes into the tree is mounted on it before it becomes a
mount namespace. A
+filesystem for the cell to write to is mapped in the same way:
+
+.. code-block:: c
+
+ fs = fsopen("tmpfs", 0);
+ fsconfig(fs, FSCONFIG_SET_STRING, "mode", "1777", 0);
+ fsconfig(fs, FSCONFIG_CMD_CREATE, NULL, NULL, 0);
+ mnt = fsmount(fs, 0, MOUNT_ATTR_NOSUID | MOUNT_ATTR_NODEV);
+ mount_setattr(mnt, "", AT_EMPTY_PATH, &attr, sizeof(attr));
+ move_mount(mnt, "", tree, "tmp", MOVE_MOUNT_F_EMPTY_PATH);
(Source: https://lore.kernel.org/all/20261105-b4-cells-v3-2-bc9095937a84@toxicpanda.com/)
I feel like you are both *so close* to something that would stand
alone and make perfect sense. I also feel like, if that's a goal,
then both series are slightly off from the bulls-eye. (Keep in mind
that I've spend a total of about ten minutes looking at the relevant
parts of the series.)
If I've understood the two series correctly, and if I'm thinking of
these abilities as something that can stand alone, then I see the
following things that I'd improve.
rootns: Why can't I use a *mountns* fd to so the configuration? Maybe
I'm misunderstanding something.
cells: The dance where I create an anonymous mountns, mount stuff into
it, and then attach it to the cell is cute. But I think the userns
interaction is wrong: you are making me assemble all the mounts in
*my* userns and then clone the entire tree into a fresh, non-anonymous
mountns bound to the current userns. And that clone operation is not
free and serves no actual practical purpose.
Why can't there be some variant of these where I can either create an
anonymous mount tree that is genuinely unbound from a userns or that
lives in *the target userns* or that *is already the final mountns*,
using just mount-related APIs? In pseudocode:
int mountns_control_fd = create_mountns(either userns-free or with a
userns_control_fd);
fsopen, move_mount, , open_tree, etc;
Finally:
cells: I find it *incredibly annoying* that one generally cannot put
new mounts into an existing container using most existing container
managers. I hit this on a surprisingly regular basis. You seem to be
baking this into the whole cells design. Why?
both of you: Can we please make it possible to do the parts of this
that oughtn't require privilege without privilege? If the cap_userns
thing ever lands, cap_userns & CAP_SYS_ADMIN ought to be more than
sufficient to permit creating fresh mounts even without creating a
userns as long as we don't do anything that affects privileges within
our own userns. Or let us create a userns, *not enter it*, and do all
the mounting without actually having CAP_SYS_ADMIN in the permitted
set.
--
Andy Lutomirski
AMA Capital Management, LLC
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 00/13] Namespace for namespace roots
2026-11-18 17:46 ` Andy Lutomirski
@ 2026-11-18 18:23 ` Jarkko Sakkinen
0 siblings, 0 replies; 36+ messages in thread
From: Jarkko Sakkinen @ 2026-11-18 18:23 UTC (permalink / raw)
To: Andy Lutomirski
Cc: josef, linux-fsdevel, linux-api, linux-doc, linux-kernel,
linux-kselftest, linux-mm, linux-security-module, Alexander Viro,
Andrew Morton, Ben Segall, Christian Brauner, David Hildenbrand,
David Howells, Davidlohr Bueso, Dietmar Eggemann, Ingo Molnar,
Jan Kara, Jonathan Corbet, John Johansen, Juri Lelli, Kees Cook,
K Prateek Nayak, Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul,
Mel Gorman, Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
On Wed, Nov 18, 2026 at 09:46:02AM -0800, Andy Lutomirski wrote:
> On Wed, Nov 18, 2026 at 9:08 AM Jarkko Sakkinen <jarkko@kernel.org> wrote:
> >
> > On Wed, Nov 18, 2026 at 07:04:21PM +0200, Jarkko Sakkinen wrote:
> > > On Wed, Nov 18, 2026 at 08:59:39AM -0800, Andy Lutomirski wrote:
> > > > On Tue, Nov 17, 2026 at 3:14 PM Jarkko Sakkinen <jarkko@kernel.org> wrote:
> > > > >
> > > > > OVERVIEW
> > > > > ========
> > > > >
> > > > > A root namespace (rootns) is a kernel object backed by a file descriptor
> > > > > that binds together:
> > > > >
> > > > > 1. A full or partial set of detached namespaces.
> > > > > 2. A dedicated PID namespace for spawning processes into, signaling
> > > > > members, and polling or waiting on PID 1 exit.
> > > > > 3. An initially empty mount namespace (CLONE_EMPTY_MNTNS) that must be
> > > > > populated before going live, without inheriting host mount-tree
> > > > > ancestors.
> > > > >
> > > > > Work on this feature started in 2025 from David Howells' container object
> > > > > patch set [1], which I turned into a namespace for namespace roots and
> > > > > rebuilt around that premise.
> > > > >
> > > > > While the patch set is manually written, the original motivation came
> > > > > from isolating LLM agents. Running untrusted agent workloads made it
> > > > > clear that OCI runtimes need to minimize their live configuration
> > > > > surface.
> > > > >
> > > > > Assembling mounts, credentials, and namespaces inside helper processes
> > > > > with a half-configured container is what I see as the main challenge,
> > > > > and the existential debate around namespaces and container objects is an
> > > > > unfocused discussion topic.
> > > >
> > > >
> > > > I've skimmed some of the series, and I see a bunch of good ideas that
> > > > involve using an fd to manage a thing. But I'm wondering how much of
> > > > the value is added by that and how much is added by having a new
> > > > *type* of thing: the "rootns".
> > > >
> > > > How much of the value comes from the rootns vs the new APIs to
> > > > configure namespaces without entering them first?
> > > >
> > > > For that matter, the cells series also seems to contain a (possibly
> > > > very similar) variant of the same thing.
> > > >
> > > > Would it make sense to come up with a patchset that does *just* the
> > > > configure-a-namespace-by-fd part? It seems to me that this should be
> > > > an easier thing to agree on, and it's a big part of the complexity of
> > > > all of this, and it solves a real problem even without
> > > > cells/rootnses/jails/whatever.
> > >
> > > Is it more accurately scope the part that is "just the fd-part" and
> > > what you consider as "extra cruft"?
>
> I'm not actually trying to say that anything is "extra cruft". What I
> mean is: there seems to be somewhat of a core that is pretty similar
> between the two patchsets, and that core seems independently useful.
>
> > >
> > > I.e., where do you draw the border?
> >
> > I'm asking this because I had similar thoughts when I started this back
> > in 2025. David had some good ideas but it did more than having a fd
> > that does not go live before everything is set up properly.
>
> I don't know that I have a very clear border, but here's an example:
>
> rootns has MOVE_MOUNT_T_ROOTNS_ROOT.
>
> cells has:
>
> +What else goes into the tree is mounted on it before it becomes a
> mount namespace. A
> +filesystem for the cell to write to is mapped in the same way:
> +
> +.. code-block:: c
> +
> + fs = fsopen("tmpfs", 0);
> + fsconfig(fs, FSCONFIG_SET_STRING, "mode", "1777", 0);
> + fsconfig(fs, FSCONFIG_CMD_CREATE, NULL, NULL, 0);
> + mnt = fsmount(fs, 0, MOUNT_ATTR_NOSUID | MOUNT_ATTR_NODEV);
> + mount_setattr(mnt, "", AT_EMPTY_PATH, &attr, sizeof(attr));
> + move_mount(mnt, "", tree, "tmp", MOVE_MOUNT_F_EMPTY_PATH);
>
> (Source: https://lore.kernel.org/all/20261105-b4-cells-v3-2-bc9095937a84@toxicpanda.com/)
>
> I feel like you are both *so close* to something that would stand
> alone and make perfect sense. I also feel like, if that's a goal,
> then both series are slightly off from the bulls-eye. (Keep in mind
> that I've spend a total of about ten minutes looking at the relevant
> parts of the series.)
Thanks, there was still a lot of relevant feedback to address.
And who knows, perhaps there's a sweet spot intersection. I would not
mind that, as I only pursue for something simple and practical.
For the time being, I'll update this series simply because there's less
to change, and polish the implementation. That does not hurt even if
cells were the ultimate solution. Part of this series can still be
useful.
>
>
> --
> Andy Lutomirski
> AMA Capital Management, LLC
Br, Jarkko
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 01/13] nsproxy: Pass nsproxy to create_new_namespaces()
2026-11-17 23:13 ` [RFC PATCH v2 01/13] nsproxy: Pass nsproxy to create_new_namespaces() Jarkko Sakkinen
@ 2026-11-18 23:15 ` sashiko-bot
0 siblings, 0 replies; 36+ messages in thread
From: sashiko-bot @ 2026-11-18 23:15 UTC (permalink / raw)
Cc: linux-security-module
> create_new_namespaces() takes a struct task_struct pointer even though
> it only reads tsk->nsproxy, preventing callers outside kernel/nsproxy.c
> from constructing a child nsproxy without mutating a task.
>
> Expose create_new_namespaces() and pass the source struct nsproxy
> pointer directly so root namespace creation can allocate a detached
> namespace set from current->nsproxy.
>
> Co-developed-by: David Howells <dhowells@redhat.com>
> Signed-off-by: David Howells <dhowells@redhat.com>
> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117231352.3816603-1-jarkko@kernel.org?part=1
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 02/13] rootns: Add core infrastructure for root namespaces
2026-11-17 23:13 ` [RFC PATCH v2 02/13] rootns: Add core infrastructure for root namespaces Jarkko Sakkinen
@ 2026-11-18 23:15 ` sashiko-bot
0 siblings, 0 replies; 36+ messages in thread
From: sashiko-bot @ 2026-11-18 23:15 UTC (permalink / raw)
Cc: linux-security-module
> Linux namespaces can be created and entered individually, but userspace
> orchestrators lack a single kernel object that binds a namespace set, a
> root mount, and an init process behind a pollable file descriptor.
>
> Add struct rootns, its lifecycle states, reference counting, uAPI
> creation flags, and anonymous inode file operations under CONFIG_ROOTNS.
> Drop active and passive namespace references on final release, send
> SIGKILL to the rootns init thread group on close when
> ROOTNS_KILL_ON_CLOSE is set, and report EPOLLHUP from poll() once the
> rootns reaches ROOTNS_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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117231352.3816603-1-jarkko@kernel.org?part=2
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 03/13] rootns: Track init lifecycle via copy_process() and pid_namespace
2026-11-17 23:13 ` [RFC PATCH v2 03/13] rootns: Track init lifecycle via copy_process() and pid_namespace Jarkko Sakkinen
@ 2026-11-18 23:15 ` sashiko-bot
0 siblings, 0 replies; 36+ messages in thread
From: sashiko-bot @ 2026-11-18 23:15 UTC (permalink / raw)
To: Jarkko Sakkinen
Cc: linux-mm, linux-security-module, Alexander Viro, Andrew Morton,
Andy Lutomirski, Ben Segall, Christian Brauner, David Hildenbrand,
David Howells, Davidlohr Bueso, Dietmar Eggemann, Ingo Molnar,
Jan Kara, Jonathan Corbet, John Johansen, Juri Lelli, Kees Cook,
K Prateek Nayak, Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul,
Mel Gorman, Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] rootns: unpaired pid_ns->rootns and refcount in copy_rootns()
and exit_rootns()
- [Medium] rootns: copy_rootns() publishes init_pid before
attach_pid(PIDTYPE_PID)
- [Medium] rootns: missing is_child_reaper() and locked state checks in
copy_rootns()
--
commit ad1de852195b8caa7fd9ea3eac031f0716f9fc81
Author: Jarkko Sakkinen <jarkko@kernel.org>
rootns: Track init lifecycle via copy_process() and pid_namespace
This commit adds copy_rootns() and exit_rootns() hooks to copy_process()
and zap_pid_ns_processes() to record the root namespace's init PID and
capture its exit status and rusage when the PID namespace shuts down.
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 5efceb8d58a78..99e22b3cd213e 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
[ ... ]
> @@ -2565,6 +2566,7 @@ __latent_entropy struct task_struct *copy_process(
> attach_pid(p, PIDTYPE_TGID);
> attach_pid(p, PIDTYPE_PGID);
> attach_pid(p, PIDTYPE_SID);
> + copy_rootns(p, NULL);
> __this_cpu_inc(process_counts);
> } else {
> current->signal->nr_threads++;
[Severity: Medium]
Does calling copy_rootns() before attach_pid(p, PIDTYPE_PID) allow
__rootns_kill() to miss the new init process?
__rootns_kill() synchronizes only on rootns->lock (not tasklist_lock) and
calls kill_pid(), which looks up pid_task(pid, PIDTYPE_PID):
CPU0 CPU1
copy_process()
write_lock_irq(&tasklist_lock)
attach_pid(p, PIDTYPE_TGID)
copy_rootns(p, c)
lock(&c->lock)
c->init_pid = get_task_pid(p, PIDTYPE_TGID)
c->state = ROOTNS_RUNNING
unlock(&c->lock)
rootns_release()
__rootns_kill(c, SIGKILL, true)
kill_pid(pid, SIGKILL, true)
pid_task(pid, PIDTYPE_PID)
--> NULL, returns -ESRCH
attach_pid(p, PIDTYPE_PID)
If a ROOTNS_KILL_ON_CLOSE file descriptor is closed during that window,
the SIGKILL is dropped and the container init process escapes termination.
> diff --git a/kernel/rootns.c b/kernel/rootns.c
> index e75d918b93ec5..e3b203322ae23 100644
> --- a/kernel/rootns.c
> +++ b/kernel/rootns.c
[ ... ]
> @@ -105,3 +106,42 @@ bool is_rootns_file(struct file *file)
> {
> return file->f_op == &rootns_fops;
> }
> +
> +void copy_rootns(struct task_struct *tsk, struct rootns *c)
> +{
> + if (likely(!c || READ_ONCE(c->state) != ROOTNS_FORKING))
> + return;
> +
> + scoped_guard(spinlock, &c->lock) {
> + get_rootns(c);
> + WRITE_ONCE(c->init_pid, get_task_pid(tsk, PIDTYPE_TGID));
> + WRITE_ONCE(c->state, ROOTNS_RUNNING);
> + }
> + wake_up_all(&c->waitq);
> +}
[Severity: Medium]
Can copy_rootns() record a non-reaper task as c->init_pid or overwrite
ROOTNS_DEAD back to ROOTNS_RUNNING?
If a caller with may_see_all_namespaces() opens the root namespace's PID
namespace via open_by_handle_at(FD_NSFS_ROOT, ...), enters it with
setns(CLONE_NEWPID), and forks PID 1 before bootstrap, c->state stays
ROOTNS_READY. Because copy_process() calls copy_rootns() for every
thread_group_leader(p) rather than checking is_child_reaper(pid), a later
bootstrap clone spawns PID 2 and commits it as c->init_pid.
In addition, c->state == ROOTNS_FORKING is only checked before acquiring
c->lock. If that external child reaper exits while bootstrap is in
flight, exit_rootns() sets c->state to ROOTNS_DEAD under c->lock, and
copy_rootns() can then overwrite c->state back to ROOTNS_RUNNING.
> +
> +void exit_rootns(struct pid_namespace *pid_ns, struct task_struct *tsk)
> +{
> + struct rootns *c = pid_ns->rootns;
> + struct task_struct *leader;
> + struct rusage rusage;
> + int status;
> +
> + if (!c)
> + return;
> +
> + leader = tsk->group_leader;
> + status = (tsk->signal->flags & SIGNAL_GROUP_EXIT) ?
> + tsk->signal->group_exit_code : leader->exit_code;
> + getrusage(leader, RUSAGE_BOTH, &rusage);
> +
> + scoped_guard(spinlock, &c->lock) {
> + c->exit_code = status;
> + c->rusage = rusage;
> + WRITE_ONCE(c->state, ROOTNS_DEAD);
> + }
> +
> + pid_ns->rootns = NULL;
> + wake_up_poll(&c->waitq, EPOLLHUP);
> + put_rootns(c);
> +}
[Severity: High]
Can exit_rootns() drop a reference that copy_rootns() never took, or
dereference a freed struct rootns via pid_ns->rootns?
copy_rootns() acquires the reference dropped by exit_rootns(), but it
never sets pid_ns->rootns = c. Even when create_rootns() later sets
ns->pid_ns_for_children->rootns = c without taking a reference,
put_rootns() frees c without clearing pid_ns->rootns.
If pid_ns is opened via open_by_handle_at(FD_NSFS_ROOT, ...) and the
rootns file descriptor is closed before bootstrap, c is freed while
pid_ns->rootns still points to it. Forking and exiting a child reaper in
pid_ns via setns(CLONE_NEWPID) then runs zap_pid_ns_processes() ->
exit_rootns(), causing a use-after-free and double put_rootns(c) (or
dropping the open control file descriptor's own reference if it was not
closed yet).
Setting task_active_pid_ns(tsk)->rootns = get_rootns(c) in copy_rootns()
instead of at creation time would keep pid_ns->rootns paired with the
reference dropped in exit_rootns().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117231352.3816603-1-jarkko@kernel.org?part=3
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 04/13] rootns: Add rootns_create() system call
2026-11-17 23:13 ` [RFC PATCH v2 04/13] rootns: Add rootns_create() system call Jarkko Sakkinen
@ 2026-11-18 23:15 ` sashiko-bot
0 siblings, 0 replies; 36+ messages in thread
From: sashiko-bot @ 2026-11-18 23:15 UTC (permalink / raw)
To: Jarkko Sakkinen
Cc: linux-mm, linux-security-module, Alexander Viro, Andrew Morton,
Andy Lutomirski, Ben Segall, Christian Brauner, David Hildenbrand,
David Howells, Davidlohr Bueso, Dietmar Eggemann, Ingo Molnar,
Jan Kara, Jonathan Corbet, John Johansen, Juri Lelli, Kees Cook,
K Prateek Nayak, Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul,
Mel Gorman, Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] rootns: UAF via unreferenced pid_ns->rootns in create_rootns()
- [High] rootns: cred->user mismatch in create_rootns_creds() for
ROOTNS_USER
--
commit 58de372391f170ac432dcc21ea8238b956c72a12
Author: Jarkko Sakkinen <jarkko@kernel.org>
rootns: Add rootns_create() system call
This commit adds the rootns_create() system call to allocate a detached
root namespace with dedicated mount and PID namespaces, optional extra
namespaces, and credentials, returning a control file descriptor.
> diff --git a/kernel/rootns.c b/kernel/rootns.c
> index e3b203322ae23..caa810b65d0da 100644
> --- a/kernel/rootns.c
> +++ b/kernel/rootns.c
> @@ -145,3 +145,142 @@ void exit_rootns(struct pid_namespace *pid_ns, struct task_struct *tsk)
> wake_up_poll(&c->waitq, EPOLLHUP);
> put_rootns(c);
> }
> +
> +/*
> + * Create credentials for a rootns. Drop keyrings from the new credential to
> + * avoid unnecessary pinning.
> + */
> +static const struct cred *create_rootns_creds(unsigned int flags)
> +{
> + struct cred *new;
> + int ret;
> +
> + new = prepare_creds();
> + if (!new)
> + return ERR_PTR(-ENOMEM);
> +
> +#ifdef CONFIG_KEYS
> + key_put(new->thread_keyring);
> + new->thread_keyring = NULL;
> + key_put(new->process_keyring);
> + new->process_keyring = NULL;
> + key_put(new->session_keyring);
> + new->session_keyring = NULL;
> + key_put(new->request_key_auth);
> + new->request_key_auth = NULL;
> +#endif
> + if (!(flags & ROOTNS_USER))
> + return new;
> +
> + ret = create_user_ns(new);
> + if (ret < 0)
> + goto err;
> + new->euid = new->user_ns->owner;
> + new->egid = new->user_ns->group;
> +
> + new->uid = new->euid;
> + new->suid = new->euid;
> + new->fsuid = new->euid;
> + new->gid = new->egid;
> + new->sgid = new->egid;
> + new->fsgid = new->egid;
> + ret = set_cred_ucounts(new);
> + if (ret < 0)
> + goto err;
> + return new;
[Severity: High]
Does overwriting new->uid with new->euid without updating new->user leave
cred->user out of sync when the caller's real and effective UIDs differ?
prepare_creds() clones new->user from current->cred->user (the caller's
real UID). If a process with real UID 0 switches its effective UID via
seteuid() before calling rootns_create(ROOTNS_USER), new->uid and
new->ucounts are set to the unprivileged effective UID, while new->user
remains INIT_USER. Tasks entering the rootns then bypass the RLIMIT_NPROC
check in copy_process() (which skips enforcement when
p->real_cred->user == INIT_USER) and charge per-user_struct resources to
the wrong user_struct.
Allocating the matching user_struct with alloc_uid(new->uid) and releasing
the old one with free_uid(new->user), as set_user() does in kernel/sys.c,
would keep cred->user consistent with cred->uid.
> +
> +err:
> + abort_creds(new);
> + return ERR_PTR(ret);
> +}
> +
> +/*
> + * Create a new rootns.
> + */
> +static struct rootns *create_rootns(unsigned int flags)
> +{
[ ... ]
> + ns = create_new_namespaces(clone_flags, current->nsproxy, cred->user_ns,
> + NULL);
> + if (IS_ERR(ns)) {
> + ret = PTR_ERR(ns);
> + goto err_put;
> + }
> +
> + c->ns = ns;
> + ns->pid_ns_for_children->rootns = c;
> + nsproxy_ns_active_get(ns);
[Severity: High]
Can storing an uncounted pointer in ns->pid_ns_for_children->rootns lead
to a use-after-free in exit_rootns()?
create_new_namespaces() adds ns->pid_ns_for_children to the namespace
tree, and nsproxy_ns_active_get() marks it active before any init task is
forked into the rootns. However, the reference on c that pairs with
exit_rootns() is only taken in copy_rootns() when c->state is
ROOTNS_FORKING, and put_rootns() does not clear
c->ns->pid_ns_for_children->rootns:
kernel/rootns.c:copy_rootns() {
if (likely(!c || READ_ONCE(c->state) != ROOTNS_FORKING))
return;
scoped_guard(spinlock, &c->lock) {
get_rootns(c);
...
}
If a process with CAP_SYS_ADMIN in init_user_ns opens the active PID
namespace via open_by_handle_at(FD_NSFS_ROOT, ...), enters it with
setns(), and forks a child while c->state is still ROOTNS_EMPTY, that
child becomes the PID namespace's child_reaper without copy_rootns()
taking a reference on c. When the child exits, zap_pid_ns_processes()
calls exit_rootns(), which dereferences the dangling pid_ns->rootns
pointer if the rootns fd was already closed, or drops the control fd's
sole reference on c while the fd is still open.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117231352.3816603-1-jarkko@kernel.org?part=4
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 05/13] rootns: Add rootns_wait() system call
2026-11-17 23:13 ` [RFC PATCH v2 05/13] rootns: Add rootns_wait() " Jarkko Sakkinen
@ 2026-11-18 23:15 ` sashiko-bot
0 siblings, 0 replies; 36+ messages in thread
From: sashiko-bot @ 2026-11-18 23:15 UTC (permalink / raw)
To: Jarkko Sakkinen
Cc: linux-mm, linux-security-module, Alexander Viro, Andrew Morton,
Andy Lutomirski, Ben Segall, Christian Brauner, David Hildenbrand,
David Howells, Davidlohr Bueso, Dietmar Eggemann, Ingo Molnar,
Jan Kara, Jonathan Corbet, John Johansen, Juri Lelli, Kees Cook,
K Prateek Nayak, Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul,
Mel Gorman, Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] rootns: unreachable init_pid check in rootns_wait_common()
- [Medium] rootns: non-freezable TASK_KILLABLE sleep in
rootns_wait_common()
--
commit ee16ae2e42910ad7c6f6428120bfc66d7f286658
Author: Jarkko Sakkinen <jarkko@kernel.org>
rootns: Add rootns_wait() system call
This commit adds the rootns_wait() system call and its compat entry point to
wait on a rootns file descriptor until its init thread group exits and
report its wait status and resource usage.
> diff --git a/kernel/rootns.c b/kernel/rootns.c
> index caa810b65d0da..83ab759a31ecd 100644
> --- a/kernel/rootns.c
> +++ b/kernel/rootns.c
[ ... ]
> +static long rootns_wait_common(int rootnsfd, unsigned int options,
> + int *status, struct rusage *ru)
> +{
> + CLASS(fd, f)(rootnsfd);
> + struct pid_namespace *pid_ns = task_active_pid_ns(current);
> + struct rootns *rootns;
> + long ret;
> +
> + if (fd_empty(f))
> + return -EBADF;
> + if (!is_rootns_file(fd_file(f)) || (options & ~WNOHANG))
> + return -EINVAL;
> +
> + rootns = fd_file(f)->private_data;
> + if (!(options & WNOHANG)) {
> + ret = wait_event_killable(rootns->waitq,
> + READ_ONCE(rootns->state) == ROOTNS_DEAD);
[Severity: Medium]
Should rootns_wait_common() use wait_event_freezable() instead of
wait_event_killable() here?
Waiters blocked in TASK_KILLABLE for the lifetime of a container are neither
marked TASK_FREEZABLE nor woken by signal_wake_up(), unlike do_wait() which
sleeps in TASK_INTERRUPTIBLE | TASK_FREEZABLE. While any task is blocked in
rootns_wait(), system suspend and hibernation fail after the PM freezer
timeout, cgroup v2 freezing of the waiter's cgroup hangs, non-fatal signals
and job control cannot interrupt the wait, and each idle waiter inflates the
system load average.
> + if (ret)
> + return ret;
> + }
> +
> + scoped_guard(spinlock, &rootns->lock) {
> + if (rootns->state != ROOTNS_DEAD)
> + return 0;
> + if (!rootns->init_pid)
> + return -ECHILD;
[Severity: Medium]
Can the !rootns->init_pid check ever be reached when init was never started?
The kernel-doc for sys_rootns_wait() states that it returns -ECHILD if init
was never started, but rootns->state only reaches ROOTNS_DEAD in
exit_rootns() after copy_rootns() has already set rootns->init_pid and
transitioned the state to ROOTNS_RUNNING. When rootns_wait() is called on a
rootns in ROOTNS_EMPTY or ROOTNS_READY before init is forked, a WNOHANG call
returns 0 at the rootns->state != ROOTNS_DEAD check above, and a blocking
call sleeps indefinitely in wait_event_killable().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117231352.3816603-1-jarkko@kernel.org?part=5
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 06/13] rootns: Add rootns_kill() system call
2026-11-17 23:13 ` [RFC PATCH v2 06/13] rootns: Add rootns_kill() " Jarkko Sakkinen
@ 2026-11-18 23:15 ` sashiko-bot
0 siblings, 0 replies; 36+ messages in thread
From: sashiko-bot @ 2026-11-18 23:15 UTC (permalink / raw)
To: Jarkko Sakkinen
Cc: linux-mm, linux-security-module, Alexander Viro, Andrew Morton,
Andy Lutomirski, Ben Segall, Christian Brauner, David Hildenbrand,
David Howells, Davidlohr Bueso, Dietmar Eggemann, Ingo Molnar,
Jan Kara, Jonathan Corbet, John Johansen, Juri Lelli, Kees Cook,
K Prateek Nayak, Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul,
Mel Gorman, Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] rootns: fork() race in rootns_kill_members() missing
tasklist_lock
- [High] rootns: missing PID namespace ancestry check in
rootns_kill_members()
--
commit ea67311730397795196206953e1b7e54d487cc13
Author: Jarkko Sakkinen <jarkko@kernel.org>
rootns: Add rootns_kill() system call
This commit adds the rootns_kill() system call to walk a root namespace's
PID namespace IDR and deliver a signal to each member thread group.
> diff --git a/kernel/rootns.c b/kernel/rootns.c
> index 83ab759a31ecd..90a070dbf4a82 100644
> --- a/kernel/rootns.c
> +++ b/kernel/rootns.c
[ ... ]
> @@ -389,3 +390,67 @@ COMPAT_SYSCALL_DEFINE4(rootns_wait, int, rootnsfd,
> return ret;
> }
> #endif
> +
> +static int rootns_kill_members(struct rootns *rootns, int sig)
> +{
> + struct pid_namespace *pid_ns = rootns->ns->pid_ns_for_children;
[Severity: High]
Does rootns_kill_members() need to check that the caller's active PID
namespace is an ancestor of pid_ns before delivering signals?
kill_pid(pid, sig, 0) passes SEND_SIG_NOINFO to send_signal_locked():
kernel/signal.c:send_signal_locked() {
...
if (info == SEND_SIG_NOINFO) {
/* Force if sent from an ancestor pid namespace */
force = !task_pid_nr_ns(current, task_active_pid_ns(t));
}
...
}
Without a PID namespace ancestry check (like access_pidfd_pidns() in
sys_pidfd_send_signal()), a holder of rootnsfd in a sibling or disjoint
PID namespace has task_pid_nr_ns(current, task_active_pid_ns(t)) == 0.
That sets force = true and bypasses SIGNAL_UNKILLABLE in
sig_task_ignored(), allowing a non-ancestor process to kill or stop the
PID namespace init with SIGKILL or SIGSTOP. A caller in a descendant PID
namespace created inside the rootns can also signal tasks upward in its
ancestor pid_ns, while a caller inside pid_ns itself has force = false so
SIGKILL and SIGSTOP are ignored on the rootns init process.
> + bool any_success = false;
> + bool any_other = false;
> + bool any_perm = false;
> + int other_err = 0;
> + struct pid *pid;
> + int nr;
> +
> + if (READ_ONCE(rootns->state) != ROOTNS_RUNNING)
> + return -ESRCH;
> +
> + scoped_guard(rcu) {
> + idr_for_each_entry(&pid_ns->idr, pid, nr) {
> + int err;
> +
> + if (!pid_task(pid, PIDTYPE_TGID))
> + continue;
> +
> + err = kill_pid(pid, sig, 0);
[Severity: High]
Can a concurrent fork() still escape signal delivery in
rootns_kill_members()?
CPU0 CPU1
copy_process()
/* queues delayed.node on
* current->signal->multiprocess
*/
alloc_pid()
/* inserts child pid into
* pid_ns->idr (tasks[] empty)
*/
rootns_kill_members()
idr_for_each_entry(&pid_ns->idr, ...)
/* child pid: pid_task(..., PIDTYPE_TGID)
* is NULL -> skipped
*/
/* parent pid: kill_pid() passes
* PIDTYPE_TGID
*/
__send_signal_locked()
/* type > PIDTYPE_TGID is false;
* delayed.signal not updated
*/
write_lock_irq(&tasklist_lock)
p->signal->shared_pending.signal =
delayed.signal;
attach_pid(p, PIDTYPE_TGID)
attach_pid(p, PIDTYPE_PID)
write_unlock_irq(&tasklist_lock)
/* child never receives sig */
__send_signal_locked() only records signals into t->signal->multiprocess
for in-flight forks when type > PIDTYPE_TGID, whereas kill_pid() uses
PIDTYPE_TGID. For any signal that does not make fatal_signal_pending()
true on the parent (such as SIGSTOP, SIGHUP, SIGINT, or a caught or
blocked SIGTERM), the child finishes copy_process() without receiving the
signal.
Because pid_ns->idr is walked without read_lock(&tasklist_lock), a parent
at a higher IDR index can also allocate a lower, already-visited IDR index
for its child (after PID wrap-around or via clone3() set_tid) and finish
attaching the child before the scan reaches the parent, escaping even
SIGKILL. In addition, copy_process() calls attach_pid(p, PIDTYPE_TGID)
before attach_pid(p, PIDTYPE_PID) under tasklist_lock, so unlocked readers
can see pid_task(pid, PIDTYPE_TGID) != NULL while kill_pid() still sees
pid_task(pid, PIDTYPE_PID) == NULL and returns -ESRCH.
Holding read_lock(&tasklist_lock) and signaling via group_send_sig_info()
with PIDTYPE_MAX (as zap_pid_ns_processes() and kill_something_info() do)
would serialize against copy_process() and populate delayed.signal for
ongoing forks.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117231352.3816603-1-jarkko@kernel.org?part=6
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 07/13] fork: Support CLONE_INTO_ROOTNS in clone3()
2026-11-17 23:13 ` [RFC PATCH v2 07/13] fork: Support CLONE_INTO_ROOTNS in clone3() Jarkko Sakkinen
@ 2026-11-18 23:15 ` sashiko-bot
0 siblings, 0 replies; 36+ messages in thread
From: sashiko-bot @ 2026-11-18 23:15 UTC (permalink / raw)
To: Jarkko Sakkinen
Cc: linux-mm, linux-security-module, Alexander Viro, Andrew Morton,
Andy Lutomirski, Ben Segall, Christian Brauner, David Hildenbrand,
David Howells, Davidlohr Bueso, Dietmar Eggemann, Ingo Molnar,
Jan Kara, Jonathan Corbet, John Johansen, Juri Lelli, Kees Cook,
K Prateek Nayak, Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul,
Mel Gorman, Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Critical] cred: missing dumpability reset and shared mm on
CLONE_INTO_ROOTNS
- [Critical] cred: privilege escalation and LSM bypass in
may_enter_rootns_creds()
- [High] rootns: UAF and refcount underflow on pid_ns->rootns without
CLONE_INTO_ROOTNS
- [Medium] fork: copy_rootns() sets ROOTNS_RUNNING before
attach_pid(PIDTYPE_PID)
- [Medium] nsproxy: missing timens_commit() and CLONE_VM check in
copy_namespaces()
--
commit 32f57f44b3303d6e1266e96415fc759ba100f243
Author: Jarkko Sakkinen <jarkko@kernel.org>
fork: Support CLONE_INTO_ROOTNS in clone3()
This commit adds CLONE_INTO_ROOTNS and struct clone_args.rootns to allow
clone3() to spawn a child process directly into an initialized root
namespace.
> diff --git a/kernel/cred.c b/kernel/cred.c
> index d01df40a9a386..afc91eed26563 100644
> --- a/kernel/cred.c
> +++ b/kernel/cred.c
[ ... ]
> @@ -251,6 +255,25 @@ struct cred *prepare_exec_creds(void)
> return new;
> }
>
> +static bool cred_cap_issubset(const struct cred *set,
> + const struct cred *subset);
> +
> +static bool may_enter_rootns_creds(const struct cred *old,
> + const struct cred *target)
> +{
> + if (cred_cap_issubset(old, target) &&
> + uid_eq(old->euid, target->euid) &&
> + gid_eq(old->egid, target->egid))
> + return true;
> +
> + if (old->user_ns == target->user_ns)
> + return false;
> +
> + return ns_capable(target->user_ns->parent, CAP_SYS_ADMIN) &&
> + ns_capable(target->user_ns->parent, CAP_SETUID) &&
> + ns_capable(target->user_ns->parent, CAP_SETGID);
> +}
[Severity: Critical]
Can a caller escalate privileges or bypass LSM restrictions when
copy_creds() replaces the child's credentials with dup_creds(rootns->cred)?
dup_creds(rootns->cred) copies all fields of struct cred from rootns->cred,
including uid, suid, fsuid, gid, sgid, fsgid, group_info, cap_bset,
cap_effective, cap_inheritable, cap_ambient, and security (passing
rootns->cred as old to security_prepare_creds()).
In the first branch of may_enter_rootns_creds(), only cap_permitted, euid,
and egid are checked. A process that creates or inherits a rootns fd and
then drops its real/saved UIDs or GIDs, clears supplementary groups with
setgroups(), drops capabilities from cap_bset or cap_effective, sets
no_new_privs, or confines itself with an LSM such as Landlock still passes
this check and spawns a child with the original unconfined rootns->cred.
In the second branch, when old->user_ns != target->user_ns, only
ns_capable() on target->user_ns->parent is checked, without verifying
cred_cap_issubset(old, target) or checking that target's UIDs, GIDs, and
group_info are mapped into target->user_ns->parent. If a process with
GLOBAL_ROOT_UID enters a child user namespace whose parent is owned by an
unprivileged user and calls rootns_create(0), the unprivileged owner of
target->user_ns->parent can clone into that rootns and gain
GLOBAL_ROOT_UID.
Conversely, when old->user_ns == target->user_ns and old->euid !=
target->euid, the early return rejects callers even when they hold
CAP_SYS_ADMIN, CAP_SETUID, and CAP_SETGID in target->user_ns.
> @@ -260,7 +283,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 rootns *rootns)
> {
> struct cred *new;
> int ret;
> @@ -283,7 +307,13 @@ int copy_creds(struct task_struct *p, u64 clone_flags)
> return 0;
> }
>
> - new = prepare_creds();
> + if (rootns) {
> + if (!may_enter_rootns_creds(current_cred(), rootns->cred))
> + return -EPERM;
> + new = dup_creds(rootns->cred);
> + } else {
> + new = prepare_creds();
> + }
> if (!new)
> return -ENOMEM;
[Severity: Critical]
Does switching p to rootns->cred leave p->exec_state->dumpable set to
TASK_DUMPABLE_OWNER and allow sharing current->mm across privilege
boundaries?
In copy_process(), copy_exec_state() runs before copy_creds() and copies
current->exec_state (or refcount-shares it when CLONE_VM | CLONE_VFORK is
used). Unlike commit_creds(), copy_creds() does not reset dumpability to
suid_dumpable when UIDs, GIDs, or capabilities change between
current_cred() and rootns->cred:
kernel/ptrace.c:task_still_dumpable() {
...
exec_state = task_exec_state_rcu(task);
if (READ_ONCE(exec_state->dumpable) == TASK_DUMPABLE_OWNER)
return true;
return ptrace_has_cap(exec_state->user_ns, mode);
}
When a dumpable privileged daemon spawns a child into a less-privileged
rootns, unprivileged tasks in that rootns matching rootns->cred can attach
via ptrace() or access /proc/<pid>/mem and /proc/<pid>/fd/* before the
child calls execve(). Because clone3_args_valid() also allows CLONE_VM |
CLONE_VFORK with CLONE_INTO_ROOTNS, the child shares current->mm with the
parent daemon, allowing tasks in the target rootns to modify the parent
daemon's live memory.
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 99e22b3cd213e..978605de8428e 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
[ ... ]
> @@ -2566,7 +2583,7 @@ __latent_entropy struct task_struct *copy_process(
> attach_pid(p, PIDTYPE_TGID);
> attach_pid(p, PIDTYPE_PGID);
> attach_pid(p, PIDTYPE_SID);
> - copy_rootns(p, NULL);
> + copy_rootns(p, clone_args_rootns(args));
> __this_cpu_inc(process_counts);
> } else {
> current->signal->nr_threads++;
[Severity: High]
Can forking into a rootns PID namespace via setns(CLONE_NEWPID) without
CLONE_INTO_ROOTNS cause a refcount underflow or use-after-free on struct
rootns?
create_rootns() sets ns->pid_ns_for_children->rootns = c without taking a
reference on c and activates the namespace in ns_tree, while put_rootns()
frees c without clearing pid_ns_for_children->rootns. A caller with
CAP_SYS_ADMIN can open an nsfs fd for pid_ns_for_children via
open_by_handle_at(FD_NSFS_ROOT, ...), call setns(pidns_fd, CLONE_NEWPID),
and fork() PID 1 without CLONE_INTO_ROOTNS. Because clone_args_rootns() is
NULL, copy_rootns() returns early without calling get_rootns(c), but when
that PID 1 exits, zap_pid_ns_processes() -> exit_rootns() still
dereferences pid_ns->rootns and calls put_rootns(c):
kernel/rootns.c:copy_rootns() {
if (likely(!c || READ_ONCE(c->state) != ROOTNS_FORKING))
return;
scoped_guard(spinlock, &c->lock) {
get_rootns(c);
WRITE_ONCE(c->init_pid, get_task_pid(tsk, PIDTYPE_TGID));
WRITE_ONCE(c->state, ROOTNS_RUNNING);
}
wake_up_all(&c->waitq);
}
If the rootns fd was already closed, exit_rootns() dereferences freed
memory; if the rootns fd is still open, exit_rootns() drops the fd's
reference and frees c prematurely.
[Severity: Medium]
Can a concurrent rootns_kill() or close() with ROOTNS_KILL_ON_CLOSE miss
the init task because copy_rootns() transitions rootns->state to
ROOTNS_RUNNING before attach_pid(p, PIDTYPE_PID)?
CPU0 CPU1
copy_process()
attach_pid(p, PIDTYPE_TGID)
copy_rootns(p, ...)
c->init_pid = ...
c->state = ROOTNS_RUNNING
SYSCALL_DEFINE2(rootns_kill, ...)
rootns_kill_members()
kill_pid(pid, sig, 0)
pid_task(pid, PIDTYPE_PID)
--> NULL (-ESRCH)
attach_pid(p, PIDTYPE_PID)
Neither __rootns_kill() nor rootns_kill_members() takes tasklist_lock, so a
signal sent in this window sees ROOTNS_RUNNING and PIDTYPE_TGID attached,
but kill_pid() looks up PIDTYPE_PID and fails with -ESRCH. Calling
copy_rootns() after attach_pid(p, PIDTYPE_PID) avoids this window.
> diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
> index 8a3c6d4e94e2a..78a1e1fb2cfd7 100644
> --- a/kernel/nsproxy.c
> +++ b/kernel/nsproxy.c
> @@ -166,12 +167,18 @@ struct nsproxy *create_new_namespaces(u64 flags,
> * 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 rootns *rootns)
> {
> struct nsproxy *old_ns = tsk->nsproxy;
> struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
> struct nsproxy *new_ns;
>
> + if (rootns) {
> + get_nsproxy(rootns->ns);
> + tsk->nsproxy = rootns->ns;
> + return 0;
> + }
[Severity: Medium]
Does returning early here skip time namespace VDSO setup when rootns->ns
has a different time namespace from the caller?
In copy_process(), copy_mm() duplicates current->mm (including any faulted
[vvar] mappings for old_ns->time_ns) before copy_namespaces() runs.
Returning early without calling timens_commit() or timens_on_fork() leaves
the child's [vvar] mapping pointing at the parent's time namespace until
execve(), and when CLONE_VM | CLONE_VFORK is used, allows tasks sharing an
mm_struct to have different time namespaces.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117231352.3816603-1-jarkko@kernel.org?part=7
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 08/13] fs: Support FSCONFIG_SET_ROOTNS in fsconfig()
2026-11-17 23:13 ` [RFC PATCH v2 08/13] fs: Support FSCONFIG_SET_ROOTNS in fsconfig() Jarkko Sakkinen
@ 2026-11-18 23:15 ` sashiko-bot
0 siblings, 0 replies; 36+ messages in thread
From: sashiko-bot @ 2026-11-18 23:15 UTC (permalink / raw)
To: Jarkko Sakkinen
Cc: linux-mm, linux-security-module, Alexander Viro, Andrew Morton,
Andy Lutomirski, Ben Segall, Christian Brauner, David Hildenbrand,
David Howells, Davidlohr Bueso, Dietmar Eggemann, Ingo Molnar,
Jan Kara, Jonathan Corbet, John Johansen, Juri Lelli, Kees Cook,
K Prateek Nayak, Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul,
Mel Gorman, Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Critical] fs: fsconfig_set_rootns() replaces fc->net_ns after
init_fs_context()
- [High] fs: proc: missing pidns_is_ancestor() check in
proc_set_rootns()
- [High] fs: broken fc->user_ns delegation in fsconfig_set_rootns()
- [Medium] fs: missing net_ns and ipc_ns capability checks in
fsconfig_set_rootns()
--
commit 5cbef69c784337269ad86c164ca92e045e18c429
Author: Jarkko Sakkinen <jarkko@kernel.org>
fs: Support FSCONFIG_SET_ROOTNS in fsconfig()
This commit adds the FSCONFIG_SET_ROOTNS command to fsconfig() so a newly
opened fs_context can be bound to a target root namespace before parsing
parameters.
> diff --git a/fs/fsopen.c b/fs/fsopen.c
> index 70024870fefa2..ca3234c8c4e47 100644
> --- a/fs/fsopen.c
> +++ b/fs/fsopen.c
[ ... ]
> +static int fsconfig_set_rootns(struct fs_context *fc, struct fs_parameter *param)
> +{
> + struct user_namespace *user_ns;
> + struct rootns *c;
> +
> + if (!is_rootns_file(param->file))
> + return -EINVAL;
> +
> + c = param->file->private_data;
> + user_ns = c->cred->user_ns;
> + if (!ns_capable(user_ns, CAP_SYS_ADMIN))
> + return -EPERM;
[Severity: Medium]
Does checking CAP_SYS_ADMIN only against c->cred->user_ns allow rebinding
fc->net_ns or mqueue's ctx->ipc_ns to an ancestor namespace where the
caller lacks privileges?
In create_rootns(), when ROOTNS_USER is passed without ROOTNS_NET or
ROOTNS_IPC, c->ns->net_ns and c->ns->ipc_ns are inherited from
current->nsproxy and remain owned by an ancestor user namespace. A caller
in an isolated network or IPC namespace that holds CAP_SYS_ADMIN in
c->cred->user_ns can then use a rootns fd to switch fc->net_ns or
ctx->ipc_ns back to that ancestor namespace without holding CAP_SYS_ADMIN
in c->ns->net_ns->user_ns or c->ns->ipc_ns->user_ns.
> +
> + put_net(fc->net_ns);
> + fc->net_ns = get_net(c->ns->net_ns);
[Severity: Critical]
Can replacing and dropping fc->net_ns here after init_fs_context() has
already run cause a use-after-free in filesystems that cache per-net state
during fsopen()?
During fsopen(), alloc_fs_context() calls fc->fs_type->init_fs_context(fc)
with the caller's current fc->net_ns. In kAFS, afs_init_fs_context()
stores an unreferenced pointer into that netns:
fs/afs/super.c:afs_init_fs_context() {
...
ctx->net = afs_net(fc->net_ns);
/* Default to the workstation cell. */
cell = afs_find_cell(ctx->net, NULL, 0, afs_cell_trace_use_fc);
if (IS_ERR(cell))
cell = NULL;
ctx->cell = cell;
...
}
When fsconfig_set_rootns() calls put_net(fc->net_ns), the initial netns
can be freed once the caller exits it, leaving ctx->net dangling when a
subsequent fsconfig() call parses "source" via afs_parse_source() ->
afs_lookup_cell(ctx->net, ...). If ctx->cell was non-NULL, it instead
holds a cell reference on the old netns and hangs afs_cell_purge() in
wait_var_event(&net->cells_outstanding) on netns exit.
Other filesystems also derive state from fc->net_ns during
init_fs_context() that becomes inconsistent after fc->net_ns changes:
nfsd_init_fs_context() and rpc_init_fs_context() set fc->user_ns from the
initial fc->net_ns->user_ns (and nfsd_fill_super() writes
nn->nfsd_client_dir into current->nsproxy->net_ns while keying the
superblock to fc->net_ns), while nfs_init_fs_context() sets
NFS_MOUNT_NETUNREACH_FATAL from fc->net_ns != &init_net.
> + if (!fc->global &&
> + (fc->fs_type->fs_flags & (FS_USERNS_MOUNT | FS_USERNS_DELEGATABLE)) &&
> + kuid_has_mapping(user_ns, fc->cred->fsuid) &&
> + kgid_has_mapping(user_ns, fc->cred->fsgid)) {
> + put_user_ns(fc->user_ns);
> + fc->user_ns = get_user_ns(user_ns);
> + }
[Severity: High]
Does delegating fc->user_ns this way work for unentered ROOTNS_USER root
namespaces or for FS_USERNS_MOUNT filesystems?
For an unentered ROOTNS_USER rootns, create_user_ns() leaves uid_map and
gid_map empty until a process exists in the namespace, and
rootns_prepare_fork() rejects fork with -ENOENT while the rootns is in
ROOTNS_EMPTY before "/" is mounted. Because kuid_has_mapping() and
kgid_has_mapping() are false, fsconfig_set_rootns() silently leaves
fc->user_ns unchanged while returning 0, so a privileged manager creates
an init_user_ns superblock (without SB_I_NODEV) and an unprivileged caller
later fails mount_capable(fc) with -EPERM. Meanwhile, mqueue_set_rootns()
unconditionally overwrites fc->user_ns with ctx->ipc_ns->user_ns, so
mqueue_get_inode() assigns unmapped current_fsuid()/current_fsgid() values
to the root inode.
Conversely, when uid_map and gid_map are populated and fc->user_ns is
switched to a target userns different from current_user_ns(),
FS_USERNS_MOUNT filesystems that require fc->user_ns == current_user_ns()
(such as ovl_fill_super(), ovl_parse_param(), and bm_fill_super()) reject
the mount with -EINVAL:
fs/overlayfs/super.c:ovl_fill_super() {
...
/* The fscontext fd may have been passed to another user namespace. */
if (fc->user_ns != current_user_ns())
goto out_err;
...
}
> + if (fc->ops->set_rootns)
> + fc->ops->set_rootns(fc, c);
> + fc->phase = FS_CONTEXT_CREATE_PARAMS;
> + return 0;
> +}
[ ... ]
> diff --git a/fs/proc/root.c b/fs/proc/root.c
> index 7fbbe92bf73a7..5976029ad3f80 100644
> --- a/fs/proc/root.c
> +++ b/fs/proc/root.c
[ ... ]
> @@ -323,6 +325,16 @@ static int proc_get_tree(struct fs_context *fc)
> return get_tree_nodev(fc, proc_fill_super);
> }
>
> +static void proc_set_rootns(struct fs_context *fc, struct rootns *rootns)
> +{
> + struct proc_fs_context *ctx = fc->fs_private;
> +
> + put_pid_ns(ctx->pid_ns);
> + ctx->pid_ns = get_pid_ns(rootns->ns->pid_ns_for_children);
> + put_user_ns(fc->user_ns);
> + fc->user_ns = get_user_ns(ctx->pid_ns->user_ns);
> +}
[Severity: High]
Should proc_set_rootns() verify that rootns->ns->pid_ns_for_children is a
descendant of task_active_pid_ns(current)?
Both proc_parse_pidns_param() and rootns_prepare_fork() enforce
pidns_is_ancestor(target, task_active_pid_ns(current)). Without that
check here (and a return value from ->set_rootns()), a process confined to
a child or sibling PID namespace within the same user namespace can use a
rootns fd to mount procfs for an ancestor or sibling PID namespace outside
its active PID namespace hierarchy.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117231352.3816603-1-jarkko@kernel.org?part=8
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 09/13] fs: Support installing rootns mount trees via move_mount()
2026-11-17 23:13 ` [RFC PATCH v2 09/13] fs: Support installing rootns mount trees via move_mount() Jarkko Sakkinen
@ 2026-11-18 23:15 ` sashiko-bot
0 siblings, 0 replies; 36+ messages in thread
From: sashiko-bot @ 2026-11-18 23:15 UTC (permalink / raw)
To: Jarkko Sakkinen
Cc: linux-mm, linux-security-module, Alexander Viro, Andrew Morton,
Andy Lutomirski, Ben Segall, Christian Brauner, David Hildenbrand,
David Howells, Davidlohr Bueso, Dietmar Eggemann, Ingo Molnar,
Jan Kara, Jonathan Corbet, John Johansen, Juri Lelli, Kees Cook,
K Prateek Nayak, Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul,
Mel Gorman, Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] fs: check_for_nsfs_mounts() checks caller mnt_ns instead of
rootns target
- [High] fs: do_move_mount() calls lock_mnt_tree() after
attach_recursive_mnt()
- [High] fs: relative target paths in move_mount_rootns() bypass is_root
checks
- [High] fs: TOCTOU race on rootns->state in move_mount_rootns()
corrupts state
- [High] fs: fsmount() alloc_mnt_ns(fc->user_ns) bypasses submount
MNT_LOCKED
--
commit f0ccb5459fd227ad26c0bf5f42a1937aaa266930
Author: Jarkko Sakkinen <jarkko@kernel.org>
fs: Support installing rootns mount trees via move_mount()
This commit adds MOVE_MOUNT_T_ROOTNS_ROOT to allow attaching detached
anonymous mount trees into a rootns mount namespace via its file descriptor,
and allocates fsmount() anonymous mount namespaces in fc->user_ns.
> diff --git a/fs/namespace.c b/fs/namespace.c
> index 010ed5d68d229..2dfb5e01d40f0 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
[ ... ]
> @@ -3792,7 +3796,13 @@ 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_ROOTNS) {
> + if (!anon_ns_root(old) || old->mnt_ns == mp.parent->mnt_ns)
> + return -EINVAL;
> + if ((flags & MNT_TREE_ROOTNS_INIT) &&
> + mp.parent != real_mount(new_path->mnt))
> + return -EBUSY;
> + } else if (check_mnt(old)) {
[Severity: High]
Can moving an nsfs mount into a rootns with MNT_TREE_ROOTNS create an
unbreakable mount namespace reference cycle?
Later in do_move_mount(), check_for_nsfs_mounts(old) calls mnt_ns_loop(),
which checks against current->nsproxy->mnt_ns rather than the destination
mp.parent->mnt_ns:
fs/namespace.c:mnt_ns_loop() {
...
mnt_ns = to_mnt_ns(get_proc_ns(d_inode(dentry)));
return current->nsproxy->mnt_ns->ns.ns_id >= mnt_ns->ns.ns_id;
}
Because the target rootns mount namespace was created after the caller's
mount namespace, current->nsproxy->mnt_ns->ns.ns_id is smaller than
rootns_mnt_ns->ns.ns_id. If the caller clones an nsfs mount referring to
rootns_mnt_ns via open_tree(OPEN_TREE_CLONE) and moves it into rootns_mnt_ns
with MOVE_MOUNT_T_ROOTNS_ROOT, mnt_ns_loop() returns false. The mounted
nsfs dentry then pins rootns_mnt_ns while rootns_mnt_ns pins the mount,
permanently leaking the mount namespace and all mounts inside it.
Passing mp.parent->mnt_ns to check_for_nsfs_mounts() and mnt_ns_loop() would
check against the actual destination namespace.
> @@ -3845,7 +3855,16 @@ static int do_move_mount(const struct path *old_path,
> if (mount_is_ancestor(old, mp.parent))
> return -ELOOP;
>
> - return attach_recursive_mnt(old, &mp);
> + lock_tree = (flags & MNT_TREE_ROOTNS) &&
> + old->mnt_ns->user_ns != mp.parent->mnt_ns->user_ns;
> + err = attach_recursive_mnt(old, &mp);
> + if (!err && lock_tree) {
> + scoped_guard(mount_writer) {
> + lock_mnt_tree(old);
> + old->mnt.mnt_flags |= MNT_LOCKED;
> + }
> + }
> + return err;
> }
[Severity: High]
Does calling lock_mnt_tree(old) after attach_recursive_mnt(old, &mp)
mishandle overmounted subtrees, shared mount propagation, and concurrent
readers?
Inside attach_recursive_mnt(), any existing mount q at the target mountpoint
(for example when MOVE_MOUNT_BENEATH or overmounting is used) is reparented
onto topmost_overmount(old) via mnt_change_mountpoint(r, mp, q), and
MNT_LOCKED is cleared on q so it remains unmountable. Running
lock_mnt_tree(old) afterwards walks into q and all of q's descendants via
next_mnt(p, old), setting MNT_LOCKED and MNT_LOCK_* on pre-existing mounts
in the rootns and preventing q from being unmounted.
In addition, if mp.parent is a shared mount in the rootns,
attach_recursive_mnt() clones old for propagation before lock_mnt_tree(old)
runs. Because attach_recursive_mnt() sets user_ns = ns->user_ns (the target
rootns user_ns rather than old->mnt_ns->user_ns), the cross-userns check
child->mnt_parent->mnt_ns->user_ns != user_ns is false for peers in the
target user_ns, leaving propagated copies unlocked. Finally, dropping
mount_lock in unlock_mount_hash() before re-acquiring mount_writer leaves a
window where old is already visible in the rootns without MNT_LOCKED or
MNT_LOCK_* set.
> @@ -4701,7 +4720,7 @@ 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->user_ns, true);
> if (IS_ERR(ns))
> return PTR_ERR(ns);
> mnt = real_mount(new_path.mnt);
[Severity: High]
Does allocating the anonymous mount namespace in fc->user_ns allow
submounts from a parent user namespace to be installed into an unprivileged
rootns without MNT_LOCKED?
When a process in a parent user namespace configures a superblock for an
unprivileged rootns via FSCONFIG_SET_ROOTNS, fc->user_ns is set to the
target rootns user_ns, so fsmount() creates a root mount M_root with
M_root->mnt_ns->user_ns equal to the rootns user_ns. If the process then
attaches a host mount M_sub (for example, a read-only bind mount or masking
mount from init_user_ns) onto M_root via move_mount(), attach_recursive_mnt()
calls lock_mnt_tree(M_sub), which only sets MNT_LOCKED on descendants p !=
M_sub and leaves M_sub itself without MNT_LOCKED.
When M_root is subsequently moved into the rootns with
MOVE_MOUNT_T_ROOTNS_ROOT, do_move_mount() sees M_root->mnt_ns->user_ns ==
mp.parent->mnt_ns->user_ns and skips lock_mnt_tree(M_root). As a result,
M_sub is never marked MNT_LOCKED in the rootns, allowing an unprivileged
user in the rootns to unmount M_sub and expose the underlying directory.
Conversely, attaching another FSCONFIG_SET_ROOTNS mount onto M_root via
normal move_mount() causes attach_recursive_mnt() to compare against
current->nsproxy->mnt_ns->user_ns (because M_root->mnt_ns is anonymous) and
spuriously lock the same-userns submount.
> @@ -4741,6 +4760,129 @@ static inline int vfs_move_mount(const struct path *from_path,
[ ... ]
> + rootns_mnt_ns = rootns->ns->mnt_ns;
> + is_root = to_name->name[0] == '/' && to_name->name[1] == '\0';
> + if (is_root) {
> + if (flags & MOVE_MOUNT_BENEATH)
> + return -EINVAL;
> + if (READ_ONCE(rootns->state) != ROOTNS_EMPTY)
> + return -EBUSY;
> +
> + to_path.mnt = mntget(&rootns_mnt_ns->root->mnt);
> + to_path.dentry = dget(rootns_mnt_ns->root->mnt.mnt_root);
> + mflags |= MNT_TREE_ROOTNS_INIT;
> + } else {
> + if (to_name->name[0] == '/')
> + return -EINVAL;
> +
> + scoped_guard(spinlock, &rootns->lock) {
> + if (rootns->state == ROOTNS_EMPTY)
> + return -ENOENT;
> + }
> +
> + lflags = 0;
> + 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,
> + &rootns->root);
> + if (ret)
> + return ret;
> + if (real_mount(to_path.mnt)->mnt_ns != rootns_mnt_ns)
> + return -EINVAL;
> + }
[Severity: High]
Can relative target paths such as "." or "subdir/.." resolve to_path to
rootns->root and bypass the is_root checks?
Because is_root only tests for the literal string "/", passing "." after
root installation enters the else branch and resolves to_path to
rootns->root:
1. If MOVE_MOUNT_BENEATH is set with to_pathname = ".", the MOVE_MOUNT_BENEATH
check in the is_root branch is bypassed. do_lock_mount() selects the
underlying nullfs root as mp.parent and mounts the new tree beneath
rootns->root, clearing MNT_LOCKED on rootns->root in
attach_recursive_mnt() so an unprivileged rootns user can unmount a
locked cross-userns root mount.
2. Without MOVE_MOUNT_BENEATH, to_pathname = "." overmounts rootns->root
without updating rootns->root (and similarly on initial "/" installation
if from_path already has overmounts stacked on its root dentry). Because
copy_fs() and preset-root lookups in path_init() do not traverse
overmounts on rootns->root, subsequent CLONE_INTO_ROOTNS processes and
move_mount_rootns() lookups stay in the shadowed lower mount.
> +
> + ret = lookup_move_mount_from(from_dfd, from_pathname, flags,
> + &from_path);
> + if (ret)
> + return ret;
> +
> + ret = vfs_move_mount(&from_path, &to_path, mflags | MNT_TREE_ROOTNS);
> + if (!ret && is_root) {
> + scoped_guard(spinlock, &rootns->lock) {
> + path_get(&from_path);
> + rootns->root = from_path;
> + WRITE_ONCE(rootns->state, ROOTNS_READY);
> + }
> + }
> +
> + return ret;
> +}
[Severity: High]
Can concurrent "/" installations race on rootns->state, leaking the previous
rootns->root and resetting a running or dead rootns back to ROOTNS_READY?
When is_root is true, rootns->state == ROOTNS_EMPTY is only checked before
lookup_move_mount_from() and before namespace_lock() is taken, while
MNT_TREE_ROOTNS_INIT in do_move_mount() only checks whether
rootns_mnt_ns->root currently has an overmount:
CPU0 CPU1
move_mount_rootns(..., "/") move_mount_rootns(..., "/")
READ_ONCE(rootns->state) ==
ROOTNS_EMPTY
READ_ONCE(rootns->state) ==
ROOTNS_EMPTY
lookup_move_mount_from()
vfs_move_mount() -> attaches M1
rootns->root = M1
rootns->state = ROOTNS_READY
...
clone3(CLONE_INTO_ROOTNS)
rootns->state = ROOTNS_RUNNING
umount2("/", MNT_DETACH)
detaches M1 from nullfs
vfs_move_mount() -> attaches M2
spin_lock(&rootns->lock)
rootns->root = M2 <-- leaks M1 path
rootns->state = ROOTNS_READY
<-- resets state from RUNNING
Overwriting rootns->root without path_put() leaks M1's vfsmount and dentry
references and races with lockless readers of rootns->root in
filename_lookup() and copy_fs(). Resetting rootns->state to ROOTNS_READY
also allows a second clone3(CLONE_INTO_ROOTNS) to run the init bootstrap path
in copy_rootns(), overwriting rootns->init_pid without put_pid() and taking
an extra get_rootns() reference that exit_rootns() never drops.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117231352.3816603-1-jarkko@kernel.org?part=9
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 10/13] arch: Wire up rootns system calls
2026-11-17 23:13 ` [RFC PATCH v2 10/13] arch: Wire up rootns system calls Jarkko Sakkinen
@ 2026-11-18 23:15 ` sashiko-bot
0 siblings, 0 replies; 36+ messages in thread
From: sashiko-bot @ 2026-11-18 23:15 UTC (permalink / raw)
Cc: linux-security-module
> Now that the core root namespace lifecycle and VFS mount-tree
> installation are in place, expose rootns_create() (473), rootns_wait()
> (474), and rootns_kill() (475) across all architecture system call
> tables and asm-generic unistd.h.
>
> Co-developed-by: David Howells <dhowells@redhat.com>
> Signed-off-by: David Howells <dhowells@redhat.com>
> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117231352.3816603-1-jarkko@kernel.org?part=10
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 11/13] docs: Document root namespace uAPI
2026-11-17 23:13 ` [RFC PATCH v2 11/13] docs: Document root namespace uAPI Jarkko Sakkinen
@ 2026-11-18 23:15 ` sashiko-bot
0 siblings, 0 replies; 36+ messages in thread
From: sashiko-bot @ 2026-11-18 23:15 UTC (permalink / raw)
Cc: linux-security-module
> Userspace container managers need a clear specification of rootns state
> transitions, mount-tree construction, credential rules, and process
> creation semantics.
>
> Add Documentation/userspace-api/rootns.rst to include the kernel-doc
> sections and system call reference from kernel/rootns.c,
> include/uapi/linux/rootns.h, fs/fsopen.c, and fs/namespace.c.
>
> Co-developed-by: David Howells <dhowells@redhat.com>
> Signed-off-by: David Howells <dhowells@redhat.com>
> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117231352.3816603-1-jarkko@kernel.org?part=11
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [RFC PATCH v2 12/13] selftests/rootns: Add root namespace test suite
2026-11-17 23:13 ` [RFC PATCH v2 12/13] selftests/rootns: Add root namespace test suite Jarkko Sakkinen
@ 2026-11-18 23:15 ` sashiko-bot
0 siblings, 0 replies; 36+ messages in thread
From: sashiko-bot @ 2026-11-18 23:15 UTC (permalink / raw)
To: Jarkko Sakkinen
Cc: linux-mm, linux-security-module, Alexander Viro, Andrew Morton,
Andy Lutomirski, Ben Segall, Christian Brauner, David Hildenbrand,
David Howells, Davidlohr Bueso, Dietmar Eggemann, Ingo Molnar,
Jan Kara, Jonathan Corbet, John Johansen, Juri Lelli, Kees Cook,
K Prateek Nayak, Liam R. Howlett, Lorenzo Stoakes, Manfred Spraul,
Mel Gorman, Michal Hocko, Mike Rapoport, Neal Gompa, Paul Moore,
Pavel Tikhomirov, Peter Zijlstra, Randy Dunlap, Serge Hallyn,
Shuah Khan, Steven Rostedt, Suren Baghdasaryan,
Valentin Schneider, Vincent Guittot, Vlastimil Babka,
Zygmunt Krynicki
Thank you for your contribution! Sashiko AI review found 9 potential
issues to consider:
- [Medium] selftests/rootns: enter_unpriv_user_mntns() fails to restore
dumpability
- [Medium] selftests/rootns: PID 1 exit race with sibling tasks in
clone_concurrent
- [Medium] selftests/rootns: missing SKIP() in setup and silent skips in
child tests
- [Medium] selftests/rootns: setns tests fail to open /proc/self/ns/mnt
and hang
- [Medium] selftests/rootns: nested_ns fails with EPERM in unmapped user
namespace
- [Medium] selftests/rootns: fsconfig test fails with EPERM at
sys_fsopen() for sysfs
- [Low] selftests/rootns: stack direction and lifetime hazard in
clone_with_flags()
- [Low] selftests/rootns: fd leak in create_rootns_as_uid() when
waitpid() fails
- [Low] selftests/rootns: fallback syscall definitions omit MIPS ABI
offsets
--
commit 29bf6658ccf4cdfdf8e29f5c0581be3d7fb38e3f
Author: Jarkko Sakkinen <jarkko@kernel.org>
selftests/rootns: Add root namespace test suite
This commit adds a kselftest harness suite under
tools/testing/selftests/rootns to test root namespace creation,
clone3(CLONE_INTO_ROOTNS), mount configuration, and permission checks.
> diff --git a/tools/testing/selftests/rootns/smoke.c b/tools/testing/selftests/rootns/smoke.c
> new file mode 100644
> index 0000000000000..350e6e8e25236
> --- /dev/null
> +++ b/tools/testing/selftests/rootns/smoke.c
> @@ -0,0 +1,1381 @@
[ ... ]
> +#ifndef __NR_rootns_create
> +#ifdef __alpha__
> +#define __NR_rootns_create 583
> +#define __NR_rootns_wait 584
> +#define __NR_rootns_kill 585
> +#else
> +#define __NR_rootns_create 473
> +#define __NR_rootns_wait 474
> +#define __NR_rootns_kill 475
> +#endif
> +#endif
[Severity: Low]
Do these fallback syscall numbers need to account for the MIPS ABI base
offsets (4000 for o32, 5000 for n64, and 6000 for n32)? Without adding
the _MIPS_SIM offset, a standalone build on MIPS without updated kernel
headers will invoke the wrong syscalls.
[ ... ]
> +static int clone_with_flags(int flags)
> +{
> + const size_t stack_size = 64 * 1024;
> + void *stack;
> + pid_t pid;
> + int status;
> + int ret;
> +
> + stack = malloc(stack_size);
> + if (!stack)
> + return -ENOMEM;
> +
> + pid = clone(clone_exit, (char *)stack + stack_size,
> + SIGCHLD | flags, NULL);
> + if (pid < 0)
> + ret = -errno;
> + else if (waitpid(pid, &status, 0) < 0)
> + ret = -errno;
> + else if (!WIFEXITED(status) || WEXITSTATUS(status))
> + ret = -EIO;
> + else
> + ret = 0;
> +
> + free(stack);
> + return ret;
> +}
[Severity: Low]
Does passing (char *)stack + stack_size to clone() write past the end of
stack on upward-growing stack architectures such as PA-RISC? In addition,
if waitpid() fails (for example on EINTR), free(stack) runs while the
child may still be executing on that stack. Using sys_clone3() with a
NULL stack avoids both issues.
[ ... ]
> + if (!err) {
> + *cfd = recv_fd(sv[0]);
> + if (*cfd < 0)
> + err = errno;
> + }
> + close(sv[0]);
> +
> + if (waitpid(pid, &status, 0) != pid && !err)
> + err = errno;
> + if (!err && (!WIFEXITED(status) || WEXITSTATUS(status)))
> + err = ECHILD;
> +
> + return err ? -err : 0;
> +}
[Severity: Low]
Does create_rootns_as_uid() leak *cfd if recv_fd() succeeds but waitpid()
fails or the child exits non-zero?
[ ... ]
> +FIXTURE(rootns) {
> + int cfd;
> +};
> +
> +FIXTURE_SETUP(rootns) {
> + self->cfd = create_test_rootns(false, ROOTNS_ALL_NAMESPACES |
> + ROOTNS_KILL_ON_CLOSE |
> + ROOTNS_CLOSE_ON_EXEC);
> + ASSERT_GE(self->cfd, 0);
> +}
[Severity: Medium]
Should FIXTURE_SETUP(rootns) call SKIP() when create_test_rootns() fails
with ENOSYS, EPERM, EACCES, or ENOSPC? Because rootns is added to TARGETS
in tools/testing/selftests/Makefile while CONFIG_ROOTNS defaults to n,
asserting self->cfd >= 0 fails all 17 tests instead of skipping them when
CONFIG_ROOTNS is disabled or when the test runs without mount/namespace
privileges.
Similarly, pivot_root and mount_empty_path do not skip on EPERM,
mount_perms omits -ENOSPC from its SKIP() check, and the child processes
in mount_perms, clone_perms, and fsconfig call _exit(0) when prerequisites
are unavailable, reporting silent passes without a skip reason.
[ ... ]
> +TEST_F(rootns, nested_ns) {
> + pid_t pid;
> + int nsfd;
> +
> + nsfd = open("/proc/self/ns/mnt", O_RDONLY | O_CLOEXEC);
> + ASSERT_GE(nsfd, 0);
> +
> + pid = clone_into_rootns(self->cfd, 0);
> + ASSERT_GE(pid, 0);
> + if (pid == 0) {
> + close(self->cfd);
> +
> + if (unshare(CLONE_NEWNS))
> + _exit(1);
> + if (clone_with_flags(CLONE_NEWNS))
> + _exit(2);
> + if (unshare(CLONE_NEWUSER))
> + _exit(3);
> + if (clone_with_flags(CLONE_NEWUSER))
> + _exit(4);
[Severity: Medium]
Won't unshare(CLONE_NEWUSER) and clone_with_flags(CLONE_NEWUSER) here fail
with EPERM? self->cfd is created with ROOTNS_ALL_NAMESPACES (which
includes ROOTNS_USER), but no uid_map or gid_map is written for its user
namespace, so create_user_ns() rejects creating a child user namespace
because the caller's UID and GID are unmapped in parent_ns. Even if
self->cfd's user namespace were mapped, unshare(CLONE_NEWUSER) moves the
child into a second unmapped user namespace before
clone_with_flags(CLONE_NEWUSER) runs.
[ ... ]
> +TEST_F(rootns, setns_same) {
> + ssize_t nwritten;
> + pid_t pid1;
> + pid_t pid2;
> + char ch;
> + int nsfd;
> + int sv[2];
> +
> + ASSERT_EQ(socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0, sv), 0);
> +
> + pid1 = clone_into_rootns(self->cfd, 0);
> + ASSERT_GE(pid1, 0);
> + if (pid1 == 0) {
> + int ret;
> +
> + close(self->cfd);
> + close(sv[0]);
> + ret = send_unshared_mntns_and_wait(sv[1]);
> + close(sv[1]);
> + _exit(ret);
> + }
> + close(sv[1]);
> +
> + nsfd = recv_fd(sv[0]);
[Severity: Medium]
Does send_unshared_mntns_and_wait() fail with ENOENT here and leave the
parent hanging in recv_fd(sv[0])?
Both self->cfd (in setns_same) and beta_cfd (in setns_foreign below) are
created with create_test_rootns(false, ...), which mounts an empty tmpfs
at /proc instead of procfs. When the child calls
send_unshared_mntns_and_wait(), open("/proc/self/ns/mnt", ...) fails with
ENOENT and the child exits without sending a descriptor. Because sv is a
SOCK_DGRAM socketpair, closing sv[1] does not deliver EOF to sv[0], so
recv_fd(sv[0]) blocks until the test times out.
[ ... ]
> +static int enter_unpriv_user_mntns(uid_t drop_uid)
> +{
> + char map[32];
> + uid_t uid;
> + gid_t gid;
> + int fd;
> + int len;
> +
> + if (geteuid() == 0 &&
> + (setresgid(drop_uid, drop_uid, drop_uid) < 0 ||
> + setresuid(drop_uid, drop_uid, drop_uid) < 0))
> + return -errno;
> +
> + uid = geteuid();
> + gid = getegid();
> + if (unshare(CLONE_NEWUSER | CLONE_NEWNS) < 0)
> + return -errno;
> +
> + fd = open("/proc/self/setgroups", O_WRONLY | O_CLOEXEC);
> + if (fd >= 0) {
> + (void)write(fd, "deny\n", 5);
> + close(fd);
> + }
> +
> + fd = open("/proc/self/uid_map", O_WRONLY | O_CLOEXEC);
> + if (fd < 0)
> + return -errno;
[Severity: Medium]
When the test runs as root, does dropping privileges via setresgid() and
setresuid() clear task dumpability and cause open("/proc/self/uid_map",
O_WRONLY | O_CLOEXEC) to fail with EACCES?
Without prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) after setresuid(), files under
/proc/self/ remain owned by global root (0:0), which is unmapped in the
newly unshared user namespace. enter_unpriv_user_mntns() then returns
-EACCES, and all three callers (mount_perms, clone_perms, and fsconfig)
treat -EACCES as _exit(0), silently skipping their unprivileged permission
checks.
[ ... ]
> + ucfd = sys_rootns_create(ROOTNS_USER | ROOTNS_CLOSE_ON_EXEC);
> + if (ucfd < 0) {
> + if (errno == EPERM || errno == EACCES ||
> + errno == EINVAL || errno == ENOSPC)
> + _exit(0);
> + _exit(2);
> + }
> +
> + sfd = sys_fsopen("sysfs", 0);
> + if (sfd < 0) {
> + if (errno == ENODEV) {
> + close(ucfd);
> + _exit(0);
> + }
> + _exit(3);
> + }
> +
> + if (sys_fsconfig(sfd, FSCONFIG_SET_ROOTNS, NULL, NULL, ucfd) < 0)
> + _exit(4);
> + if (sys_fsconfig(sfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) != -1 ||
> + errno != EPERM)
> + _exit(5);
[Severity: Medium]
Doesn't sys_fsopen("sysfs", 0) fail with EPERM here before reaching
FSCONFIG_SET_ROOTNS?
enter_unpriv_user_mntns() unshares CLONE_NEWUSER | CLONE_NEWNS but keeps
the parent network namespace, so sysfs_init_fs_context() ->
kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET) rejects sys_fsopen("sysfs", 0)
with EPERM and the child exits with status 3. Furthermore, even if
CLONE_NEWNET were unshared, sysfs_init_fs_context() sets fc->global = true
and binds fc->user_ns to netns->user_ns, so FSCONFIG_CMD_CREATE would
succeed rather than failing with EPERM.
[ ... ]
> + ent_pid = clone_into_rootns(self->cfd, 0);
> + if (ent_pid < 0)
> + _exit(1);
> + if (ent_pid == 0) {
> + unsigned char my_pid = (unsigned char)getpid();
> +
> + if (write(ready_pipe[1], &my_pid, 1) != 1)
> + _exit(2);
> + close(ready_pipe[1]);
> + (void)read(hold_pipe[0], &ch, 1);
> + close(hold_pipe[0]);
> + _exit(0);
> + }
> +
> + close(ready_pipe[1]);
> + close(hold_pipe[0]);
> + close(self->cfd);
> + _exit(reap_child_exit_code(ent_pid) == 0 ? 0 : 3);
> + }
> + }
> +
> + close(start_pipe[0]);
> + close(ready_pipe[1]);
> + close(hold_pipe[0]);
> + close(start_pipe[1]);
> +
> + for (i = 0; i < 4; i++) {
> + unsigned char pid_byte = 0;
> +
> + ASSERT_EQ(read(ready_pipe[0], &pid_byte, 1), 1);
> + ASSERT_GE(pid_byte, 1);
> + ASSERT_LE(pid_byte, 4);
> + seen_mask |= 1U << pid_byte;
> + }
> + close(ready_pipe[0]);
> + close(hold_pipe[1]);
> +
> + ASSERT_EQ(seen_mask, 0x1eU);
> +
> + for (i = 0; i < 4; i++)
> + ASSERT_EQ(reap_child_exit_code(workers[i]), 0);
[Severity: Medium]
When close(hold_pipe[1]) wakes all four processes in the rootns PID
namespace at once, can PID 1 exit before PIDs 2..4 and kill them via
zap_pid_ns_processes()?
CPU0 (rootns PID 1) CPU1 (rootns PID 2)
read(hold_pipe[0]) returns 0
read(hold_pipe[0]) returns 0
_exit(0)
zap_pid_ns_processes()
send_sig_info(SIGKILL, p)
terminated by SIGKILL
worker: reap_child_exit_code() -> -2
worker exits with 3 <-- test fails
Because reap_child_exit_code() requires WIFEXITED(status), any non-init
sibling killed by SIGKILL before completing _exit(0) causes its worker to
exit with code 3 and fails the test.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117231352.3816603-1-jarkko@kernel.org?part=12
^ permalink raw reply [flat|nested] 36+ messages in thread
end of thread, other threads:[~2026-11-18 23:15 UTC | newest]
Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 23:13 [RFC PATCH v2 00/13] Namespace for namespace roots Jarkko Sakkinen
2026-11-17 23:13 ` [RFC PATCH v2 01/13] nsproxy: Pass nsproxy to create_new_namespaces() Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 02/13] rootns: Add core infrastructure for root namespaces Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 03/13] rootns: Track init lifecycle via copy_process() and pid_namespace Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 04/13] rootns: Add rootns_create() system call Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 05/13] rootns: Add rootns_wait() " Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 06/13] rootns: Add rootns_kill() " Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 07/13] fork: Support CLONE_INTO_ROOTNS in clone3() Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 08/13] fs: Support FSCONFIG_SET_ROOTNS in fsconfig() Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 09/13] fs: Support installing rootns mount trees via move_mount() Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 10/13] arch: Wire up rootns system calls Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 11/13] docs: Document root namespace uAPI Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 12/13] selftests/rootns: Add root namespace test suite Jarkko Sakkinen
2026-11-18 23:15 ` sashiko-bot
2026-11-17 23:13 ` [RFC PATCH v2 13/13] MAINTAINERS: Add entry for ROOT NAMESPACE Jarkko Sakkinen
2026-11-18 14:47 ` [RFC PATCH v2 00/13] Namespace for namespace roots Josef Bacik
2026-11-18 15:28 ` Jarkko Sakkinen
2026-11-18 15:39 ` Jarkko Sakkinen
2026-11-18 15:46 ` Jarkko Sakkinen
2026-11-18 16:59 ` Andy Lutomirski
2026-11-18 17:04 ` Jarkko Sakkinen
2026-11-18 17:08 ` Jarkko Sakkinen
2026-11-18 17:30 ` Jarkko Sakkinen
2026-11-18 17:46 ` Andy Lutomirski
2026-11-18 18:23 ` Jarkko Sakkinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox