Skip to content

Commit 3fa0af4

Browse files
zgttotevjrjohansen
authored andcommitted
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 <[email protected]> Fixes: c05e705 ("apparmor: add fine grained af_unix mediation") Signed-off-by: John Johansen <[email protected]>
1 parent c5bf96d commit 3fa0af4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

security/apparmor/af_unix.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* License.
1313
*/
1414

15+
#include <linux/fs.h>
1516
#include <net/tcp_states.h>
1617

1718
#include "include/audit.h"
@@ -44,8 +45,11 @@ static int unix_fs_perm(const char *op, u32 mask, const struct cred *subj_cred,
4445
*/
4546
if (path->dentry) {
4647
/* the sunpath may not be valid for this ns so use the path */
47-
struct path_cond cond = { path->dentry->d_inode->i_uid,
48-
path->dentry->d_inode->i_mode
48+
struct inode *inode = path->dentry->d_inode;
49+
vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_idmap(path->mnt), inode);
50+
struct path_cond cond = {
51+
.uid = vfsuid_into_kuid(vfsuid),
52+
.mode = inode->i_mode,
4953
};
5054

5155
return aa_path_perm(op, subj_cred, label, path,

0 commit comments

Comments
 (0)