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

selinux: log anon inode class name

Log the anonymous inode class name in the security hook
inode_init_security_anon. This name is the key for name based type
transitions on the anon_inode security class on creation. Example:

type=AVC msg=audit(02/16/22 22:02:50.585:216) : avc: granted \
{ create } for pid=2136 comm=mariadbd anonclass=[io_uring] \
scontext=system_u:system_r:mysqld_t:s0 \
tcontext=system_u:system_r:mysqld_iouring_t:s0 tclass=anon_inode

Add a new LSM audit data type holding the inode and the class name.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
[PM: adjusted 'anonclass' to be a trusted string, cgzones approved]
Signed-off-by: Paul Moore <paul@paul-moore.com>

authored by

Christian Göttsche and committed by
Paul Moore
c29722fa ded34574

+7 -2
+2
include/linux/lsm_audit.h
··· 76 76 #define LSM_AUDIT_DATA_IBENDPORT 14 77 77 #define LSM_AUDIT_DATA_LOCKDOWN 15 78 78 #define LSM_AUDIT_DATA_NOTIFICATION 16 79 + #define LSM_AUDIT_DATA_ANONINODE 17 79 80 union { 80 81 struct path path; 81 82 struct dentry *dentry; ··· 97 96 struct lsm_ibpkey_audit *ibpkey; 98 97 struct lsm_ibendport_audit *ibendport; 99 98 int reason; 99 + const char *anonclass; 100 100 } u; 101 101 /* this union contains LSM specific data */ 102 102 union {
+3
security/lsm_audit.c
··· 433 433 audit_log_format(ab, " lockdown_reason=\"%s\"", 434 434 lockdown_reasons[a->u.reason]); 435 435 break; 436 + case LSM_AUDIT_DATA_ANONINODE: 437 + audit_log_format(ab, " anonclass=%s", a->u.anonclass); 438 + break; 436 439 } /* switch (a->type) */ 437 440 } 438 441
+2 -2
security/selinux/hooks.c
··· 2964 2964 * allowed to actually create this type of anonymous inode. 2965 2965 */ 2966 2966 2967 - ad.type = LSM_AUDIT_DATA_INODE; 2968 - ad.u.inode = inode; 2967 + ad.type = LSM_AUDIT_DATA_ANONINODE; 2968 + ad.u.anonclass = name ? (const char *)name->name : "?"; 2969 2969 2970 2970 return avc_has_perm(&selinux_state, 2971 2971 tsec->sid,