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 09/13] fs: Support MOVE_MOUNT_T_MNTNS in move_mount()
Date: Thu, 19 Nov 2026 19:36:59 +0000 [thread overview]
Message-ID: <sashiko-outbox-223951@kernel.org> (raw)
In-Reply-To: <20261118193539.240065-10-jarkko@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] fs: broken cross-userns mount locking in attach_recursive_mnt()
- [High] fs: relative root-mount alias bypass and unlocked check in
move_mount_mntns()
--
commit 444327893c38a5707689f91b2605debf89b46300
Author: Jarkko Sakkinen <jarkko@kernel.org>
fs: Support MOVE_MOUNT_T_MNTNS in move_mount()
This commit adds the MOVE_MOUNT_T_MNTNS flag to move_mount() to allow
attaching detached anonymous mount trees directly into a target mount
namespace identified by an nsfs file descriptor.
> diff --git a/fs/namespace.c b/fs/namespace.c
> index a6c0a31e275ae..2bd973a490d34 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
[ ... ]
> @@ -2639,6 +2648,7 @@ static int attach_recursive_mnt(struct mount *source_mnt,
> HLIST_HEAD(tree_list);
> struct mnt_namespace *ns = dest_mnt->mnt_ns;
> struct user_namespace *user_ns = ns->user_ns;
> + struct user_namespace *source_user_ns;
> struct pinned_mountpoint root = {};
> struct mountpoint *shorter = NULL;
> struct mount *child, *p;
> @@ -2662,6 +2672,8 @@ static int attach_recursive_mnt(struct mount *source_mnt,
> user_ns = current->nsproxy->mnt_ns->user_ns;
> else
> user_ns = ns->user_ns;
> + source_user_ns = (!moving && source_mnt->mnt_ns) ?
> + source_mnt->mnt_ns->user_ns : user_ns;
>
> /*
> * Preallocate a mountpoint in case the new mounts need to be
> @@ -2730,6 +2742,12 @@ static int attach_recursive_mnt(struct mount *source_mnt,
> /* Notice when we are propagating across user namespaces */
> if (child->mnt_parent->mnt_ns->user_ns != user_ns)
> lock_mnt_tree(child);
> + if (!is_anon_ns(child->mnt_parent->mnt_ns) &&
> + child->mnt_parent->mnt_ns->user_ns != source_user_ns) {
> + lock_mnt_tree(child);
> + if (list_empty(&child->mnt_expire))
> + child->mnt.mnt_flags |= MNT_LOCKED;
> + }
> q = __lookup_mnt(&child->mnt_parent->mnt,
> child->mnt_mountpoint);
> commit_tree(child);
[Severity: High]
Can cross-user-namespace mount locking be bypassed when a detached mount
tree is staged onto an anonymous mount before being attached to a target
mount namespace?
If an anonymous mount tree S owned by a privileged user namespace is
attached via move_mount() onto a subdirectory of an anonymous mount R
owned by a less-privileged user_ns_B (for example, created with
FSCONFIG_SET_ROOTNS or by a task in user_ns_B),
is_anon_ns(child->mnt_parent->mnt_ns) is true, so the new source_user_ns
check is skipped. If the caller is in user_ns_B, user_ns is also
user_ns_B, so lock_mnt_tree() is not called either. commit_tree(S) then
moves every mount in S into R->mnt_ns (owned by user_ns_B), so when R is
later attached into a mount namespace owned by user_ns_B,
source_user_ns == user_ns_B and S is never locked, allowing tasks in
user_ns_B to unmount masked directories or clear read-only/nosuid/nodev/
noexec flags.
Conversely, when a privileged manager in init_user_ns attaches a submount
owned by user_ns_B onto an anonymous root mount R also owned by user_ns_B
(via FSCONFIG_SET_ROOTNS), is_anon_ns(ns) sets user_ns to init_user_ns
rather than ns->user_ns, so child->mnt_parent->mnt_ns->user_ns != user_ns
spuriously locks the submount.
In addition, tree_list contains all secondary mounts created by
propagate_mnt(), and for normal mounts or automounts source_user_ns equals
user_ns. Every secondary copy propagated into a non-anonymous mount
namespace in another user namespace therefore hits this block and gets
MNT_LOCKED set on its root even when q == NULL (nothing was covered at
the mountpoint), preventing unprivileged users or shrink_submounts() from
unmounting uncovered propagated mounts. And because source_user_ns is
computed unconditionally for all !moving mounts, regular move_mount()
without MOVE_MOUNT_T_MNTNS also locks detached trees intentionally handed
over across user namespaces via SCM_RIGHTS or inheritance, regressing
33aadc7c7205 ("namespace: handle mount locking for automounts correctly").
[ ... ]
> @@ -4751,6 +4778,127 @@ static inline int vfs_move_mount(const struct path *from_path,
[ ... ]
> +static int move_mount_mntns(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)
> +{
[ ... ]
> + 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,
> + &mntns_root);
> + if (ret)
> + return ret;
> + if (real_mount(to_path.mnt)->mnt_ns != target_mnt_ns ||
> + to_path.mnt == &target_mnt_ns->root->mnt)
> + return -EINVAL;
> + if (real_mount(to_path.mnt)->mnt_parent == target_mnt_ns->root &&
> + to_path.dentry == to_path.mnt->mnt_root)
> + return (flags & MOVE_MOUNT_BENEATH) ? -EINVAL : -EBUSY;
> + }
> +
> + ret = lookup_move_mount_from(from_dfd, from_pathname, flags,
> + &from_path);
> + if (ret)
> + return ret;
> +
> + return vfs_move_mount(&from_path, &to_path, mflags | MNT_TREE_MNTNS);
> +}
[Severity: High]
Does the root-mount alias check in move_mount_mntns() miss any target
mount namespace where more than one mount is stacked on
target_mnt_ns->root?
mnt_ns_get_root() follows the entire overmount chain on
target_mnt_ns->root (nullfs) to the topmost live root mount in
mntns_root. Whenever two or more mounts are stacked on
target_mnt_ns->root (for example nullfs -> rootfs -> real_root in a
cloned namespace, or a root that has been overmounted), the live root
mount's mnt_parent is the intermediate mount rather than
target_mnt_ns->root. A relative path such as "." or "subdir/.." then
resolves to mntns_root with mnt_parent != target_mnt_ns->root, bypassing
this check and allowing the caller to overmount the namespace root or
mount beneath it with MOVE_MOUNT_BENEATH.
Also, filename_lookup() does not enforce LOOKUP_IS_SCOPED (or recheck
reachability from mntns_root under lock), so following a procfs magic link
inside target_mnt_ns can escape to a mount outside or beneath mntns_root.
Finally, these checks inspect to_path.mnt->mnt_ns and mnt_parent without
holding namespace_sem or mount_lock, and do_move_mount() only revalidates
MNT_TREE_MNTNS_INIT after locking the mountpoint; if a resolved submount
is concurrently pivoted to the root of target_mnt_ns before
do_lock_mount() acquires namespace_lock(), MOVE_MOUNT_BENEATH will attach
the new mount directly onto target_mnt_ns->root beneath the namespace
root.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118193539.240065-1-jarkko@kernel.org?part=9
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
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 [this message]
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-223951@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