Skip to content

Commit c5bf96d

Browse files
zgttotevjrjohansen
authored andcommitted
apparmor: shift ouid when mediating hard links in userns
When using AppArmor profiles inside an unprivileged container, the link operation observes an unshifted ouid. (tested with LXD and Incus) For example, root inside container and uid 1000000 outside, with `owner /root/link l,` profile entry for ln: /root$ touch chain && ln chain link ==> dmesg apparmor="DENIED" operation="link" class="file" namespace="root//lxd-feet_<var-snap-lxd-common-lxd>" profile="linkit" name="/root/link" pid=1655 comm="ln" requested_mask="l" denied_mask="l" fsuid=1000000 ouid=0 [<== should be 1000000] target="/root/chain" Fix by mapping inode uid of old_dentry in aa_path_link() rather than using it directly, similarly to how it's mapped in __file_path_perm() later in the file. Signed-off-by: Gabriel Totev <[email protected]> Signed-off-by: John Johansen <[email protected]>
1 parent 88fec35 commit c5bf96d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

security/apparmor/file.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,11 @@ int aa_path_link(const struct cred *subj_cred,
430430
{
431431
struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
432432
struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
433+
struct inode *inode = d_backing_inode(old_dentry);
434+
vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_idmap(target.mnt), inode);
433435
struct path_cond cond = {
434-
d_backing_inode(old_dentry)->i_uid,
435-
d_backing_inode(old_dentry)->i_mode
436+
.uid = vfsuid_into_kuid(vfsuid),
437+
.mode = inode->i_mode,
436438
};
437439
char *buffer = NULL, *buffer2 = NULL;
438440
struct aa_profile *profile;

0 commit comments

Comments
 (0)