From: sashiko-bot@kernel.org
To: "Jarkko Sakkinen" <jarkko@kernel.org>
Cc: linux-mm@kvack.org, linux-security-module@vger.kernel.org,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Ben Segall" <bsegall@google.com>,
"Christian Brauner" <brauner@kernel.org>,
"David Hildenbrand" <david@kernel.org>,
"David Howells" <dhowells@redhat.com>,
"Davidlohr Bueso" <dave@stgolabs.net>,
"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
"Ingo Molnar" <mingo@redhat.com>, "Jan Kara" <jack@suse.cz>,
"Jonathan Corbet" <corbet@lwn.net>,
"Juri Lelli" <juri.lelli@redhat.com>,
"Kees Cook" <kees@kernel.org>,
"K Prateek Nayak" <kprateek.nayak@amd.com>,
"Liam R. Howlett" <liam@infradead.org>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Manfred Spraul" <manfred@colorfullife.com>,
"Mel Gorman" <mgorman@suse.de>, "Michal Hocko" <mhocko@suse.com>,
"Mike Rapoport" <rppt@kernel.org>, "Neal Gompa" <neal@gompa.dev>,
"Paul Moore" <paul@paul-moore.com>,
"Pavel Tikhomirov" <ptikhomirov@virtuozzo.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Serge Hallyn" <sergeh@kernel.org>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Valentin Schneider" <vschneid@redhat.com>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
"Vlastimil Babka" <vbabka@kernel.org>
Subject: Re: [RFC PATCH 07/13] rootns: Add rootns_enter() system call
Date: Wed, 18 Nov 2026 05:09:49 +0000 [thread overview]
Message-ID: <sashiko-outbox-220142@kernel.org> (raw)
In-Reply-To: <20261117050841.3289652-8-jarkko@kernel.org>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [Critical] cred: privilege escalation and NNP bypass in
may_enter_rootns_creds()
- [High] cred: missing dumpability reset in copy_creds() on rootns entry
- [High] rootns: refcount underflow and UAF of rootns via setns() on
pid_ns
- [High] rootns: sys_rootns_enter() calls kernel_clone() without arch
fork wrappers
- [Medium] nsproxy: missing timens_commit() in copy_namespaces() on
rootns entry
- [Medium] fork: stale rootns->root used in copy_fs() after pivot_root()
- [Medium] rootns: rootns_may_setns() rejects setns() to inherited
rootns namespaces
--
commit 2b3b027946b3cddbb69540b1d520fd1496bf137c
Author: Jarkko Sakkinen <jarkko@kernel.org>
rootns: Add rootns_enter() system call
This commit introduces the rootns_enter() system call to fork a child
process directly into a configured rootns, along with credential checks
and namespace provenance tracking for setns().
> diff --git a/kernel/cred.c b/kernel/cred.c
> index d01df40a9a386..97d334db7758a 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 (task_no_new_privs(current) || 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 process bypass PR_SET_NO_NEW_PRIVS, regain dropped credentials, or
escape an LSM domain through may_enter_rootns_creds()?
When may_enter_rootns_creds() succeeds, copy_creds() replaces the child's
entire struct cred with dup_creds(rootns->cred). The early return runs
before the task_no_new_privs(current) check and only compares euid, egid,
and cred_cap_issubset(old, target). For a ROOTNS_USER namespace where
old->euid is target->user_ns->owner, cred_cap_issubset() returns true
even if old dropped capabilities or set PR_SET_NO_NEW_PRIVS, letting the
child gain full capabilities in target->user_ns.
Even in the same user namespace, the early return does not check real,
saved, or fs UIDs/GIDs, group_info, cap_effective, cap_bset, securebits,
or the LSM security blob. A process that creates a rootns and later
drops real/saved UIDs, clears supplementary groups, drops bounding set
bits, or restricts itself with Landlock can call rootns_enter() to spawn
a child with the original unrestricted rootns->cred.
In the second branch, CAP_SETUID and CAP_SETGID are checked only against
target->user_ns->parent without checking old->user_ns or verifying that
target's UIDs, GIDs, and supplementary groups are mapped into
target->user_ns->parent. Conversely, when old->user_ns == target->user_ns,
a caller holding CAP_SYS_ADMIN, CAP_SETUID, and CAP_SETGID in old->user_ns
is rejected if its euid or egid differs from target.
> @@ -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: High]
Does switching credentials to rootns->cred in copy_creds() leave
p->exec_state->dumpable set to TASK_DUMPABLE_OWNER?
In copy_process(), copy_exec_state() copies current->exec_state->dumpable
into p->exec_state before copy_creds() runs. Unlike commit_creds(),
copy_creds() does not reset dumpable to suid_dumpable when UIDs, GIDs, or
capabilities change. When a privileged daemon calls rootns_enter() to
fork into a rootns owned by an unprivileged user, processes inside the
target user namespace pass task_still_dumpable() and can ptrace the child
before execve(), reading the daemon's duplicated memory or stealing its
open file descriptors via pidfd_getfd().
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 99e22b3cd213e..5e23d36b7ac3e 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
[ ... ]
> @@ -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;
> }
[Severity: Medium]
If a process inside a running rootns changes the root mount with
pivot_root() or overmounts "/", will subsequent rootns_enter() calls get
a stale root path here?
rootns->root holds the initial mount installed by MOVE_MOUNT_T_ROOTNS_ROOT
and is not updated by pivot_root(). Setting tsk->fs root and pwd to
&rootns->root gives newly entering tasks the old root mount instead of
the current root of rootns->ns->mnt_ns.
> diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
> index a76837b3ee332..0c6407757d896 100644
> --- a/kernel/nsproxy.c
> +++ b/kernel/nsproxy.c
> @@ -169,13 +169,21 @@ struct nsproxy *create_new_namespaces(u64 flags,
> /*
> * called from clone. This now handles copy for nsproxy and all
> * namespaces therein.
> + *
> + * Namespaces derived from a rootns member inherit the same rootns domain.
> */
> -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 without calling timens_commit() leave the child
with the parent's VDSO vvar mappings when entering a rootns in a
different time namespace?
copy_mm() runs before copy_namespaces() and duplicates the caller's vvar
PTEs into tsk->mm. When old_ns->time_ns differs from rootns->ns->time_ns,
skipping timens_commit() leaves the old vvar mappings in place until
execve(), so vDSO clock_gettime() in the child reads the wrong time
namespace offsets.
> diff --git a/kernel/rootns.c b/kernel/rootns.c
> index f59b2fe9910de..e286c1e753b71 100644
> --- a/kernel/rootns.c
> +++ b/kernel/rootns.c
[ ... ]
> +static atomic64_t rootns_id = ATOMIC64_INIT(0);
> +
> +static void rootns_tag_namespaces(struct rootns *c, const struct nsproxy *old)
> +{
> + struct nsproxy *ns = c->ns;
> +
> + if (c->cred->user_ns != current_user_ns())
> + c->cred->user_ns->ns.rootns_id = c->id;
> + from_mnt_ns(ns->mnt_ns)->rootns_id = c->id;
> + ns->pid_ns_for_children->ns.rootns_id = c->id;
> + if (ns->uts_ns != old->uts_ns)
> + ns->uts_ns->ns.rootns_id = c->id;
> + if (ns->ipc_ns != old->ipc_ns)
> + ns->ipc_ns->ns.rootns_id = c->id;
> + if (ns->cgroup_ns != old->cgroup_ns)
> + ns->cgroup_ns->ns.rootns_id = c->id;
> + if (ns->net_ns != old->net_ns)
> + ns->net_ns->ns.rootns_id = c->id;
> +}
> +
> +bool rootns_may_setns(struct rootns *rootns, struct ns_common *ns)
> +{
> + if (!ns)
> + return false;
> + if (!rootns || is_current_namespace(ns))
> + return true;
> +
> + return ns->rootns_id == rootns->id;
> +}
[Severity: Medium]
Does rootns_may_setns() reject intra-rootns setns() back to a namespace
that the rootns inherited at creation time?
rootns_tag_namespaces() only sets c->id on newly created namespaces, so
any namespace inherited from the creator (such as time_ns, or UTS, IPC,
cgroup, net, or user namespaces omitted from rootns_create() flags) keeps
its previous rootns_id. If a task inside the rootns unshares one of
those namespace types, is_current_namespace(ns) becomes false for the
rootns's initial namespace and ns->rootns_id != rootns->id, causing
setns() back to PID 1's namespace to fail with -EPERM.
> @@ -249,6 +308,7 @@ static struct rootns *create_rootns(unsigned int flags)
> c->ns = ns;
> ns->rootns = c;
> ns->pid_ns_for_children->rootns = c;
> + rootns_tag_namespaces(c, current->nsproxy);
> nsproxy_ns_active_get(ns);
>
> return c;
[Severity: High]
Can an external task joining ns->pid_ns_for_children via setns() trigger
a refcount underflow and use-after-free on struct rootns?
create_rootns() sets ns->pid_ns_for_children->rootns = c without taking a
reference on c, and marks ns->pid_ns_for_children active in the namespace
tree via nsproxy_ns_active_get(ns). The reference on c that pairs with
exit_rootns()'s put_rootns(c) is only acquired in copy_rootns() when PID 1
is forked through sys_rootns_enter() in state ROOTNS_FORKING:
kernel/rootns.c:copy_rootns() {
if (likely(!c || READ_ONCE(c->state) != ROOTNS_FORKING))
return;
scoped_guard(spinlock, &c->lock) {
get_rootns(c);
...
}
Because rootns_may_setns() returns true when task_rootns(current) is NULL,
a process outside any rootns can open ns->pid_ns_for_children from nsfs,
call setns(fd, CLONE_NEWPID), and fork() PID 1 with args->rootns == NULL.
copy_rootns() then skips get_rootns(c), but when that child exits,
zap_pid_ns_processes() -> exit_rootns() still calls put_rootns(c),
dropping the rootns fd's reference and freeing c while the fd is still
open (or dereferencing a dangling pid_ns->rootns if the fd was already
closed, since put_rootns() does not clear pid_ns->rootns).
> @@ -455,3 +515,85 @@ SYSCALL_DEFINE2(rootns_kill, int, rootnsfd, int, sig)
[ ... ]
> +SYSCALL_DEFINE1(rootns_enter, int, rootnsfd)
> +{
[ ... ]
> + args.rootns = rootns;
> + ret = kernel_clone(&args);
[Severity: High]
Is calling kernel_clone() directly from a regular C syscall safe on
architectures that require fork/clone entry wrappers?
On alpha, m68k, parisc, mips, arc, nios2, and openrisc, fork and clone
syscalls enter through assembly wrappers that allocate a switch_stack or
save callee-saved registers before calling C code, which copy_thread()
then reads from the stack. On sparc, the wrapper must flush register
windows via synchronize_user_stack(), and copy_thread() checks whether
UREG_G1 is __NR_clone3 to return 0 in the child instead of the parent's
PID. Calling kernel_clone() from sys_rootns_enter() bypasses those paths
and corrupts the child's register state or return value on those
architectures.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117050841.3289652-1-jarkko@kernel.org?part=7
next prev parent reply other threads:[~2026-11-18 5:09 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 5:08 [RFC PATCH 00/13] Namespace for namespace roots Jarkko Sakkinen
2026-11-17 5:08 ` [RFC PATCH 01/13] nsproxy: Pass nsproxy to create_new_namespaces() Jarkko Sakkinen
2026-11-18 5:09 ` sashiko-bot
2026-11-17 5:08 ` [RFC PATCH 02/13] rootns: Add core infrastructure for root namespaces Jarkko Sakkinen
2026-11-18 5:09 ` sashiko-bot
2026-11-17 5:08 ` [RFC PATCH 03/13] rootns: Track init lifecycle via copy_process() and pid_namespace Jarkko Sakkinen
2026-11-18 5:09 ` sashiko-bot
2026-11-17 5:08 ` [RFC PATCH 04/13] rootns: Add rootns_create() system call Jarkko Sakkinen
2026-11-18 5:09 ` sashiko-bot
2026-11-17 5:08 ` [RFC PATCH 05/13] rootns: Add rootns_wait() " Jarkko Sakkinen
2026-11-18 5:09 ` sashiko-bot
2026-11-17 5:08 ` [RFC PATCH 06/13] rootns: Add rootns_kill() " Jarkko Sakkinen
2026-11-18 5:09 ` sashiko-bot
2026-11-17 5:08 ` [RFC PATCH 07/13] rootns: Add rootns_enter() " Jarkko Sakkinen
2026-11-17 17:42 ` Andy Lutomirski
2026-11-17 20:03 ` Jarkko Sakkinen
2026-11-17 20:53 ` Andy Lutomirski
2026-11-18 5:09 ` sashiko-bot [this message]
2026-11-17 5:08 ` [RFC PATCH 08/13] fs: Support FSCONFIG_SET_ROOTNS in fsconfig() Jarkko Sakkinen
2026-11-18 5:09 ` sashiko-bot
2026-11-17 5:08 ` [RFC PATCH 09/13] fs: Support installing rootns mount trees via move_mount() Jarkko Sakkinen
2026-11-18 5:09 ` sashiko-bot
2026-11-17 5:08 ` [RFC PATCH 10/13] arch: Wire up rootns system calls Jarkko Sakkinen
2026-11-18 5:09 ` sashiko-bot
2026-11-17 5:08 ` [RFC PATCH 11/13] docs: Document root namespace uAPI Jarkko Sakkinen
2026-11-18 5:09 ` sashiko-bot
2026-11-17 5:08 ` [RFC PATCH 12/13] selftests/rootns: Add root namespace test suite Jarkko Sakkinen
2026-11-18 5:09 ` sashiko-bot
2026-11-17 5:08 ` [RFC PATCH 13/13] MAINTAINERS: Add entry for ROOT NAMESPACE Jarkko Sakkinen
2026-11-17 11:10 ` [RFC PATCH 00/13] Namespace for namespace roots Jarkko Sakkinen
2026-11-17 17:44 ` Andy Lutomirski
2026-11-17 18:48 ` Jarkko Sakkinen
2026-11-17 19:10 ` Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-220142@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=bsegall@google.com \
--cc=corbet@lwn.net \
--cc=dave@stgolabs.net \
--cc=david@kernel.org \
--cc=dhowells@redhat.com \
--cc=dietmar.eggemann@arm.com \
--cc=jack@suse.cz \
--cc=jarkko@kernel.org \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kprateek.nayak@amd.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=linux-security-module@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=manfred@colorfullife.com \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=neal@gompa.dev \
--cc=paul@paul-moore.com \
--cc=peterz@infradead.org \
--cc=ptikhomirov@virtuozzo.com \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sergeh@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=viro@zeniv.linux.org.uk \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.