[RFC PATCH v8 09/29] apparmor: Mediate MOVE_MOUNT_CLONE as recursive bind
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Sun Nov 29 00:11:08 UTC 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] apparmor: aa_move_mount() fails with -EACCES on foreign
target_mnt_ns to_path
--
commit 0fe740e3c444486594296da1a53a300752de0fc2
Author: Jarkko Sakkinen <jarkko at kernel.org>
apparmor: Mediate MOVE_MOUNT_CLONE as recursive bind
This commit passes move_mount() flags through aa_move_mount() and maps
MOVE_MOUNT_CLONE to MS_BIND | MS_REC while keeping from_path so AppArmor
checks both source and destination paths against recursive bind rules.
> diff --git a/security/apparmor/mount.c b/security/apparmor/mount.c
> index 4ed7b9136bebf..8d3db6bfdfb61 100644
> --- a/security/apparmor/mount.c
> +++ b/security/apparmor/mount.c
> @@ -423,13 +423,15 @@ int aa_mount_change_type(const struct cred *subj_cred,
>
> int aa_move_mount(const struct cred *subj_cred,
> struct aa_label *label, const struct path *from_path,
> - const struct path *to_path)
> + const struct path *to_path, unsigned int flags)
> {
> struct aa_profile *profile;
> char *to_buffer = NULL, *from_buffer = NULL;
> + unsigned long mnt_flags = (flags & MOVE_MOUNT_CLONE) ?
> + (MS_BIND | MS_REC) : MS_MOVE;
> int error;
> DEFINE_AUDIT_MOUNT(ad, OP_MOUNT, subj_cred);
> - ad.mnt.flags = MS_MOVE;
> + ad.mnt.flags = mnt_flags;
>
> AA_BUG(!label);
> AA_BUG(!from_path);
> @@ -441,12 +443,12 @@ int aa_move_mount(const struct cred *subj_cred,
> if (!to_buffer || !from_buffer)
> goto out;
>
> - if (!our_mnt(from_path->mnt))
> + if (!(flags & MOVE_MOUNT_CLONE) && !our_mnt(from_path->mnt))
> /* moving a mount detached from the namespace */
> from_path = NULL;
> error = fn_for_each(label, profile,
> match_mnt(profile, to_path, to_buffer, from_path,
> - from_buffer, NULL, MS_MOVE, NULL, false,
> + from_buffer, NULL, mnt_flags, NULL, false,
> &ad));
[Severity: High]
Does match_mnt() fail with -EACCES on to_path for every valid
MOVE_MOUNT_CLONE call when the profile does not set attach_disconnected?
move_mount() only allows MOVE_MOUNT_CLONE together with
MOVE_MOUNT_T_MNTNS, where move_mount_mntns() resolves to_path in
target_mnt_ns, and do_move_mount() requires from_path to be in the
caller's mount namespace while target_mnt_ns is a different mount
namespace:
fs/namespace.c:do_move_mount() {
...
case MNT_TREE_CLONE:
if (!check_mnt(old) || old->mnt_ns == target_mnt_ns ||
(old->mnt.mnt_sb->s_flags & SB_NOUSER))
return -EINVAL;
...
}
Because to_path->mnt belongs to target_mnt_ns, our_mnt(to_path->mnt) is
always false in match_mnt() -> match_mnt_path_str() -> aa_path_name() ->
d_namespace_path(). Without PATH_CONNECT_PATH, disconnect() returns
-EACCES ("Failed name lookup - disconnected path") and
match_mnt_path_str() aborts via aa_audit_perm_error() before
do_match_mnt() is ever reached to evaluate recursive bind rules.
Also, because a valid MOVE_MOUNT_CLONE requires check_mnt(old),
our_mnt(from_path->mnt) is already true for valid calls, so gating
!our_mnt(from_path->mnt) with !(flags & MOVE_MOUNT_CLONE) only changes
behavior for invalid detached or foreign source mounts that
do_move_mount() will reject with -EINVAL.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261128235808.2369970-1-jarkko@kernel.org?part=9
More information about the Linux-security-module-archive
mailing list