selinux: log anon inode class name
authorChristian Göttsche <cgzones@googlemail.com>
Tue, 8 Mar 2022 17:09:26 +0000 (18:09 +0100)
committerPaul Moore <paul@paul-moore.com>
Tue, 3 May 2022 20:09:03 +0000 (16:09 -0400)
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>
include/linux/lsm_audit.h
security/lsm_audit.c
security/selinux/hooks.c

index 17d02eda953898958ee184653e0fa2e56e532772..97a8b21eb03339166c96e94743148e9e96fb2bc4 100644 (file)
@@ -76,6 +76,7 @@ struct common_audit_data {
 #define LSM_AUDIT_DATA_IBENDPORT 14
 #define LSM_AUDIT_DATA_LOCKDOWN 15
 #define LSM_AUDIT_DATA_NOTIFICATION 16
+#define LSM_AUDIT_DATA_ANONINODE       17
        union   {
                struct path path;
                struct dentry *dentry;
@@ -96,6 +97,7 @@ struct common_audit_data {
                struct lsm_ibpkey_audit *ibpkey;
                struct lsm_ibendport_audit *ibendport;
                int reason;
+               const char *anonclass;
        } u;
        /* this union contains LSM specific data */
        union {
index 1897cbf6fc6905f86912d391c9a51fad2cff83d9..78a278f28e49ab0a59ffffbc81bd61bcc4bc28de 100644 (file)
@@ -433,6 +433,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
                audit_log_format(ab, " lockdown_reason=\"%s\"",
                                 lockdown_reasons[a->u.reason]);
                break;
+       case LSM_AUDIT_DATA_ANONINODE:
+               audit_log_format(ab, " anonclass=%s", a->u.anonclass);
+               break;
        } /* switch (a->type) */
 }
 
index f1ee1bfc11dec0009388ae03b3af0fbbe91a33b2..beceb89f68d9cb5277c4cfcb091153965b4f8d51 100644 (file)
@@ -2964,8 +2964,8 @@ static int selinux_inode_init_security_anon(struct inode *inode,
         * allowed to actually create this type of anonymous inode.
         */
 
-       ad.type = LSM_AUDIT_DATA_INODE;
-       ad.u.inode = inode;
+       ad.type = LSM_AUDIT_DATA_ANONINODE;
+       ad.u.anonclass = name ? (const char *)name->name : "?";
 
        return avc_has_perm(&selinux_state,
                            tsec->sid,