Re: [RFC PATCH v7 07/26] mount: Support MOVE_MOUNT_CLONE with MOVE_MOUNT_T_MNTNS

From: bot+bpf-ci

Date: Sun Nov 22 2026 - 15:28:21 EST


> mount: Support MOVE_MOUNT_CLONE with MOVE_MOUNT_T_MNTNS

TL;DR: MOVE_MOUNT_CLONE is reported to LSMs as a plain move, so AppArmor may
mediate it as MS_MOVE rather than a bind and could allow or refuse the clone
wrongly; should LSMs be told it is a clone?

> diff --git a/fs/namespace.c b/fs/namespace.c
> --- a/fs/namespace.c
> +++ b/fs/namespace.c

[ ... ]

> @@ -3842,6 +3840,36 @@ static int do_move_mount(const struct path *old_path,
> + if (flags & MNT_TREE_CLONE) {
> + unsigned int copy_flags;
> +
> + if (!check_mnt(old) || old->mnt_ns == target_mnt_ns ||
> + (old->mnt.mnt_sb->s_flags & SB_NOUSER))
> + return -EINVAL;
> + src_user_ns = old->mnt_ns->user_ns;
> + copy_flags = (target_mnt_ns->user_ns != src_user_ns) ?
> + (CL_SLAVE | CL_COPY_UNBINDABLE) :
> + CL_COPY_MNT_NS_FILE;
> + cloned = __do_loopback(old_path, true, copy_flags);

With MOVE_MOUNT_CLONE this makes a recursive bind of old_path, but the only
LSM hook on this path is still security_move_mount(from_path, to_path) in
vfs_move_mount(). LSMs get no indication that the operation is a clone
rather than a move.

The clone branch requires check_mnt(old), so from_path is always attached
to the caller's namespace. AppArmor's aa_move_mount() chooses between its
cases on exactly that property:

if (!our_mnt(from_path->mnt))
/* moving a mount detached from the namespace */
from_path = NULL;
... match_mnt(profile, to_path, ..., from_path, ..., MS_MOVE, ...)

So AppArmor will evaluate this as an MS_MOVE of an attached mount at
from_path, the same check it makes for a real move. But nothing is moved
here. A copy of the source and of everything mounted below it is attached
at to_path, and since path_mounted() is no longer required, any directory
can be the source.

With open_tree(OPEN_TREE_CLONE) followed by move_mount(), AppArmor sees a
detached source (from_path == NULL) and applies its detached-move rules.
Can a profile that allows moving the mount at /src (an MS_MOVE rule with
/src as the source) now also clone /src, or any directory below it, into
another mount namespace? Conversely, could a profile that only allows
detached moves refuse an operation that is equivalent to open_tree() plus
move_mount()?

Should the clone be reported to LSMs as a bind, for example through a
separate hook, a flag passed to security_move_mount(), or a call to the
bind-mount mediation?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45063222848