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 08/13] fs: Support FSCONFIG_SET_ROOTNS in fsconfig()
Date: Wed, 18 Nov 2026 05:09:51 +0000 [thread overview]
Message-ID: <sashiko-outbox-220143@kernel.org> (raw)
In-Reply-To: <20261117050841.3289652-9-jarkko@kernel.org>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Critical] fs: fsconfig_set_rootns() replaces fc->net_ns after
init_fs_context() runs
- [High] fs: proc: missing pidns_is_ancestor() check in
proc_set_rootns()
- [High] fs: broken fc->user_ns delegation in fsconfig_set_rootns()
--
commit c40a472d45a1ca48a5976af47a79bdbf753d63b0
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 filesystem context can be bound to a target rootns file descriptor
before parameters are parsed.
> diff --git a/fs/fsopen.c b/fs/fsopen.c
> index 70024870fefa2..98d407fd249bc 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;
> +
> + 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 fc->fs_type->init_fs_context()
has already run during fsopen() cause a use-after-free on ctx->net in kAFS?
alloc_fs_context() invokes init_fs_context() during fsopen(), where
afs_init_fs_context() caches an unreferenced net_generic pointer from the
initial fc->net_ns:
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), an unprivileged caller
in a user and network namespace can let that initial network namespace exit so
cleanup_net() frees struct net and its pernet struct afs_net, and then call
fsconfig(fsfd, FSCONFIG_SET_STRING, "source", "#cell:vol", 0) to trigger a
use-after-free in afs_parse_source() -> afs_lookup_cell(ctx->net, ...).
In addition, nfsd_init_fs_context() and rpc_init_fs_context() set fc->user_ns
from fc->net_ns->user_ns during fsopen(), so switching fc->net_ns afterwards
leaves fc->user_ns bound to the fsopen() caller's user namespace and bypasses
the sget_fc() non-initial user_ns check. nfs_init_fs_context() also evaluates
fc->net_ns != &init_net during fsopen() when setting NFS_MOUNT_NETUNREACH_FATAL,
which becomes stale once fc->net_ns changes.
> + 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;
> +}
[Severity: High]
Does gating the fc->user_ns update on kuid_has_mapping() and
kgid_has_mapping() silently skip user namespace delegation for an unentered
ROOTNS_USER rootns?
When rootns_create() creates a rootns with ROOTNS_USER, create_user_ns()
initializes user_ns->uid_map and user_ns->gid_map with zero extents, and
sys_rootns_enter() rejects entering the rootns with -ENOENT while its state is
ROOTNS_EMPTY before "/" is mounted. Because no ID mappings can exist yet in
that unentered user namespace (or when a host manager's fsuid/fsgid lies
outside the container's subordinate ID range), kuid_has_mapping() and
kgid_has_mapping() return false and fsconfig_set_rootns() returns 0 without
updating fc->user_ns, causing privileged managers to create init_user_ns-owned
superblocks and unprivileged callers to fail mount_capable(fc) with -EPERM.
Meanwhile, mqueue_set_rootns() unconditionally sets fc->user_ns to
ctx->ipc_ns->user_ns even when current_fsuid() and current_fsgid() are
unmapped there, leaving the root inode created by mqueue_fill_super() ->
mqueue_get_inode() with unmapped i_uid and i_gid. Conversely, when ID
mappings do exist and fc->user_ns is switched to a target user_ns that differs
from current_user_ns(), FS_USERNS_MOUNT filesystems such as overlayfs
(ovl_fill_super() and ovl_parse_param()) and binfmt_misc (bm_fill_super())
explicitly check fc->user_ns != current_user_ns() and fail with -EINVAL.
[ ... ]
> 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
[ ... ]
> +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]
Does proc_set_rootns() allow a task in a child or sibling PID namespace to
mount procfs for a non-descendant PID namespace by omitting a
pidns_is_ancestor() check?
proc_parse_pidns_param(), pidns_install(), and sys_rootns_enter() all require
pidns_is_ancestor(target, task_active_pid_ns(current)) so a process confined
to a sub-PID namespace cannot access or mount procfs for an ancestor or
sibling PID namespace. Because fsconfig_set_rootns() only checks
ns_capable(user_ns, CAP_SYS_ADMIN) and proc_set_rootns() unconditionally binds
ctx->pid_ns to rootns->ns->pid_ns_for_children, a process in a child PID
namespace within the same user namespace that receives a rootnsfd can mount
procfs for that outer or sibling PID namespace.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117050841.3289652-1-jarkko@kernel.org?part=8
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
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 [this message]
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-220143@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox