Skip to contentSkip to conversation

Userspace AVC auditing on policy load

DISCUSSION Chris PeBenito 4 participants 11 messages Aug 26, 2020 SELinux security module

lore
Share & tools
lore
#0 lore raw

I was looking into this dbus-broker audit message, which has the wrong audit type:

audit[422]: USER_AVC pid=422 uid=999 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t msg='avc: received policyload notice (seqno=2)

This is due to dbus-broker setting their avc log callback to send USER_AVC audit messages for everything that comes to the libselinux log callback. I think the right thing to do there is to change it to emit USER_SELINUX_ERR audit messages if the log message is SELINUX_ERROR, otherwise log the message using their regular method (stderr I think).

But the question became, why is the userspace AVC not simply emitting its own USER_MAC_POLICY_LOAD audit message instead of sending a message to the log callback?

Signature · 1 line
Chris PeBenito
maintainer
#1 lore raw
Quoted 7 lines · Chris PeBenito

I was looking into this dbus-broker audit message, which has the wrong audit type:

audit[422]: USER_AVC pid=422 uid=999 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t msg='avc: received policyload notice (seqno=2)

Quoted 8 lines

This is due to dbus-broker setting their avc log callback to send USER_AVC audit messages for everything that comes to the libselinux log callback. I think the right thing to do there is to change it to emit USER_SELINUX_ERR audit messages if the log message is SELINUX_ERROR, otherwise log the message using their regular method (stderr I think).

But the question became, why is the userspace AVC not simply emitting its own USER_MAC_POLICY_LOAD audit message instead of sending a message to the log callback?

IIRC, the original userspace AVC support predates audit and the intent was for the application to deal with dispatching messages as desired from its callback, whether via libaudit or via syslog or whatever. Not opposed to revisiting that but it would require some care, e.g. not sure you'd want both libselinux and the application calling audit_open().

#2 lore raw
In reply to Chris PeBenito
Quoted 7 lines · Chris PeBenito

I was looking into this dbus-broker audit message, which has the wrong audit type:

audit[422]: USER_AVC pid=422 uid=999 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t msg='avc:  received policyload notice (seqno=2)

This is due to dbus-broker setting their avc log callback to send USER_AVC audit messages for everything that comes to the libselinux log callback. I think the right thing to do there is to change it to emit USER_SELINUX_ERR audit messages if the log message is SELINUX_ERROR, otherwise log the message using their regular method (stderr I think).

But the question became, why is the userspace AVC not simply emitting its own USER_MAC_POLICY_LOAD audit message instead of sending a message to the log callback?

Ok, I missed that there is a SELINUX_AVC log type and that's how the userspace denial messages are sent out. How about adding SELINUX_POLICYLOAD and SELINUX_ENFORCE log types so that callers can emit appropriate audit messages?

Signature · 1 line
Chris PeBenito
maintainer
#3 lore raw
Quoted 14 lines · Chris PeBenito
Quoted 12 lines · Chris PeBenito

I was looking into this dbus-broker audit message, which has the wrong audit type:

audit[422]: USER_AVC pid=422 uid=999 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t msg='avc: received policyload notice (seqno=2)

This is due to dbus-broker setting their avc log callback to send USER_AVC audit messages for everything that comes to the libselinux log callback. I think the right thing to do there is to change it to emit USER_SELINUX_ERR audit messages if the log message is SELINUX_ERROR, otherwise log the message using their regular method (stderr I think).

Quoted 7 lines
Quoted 3 lines

But the question became, why is the userspace AVC not simply emitting its own USER_MAC_POLICY_LOAD audit message instead of sending a message to the log callback?

Ok, I missed that there is a SELINUX_AVC log type and that's how the userspace denial messages are sent out. How about adding SELINUX_POLICYLOAD and SELINUX_ENFORCE log types so that callers can emit appropriate audit messages?

Do we need two different new types or just one? Otherwise, I don't have a problem with adding new ones as long as it doesn't break existing applications.

#4 lore raw
Quoted 20 lines · Stephen Smalley
Quoted 18 lines · Chris PeBenito
Quoted 15 lines · Chris PeBenito

I was looking into this dbus-broker audit message, which has the wrong audit type:

audit[422]: USER_AVC pid=422 uid=999 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t msg='avc: received policyload notice (seqno=2)

This is due to dbus-broker setting their avc log callback to send USER_AVC audit messages for everything that comes to the libselinux log callback. I think the right thing to do there is to change it to emit USER_SELINUX_ERR audit messages if the log message is SELINUX_ERROR, otherwise log the message using their regular method (stderr I think).

But the question became, why is the userspace AVC not simply emitting its own USER_MAC_POLICY_LOAD audit message instead of sending a message to the log callback?

