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>,
"Andy Lutomirski" <luto@amacapital.net>,
"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>,
"John Johansen" <john.johansen@canonical.com>,
"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>,
"Zygmunt Krynicki" <zygmunt.krynicki@canonical.com>
Subject: Re: [RFC PATCH v2 08/13] fs: Support FSCONFIG_SET_ROOTNS in fsconfig()
Date: Wed, 18 Nov 2026 23:15:19 +0000 [thread overview]
Message-ID: <sashiko-outbox-222162@kernel.org> (raw)
In-Reply-To: <20261117231352.3816603-9-jarkko@kernel.org>
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
next prev parent reply other threads:[~2026-11-18 23:15 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
2026-11-19 17:30 ` Josef Bacik
2026-11-19 17:43 ` Jarkko Sakkinen
2026-11-19 17:51 ` Jarkko Sakkinen
2026-11-19 22:50 ` Andy Lutomirski
2026-11-19 23:27 ` Andy Lutomirski
2026-11-20 12:32 ` Alexander Mikhalitsyn
2026-11-20 13:13 ` Jarkko Sakkinen
2026-11-20 13:24 ` Alexander Mikhalitsyn
2026-11-20 13:57 ` 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-222162@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=john.johansen@canonical.com \
--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=luto@amacapital.net \
--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 \
--cc=zygmunt.krynicki@canonical.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.