[RFC PATCH v5 06/25] mount: Support MOVE_MOUNT_T_MNTNS in move_mount()
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Sun Nov 22 00:10:55 UTC 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] fs: namespace: broken cross-userns locking in
attach_recursive_mnt()
--
commit 74ae0b488300551c347e9b244e2d68e31f9a48cf
Author: Jarkko Sakkinen <jarkko at kernel.org>
mount: 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 specified by an nsfs file descriptor.
> diff --git a/fs/namespace.c b/fs/namespace.c
> index b2dc84c0d0d66..b65f1fdd92811 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
[ ... ]
> @@ -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,9 @@ 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;
> + if (move_mntns && src_ns)
> + user_ns = src_ns->user_ns;
>
> /*
> * Preallocate a mountpoint in case the new mounts need to be
> @@ -2728,8 +2743,12 @@ static int attach_recursive_mnt(struct mount *source_mnt,
> 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)
> + if (child->mnt_parent->mnt_ns->user_ns != user_ns) {
> lock_mnt_tree(child);
> + if ((move_mntns || is_anon_ns(ns)) &&
> + 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]
Does overwriting user_ns with src_ns->user_ns break cross-user-namespace
mount locking when source_mnt is attached via MOVE_MOUNT_T_MNTNS?
move_mount_mntns() checks CAP_SYS_ADMIN in target_mnt_ns->user_ns
(ns->user_ns), not src_ns->user_ns. When src_ns->user_ns differs from
ns->user_ns (for example, an anonymous mount created in a less-privileged
user namespace U2 is attached by a manager into a mount namespace owned by
U1) and dest_mnt propagates to a slave mount in a namespace owned by U2,
child->mnt_parent->mnt_ns->user_ns == user_ns (both U2).
lock_mnt_tree(child) is then skipped on the copy propagated from U1 into
U2, leaving MNT_READONLY, MNT_NOSUID, MNT_NODEV, MNT_NOEXEC, and submounts
unlocked in U2.
In the same case, for the primary mount (child == source_mnt) attached
into target_mnt_ns, child->mnt_parent->mnt_ns->user_ns (U1) != user_ns
(U2) is true, which locks source_mnt with MNT_LOCKED inside the privileged
target_mnt_ns itself. Also, checking move_mntns unconditionally for all
entries in tree_list sets MNT_LOCKED on the root of every cross-userns
propagated copy (child != source_mnt), preventing slave namespaces from
unmounting propagated mounts that did not cover an existing locked mount.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121000844.1863324-1-jarkko@kernel.org?part=6
More information about the Linux-security-module-archive
mailing list