Skip to contentSkip to conversation

unnecessary log output in selinux_status_updated

DISCUSSION Petr Lautrbach 2 participants 5 messages Oct 7, 2022 – Oct 11, 2022 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hi,

Commit 05bdc03130d74 ("libselinux: use kernel status page by default") changed selinux_status_updated() so that it calls avc_process_policyload() and avc_process_setenforce() and both functions call avc_log() and avc_log() logs to stderr by default. So when a process like rpm checks whether there was a change, it gets output on stderr which previously wasn't there.

Before this change:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

from selinux import *
selinux_status_open(0);

0

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

selinux_status_updated();

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_mkload_policy(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

1

Current version:

Quoted 1 line
Quoted 1 line
Quoted 1 line

from selinux import *

elinux_status_updated();
selinux_mkload_policy(0);
selinux_status_updated();

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_open(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_mkload_policy(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

uavc: op=load_policy lsm=selinux seqno=2 res=11

The calling process could set its callback but it seems unnecessarily complicated just for selinux_status_updated() which is supposed to check whether something has changed or not. Also processing events in this function seems to be unnecessary.

It looks like the reason for the new code added to selinux_status_updated() is that there were several avc_netlink_check_nb() calls replaced by selinux_status_updated(). Given the problem described above, I don't think it's correct and I would like to change selinux_status_updated() back and use another mechanism that would help with the replacement.

So what do you think about it?

Petr

maintainer
#1 lore raw
Quoted 43 lines · Petr Lautrbach

Hi,

Commit 05bdc03130d74 ("libselinux: use kernel status page by default") changed selinux_status_updated() so that it calls avc_process_policyload() and avc_process_setenforce() and both functions call avc_log() and avc_log() logs to stderr by default. So when a process like rpm checks whether there was a change, it gets output on stderr which previously wasn't there.

Before this change:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

from selinux import *
selinux_status_open(0);

0

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

selinux_status_updated();

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_mkload_policy(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

1

Current version:

Quoted 1 line
Quoted 1 line
Quoted 1 line

from selinux import *

elinux_status_updated();
selinux_mkload_policy(0);
selinux_status_updated();

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_open(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_mkload_policy(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

uavc: op=load_policy lsm=selinux seqno=2 res=11

The calling process could set its callback but it seems unnecessarily complicated just for selinux_status_updated() which is supposed to check whether something has changed or not. Also processing events in this function seems to be unnecessary.

Quoted 8 lines

It looks like the reason for the new code added to selinux_status_updated() is that there were several avc_netlink_check_nb() calls replaced by selinux_status_updated(). Given the problem described above, I don't think it's correct and I would like to change selinux_status_updated() back and use another mechanism that would help with the replacement.

So what do you think about it?

The goal was to switch the AVC and all of its users (e.g. selinux_check_access) over to using the much more efficient SELinux kernel status page mechanism for setenforce and policy load notifications on newer kernels instead of the SELinux netlink mechanism (which imposed extra syscall overhead on the critical path).

Understand your concern but unsure as to whether we can just change selinux_status_updated() back now.
Would require an audit of all users of selinux_status_updated(), both direct and indirect, to ensure that none of them are relying on this behavior. We can obviously fix the callers within libselinux but addressing external callers is more problematic and is arguably an ABI change. Would need to look at all users of the AVC, selinux_check_access(), etc.
This change happened 2 years ago so I have to wonder why it is only coming up now?

#2 lore raw
Quoted 59 lines · Stephen Smalley
Quoted 43 lines · Petr Lautrbach

Hi,

Commit 05bdc03130d74 ("libselinux: use kernel status page by default") changed selinux_status_updated() so that it calls avc_process_policyload() and avc_process_setenforce() and both functions call avc_log() and avc_log() logs to stderr by default. So when a process like rpm checks whether there was a change, it gets output on stderr which previously wasn't there.

Before this change:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

from selinux import *
selinux_status_open(0);

0

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

selinux_status_updated();

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_mkload_policy(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

1

Current version:

Quoted 1 line
Quoted 1 line
Quoted 1 line

from selinux import *

elinux_status_updated();
selinux_mkload_policy(0);
selinux_status_updated();

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_open(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_mkload_policy(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

uavc: op=load_policy lsm=selinux seqno=2 res=11

The calling process could set its callback but it seems unnecessarily complicated just for selinux_status_updated() which is supposed to check whether something has changed or not. Also processing events in this function seems to be unnecessary.

Quoted 8 lines

It looks like the reason for the new code added to selinux_status_updated() is that there were several avc_netlink_check_nb() calls replaced by selinux_status_updated(). Given the problem described above, I don't think it's correct and I would like to change selinux_status_updated() back and use another mechanism that would help with the replacement.

So what do you think about it?

The goal was to switch the AVC and all of its users (e.g. selinux_check_access) over to using the much more efficient SELinux kernel status page mechanism for setenforce and policy load notifications on newer kernels instead of the SELinux netlink mechanism (which imposed extra syscall overhead on the critical path).

Quoted 10 lines

Understand your concern but unsure as to whether we can just change selinux_status_updated() back now.
Would require an audit of all users of selinux_status_updated(), both direct and indirect, to ensure that none of them are relying on this behavior. We can obviously fix the callers within libselinux but addressing external callers is more problematic and is arguably an ABI change. Would need to look at all users of the AVC, selinux_check_access(), etc.
This change happened 2 years ago so I have to wonder why it is only coming up now?

Nobody has noticed it.

83 avc_log(SELINUX_POLICYLOAD,
84 "%s: op=load_policy lsm=selinux seqno=%u res=1",
85 avc_prefix, seqno);

There's missing '\n' and so this message is sooner or later overwritten by something else, see
https://bugzilla.redhat.com/show_bug.cgi?id=2123637 and
https://bugzilla.redhat.com/show_bug.cgi?id=2123719

maintainer
#3 lore raw
Quoted 75 lines · Petr Lautrbach
Quoted 59 lines · Stephen Smalley
Quoted 43 lines · Petr Lautrbach

Hi,

Commit 05bdc03130d74 ("libselinux: use kernel status page by default") changed selinux_status_updated() so that it calls avc_process_policyload() and avc_process_setenforce() and both functions call avc_log() and avc_log() logs to stderr by default. So when a process like rpm checks whether there was a change, it gets output on stderr which previously wasn't there.

Before this change:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

from selinux import *
selinux_status_open(0);

0

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

selinux_status_updated();

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_mkload_policy(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

1

Current version:

Quoted 1 line
Quoted 1 line
Quoted 1 line

from selinux import *

elinux_status_updated();
selinux_mkload_policy(0);
selinux_status_updated();

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_open(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_mkload_policy(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

uavc: op=load_policy lsm=selinux seqno=2 res=11

The calling process could set its callback but it seems unnecessarily complicated just for selinux_status_updated() which is supposed to check whether something has changed or not. Also processing events in this function seems to be unnecessary.

Quoted 8 lines

It looks like the reason for the new code added to selinux_status_updated() is that there were several avc_netlink_check_nb() calls replaced by selinux_status_updated(). Given the problem described above, I don't think it's correct and I would like to change selinux_status_updated() back and use another mechanism that would help with the replacement.

So what do you think about it?

The goal was to switch the AVC and all of its users (e.g. selinux_check_access) over to using the much more efficient SELinux kernel status page mechanism for setenforce and policy load notifications on newer kernels instead of the SELinux netlink mechanism (which imposed extra syscall overhead on the critical path).

Quoted 10 lines

Understand your concern but unsure as to whether we can just change selinux_status_updated() back now.
Would require an audit of all users of selinux_status_updated(), both direct and indirect, to ensure that none of them are relying on this behavior. We can obviously fix the callers within libselinux but addressing external callers is more problematic and is arguably an ABI change. Would need to look at all users of the AVC, selinux_check_access(), etc.
This change happened 2 years ago so I have to wonder why it is only coming up now?

Nobody has noticed it.

Quoted 8 lines

83 avc_log(SELINUX_POLICYLOAD,
84 "%s: op=load_policy lsm=selinux seqno=%u res=1",
85 avc_prefix, seqno);

There's missing '\n' and so this message is sooner or later overwritten by something else, see
https://bugzilla.redhat.com/show_bug.cgi?id=2123637 and
https://bugzilla.redhat.com/show_bug.cgi?id=2123719

Ok, regardless, we need to ensure that changing it won't break systemd, dbus, or any other userspace object managers.

#4 lore raw
Quoted 80 lines · Stephen Smalley
Quoted 79 lines · Petr Lautrbach
Quoted 59 lines · Stephen Smalley
Quoted 43 lines · Petr Lautrbach

Hi,

Commit 05bdc03130d74 ("libselinux: use kernel status page by default") changed selinux_status_updated() so that it calls avc_process_policyload() and avc_process_setenforce() and both functions call avc_log() and avc_log() logs to stderr by default. So when a process like rpm checks whether there was a change, it gets output on stderr which previously wasn't there.

Before this change:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

from selinux import *
selinux_status_open(0);

0

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

selinux_status_updated();

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_mkload_policy(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

1

Current version:

Quoted 1 line
Quoted 1 line
Quoted 1 line

from selinux import *

elinux_status_updated();
selinux_mkload_policy(0);
selinux_status_updated();

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_open(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_mkload_policy(0);

0

Quoted 1 line
Quoted 1 line
Quoted 1 line

selinux_status_updated();

uavc: op=load_policy lsm=selinux seqno=2 res=11

The calling process could set its callback but it seems unnecessarily complicated just for selinux_status_updated() which is supposed to check whether something has changed or not. Also processing events in this function seems to be unnecessary.

Quoted 8 lines

It looks like the reason for the new code added to selinux_status_updated() is that there were several avc_netlink_check_nb() calls replaced by selinux_status_updated(). Given the problem described above, I don't think it's correct and I would like to change selinux_status_updated() back and use another mechanism that would help with the replacement.

So what do you think about it?

The goal was to switch the AVC and all of its users (e.g. selinux_check_access) over to using the much more efficient SELinux kernel status page mechanism for setenforce and policy load notifications on newer kernels instead of the SELinux netlink mechanism (which imposed extra syscall overhead on the critical path).

Quoted 10 lines

Understand your concern but unsure as to whether we can just change selinux_status_updated() back now.
Would require an audit of all users of selinux_status_updated(), both direct and indirect, to ensure that none of them are relying on this behavior. We can obviously fix the callers within libselinux but addressing external callers is more problematic and is arguably an ABI change. Would need to look at all users of the AVC, selinux_check_access(), etc.
This change happened 2 years ago so I have to wonder why it is only coming up now?

Nobody has noticed it.

83 avc_log(SELINUX_POLICYLOAD,
84 "%s: op=load_policy lsm=selinux seqno=%u res=1",
85 avc_prefix, seqno);

Quoted 7 lines
Quoted 4 lines

There's missing '\n' and so this message is sooner or later overwritten by something else, see
https://bugzilla.redhat.com/show_bug.cgi?id=2123637 and
https://bugzilla.redhat.com/show_bug.cgi?id=2123719

Ok, regardless, we need to ensure that changing it won't break systemd, dbus, or any other userspace object managers.

rpm maintainer decided to implement a logging callback [1], and so there's no need to change this back.

[1] https://github.com/rpm-software-management/rpm/pull/2201

Petr