selinux: log anon inode class name
Subsystems (2)
PATCH 1/1 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]" dev="anon_inodefs" ino=6871 scontext=system_u:system_r:mysqld_t:s0 tcontext=system_u:system_r:mysqld_iouring_t:s0 tclass=anon_inodeAdd a new LSM audit data type holding the inode and the class name.
Also warn if the security hook gets called with no name set; currently the only caller fs/anon_inodes.c:anon_inode_make_secure_inode() passes one.
--- include/linux/lsm_audit.h | 5 +++++ security/lsm_audit.c | 21 +++++++++++++++++++++ security/selinux/hooks.c | 7 +++++-- 3 files changed, 31 insertions(+), 2 deletions(-)
include/linux/lsm_audit.h +5 -0
@@ -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 17union {struct path path;struct dentry *dentry;
@@ -96,6 +97,10 @@ struct common_audit_data {struct lsm_ibpkey_audit *ibpkey;struct lsm_ibendport_audit *ibendport;int reason; +struct { +struct inode *inode; +const char *anonclass; + } anoninode_struct; } u;/* this union contains LSM specific data */ union {
security/lsm_audit.c +21 -0
@@ -433,6 +433,27 @@ 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 : { +struct dentry *dentry; +struct inode *inode; + +rcu_read_lock (); + inode = a->u.anoninode_struct.inode; + dentry =d_find_alias_rcu (inode); +if (dentry) { +audit_log_format (ab," name=" ); +spin_lock (&dentry->d_lock); +audit_log_untrustedstring (ab, dentry->d_name.name); +spin_unlock (&dentry->d_lock); + } +audit_log_format (ab," anonclass=" ); +audit_log_untrustedstring (ab, a->u.anoninode_struct.anonclass); +audit_log_format (ab," dev=" ); +audit_log_untrustedstring (ab, inode->i_sb->s_id); +audit_log_format (ab," ino=%lu" , inode->i_ino); +rcu_read_unlock (); +break ; + } }/* switch (a->type) */ }
security/selinux/hooks.c +5 -2
@@ -2932,6 +2932,8 @@ static int selinux_inode_init_security_anon(struct inode *inode,if (unlikely (!selinux_initialized (&selinux_state)))return 0 ; +WARN_ON (!name); + isec =selinux_inode (inode);/*
@@ -2965,8 +2967,9 @@ 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.anoninode_struct.inode = inode; + ad.u.anoninode_struct.anonclass = name ? (const char *)name->name :"unknown(null)" ; return avc_has_perm(&selinux_state, tsec->sid,
Signature · 1 line
2.35.1
Paul Moore
maintainerQuoted 19 lines · Christian Göttsche
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 theanon_inodesecurity 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]" dev="anon_inodefs" ino=6871 scontext=system_u:system_r:mysqld_t:s0 tcontext=system_u:system_r:mysqld_iouring_t:s0 tclass=anon_inodeAdd a new LSM audit data type holding the inode and the class name.
Also warn if the security hook gets called with no name set; currently the only caller fs/anon_inodes.c:anon_inode_make_secure_inode() passes one.
Signed-off-by Christian Göttsche <[email protected]>--- include/linux/lsm_audit.h | 5 +++++ security/lsm_audit.c | 21 +++++++++++++++++++++ security/selinux/hooks.c | 7 +++++-- 3 files changed, 31 insertions(+), 2 deletions(-)
...
Quoted 34 lines
include/linux/lsm_audit.h +5
-0@@ -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 17union {struct path path;struct dentry *dentry;@@ -96,6 +97,10 @@ struct common_audit_data {struct lsm_ibpkey_audit *ibpkey;struct lsm_ibendport_audit *ibendport;int reason; +struct { +struct inode *inode; +const char *anonclass; + } anoninode_struct; } u;/* this union contains LSM specific data */ union {security/lsm_audit.c +3
-0@@ -433,6 +433,27 @@ 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 : { +struct dentry *dentry; +struct inode *inode;
security/lsm_audit.c static void dump_common_audit_data(struct audit_buffer *ab, · line 448
Quoted 10 lines
security/lsm_audit.c +10
-0+ +rcu_read_lock (); + inode = a->u.anoninode_struct.inode; + dentry =d_find_alias_rcu (inode); +if (dentry) { +audit_log_format (ab," name=" ); +spin_lock (&dentry->d_lock); +audit_log_untrustedstring (ab, dentry->d_name.name); +spin_unlock (&dentry->d_lock); + }
I'm not sure we are ever going to get a useful dentry name for anonymous inodes, I think we can probably drop this. The "anonclass=" field will likely be much more interesting and helpful.
security/lsm_audit.c static void dump_common_audit_data(struct audit_buffer *ab, · line 452
Quoted 4 lines
security/lsm_audit.c +4
-0+audit_log_format (ab," anonclass=" ); +audit_log_untrustedstring (ab, a->u.anoninode_struct.anonclass); +audit_log_format (ab," dev=" ); +audit_log_untrustedstring (ab, inode->i_sb->s_id);
I'm pretty sure this is always going to end up being "anon_inodefs" and thus not very useful.
security/lsm_audit.c static void dump_common_audit_data(struct audit_buffer *ab, · line 453
Quoted 1 line
security/lsm_audit.c +1
-0+audit_log_format (ab," ino=%lu" , inode->i_ino);
Similarly, I'm not sure how useful the inode number is in practice. I've never tried, but can a user lookup an anonymous inode via the inode number?
Quoted 14 lines
security/selinux/hooks.c +2
-0@@ -2932,6 +2932,8 @@ static int selinux_inode_init_security_anon(struct inode *inode,if (unlikely (!selinux_initialized (&selinux_state)))return 0 ; +WARN_ON (!name); + isec =selinux_inode (inode);/*
security/selinux/hooks.c static int selinux_inode_init_security_anon(struct inode *inode, · line 2972
Quoted 8 lines
security/selinux/hooks.c +3
-2@@ -2965,8 +2967,9 @@ 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.anoninode_struct.inode = inode; + ad.u.anoninode_struct.anonclass = name ? (const char *)name->name :"unknown(null)" ;
This doesn't seem to match well with the newly added WARN_ON() assertion above. I would suggest dropping the WARN_ON() assertion as security_transition_sid() can already handle that safely, and leaving the tertiary statement above; however I think we should probably change the anonclass string to "?" as that is the common unset field value used by audit.
Signature · 1 line
paul-moore.com
PATCH v2 1/1 selinux: log anon inode class name
In reply to Christian GöttscheLog 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_inodeAdd a new LSM audit data type holding the inode and the class name.
---
v2:
- drop dev= and name= output for anonymous inodes, and hence simplify the common_audit_data union member.
- drop WARN_ON() on empty name passed to inode_init_security_anon hook
--- include/linux/lsm_audit.h | 2 ++ security/lsm_audit.c | 4 ++++ security/selinux/hooks.c | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-)
include/linux/lsm_audit.h +2 -0
@@ -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 17union {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 {
security/lsm_audit.c +4 -0
@@ -433,6 +433,10 @@ 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=" ); +audit_log_untrustedstring (ab, a->u.anonclass); +break ; }/* switch (a->type) */ }
security/selinux/hooks.c +2 -2
@@ -2965,8 +2965,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,
Signature · 1 line
2.35.1
Quoted 105 lines · Paul Moore
Quoted 19 lines · Christian Göttsche
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 theanon_inodesecurity 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]" dev="anon_inodefs" ino=6871 scontext=system_u:system_r:mysqld_t:s0 tcontext=system_u:system_r:mysqld_iouring_t:s0 tclass=anon_inodeAdd a new LSM audit data type holding the inode and the class name.
Also warn if the security hook gets called with no name set; currently the only caller fs/anon_inodes.c:anon_inode_make_secure_inode() passes one.
Signed-off-by Christian Göttsche <[email protected]>--- include/linux/lsm_audit.h | 5 +++++ security/lsm_audit.c | 21 +++++++++++++++++++++ security/selinux/hooks.c | 7 +++++-- 3 files changed, 31 insertions(+), 2 deletions(-)...
Quoted 34 lines
include/linux/lsm_audit.h +5
-0@@ -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 17union {struct path path;struct dentry *dentry;@@ -96,6 +97,10 @@ struct common_audit_data {struct lsm_ibpkey_audit *ibpkey;struct lsm_ibendport_audit *ibendport;int reason; +struct { +struct inode *inode; +const char *anonclass; + } anoninode_struct; } u;/* this union contains LSM specific data */ union {security/lsm_audit.c +3
-0@@ -433,6 +433,27 @@ 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 : { +struct dentry *dentry; +struct inode *inode;security/lsm_audit.c static void dump_common_audit_data(struct audit_buffer *ab, · line 448
Quoted 10 lines
security/lsm_audit.c +10
-0+ +rcu_read_lock (); + inode = a->u.anoninode_struct.inode; + dentry =d_find_alias_rcu (inode); +if (dentry) { +audit_log_format (ab," name=" ); +spin_lock (&dentry->d_lock); +audit_log_untrustedstring (ab, dentry->d_name.name); +spin_unlock (&dentry->d_lock); + }I'm not sure we are ever going to get a useful dentry name for anonymous inodes, I think we can probably drop this. The "anonclass=" field will likely be much more interesting and helpful.
security/lsm_audit.c static void dump_common_audit_data(struct audit_buffer *ab, · line 452
Quoted 4 lines
security/lsm_audit.c +4
-0+audit_log_format (ab," anonclass=" ); +audit_log_untrustedstring (ab, a->u.anoninode_struct.anonclass); +audit_log_format (ab," dev=" ); +audit_log_untrustedstring (ab, inode->i_sb->s_id);I'm pretty sure this is always going to end up being "
anon_inodefs" and thus not very useful.security/lsm_audit.c static void dump_common_audit_data(struct audit_buffer *ab, · line 453
Quoted 1 line
security/lsm_audit.c +1
-0+audit_log_format (ab," ino=%lu" , inode->i_ino);Similarly, I'm not sure how useful the inode number is in practice. I've never tried, but can a user lookup an anonymous inode via the inode number?
Quoted 17 lines
security/selinux/hooks.c +2
-0@@ -2932,6 +2932,8 @@ static int selinux_inode_init_security_anon(struct inode *inode,if (unlikely (!selinux_initialized (&selinux_state)))return 0 ; +WARN_ON (!name); + isec =selinux_inode (inode);/* @@ -2965,8 +2967,9 @@ static int selinux_inode_init_security_anon(struct inode *inode,* allowed to actually create this type of anonymous inode. */
Quoted 12 lines
security/selinux/hooks.c static int selinux_inode_init_security_anon(struct inode *inode, · line 2972
Quoted 5 lines
security/selinux/hooks.c +3
-2- ad.type =LSM_AUDIT_DATA_INODE ; - ad.u.inode = inode; + ad.type =LSM_AUDIT_DATA_ANONINODE ; + ad.u.anoninode_struct.inode = inode; + ad.u.anoninode_struct.anonclass = name ? (const char *)name->name :"unknown(null)" ;This doesn't seem to match well with the newly added
WARN_ON()assertion above. I would suggest dropping theWARN_ON()assertion assecurity_transition_sid()can already handle that safely, and leaving the tertiary statement above; however I think we should probably change the anonclass string to "?" as that is the common unset field value used by audit.
Is the hook inode_init_security_anon expected to be called with an empty name though?
The condition was just a fallback to not crash the kernel. (Dropped in v2.)
Quoted 3 lines
--
paul-moore.com
Paul Moore
maintainerQuoted 50 lines · Christian Göttsche
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 theanon_inodesecurity 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_inodeAdd a new LSM audit data type holding the inode and the class name.
Signed-off-by Christian Göttsche <[email protected]>---
v2:
- drop dev= and name= output for anonymous inodes, and hence simplify thecommon_audit_dataunion member.
- dropWARN_ON()on empty name passed toinode_init_security_anonhook--- include/linux/lsm_audit.h | 2 ++ security/lsm_audit.c | 4 ++++ security/selinux/hooks.c | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-)include/linux/lsm_audit.h +2
-0@@ -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 17union {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 {security/lsm_audit.c +0
-0
security/lsm_audit.c static void dump_common_audit_data(struct audit_buffer *ab, · line 438
Quoted 6 lines
security/lsm_audit.c +3
-0@@ -433,6 +433,10 @@ 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=" ); +audit_log_untrustedstring (ab, a->u.anonclass);
My apologies, I didn't notice this in the previous patch ... I don't think we need to log this as an untrusted string as the string value is coming from the kernel, not userspace, so we could rewrite the above as the following:
audit_log_format(ab, " anonclass=%s", a->u.anonclass);
... if you are okay with that, I can make the change when I merge the patch or you can submit another revision, let me know which you would prefer.
The rest of the patch looks good, thanks!
Quoted 21 lines
security/lsm_audit.c +1
-0+break ; }/* switch (a->type) */ }security/selinux/hooks.c +2
-3@@ -2965,8 +2965,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, --2.35.1
Signature · 1 line
paul-moore.com
Paul Moore
maintainerQuoted 64 lines · Paul Moore
Quoted 50 lines · Christian Göttsche
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 theanon_inodesecurity 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_inodeAdd a new LSM audit data type holding the inode and the class name.
Signed-off-by Christian Göttsche <[email protected]>---
v2:
- drop dev= and name= output for anonymous inodes, and hence simplify thecommon_audit_dataunion member.
- dropWARN_ON()on empty name passed toinode_init_security_anonhook--- include/linux/lsm_audit.h | 2 ++ security/lsm_audit.c | 4 ++++ security/selinux/hooks.c | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-)include/linux/lsm_audit.h +2
-0@@ -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 17union {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 {security/lsm_audit.c +0
-0security/lsm_audit.c static void dump_common_audit_data(struct audit_buffer *ab, · line 438
Quoted 6 lines
security/lsm_audit.c +3
-0@@ -433,6 +433,10 @@ 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=" ); +audit_log_untrustedstring (ab, a->u.anonclass);My apologies, I didn't notice this in the previous patch ... I don't think we need to log this as an untrusted string as the string value is coming from the kernel, not userspace, so we could rewrite the above as the following:
Quoted 7 lines
audit_log_format(ab, " anonclass=%s", a->u.anonclass);... if you are okay with that, I can make the change when I merge the patch or you can submit another revision, let me know which you would prefer.
The rest of the patch looks good, thanks!
Hi Christian,
I just wanted to follow up on this as we are at -rc4 this week and if we want this to go during the next merge window this would need to be merged soon ...
Signature · 1 line
paul-moore.com
Quoted 66 lines · Paul Moore
Quoted 64 lines · Paul Moore
Quoted 50 lines · Christian Göttsche
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 theanon_inodesecurity 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_inodeAdd a new LSM audit data type holding the inode and the class name.
Signed-off-by Christian Göttsche <[email protected]>---
v2:
- drop dev= and name= output for anonymous inodes, and hence simplify thecommon_audit_dataunion member.
- dropWARN_ON()on empty name passed toinode_init_security_anonhook--- include/linux/lsm_audit.h | 2 ++ security/lsm_audit.c | 4 ++++ security/selinux/hooks.c | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-)include/linux/lsm_audit.h +2
-0@@ -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 17union {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 {security/lsm_audit.c +0
-0security/lsm_audit.c static void dump_common_audit_data(struct audit_buffer *ab, · line 438
Quoted 6 lines
security/lsm_audit.c +3
-0@@ -433,6 +433,10 @@ 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=" ); +audit_log_untrustedstring (ab, a->u.anonclass);My apologies, I didn't notice this in the previous patch ... I don't think we need to log this as an untrusted string as the string value is coming from the kernel, not userspace, so we could rewrite the above as the following:
Quoted 5 lines
Quoted 5 lines
audit_log_format(ab, " anonclass=%s", a->u.anonclass);... if you are okay with that, I can make the change when I merge the patch or you can submit another revision, let me know which you would prefer.
Feel free to adjust while merging, thanks.
Quoted 11 lines
Quoted 2 lines
The rest of the patch looks good, thanks!
Hi Christian,
I just wanted to follow up on this as we are at -rc4 this week and if we want this to go during the next merge window this would need to be merged soon ...
--
paul-moore.com
Paul Moore
maintainerQuoted 66 lines · Christian Göttsche
Quoted 65 lines · Paul Moore
Quoted 64 lines · Paul Moore
Quoted 50 lines · Christian Göttsche
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 theanon_inodesecurity 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_inodeAdd a new LSM audit data type holding the inode and the class name.
Signed-off-by Christian Göttsche <[email protected]>---
v2:
- drop dev= and name= output for anonymous inodes, and hence simplify thecommon_audit_dataunion member.
- dropWARN_ON()on empty name passed toinode_init_security_anonhook--- include/linux/lsm_audit.h | 2 ++ security/lsm_audit.c | 4 ++++ security/selinux/hooks.c | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-)include/linux/lsm_audit.h +2
-0@@ -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 17union {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 {security/lsm_audit.c +0
-0security/lsm_audit.c static void dump_common_audit_data(struct audit_buffer *ab, · line 438
Quoted 6 lines
security/lsm_audit.c +3
-0@@ -433,6 +433,10 @@ 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=" ); +audit_log_untrustedstring (ab, a->u.anonclass);My apologies, I didn't notice this in the previous patch ... I don't think we need to log this as an untrusted string as the string value is coming from the kernel, not userspace, so we could rewrite the above as the following:
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
audit_log_format(ab, " anonclass=%s", a->u.anonclass);... if you are okay with that, I can make the change when I merge the patch or you can submit another revision, let me know which you would prefer.
Feel free to adjust while merging, thanks.
Adjusted and merged, thanks.
Signature · 1 line
paul-moore.com