]> git.ipfire.org Git - thirdparty/linux.git/commit
apparmor: shift uid when mediating af_unix in userns
authorGabriel Totev <gabriel.totev@zetier.com>
Wed, 16 Apr 2025 22:42:09 +0000 (18:42 -0400)
committerJohn Johansen <john.johansen@canonical.com>
Sun, 20 Jul 2025 09:19:27 +0000 (02:19 -0700)
commit3fa0af4cc8a31d4139ee85a7b0e3d9b4f37b3093
treebaf5614767d04bc8e1793e48fc5137a808044222
parentc5bf96d20fd787e4909b755de4705d52f3458836
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>
security/apparmor/af_unix.c