Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

apparmor: shift uid when mediating af_unix in userns

Avoid unshifted ouids for socket file operations as observed when using
AppArmor profiles in unprivileged containers with LXD or Incus.

For example, root inside container and uid 1000000 outside, with
`owner /root/sock rw,` profile entry for nc:

/root$ nc -lkU sock & nc -U sock
==> dmesg
apparmor="DENIED" operation="connect" class="file"
namespace="root//lxd-podia_<var-snap-lxd-common-lxd>" profile="sockit"
name="/root/sock" pid=3924 comm="nc" requested_mask="wr" denied_mask="wr"
fsuid=1000000 ouid=0 [<== should be 1000000]

Fix by performing uid mapping as per common_perm_cond() in lsm.c

Signed-off-by: Gabriel Totev <gabriel.totev@zetier.com>
Fixes: c05e705812d1 ("apparmor: add fine grained af_unix mediation")
Signed-off-by: John Johansen <john.johansen@canonical.com>

authored by

Gabriel Totev and committed by
John Johansen
3fa0af4c c5bf96d2

+6 -2
+6 -2
security/apparmor/af_unix.c
··· 12 12 * License. 13 13 */ 14 14 15 + #include <linux/fs.h> 15 16 #include <net/tcp_states.h> 16 17 17 18 #include "include/audit.h" ··· 45 44 */ 46 45 if (path->dentry) { 47 46 /* the sunpath may not be valid for this ns so use the path */ 48 - struct path_cond cond = { path->dentry->d_inode->i_uid, 49 - path->dentry->d_inode->i_mode 47 + struct inode *inode = path->dentry->d_inode; 48 + vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_idmap(path->mnt), inode); 49 + struct path_cond cond = { 50 + .uid = vfsuid_into_kuid(vfsuid), 51 + .mode = inode->i_mode, 50 52 }; 51 53 52 54 return aa_path_perm(op, subj_cred, label, path,