[RFC PATCH v8 09/29] apparmor: Mediate MOVE_MOUNT_CLONE as recursive bind

Jarkko Sakkinen jarkko at kernel.org
Sat Nov 28 23:57:48 UTC 2026


When move_mount() is invoked with MOVE_MOUNT_CLONE, the source mount is
recursively loopback-cloned from the caller's mount namespace rather
than moved or attached from a detached anonymous mount.

Pass flags through aa_move_mount() and mediate MOVE_MOUNT_CLONE as
MS_BIND | MS_REC while keeping from_path so AppArmor checks both source
and destination paths against recursive bind rules.

Signed-off-by: Jarkko Sakkinen <jarkko at kernel.org>
---
 security/apparmor/include/mount.h |  2 +-
 security/apparmor/lsm.c           |  2 +-
 security/apparmor/mount.c         | 12 +++++++-----
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/security/apparmor/include/mount.h b/security/apparmor/include/mount.h
index 46834f828179..d771ee240d42 100644
--- a/security/apparmor/include/mount.h
+++ b/security/apparmor/include/mount.h
@@ -43,7 +43,7 @@ int aa_move_mount_old(const struct cred *subj_cred,
 		      const char *old_name);
 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);
 
 int aa_new_mount(const struct cred *subj_cred,
 		 struct aa_label *label, const char *dev_name,
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index aefa71bc1cd2..797944de8273 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -751,7 +751,7 @@ static int apparmor_move_mount(const struct path *from_path,
 	label = __begin_current_label_crit_section(&needput);
 	if (!unconfined(label))
 		error = aa_move_mount(current_cred(), label, from_path,
-				      to_path);
+				      to_path, flags);
 	__end_current_label_crit_section(label, needput);
 
 	return error;
diff --git a/security/apparmor/mount.c b/security/apparmor/mount.c
index 4ed7b9136beb..8d3db6bfdfb6 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));
 out:
 	aa_put_buffer(to_buffer);
@@ -467,7 +469,7 @@ int aa_move_mount_old(const struct cred *subj_cred, struct aa_label *label,
 	if (error)
 		return error;
 
-	error = aa_move_mount(subj_cred, label, &old_path, path);
+	error = aa_move_mount(subj_cred, label, &old_path, path, 0);
 	path_put(&old_path);
 
 	return error;
-- 
2.47.3




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