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

Jarkko Sakkinen jarkko at kernel.org
Mon Nov 23 14:05:58 UTC 2026


On Sun, Nov 22, 2026 at 08:28:11PM +0000, bot+bpf-ci at kernel.org wrote:
> 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?

Mediation can be trivially achieved:

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;

Br, Jarkko



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