Quoted 7 lines
Quoted 3 lines

Ok, I missed that there is a SELINUX_AVC log type and that's how the userspace denial messages are sent out. How about adding SELINUX_POLICYLOAD and SELINUX_ENFORCE log types so that callers can emit appropriate audit messages?

Do we need two different new types or just one? Otherwise, I don't have a problem with adding new ones as long as it doesn't break existing applications.

Perhaps just the policyload. There is a USER_MAC_POLICY_LOAD audit type which made me think of adding the SELINUX_POLICYLOAD type to the logging callback. There is the log message after processing the setenforce, but there isn't currently a corresponding USER_MAC_STATUS audit message type. It seems like it is justifiable to have a USER_MAC_STATUS audit message for consistency, but I'm not sure how much value it provides.

Signature · 1 line
Chris PeBenito
#5 lore raw
In reply to Stephen Smalley
Quoted 20 lines · Stephen Smalley
Quoted 18 lines · Chris PeBenito
Quoted 15 lines · Chris PeBenito

I was looking into this dbus-broker audit message, which has the wrong audit type:

audit[422]: USER_AVC pid=422 uid=999 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t msg='avc: received policyload notice (seqno=2)

This is due to dbus-broker setting their avc log callback to send USER_AVC audit messages for everything that comes to the libselinux log callback. I think the right thing to do there is to change it to emit USER_SELINUX_ERR audit messages if the log message is SELINUX_ERROR, otherwise log the message using their regular method (stderr I think).

But the question became, why is the userspace AVC not simply emitting its own USER_MAC_POLICY_LOAD audit message instead of sending a message to the log callback?

Quoted 7 lines
Quoted 3 lines

Ok, I missed that there is a SELINUX_AVC log type and that's how the userspace denial messages are sent out. How about adding SELINUX_POLICYLOAD and SELINUX_ENFORCE log types so that callers can emit appropriate audit messages?

Do we need two different new types or just one? Otherwise, I don't have a problem with adding new ones as long as it doesn't break existing applications.

Regarding the risk of breaking existing applications, I did some checking on some userspace AVC users and what they do in their log callback:

* systemd only audits SELINUX_AVC and SELINUX_ERROR messages and ignores others(as Petr noted)
* xorg-server audits SELINUX_AVC correctly but audits SELINUX_INFO as USER_MAC_POLICY_LOAD and everything else it ignores the type and audits as AUDIT_USER_SELINUX_ERR
* dbus-broker ignores type and audits everything as USER_AVC
* dbus-service ignores type and audits everything as USER AVC
* pam: pam_rootok ignores type and audits everything as USER_AVC
* sepgsql custom AVC implementation (this was news to me)
* shadow-utils only audits SELINUX_AVC and SELINUX_ERROR messages and others go to syslog
* cronie: no callback set

That's all the ones I could think of. Which ones am I missing?

Signature · 1 line
Chris PeBenito
maintainer
#6 lore raw
Quoted 46 lines · Chris PeBenito
Quoted 20 lines · Stephen Smalley
Quoted 18 lines · Chris PeBenito
Quoted 15 lines · Chris PeBenito

I was looking into this dbus-broker audit message, which has the wrong audit type:

audit[422]: USER_AVC pid=422 uid=999 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t msg='avc: received policyload notice (seqno=2)

This is due to dbus-broker setting their avc log callback to send USER_AVC audit messages for everything that comes to the libselinux log callback. I think the right thing to do there is to change it to emit USER_SELINUX_ERR audit messages if the log message is SELINUX_ERROR, otherwise log the message using their regular method (stderr I think).

But the question became, why is the userspace AVC not simply emitting its own USER_MAC_POLICY_LOAD audit message instead of sending a message to the log callback?

Quoted 7 lines
Quoted 3 lines

Ok, I missed that there is a SELINUX_AVC log type and that's how the userspace denial messages are sent out. How about adding SELINUX_POLICYLOAD and SELINUX_ENFORCE log types so that callers can emit appropriate audit messages?

Do we need two different new types or just one? Otherwise, I don't have a problem with adding new ones as long as it doesn't break existing applications.

Regarding the risk of breaking existing applications, I did some checking on some userspace AVC users and what they do in their log callback:

* systemd only audits SELINUX_AVC and SELINUX_ERROR messages and ignores others(as Petr noted)
* xorg-server audits SELINUX_AVC correctly but audits SELINUX_INFO as USER_MAC_POLICY_LOAD and everything else it ignores the type and audits as AUDIT_USER_SELINUX_ERR
* dbus-broker ignores type and audits everything as USER_AVC
* dbus-service ignores type and audits everything as USER AVC
* pam: pam_rootok ignores type and audits everything as USER_AVC
* sepgsql custom AVC implementation (this was news to me)
* shadow-utils only audits SELINUX_AVC and SELINUX_ERROR messages and others go to syslog
* cronie: no callback set

