Skip to content

Commit 8026e40

Browse files
committed
apparmor: Fix move_mount mediation by detecting if source is detached
Prevent move_mount from applying the attach_disconnected flag to move_mount(). This prevents detached mounts from appearing as / when applying mount mediation, which is not only incorrect but could result in bad policy being generated. Basic mount rules like allow mount, allow mount options=(move) -> /target/, will allow detached mounts, allowing older policy to continue to function. New policy gains the ability to specify `detached` as a source option allow mount detached -> /target/, In addition make sure support of move_mount is advertised as a feature to userspace so that applications that generate policy can respond to the addition. Note: this fixes mediation of move_mount when a detached mount is used, it does not fix the broader regression of apparmor mediation of mounts under the new mount api. Link: https://lore.kernel.org/all/68c166b8-5b4d-4612-8042-1dee3334385b@leemhuis.info/T/#mb35fdde37f999f08f0b02d58dc1bf4e6b65b8da2 Fixes: 157a353 ("apparmor: Fix regression in mount mediation") Reviewed-by: Georgia Garcia <georgia.garcia@canonical.com> Signed-off-by: John Johansen <john.johansen@canonical.com>
1 parent 610a9b8 commit 8026e40

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

security/apparmor/apparmorfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,7 @@ static struct aa_sfs_entry aa_sfs_entry_policy[] = {
23732373

23742374
static struct aa_sfs_entry aa_sfs_entry_mount[] = {
23752375
AA_SFS_FILE_STRING("mask", "mount umount pivot_root"),
2376+
AA_SFS_FILE_STRING("move_mount", "detached"),
23762377
{ }
23772378
};
23782379

security/apparmor/mount.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,10 @@ int aa_move_mount(const struct cred *subj_cred,
499499
error = -ENOMEM;
500500
if (!to_buffer || !from_buffer)
501501
goto out;
502+
503+
if (!our_mnt(from_path->mnt))
504+
/* moving a mount detached from the namespace */
505+
from_path = NULL;
502506
error = fn_for_each_confined(label, profile,
503507
match_mnt(subj_cred, profile, to_path, to_buffer,
504508
from_path, from_buffer,

0 commit comments

Comments
 (0)