[RFC PATCH v8 08/29] mount: Support MOVE_MOUNT_CLONE with MOVE_MOUNT_T_MNTNS
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Sun Nov 29 00:28:09 UTC 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mount: missing CL_LOCK_SOURCE in do_move_mount() cross-userns
clone
--
commit 0d1d8da112faced6c7bc49b0fc725fadd1aaab58
Author: Jarkko Sakkinen <jarkko at kernel.org>
mount: Support MOVE_MOUNT_CLONE with MOVE_MOUNT_T_MNTNS
This commit adds MOVE_MOUNT_CLONE for use with MOVE_MOUNT_T_MNTNS so
move_mount() can recursively loopback-clone a path from the caller's mount
namespace directly into a target mount namespace file descriptor.
> diff --git a/fs/namespace.c b/fs/namespace.c
> index fadc4c3b1fb2a..e60c589ae0152 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
[ ... ]
> @@ -3847,6 +3845,36 @@ static int do_move_mount(const struct path *old_path,
> if (m == target_mnt_ns->root)
> return beneath ? -EINVAL : -EBUSY;
> }
> + 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);
[Severity: High]
Should copy_flags include CL_LOCK_SOURCE and test
!in_userns(target_mnt_ns->user_ns, src_user_ns) when cloning across user
namespaces?
Native non-expiring submounts in old->mnt_ns do not have MNT_LOCKED set
before attach_recursive_mnt() runs:
fs/namespace.c:copy_tree() {
...
bool src_locked = (src_mnt->mnt.mnt_flags & MNT_LOCKED) ||
((flag & CL_LOCK_SOURCE) &&
list_empty(&src_mnt->mnt_expire));
...
if (!(flag & CL_COPY_MNT_NS_FILE) &&
is_mnt_ns_file(src_mnt->mnt.mnt_root)) {
if (src_locked) {
/* Both a mount namespace file and locked. */
dst_mnt = ERR_PTR(-EPERM);
goto out;
}
src_mnt = skip_mnt_tree(src_mnt);
continue;
}
...
}
Without CL_LOCK_SOURCE, copy_tree() sees src_locked as false and skips any
nsfs submount and its overmounts via skip_mnt_tree() instead of returning
-EPERM, exposing underlying files or directories covered in the source
mount namespace.
In addition, when target_mnt_ns->user_ns is an ancestor of src_user_ns,
checking target_mnt_ns->user_ns != src_user_ns passes CL_COPY_UNBINDABLE
even though attach_recursive_mnt() computes
cross_src = !in_userns(ns->user_ns, src_user_ns) as false, leaving copied
unbindable submounts unlocked and causing attachment onto a shared
destination mount to fail with -EINVAL in tree_contains_unbindable().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261128235808.2369970-1-jarkko@kernel.org?part=8
More information about the Linux-security-module-archive
mailing list