Quoted 1 line

That's all the ones I could think of. Which ones am I missing?

Short of searching for everything that calls avc_init() or
selinux_set_callback(), I don't know. Android defines a common log
callback via https://android.googlesource.com/platform/external/selinux/+/refs/heads/master/libselinux/src/android/android.c#236
that funnels everything except for INFO and WARNING to its error stream.

Sounds like introducing new types will do no harm with the possible exception of XSELinux and that's rarely used.
Certainly won't break anything.

#7 lore raw
In reply to Chris PeBenito
Quoted 45 lines · Chris PeBenito
Quoted 20 lines · Stephen Smalley
Quoted 18 lines · Chris PeBenito
Quoted 15 lines · Chris PeBenito

I was looking into this dbus-broker audit message, which has the wrong audit type:

audit[422]: USER_AVC pid=422 uid=999 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t msg='avc: received policyload notice (seqno=2)

This is due to dbus-broker setting their avc log callback to send USER_AVC audit messages for everything that comes to the libselinux log callback. I think the right thing to do there is to change it to emit USER_SELINUX_ERR audit messages if the log message is SELINUX_ERROR, otherwise log the message using their regular method (stderr I think).

But the question became, why is the userspace AVC not simply emitting its own USER_MAC_POLICY_LOAD audit message instead of sending a message to the log callback?

Quoted 6 lines
Quoted 3 lines

Ok, I missed that there is a SELINUX_AVC log type and that's how the userspace denial messages are sent out. How about adding SELINUX_POLICYLOAD and SELINUX_ENFORCE log types so that callers can emit appropriate audit messages?

Do we need two different new types or just one? Otherwise, I don't have a problem with adding new ones as long as it doesn't break existing applications.

Regarding the risk of breaking existing applications, I did some checking on some userspace AVC users and what they do in their log callback:

* systemd only audits SELINUX_AVC and SELINUX_ERROR messages and ignores others(as Petr noted)
* xorg-server audits SELINUX_AVC correctly but audits SELINUX_INFO as USER_MAC_POLICY_LOAD and everything else it ignores the type and audits as AUDIT_USER_SELINUX_ERR
* dbus-broker ignores type and audits everything as USER_AVC
* dbus-service ignores type and audits everything as USER AVC
* pam: pam_rootok ignores type and audits everything as USER_AVC
* sepgsql custom AVC implementation (this was news to me)
* shadow-utils only audits SELINUX_AVC and SELINUX_ERROR messages and others go to syslog
* cronie: no callback set

Quoted 1 line

That's all the ones I could think of. Which ones am I missing?

Probably libreswan, AFAIK that one might also still be using avc_has_perm() instead of selinux_check_access().

Signature · 4 lines
gpg --locate-keys [email protected]
Key fingerprint = FCD2 3660 5D6B 9D27 7FC6  E0FF DA7E 521F 10F6 4098
https://sks-keyservers.net/pks/lookup?op=get&search=0xDA7E521F10F64098
Dominick Grift
#8 lore raw
Quoted 47 lines · Dominick Grift
Quoted 45 lines · Chris PeBenito
Quoted 20 lines · Stephen Smalley
Quoted 18 lines · Chris PeBenito
Quoted 15 lines · Chris PeBenito

I was looking into this dbus-broker audit message, which has the wrong audit type:

audit[422]: USER_AVC pid=422 uid=999 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t msg='avc: received policyload notice (seqno=2)

This is due to dbus-broker setting their avc log callback to send USER_AVC audit messages for everything that comes to the libselinux log callback. I think the right thing to do there is to change it to emit USER_SELINUX_ERR audit messages if the log message is SELINUX_ERROR, otherwise log the message using their regular method (stderr I think).

But the question became, why is the userspace AVC not simply emitting its own USER_MAC_POLICY_LOAD audit message instead of sending a message to the log callback?

Quoted 6 lines
Quoted 3 lines

Ok, I missed that there is a SELINUX_AVC log type and that's how the userspace denial messages are sent out. How about adding SELINUX_POLICYLOAD and SELINUX_ENFORCE log types so that callers can emit appropriate audit messages?

Do we need two different new types or just one? Otherwise, I don't have a problem with adding new ones as long as it doesn't break existing applications.

Regarding the risk of breaking existing applications, I did some checking on some userspace AVC users and what they do in their log callback:

