[RFC PATCH v7 06/26] mount: Support MOVE_MOUNT_T_MNTNS in move_mount()

sashiko-bot at kernel.org sashiko-bot at kernel.org
Sun Nov 22 20:02:32 UTC 2026


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] fs: propagate_mnt() before lock_mnt_tree() in
  attach_recursive_mnt()
--

commit 1a941bfde892dcdbb8ea855a00043b140fa232a3
Author: Jarkko Sakkinen <jarkko at kernel.org>

mount: Support MOVE_MOUNT_T_MNTNS in move_mount()

This commit adds MOVE_MOUNT_T_MNTNS 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 1bb9f90a65239..93dd11da7e734 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
[ ... ]
> @@ -2725,11 +2738,22 @@ static int attach_recursive_mnt(struct mount *source_mnt,
>  	hlist_add_head(&source_mnt->mnt_hash, &tree_list);
>  
>  	hlist_for_each_entry_safe(child, n, &tree_list, mnt_hash) {
> +		struct user_namespace *child_user_ns =
> +			child->mnt_parent->mnt_ns->user_ns;
> +		bool cross_child_src = cross_src &&
> +				       !in_userns(child_user_ns, src_user_ns);
>  		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)
> +		/*
> +		 * Notice when we are propagating or attaching a foreign
> +		 * source tree across user namespaces.
> +		 */
> +		if (child_user_ns != user_ns || cross_child_src) {
>  			lock_mnt_tree(child);
> +			if (cross_child_src && list_empty(&child->mnt_expire))
> +				child->mnt.mnt_flags |= MNT_LOCKED;
> +		}

[Severity: High]
Does running lock_mnt_tree() after propagate_mnt() allow copy_tree() to
strip covering nsfs submounts from propagated copies when attaching a
tree across user namespaces with MOVE_MOUNT_T_MNTNS?

Earlier in attach_recursive_mnt(), when dest_mnt is shared,
propagate_mnt() clones source_mnt via copy_tree() without
CL_COPY_MNT_NS_FILE:

fs/namespace.c:copy_tree() {
    ...
			if (!(flag & CL_COPY_MNT_NS_FILE) &&
			    is_mnt_ns_file(src_mnt->mnt.mnt_root)) {
				if (src_mnt->mnt.mnt_flags & MNT_LOCKED) {
					/* Both a mount namespace file and locked. */
					dst_mnt = ERR_PTR(-EPERM);
					goto out;
				}
				src_mnt = skip_mnt_tree(src_mnt);
				continue;
			}
    ...
}

When a manager in an ancestor user namespace (src_user_ns) clones a tree
containing an unlocked nsfs submount via open_tree(OPEN_TREE_CLONE |
AT_RECURSIVE) and attaches it into a less privileged target_mnt_ns onto a
mount that an admin in target_mnt_ns->user_ns has made MS_SHARED,
source_mnt's submounts do not have MNT_LOCKED set yet when
propagate_mnt() runs.  Instead of failing with -EPERM, copy_tree() skips
the nsfs submount on the peer or slave copies, revealing whatever was
masked beneath it in target_mnt_ns.

Locking source_mnt before calling propagate_mnt() when cross_src is true
would ensure copy_tree() sees MNT_LOCKED on the submounts.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122193539.3334213-1-jarkko@kernel.org?part=6



More information about the Linux-security-module-archive mailing list