From: sashiko-bot@kernel.org
To: "Jarkko Sakkinen" <jarkko@kernel.org>,
"David Howells" <dhowells@redhat.com>
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>,
"Anna-Maria Behnsen" <anna-maria@linutronix.de>,
"Ben Segall" <bsegall@google.com>,
"Christian Brauner" <brauner@kernel.org>,
"David Hildenbrand" <david@kernel.org>,
"Davidlohr Bueso" <dave@stgolabs.net>,
"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
"Frederic Weisbecker" <frederic@kernel.org>,
"Ingo Molnar" <mingo@redhat.com>, "Jan Kara" <jack@suse.cz>,
"John Johansen" <john.johansen@canonical.com>,
"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>,
"Thomas Gleixner" <tglx@kernel.org>,
"Valentin Schneider" <vschneid@redhat.com>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
"Vincenzo Frascino" <vincenzo.frascino@arm.com>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Zygmunt Krynicki" <zygmunt.krynicki@canonical.com>
Subject: Re: [RFC PATCH v3 08/13] fs: Support FSCONFIG_SET_ROOTNS in fsconfig()
Date: Thu, 19 Nov 2026 19:36:57 +0000 [thread overview]
Message-ID: <sashiko-outbox-223950@kernel.org> (raw)
In-Reply-To: <20261118193539.240065-9-jarkko@kernel.org>
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] fs: unprivileged devpts mount via fsconfig_set_rootns()
bypasses pty_reserve
- [High] fs: alloc_mnt_ns(fc->user_ns) in fsmount() breaks submount
MNT_LOCKED
- [Medium] fs: missing FS_CONTEXT_FAILED transition on set_rootns()
error
- [Medium] fs: fsconfig_set_rootns() loses cpuset context state on
re-init
- [Medium] fs: may_mount() in fsmount() bypasses fc->user_ns capability
check
- [Low] fs: missing @init kernel-doc entry in alloc_fs_context()
--
commit fada980b534067d9740aa79ea2751dbe127d6be7
Author: Jarkko Sakkinen <jarkko@kernel.org>
fs: Support FSCONFIG_SET_ROOTNS in fsconfig()
This commit adds FSCONFIG_SET_ROOTNS to bind a newly opened fs_context to
a target rootns before supplying parameters, allowing unprivileged callers
to open FS_USERNS_MOUNT contexts and configure mounts for a rootns where
they hold CAP_SYS_ADMIN.
> diff --git a/fs/fs_context.c b/fs/fs_context.c
> index a50584df97bea..542dede2f8643 100644
> --- a/fs/fs_context.c
> +++ b/fs/fs_context.c
> @@ -259,7 +259,8 @@ static struct fs_context *alloc_fs_context(struct file_system_type *fs_type,
> struct dentry *reference,
> unsigned int sb_flags,
> unsigned int sb_flags_mask,
> - enum fs_context_purpose purpose)
> + enum fs_context_purpose purpose,
> + bool init)
> {
[Severity: Low]
The kernel-doc comment above alloc_fs_context() is missing an @init entry
for the new parameter.
[ ... ]
> diff --git a/fs/fsopen.c b/fs/fsopen.c
> index 70024870fefa2..3e36270baadb3 100644
> --- a/fs/fsopen.c
> +++ b/fs/fsopen.c
> @@ -41,6 +46,76 @@ 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, allowing unprivileged callers to configure ``FS_USERNS_MOUNT``
> + * filesystems without entering the user namespace first.
> + *
> + * The context is initialized against the ``rootns`` network namespace,
> + * ``fc->user_ns`` is delegated to the ``rootns`` user namespace for
> + * ``FS_USERNS_MOUNT`` and ``FS_USERNS_DELEGATABLE`` filesystems when the
> + * mounter ``fsuid``/``fsgid`` map into it or the caller lacks
> + * ``CAP_SYS_ADMIN`` in its own 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;
> + int ret;
> +
> + if (!is_rootns_file(param->file))
> + return -EINVAL;
> +
> + c = param->file->private_data;
> + user_ns = c->user_ns;
> + if (!ns_capable(user_ns, CAP_SYS_ADMIN))
> + return -EPERM;
> +
> + if (fc->need_free && fc->ops && fc->ops->free)
> + fc->ops->free(fc);
> + fc->need_free = false;
> + fc->fs_private = NULL;
> + fc->s_fs_info = NULL;
> + fc->ops = NULL;
> + fc->sb_flags = 0;
> + fc->global = false;
> + security_free_mnt_opts(&fc->security);
> +
> + put_net(fc->net_ns);
> + fc->net_ns = get_net(c->ns->net_ns);
> + put_user_ns(fc->user_ns);
> + if ((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)) ||
> + !ns_capable(fc->cred->user_ns, CAP_SYS_ADMIN)))
> + fc->user_ns = get_user_ns(user_ns);
> + else
> + fc->user_ns = get_user_ns(fc->cred->user_ns);
> +
> + ret = fc->fs_type->init_fs_context(fc);
[Severity: Medium]
Does re-calling fc->fs_type->init_fs_context(fc) here lose the cpuset
configuration when fsopen("cpuset", 0) was opened by a caller with
may_mount() == true?
During the initial fs_context_for_mount() in fsopen(),
cpuset_init_fs_context() configures cpuset_fs_context_ops,
ctx->subsys_mask, and CGRP_ROOT_NOPREFIX, and then replaces fc->fs_type
with &cgroup_fs_type:
kernel/cgroup/cgroup.c:cpuset_init_fs_context() {
...
get_filesystem(&cgroup_fs_type);
put_filesystem(fc->fs_type);
fc->fs_type = &cgroup_fs_type;
...
}
When fsconfig_set_rootns() frees the initial context and calls
fc->fs_type->init_fs_context(fc) again, it invokes
cgroup_init_fs_context() instead of cpuset_init_fs_context(), leaving
ctx->subsys_mask as 0 and fc->ops as &cgroup1_fs_context_ops so cpuset
parameter parsing or superblock creation fails.
> + if (ret < 0) {
> + fc->phase = FS_CONTEXT_FAILED;
> + return ret;
> + }
> + fc->need_free = true;
> +
> + if (fc->ops->set_rootns) {
> + ret = fc->ops->set_rootns(fc, c);
> + if (ret < 0)
> + return ret;
> + }
[Severity: Medium]
Should fc->phase be set to FS_CONTEXT_FAILED when fc->ops->set_rootns()
fails?
By the time set_rootns() runs, the prior filesystem-private state has been
freed, fc->net_ns and fc->user_ns have been overwritten, and
init_fs_context() has re-run in the fsconfig() caller's task context. If
proc_set_rootns() returns -EINVAL, leaving fc->phase in
FS_CONTEXT_CREATE_NS (or FS_CONTEXT_AWAITING_NS) with fc->rootns_bound
still false leaves a partially mutated context usable for subsequent
parameter parsing, superblock creation, or repeated FSCONFIG_SET_ROOTNS
calls.
[ ... ]
> @@ -137,17 +214,23 @@ SYSCALL_DEFINE2(fsopen, const char __user *, _fs_name, unsigned int, flags)
>
> audit_log_fsopen(fs_name);
>
> - fs_type = get_fs_type(fs_name);
> + fs_type = priv ? get_fs_type(fs_name) : get_fs_type_noload(fs_name);
> kfree(fs_name);
> if (!fs_type)
> - return -ENODEV;
> + return priv ? -ENODEV : -EPERM;
>
> - fc = fs_context_for_mount(fs_type, 0);
> + if (!priv && !(fs_type->fs_flags & FS_USERNS_MOUNT)) {
> + put_filesystem(fs_type);
> + return -EPERM;
> + }
> +
> + fc = priv ? fs_context_for_mount(fs_type, 0) :
> + fs_context_for_unpriv_mount(fs_type);
[Severity: High]
Does allowing an unprivileged caller in the initial mount namespace to
open and configure a devpts context via FSCONFIG_SET_ROOTNS bypass
pty_reserve?
devpts has FS_USERNS_MOUNT set, and devpts_init_fs_context() grants access
to the reserved PTY pool solely based on whether current is in the initial
mount namespace:
fs/devpts/inode.c:devpts_init_fs_context() {
...
if (fc->purpose == FS_CONTEXT_FOR_MOUNT &&
current->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns)
fsi->mount_opts.reserve = true;
...
}
Previously, fsopen() required may_mount(), forcing unprivileged callers to
unshare a mount namespace first. With this regression, an unprivileged
user in init_task.nsproxy->mnt_ns can open devpts, bind it to a userns via
FSCONFIG_SET_ROOTNS (which runs devpts_init_fs_context() while still in
the initial mount namespace, setting fsi->mount_opts.reserve = true), and
allocate PTYs from the host emergency reserve up to pty_limit.
[ ... ]
> diff --git a/fs/namespace.c b/fs/namespace.c
> index 781380945d784..a6c0a31e275ae 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -4658,6 +4659,16 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
> if (ret)
> return ret;
>
> + if (!(flags & FSMOUNT_NAMESPACE)) {
> + if (fc->rootns_bound) {
> + if (!ns_capable(fc->user_ns, CAP_SYS_ADMIN) &&
> + !may_mount())
> + return -EPERM;
> + } else if (!may_mount()) {
> + return -EPERM;
> + }
> + }
[Severity: Medium]
When fc->rootns_bound is true, can a caller lacking CAP_SYS_ADMIN in
fc->user_ns bypass the fc->user_ns capability check by satisfying
may_mount() in its own unprivileged mount namespace (or by passing
FSMOUNT_NAMESPACE)?
Because alloc_mnt_ns() below unconditionally uses fc->user_ns whenever
fc->rootns_bound is true, a task that passes this check via may_mount() in
an unrelated user namespace still allocates the anonymous mount namespace
in fc->user_ns and charges UCOUNT_MNT_NAMESPACES against fc->user_ns.
> +
> /* There must be a valid superblock or we can't mount it */
> ret = -EINVAL;
> if (!fc->root)
> @@ -4699,7 +4710,8 @@ 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->rootns_bound ? fc->user_ns :
> + current->nsproxy->mnt_ns->user_ns, true);
[Severity: High]
Does allocating fsmount()'s anonymous mount namespace in fc->user_ns leave
host submounts without MNT_LOCKED when an external manager in init_user_ns
assembles a mount tree for an unprivileged rootns?
When a manager in init_user_ns creates a rootns-bound anonymous root mount
(so dest_mnt->mnt_ns is anonymous with user_ns == fc->user_ns) and attaches
a host submount from init_user_ns onto it via move_mount(),
attach_recursive_mnt() compares child->mnt_parent->mnt_ns->user_ns
(fc->user_ns) against current->nsproxy->mnt_ns->user_ns (&init_user_ns):
fs/namespace.c:attach_recursive_mnt() {
...
if (is_anon_ns(ns))
user_ns = current->nsproxy->mnt_ns->user_ns;
else
user_ns = ns->user_ns;
...
/* Notice when we are propagating across user namespaces */
if (child->mnt_parent->mnt_ns->user_ns != user_ns)
lock_mnt_tree(child);
...
}
lock_mnt_tree(child) only sets MNT_LOCKED on descendants p != child,
leaving child itself unlocked, and commit_tree(child) then moves child into
the anonymous mount namespace owned by fc->user_ns. When the assembled
anonymous tree is later moved into the target mount namespace (also owned
by fc->user_ns), the user namespaces match, so attach_recursive_mnt() does
not lock the tree and unprivileged users in the target namespace can
unmount the host submount to expose the underlying directory. Conversely,
attaching a submount that was also created with FSCONFIG_SET_ROOTNS for
fc->user_ns onto the anonymous root mount sees
child->mnt_parent->mnt_ns->user_ns != user_ns and spuriously runs
lock_mnt_tree().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118193539.240065-1-jarkko@kernel.org?part=8
next prev parent reply other threads:[~2026-11-19 19:37 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 19:35 [RFC PATCH v3 00/13] Namespace for namespace roots Jarkko Sakkinen
2026-11-18 19:35 ` [RFC PATCH v3 01/13] nsproxy: Pass nsproxy to create_new_namespaces() Jarkko Sakkinen
2026-11-18 19:35 ` [RFC PATCH v3 02/13] rootns: Add core infrastructure for root namespaces Jarkko Sakkinen
2026-11-18 19:35 ` [RFC PATCH v3 03/13] rootns: Track init lifecycle via copy_process() and pid_namespace Jarkko Sakkinen
2026-11-18 19:35 ` [RFC PATCH v3 04/13] rootns: Add rootns_create() system call Jarkko Sakkinen
2026-11-18 19:35 ` [RFC PATCH v3 05/13] rootns: Add rootns_wait() " Jarkko Sakkinen
2026-11-19 19:36 ` sashiko-bot
2026-11-18 19:35 ` [RFC PATCH v3 06/13] rootns: Add rootns_kill() " Jarkko Sakkinen
2026-11-18 19:35 ` [RFC PATCH v3 07/13] fork: Support CLONE_INTO_ROOTNS in clone3() Jarkko Sakkinen
2026-11-19 19:36 ` sashiko-bot
2026-11-18 19:35 ` [RFC PATCH v3 08/13] fs: Support FSCONFIG_SET_ROOTNS in fsconfig() Jarkko Sakkinen
2026-11-19 19:36 ` sashiko-bot [this message]
2026-11-18 19:35 ` [RFC PATCH v3 09/13] fs: Support MOVE_MOUNT_T_MNTNS in move_mount() Jarkko Sakkinen
2026-11-19 19:36 ` sashiko-bot
2026-11-18 19:35 ` [RFC PATCH v3 10/13] arch: Wire up rootns system calls Jarkko Sakkinen
2026-11-18 19:35 ` [RFC PATCH v3 11/13] docs: Document root namespace uAPI Jarkko Sakkinen
2026-11-18 19:35 ` [RFC PATCH v3 12/13] selftests/rootns: Add root namespace test suite Jarkko Sakkinen
2026-11-19 19:37 ` sashiko-bot
2026-11-18 19:35 ` [RFC PATCH v3 13/13] MAINTAINERS: Add entry for ROOT NAMESPACE Jarkko Sakkinen
2026-11-18 19:54 ` [RFC PATCH v3 00/13] Namespace for namespace roots Jarkko Sakkinen
2026-11-18 20:42 ` Jarkko Sakkinen
2026-11-18 21:22 ` Jarkko Sakkinen
2026-11-19 4:43 ` Jarkko Sakkinen
2026-11-19 6:21 ` Jarkko Sakkinen
2026-11-18 22:36 ` Vlastimil Babka (SUSE)
2026-11-18 23:33 ` 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-223950@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=anna-maria@linutronix.de \
--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=frederic@kernel.org \
--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=tglx@kernel.org \
--cc=vbabka@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vincenzo.frascino@arm.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox