[RFC PATCH v4 09/14] fs: Support MOVE_MOUNT_T_MNTNS in move_mount()
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Fri Nov 20 22:44:48 UTC 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] fs: cross-userns mount locking bypass in attach_recursive_mnt()
--
commit 5e90ce5c3ee9b66d7c6a41077c19c225ae139217
Author: Jarkko Sakkinen <jarkko at kernel.org>
fs: Support MOVE_MOUNT_T_MNTNS in move_mount()
This commit adds the MOVE_MOUNT_T_MNTNS flag to move_mount() so that
detached anonymous mount trees can be attached directly into a target
mount namespace specified by an nsfs file descriptor.
> diff --git a/fs/namespace.c b/fs/namespace.c
> index dfe0ee9ecdcd0..36ed48c3f6467 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
[ ... ]
> @@ -2632,7 +2642,8 @@ enum mnt_tree_flags_t {
> * Otherwise a negative error code is returned.
> */
> static int attach_recursive_mnt(struct mount *source_mnt,
> - const struct pinned_mountpoint *dest)
> + const struct pinned_mountpoint *dest,
> + bool move_mntns)
> {
> struct mount *dest_mnt = dest->parent;
> struct mountpoint *dest_mp = dest->mp;
> @@ -2641,6 +2652,7 @@ static int attach_recursive_mnt(struct mount *source_mnt,
> struct user_namespace *user_ns = ns->user_ns;
> struct pinned_mountpoint root = {};
> struct mountpoint *shorter = NULL;
> + struct mnt_namespace *src_ns;
> struct mount *child, *p;
> struct mount *top;
> struct hlist_node *n;
> @@ -2662,6 +2674,7 @@ static int attach_recursive_mnt(struct mount *source_mnt,
> user_ns = current->nsproxy->mnt_ns->user_ns;
> else
> user_ns = ns->user_ns;
> + src_ns = moving ? NULL : source_mnt->mnt_ns;
>
> /*
> * Preallocate a mountpoint in case the new mounts need to be
> @@ -2694,6 +2707,12 @@ static int attach_recursive_mnt(struct mount *source_mnt,
> if (err)
> goto out_cleanup_ids;
>
> + if (move_mntns && src_ns && src_ns->user_ns != user_ns) {
> + lock_mnt_tree(source_mnt);
> + if (list_empty(&source_mnt->mnt_expire))
> + source_mnt->mnt.mnt_flags |= MNT_LOCKED;
> + }
[Severity: High]
Does calling lock_mnt_tree(source_mnt) after propagate_mnt() leave
secondary copies unlocked when MOVE_MOUNT_T_MNTNS attaches a tree onto a
shared destination mount across user namespaces?
When IS_MNT_SHARED(dest_mnt) is true, propagate_mnt() clones source_mnt
into tree_list before source_mnt is locked here, so the clones do not
inherit MNT_LOCK_* or MNT_LOCKED (and copy_tree() silently skips unlocked
nsfs submounts instead of failing with -EPERM). Then the tree_list loop
checks:
fs/namespace.c:attach_recursive_mnt() {
...
hlist_for_each_entry_safe(child, n, &tree_list, mnt_hash) {
struct mount *q;
hlist_del_init(&child->mnt_hash);
/* Notice when we are propagating across user namespaces */
if (child->mnt_parent->mnt_ns->user_ns != user_ns)
lock_mnt_tree(child);
...
}
Because user_ns is dest_mnt->mnt_ns->user_ns rather than src_ns->user_ns,
secondary copies propagated to peer or slave mounts in the target user
namespace match user_ns and skip lock_mnt_tree(child), allowing root in
the target user namespace to unmount masking submounts or clear read-only,
nosuid, nodev, and noexec flags.
In addition, if a foreign anonymous mount from another user namespace was
previously attached via regular move_mount() as a submount of an anonymous
mount tree already owned by the target user namespace, commit_tree() set
the submount's mnt_ns to the anonymous tree without setting MNT_LOCKED on
that submount's root, and attaching the anonymous tree with
MOVE_MOUNT_T_MNTNS skips lock_mnt_tree() because src_ns->user_ns already
equals user_ns.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119224312.1037966-1-jarkko@kernel.org?part=9
More information about the Linux-security-module-archive
mailing list