libselinux: Revise userspace AVC avc_log() for auditable events.
RFC PATCH 1/1 libselinux: Revise userspace AVC avc_log() for auditable events.
I put up a PR for dbus-broker to revise its auditing:
https://github.com/bus1/dbus-broker/pull/240
Steve Grubb mentioned that there wasn't much useful info in terms of the audit message itself, since it isn't key:value pairs.
I'm looking to revise the avc_log() messages for SELINUX_ERROR, SELINUX_SETENFORCE, and SELINUX_POLICYLOAD messages such that they more closely reseble the kernel audits.
*This patch is _incomplete*; I implemented a few changes to get early feedback on the direction I'm taking. What seems potentially contentious is the 'lsm=selinux_uavc' and op= choices.
--- libselinux/src/avc_internal.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
libselinux/src/avc_internal.c +6 -6
@@ -59,14 +59,14 @@ int avc_process_setenforce(int enforcing)int rc =0 ;avc_log (SELINUX_SETENFORCE , -"%s: received setenforce notice (enforcing=%d)\n" , +"%s: op=setenforce lsm=selinux_uavc enforcing=%d res=1" , avc_prefix, enforcing);if (avc_setenforce) goto out; avc_enforcing = enforcing;if (avc_enforcing && (rc =avc_ss_reset (0 )) <0 ) {avc_log (SELINUX_ERROR , -"%s: cache reset returned %d (errno %d)\n" , +"%s: op=cache_reset lsm=selinux_uavc rc=%d errno=%d res=0" , avc_prefix, rc, errno);return rc; }
@@ -81,12 +81,12 @@ int avc_process_policyload(uint32_t seqno)int rc =0 ;avc_log (SELINUX_POLICYLOAD , -"%s: received policyload notice (seqno=%u)\n" , +"%s: op=load_policy lsm=selinux_uavc seqno=%u res=1" , avc_prefix, seqno); rc =avc_ss_reset (seqno);if (rc <0 ) {avc_log (SELINUX_ERROR , -"%s: cache reset returned %d (errno %d)\n" , +"%s: op=cache_reset lsm=selinux_uavc rc=%d errno=%d res=0" , avc_prefix, rc, errno);return rc; }
@@ -157,7 +157,7 @@ static int avc_netlink_receive(void *buf, unsigned buflen, int blocking)return -1 ; }else if (rc <1 ) { -avc_log (SELINUX_ERROR ,"%s: netlink poll: error %d\n" , +avc_log (SELINUX_ERROR ,"%s: op=netlink_poll lsm=selinux_uavc errno=%d res=0" , avc_prefix, errno);return rc; }
@@ -214,7 +214,7 @@ static int avc_netlink_process(void *buf) errno = -err->error;avc_log (SELINUX_ERROR , -"%s: netlink error: %d\n" , avc_prefix, errno); +"%s: op=netlink_msgtype lsm=selinux_uavc errno=%d res=0" , avc_prefix, errno);return -1 ; }
Signature · 1 line
2.26.2
Stephen Smalley
maintainerQuoted 7 lines · Chris PeBenito
I put up a PR for dbus-broker to revise its auditing:
https://github.com/bus1/dbus-broker/pull/240
Steve Grubb mentioned that there wasn't much useful info in terms of the audit message itself, since it isn't key:value pairs.
Does that matter since it is all just stuffed as a string value for the msg= field?
Quoted 7 lines
I'm looking to revise the
avc_log()messages forSELINUX_ERROR,SELINUX_SETENFORCE, andSELINUX_POLICYLOADmessages such that they more closely reseble the kernel audits.*This patch is _incomplete*; I implemented a few changes to get early feedback on the direction I'm taking. What seems potentially contentious is the 'lsm=selinux_uavc' and op= choices.
Yes, I don't see the point of using a different lsm= value than just "selinux"; the fact that it is a userspace event should get reflected in some other way, right?
Quoted 9 lines
libselinux/src/avc_internal.c +0
-1@@ -59,14 +59,14 @@ int avc_process_setenforce(int enforcing)int rc =0 ; avc_log(SELINUX_SETENFORCE, - "%s: received setenforce notice (enforcing=%d)\n",
libselinux/src/avc_internal.c int avc_process_setenforce(int enforcing) · line 70
Quoted 10 lines
libselinux/src/avc_internal.c +2
-1+"%s: op=setenforce lsm=selinux_uavc enforcing=%d res=1" , avc_prefix, enforcing);if (avc_setenforce) goto out; avc_enforcing = enforcing;if (avc_enforcing && (rc =avc_ss_reset (0 )) <0 ) {avc_log (SELINUX_ERROR , -"%s: cache reset returned %d (errno %d)\n" , +"%s: op=cache_reset lsm=selinux_uavc rc=%d errno=%d res=0" , avc_prefix, rc, errno);
If we do this at all, I would think the op= would still be setenforce and this would just be an error for it.
Looking at the kernel, we aren't even checking avc_ss_reset() for failure and none of the kernel avc callbacks ever return an error.
libselinux/src/avc_internal.c int avc_process_policyload(uint32_t seqno) · line 90
Quoted 13 lines
libselinux/src/avc_internal.c +2
-2@@ -81,12 +81,12 @@ int avc_process_policyload(uint32_t seqno)int rc =0 ;avc_log (SELINUX_POLICYLOAD , -"%s: received policyload notice (seqno=%u)\n" , +"%s: op=load_policy lsm=selinux_uavc seqno=%u res=1" , avc_prefix, seqno); rc =avc_ss_reset (seqno);if (rc <0 ) {avc_log (SELINUX_ERROR , -"%s: cache reset returned %d (errno %d)\n" , +"%s: op=cache_reset lsm=selinux_uavc rc=%d errno=%d res=0" , avc_prefix, rc, errno);
Ditto.
libselinux/src/avc_internal.c static int avc_netlink_receive(void *buf, unsigned buflen, int blocking) · line 163
Quoted 9 lines
libselinux/src/avc_internal.c +1
-1@@ -157,7 +157,7 @@ static int avc_netlink_receive(void *buf, unsigned buflen, int blocking)return -1 ; }else if (rc <1 ) { -avc_log (SELINUX_ERROR ,"%s: netlink poll: error %d\n" , +avc_log (SELINUX_ERROR ,"%s: op=netlink_poll lsm=selinux_uavc errno=%d res=0" , avc_prefix, errno);return rc; }
Not sure what to do with these; arguably they aren't audit events at all, just error logging.
libselinux/src/avc_internal.c static int avc_netlink_process(void *buf) · line 219
Quoted 8 lines
libselinux/src/avc_internal.c +1
-1@@ -214,7 +214,7 @@ static int avc_netlink_process(void *buf) errno = -err->error;avc_log (SELINUX_ERROR , -"%s: netlink error: %d\n" , avc_prefix, errno); +"%s: op=netlink_msgtype lsm=selinux_uavc errno=%d res=0" , avc_prefix, errno);return -1 ; }
Ditto.
Stephen Smalley
maintainerQuoted 27 lines · Chris PeBenito
Quoted 9 lines · Stephen Smalley
Quoted 7 lines · Chris PeBenito
libselinux/src/avc_internal.c +0
-0@@ -59,14 +59,14 @@ int avc_process_setenforce(int enforcing)int rc =0 ;Quoted 15 lines
libselinux/src/avc_internal.c int avc_process_setenforce(int enforcing) · line 70
Quoted 12 lines
libselinux/src/avc_internal.c +2
-2avc_log (SELINUX_SETENFORCE , -"%s: received setenforce notice (enforcing=%d)\n" , +"%s: op=setenforce lsm=selinux_uavc enforcing=%d res=1" , avc_prefix, enforcing);if (avc_setenforce) goto out; avc_enforcing = enforcing;if (avc_enforcing && (rc =avc_ss_reset (0 )) <0 ) {avc_log (SELINUX_ERROR , -"%s: cache reset returned %d (errno %d)\n" , +"%s: op=cache_reset lsm=selinux_uavc rc=%d errno=%d res=0" , avc_prefix, rc, errno);If we do this at all, I would think the op= would still be setenforce and this would just be an error for it.
Quoted 3 lines
At this point we already audited success for the setenforce operation. Wouldn't it be confusing to have a op=setenforce res=1 and then immediately op=setenforce res=0?
Yes. On second thought, I don't think any of the SELINUX_ERROR messages are intended for audit and since that is already a different type value, the callbacks can already redirect those to stderr or syslog as appropriate instead of audit.
Quoted 6 lines
Quoted 2 lines
Looking at the kernel, we aren't even checking
avc_ss_reset()for failure and none of the kernel avc callbacks ever return an error.I'm not deeply familiar with the AVC intricacies. If the cache fails to clear, then there could be wrong cache entries, no? If so, I would argue that it's worthy of an audit. If not, then I agree that it's not auditable.
The AVC reset itself can't fail, only the callbacks registered by the application. Original design/concept was e.g. if the object manager could not flush all migrated permissions for some reason. Don't think there are any such callbacks that can fail today.
Stephen Smalley
maintainerQuoted 40 lines · Chris PeBenito
Quoted 29 lines · Stephen Smalley
Quoted 27 lines · Chris PeBenito
Quoted 24 lines · Stephen Smalley
Quoted 9 lines · Chris PeBenito
libselinux/src/avc_internal.c +0
-1@@ -59,14 +59,14 @@ int avc_process_setenforce(int enforcing)int rc =0 ; avc_log(SELINUX_SETENFORCE, - "%s: received setenforce notice (enforcing=%d)\n",libselinux/src/avc_internal.c int avc_process_setenforce(int enforcing) · line 70
Quoted 10 lines
libselinux/src/avc_internal.c +2
-1+"%s: op=setenforce lsm=selinux_uavc enforcing=%d res=1" , avc_prefix, enforcing);if (avc_setenforce) goto out; avc_enforcing = enforcing;if (avc_enforcing && (rc =avc_ss_reset (0 )) <0 ) {avc_log (SELINUX_ERROR , -"%s: cache reset returned %d (errno %d)\n" , +"%s: op=cache_reset lsm=selinux_uavc rc=%d errno=%d res=0" , avc_prefix, rc, errno);If we do this at all, I would think the op= would still be setenforce and this would just be an error for it.
Quoted 8 lines
Quoted 3 lines
At this point we already audited success for the setenforce operation. Wouldn't it be confusing to have a op=setenforce res=1 and then immediately op=setenforce res=0?
Yes. On second thought, I don't think any of the
SELINUX_ERRORmessages are intended for audit and since that is already a different type value, the callbacks can already redirect those to stderr or syslog as appropriate instead of audit.
Quoted 4 lines
Are the typebounds and validatetrans in UAVC passed to the kernel for evaluation? The kernel audits failures on those as
SELINUX_ERR. If the UAVC handles them itself, it seems that those failures should be audited asUSER_SELINUX_ERR.
The userspace AVC defers all of the security_compute_av() logic to the kernel.
Quoted 29 lines · Stephen Smalley
Quoted 27 lines · Chris PeBenito
Quoted 24 lines · Stephen Smalley
Quoted 9 lines · Chris PeBenito
libselinux/src/avc_internal.c +0
-1@@ -59,14 +59,14 @@ int avc_process_setenforce(int enforcing)int rc =0 ; avc_log(SELINUX_SETENFORCE, - "%s: received setenforce notice (enforcing=%d)\n",libselinux/src/avc_internal.c int avc_process_setenforce(int enforcing) · line 70
Quoted 10 lines
libselinux/src/avc_internal.c +2
-1+"%s: op=setenforce lsm=selinux_uavc enforcing=%d res=1" , avc_prefix, enforcing);if (avc_setenforce) goto out; avc_enforcing = enforcing;if (avc_enforcing && (rc =avc_ss_reset (0 )) <0 ) {avc_log (SELINUX_ERROR , -"%s: cache reset returned %d (errno %d)\n" , +"%s: op=cache_reset lsm=selinux_uavc rc=%d errno=%d res=0" , avc_prefix, rc, errno);If we do this at all, I would think the op= would still be setenforce and this would just be an error for it.
Quoted 8 lines
Quoted 3 lines
At this point we already audited success for the setenforce operation. Wouldn't it be confusing to have a op=setenforce res=1 and then immediately op=setenforce res=0?
Yes. On second thought, I don't think any of the
SELINUX_ERRORmessages are intended for audit and since that is already a different type value, the callbacks can already redirect those to stderr or syslog as appropriate instead of audit.
Are the typebounds and validatetrans in UAVC passed to the kernel for evaluation? The kernel audits failures on those as SELINUX_ERR. If the UAVC handles them itself, it seems that those failures should be audited as USER_SELINUX_ERR.
Signature · 1 line
Chris PeBenito
Quoted 17 lines · Stephen Smalley
Quoted 7 lines · Chris PeBenito
I put up a PR for dbus-broker to revise its auditing:
https://github.com/bus1/dbus-broker/pull/240
Steve Grubb mentioned that there wasn't much useful info in terms of the audit message itself, since it isn't key:value pairs.
Does that matter since it is all just stuffed as a string value for the msg= field?
Quoted 4 lines
I'm looking to revise the
avc_log()messages forSELINUX_ERROR,SELINUX_SETENFORCE, andSELINUX_POLICYLOADmessages such that they more closely reseble the kernel audits.
Quoted 7 lines
Quoted 3 lines
*This patch is _incomplete*; I implemented a few changes to get early feedback on the direction I'm taking. What seems potentially contentious is the 'lsm=selinux_uavc' and op= choices.
Yes, I don't see the point of using a different lsm= value than just "selinux"; the fact that it is a userspace event should get reflected in some other way, right?
Fair point. It's reflected in USER_MAC_POLICY_LOAD instead of MAC_POLICY_LOAD, as an example.
Quoted 7 lines
Quoted 7 lines
libselinux/src/avc_internal.c +0
-0@@ -59,14 +59,14 @@ int avc_process_setenforce(int enforcing)int rc =0 ;
Quoted 15 lines
libselinux/src/avc_internal.c int avc_process_setenforce(int enforcing) · line 70
Quoted 12 lines
libselinux/src/avc_internal.c +2
-2avc_log (SELINUX_SETENFORCE , -"%s: received setenforce notice (enforcing=%d)\n" , +"%s: op=setenforce lsm=selinux_uavc enforcing=%d res=1" , avc_prefix, enforcing);if (avc_setenforce) goto out; avc_enforcing = enforcing;if (avc_enforcing && (rc =avc_ss_reset (0 )) <0 ) {avc_log (SELINUX_ERROR , -"%s: cache reset returned %d (errno %d)\n" , +"%s: op=cache_reset lsm=selinux_uavc rc=%d errno=%d res=0" , avc_prefix, rc, errno);If we do this at all, I would think the op= would still be setenforce and this would just be an error for it.
At this point we already audited success for the setenforce operation. Wouldn't it be confusing to have a op=setenforce res=1 and then immediately op=setenforce res=0?
Quoted 2 lines
Looking at the kernel, we aren't even checking
avc_ss_reset()for failure and none of the kernel avc callbacks ever return an error.
I'm not deeply familiar with the AVC intricacies. If the cache fails to clear, then there could be wrong cache entries, no? If so, I would argue that it's worthy of an audit. If not, then I agree that it's not auditable.
Quoted 4 lines
Quoted 4 lines
libselinux/src/avc_internal.c +0
-0@@ -157,7 +157,7 @@ static int avc_netlink_receive(void *buf, unsigned buflen, int blocking)return -1 ; }else if (rc <1 ) {
Quoted 8 lines
libselinux/src/avc_internal.c static int avc_netlink_receive(void *buf, unsigned buflen, int blocking) · line 163
Quoted 5 lines
libselinux/src/avc_internal.c +1
-1-avc_log (SELINUX_ERROR ,"%s: netlink poll: error %d\n" , +avc_log (SELINUX_ERROR ,"%s: op=netlink_poll lsm=selinux_uavc errno=%d res=0" , avc_prefix, errno);return rc; }Not sure what to do with these; arguably they aren't audit events at all, just error logging.
Perhaps the question is: are any of SELINUX_ERROR actually auditable? If so, it would seem the answer is to either add another log level for auditable errors. If not, then the few UAVC users that audit SELINUX_ERROR need to be fixed. Alternatively we could change these non-auditable SELINUX_ERRORs to SELINUX_WARNING, since admins can't do much about these in most (all?) cases.
Maybe we should add a log callback function to libselinux that UAVC users could optionally use. It would audit where appropriate and otherwise syslog/stderr the message. That would provide an upgrade path for consistent auditing while still allowing UAVC users the option to handle the log callback another way when desired. A another option would be to introduce a new callback specifically for auditing.
Signature · 1 line
Chris PeBenito