* systemd only audits SELINUX_AVC and SELINUX_ERROR messages and ignores others(as Petr noted)
* xorg-server audits SELINUX_AVC correctly but audits SELINUX_INFO as USER_MAC_POLICY_LOAD and everything else it ignores the type and audits as AUDIT_USER_SELINUX_ERR
* dbus-broker ignores type and audits everything as USER_AVC
* dbus-service ignores type and audits everything as USER AVC
* pam: pam_rootok ignores type and audits everything as USER_AVC
* sepgsql custom AVC implementation (this was news to me)
* shadow-utils only audits SELINUX_AVC and SELINUX_ERROR messages and others go to syslog
* cronie: no callback set

Quoted 4 lines
Quoted 1 line

That's all the ones I could think of. Which ones am I missing?

Probably libreswan, AFAIK that one might also still be using avc_has_perm() instead of selinux_check_access().

You're correct, it is still use avc_has_perm(). There is no log callback set here.

Signature · 1 line
Chris PeBenito
#9 lore raw
Quoted 48 lines · Chris PeBenito
Quoted 47 lines · Dominick Grift
Quoted 45 lines · Chris PeBenito
Quoted 20 lines · Stephen Smalley
Quoted 18 lines · Chris PeBenito
Quoted 15 lines · Chris PeBenito

I was looking into this dbus-broker audit message, which has the wrong audit type:

audit[422]: USER_AVC pid=422 uid=999 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t msg='avc: received policyload notice (seqno=2)

This is due to dbus-broker setting their avc log callback to send USER_AVC audit messages for everything that comes to the libselinux log callback. I think the right thing to do there is to change it to emit USER_SELINUX_ERR audit messages if the log message is SELINUX_ERROR, otherwise log the message using their regular method (stderr I think).

But the question became, why is the userspace AVC not simply emitting its own USER_MAC_POLICY_LOAD audit message instead of sending a message to the log callback?

Quoted 6 lines
Quoted 3 lines

Ok, I missed that there is a SELINUX_AVC log type and that's how the userspace denial messages are sent out. How about adding SELINUX_POLICYLOAD and SELINUX_ENFORCE log types so that callers can emit appropriate audit messages?

Do we need two different new types or just one? Otherwise, I don't have a problem with adding new ones as long as it doesn't break existing applications.

Regarding the risk of breaking existing applications, I did some checking on some userspace AVC users and what they do in their log callback:

* systemd only audits SELINUX_AVC and SELINUX_ERROR messages and ignores others(as Petr noted)
* xorg-server audits SELINUX_AVC correctly but audits SELINUX_INFO as USER_MAC_POLICY_LOAD and everything else it ignores the type and audits as AUDIT_USER_SELINUX_ERR
* dbus-broker ignores type and audits everything as USER_AVC
* dbus-service ignores type and audits everything as USER AVC
* pam: pam_rootok ignores type and audits everything as USER_AVC
* sepgsql custom AVC implementation (this was news to me)
* shadow-utils only audits SELINUX_AVC and SELINUX_ERROR messages and others go to syslog
* cronie: no callback set

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

That's all the ones I could think of. Which ones am I missing?

Probably libreswan, AFAIK that one might also still be using avc_has_perm() instead of selinux_check_access().

You're correct, it is still use avc_has_perm(). There is no log callback set here.

glibc nscd (also seems to be still using avc_has_perm())

Signature · 4 lines
gpg --locate-keys [email protected]
Key fingerprint = FCD2 3660 5D6B 9D27 7FC6  E0FF DA7E 521F 10F6 4098
https://sks-keyservers.net/pks/lookup?op=get&search=0xDA7E521F10F64098
Dominick Grift
#10 lore raw
In reply to Chris PeBenito
Quoted 11 lines · Chris PeBenito

I was looking into this dbus-broker audit message, which has the wrong audit type:

audit[422]: USER_AVC pid=422 uid=999 auid=4294967295 ses=4294967295 subj=system_u:system_r:system_dbusd_t msg='avc: received policyload notice (seqno=2)

This is due to dbus-broker setting their avc log callback to send USER_AVC audit messages for everything that comes to the libselinux log callback. I think the right thing to do there is to change it to emit USER_SELINUX_ERR audit messages if the log message is SELINUX_ERROR, otherwise log the message using their regular method (stderr I think).

Similar problem existed in systemd. It was fixed by the following commit
https://github.com/systemd/systemd/commit/6227fc14c48c4c17daed4b91f61cdd4aa375790a
which lets systemd log callback to ignore everything but SELINUX_AVC and SELINUX_ERR

I believe this is the same problem which should be fixed in dbus and dbus-broker

Quoted 7 lines

But the question became, why is the userspace AVC not simply emitting its own USER_MAC_POLICY_LOAD audit message instead of sending a message to the log callback?

Signature · 1 line
Chris PeBenito