Skip to content

Commit c29722f

Browse files
cgzonespcmoore
authored andcommitted
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>
1 parent ded3457 commit c29722f

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

include/linux/lsm_audit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct common_audit_data {
7676
#define LSM_AUDIT_DATA_IBENDPORT 14
7777
#define LSM_AUDIT_DATA_LOCKDOWN 15
7878
#define LSM_AUDIT_DATA_NOTIFICATION 16
79+
#define LSM_AUDIT_DATA_ANONINODE 17
7980
union {
8081
struct path path;
8182
struct dentry *dentry;
@@ -96,6 +97,7 @@ struct common_audit_data {
9697
struct lsm_ibpkey_audit *ibpkey;
9798
struct lsm_ibendport_audit *ibendport;
9899
int reason;
100+
const char *anonclass;
99101
} u;
100102
/* this union contains LSM specific data */
101103
union {

security/lsm_audit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
433433
audit_log_format(ab, " lockdown_reason=\"%s\"",
434434
lockdown_reasons[a->u.reason]);
435435
break;
436+
case LSM_AUDIT_DATA_ANONINODE:
437+
audit_log_format(ab, " anonclass=%s", a->u.anonclass);
438+
break;
436439
} /* switch (a->type) */
437440
}
438441

security/selinux/hooks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,8 +2964,8 @@ static int selinux_inode_init_security_anon(struct inode *inode,
29642964
* allowed to actually create this type of anonymous inode.
29652965
*/
29662966

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 : "?";
29692969

29702970
return avc_has_perm(&selinux_state,
29712971
tsec->sid,

0 commit comments

Comments
 (0)