Bug 2140726

Summary: Audit rules for /proc are not loaded on boot
Product: Red Hat Enterprise Linux 9 Reporter: Juan Gamba <jgamba>
Component: auditAssignee: Sergio Correia <scorreia>
Status: CLOSED MIGRATED QA Contact: BaseOS QE Security Team <qe-baseos-security>
Severity: high Docs Contact:
Priority: high    
Version: 9.0CC: alakatos, ravpatil, rmetrich, rsroka, sgrubb
Target Milestone: rcKeywords: MigratedToJIRA, Patch, Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-09-19 17:35:11 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Juan Gamba 2022-11-07 18:45:44 UTC
Description of problem:

Audit rules for "-F dir=/proc" fails to load on boot, the rules works if loaded manually later.
This behavior differs from RHEL 7 (the rules for /proc are loaded correctly on boot)

Version-Release number of selected component (if applicable):

audit-3.0.7-101.el9_0.2.x86_64

How reproducible:

Always

Steps to Reproduce:
1. # vi /etc/audit/rules.d/test.rules
-a never,exit -F arch=b32 -F dir=/proc -S fchmodat
2. # reboot
3. # auditctl -l

Actual results:

# auditctl -l
No rules.

Expected results:

# auditctl -l
-a never,exit -F arch=b32 -S fchmodat -F dir=/proc 

Additional info:

The list of syscalls is actually quite extensive, the same behavior occurs with any syscall we tested, it does not occur if we use a different "-F dir=" value, this behavior is only present on /proc so far.
Another detail, if we run auditd with -f, we can see below log record on system boot's journal:

auditd[xxx]: type=CONFIG_CHANGE msg=audit(xxxxxxxxxx.xxx:xxx): op=remove_rule dir="/proc" key=(null) list=4 res=1

Juan Gamba
Principal Technical Support Engineer
Red Hat - Support Delivery

Comment 1 Steve Grubb 2022-11-07 20:19:31 UTC
auditd is probably starting before procfs is mounted.

Comment 2 Juan Gamba 2022-11-07 20:38:27 UTC
is this a kernel problem then?
I saw it on RHEL 8 as well.

Comment 3 Steve Grubb 2022-11-07 20:45:59 UTC
You'd need to test against RHEL 5 or 6 to see what the original behavior was.
One solution I've is writing a udev rule that loads audit rules when something of interest comes along.

Comment 4 Renaud Métrich 2022-11-08 14:12:59 UTC
The issue is easily reproducible, it's not only happening at boot, but when restarting auditd service.

Manually adding the rule works.

Digging more, I could find that it's due to the following property in the auditd service:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
ProtectControlGroups=true
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

Example 1: (FAILS):

-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
# systemctl cat load_audit.service 
# /etc/systemd/system/load_audit.service
[Service]
Type=oneshot

ExecStartPre=/usr/sbin/auditctl -D
ExecStart=/usr/sbin/auditctl -a never,exit -F arch=b64 -S fchmodat -F dir=/proc

ProtectControlGroups=true
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

Test:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
# systemctl restart load_audit.service 
# auditctl -l
No rules
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------



Example 2: (without "ProtectControlGroups=true", WORKS):

-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
# systemctl cat load_audit.service 
# /etc/systemd/system/load_audit.service
[Service]
Type=oneshot

ExecStartPre=/usr/sbin/auditctl -D
ExecStart=/usr/sbin/auditctl -a never,exit -F arch=b64 -S fchmodat -F dir=/proc

#ProtectControlGroups=true
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

Test:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
# systemctl restart load_audit.service 
# auditctl -l
-a never,exit -F arch=b64 -S fchmodat -F dir=/proc
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

No error gets reported by auditctl command.
So there is something happening in the kernel due to the protection above, but no error is returned through NETLINK layer.
The straces are IDENTICAL, including returned data:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
sendto(4<NETLINK:[AUDIT:xxx]>, [{nlmsg_len=1064, nlmsg_type=AUDIT_ADD_RULE, nlmsg_flags=NLM_F_REQUEST|NLM_F_ACK, nlmsg_seq=2, nlmsg_pid=0}, "\x04\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"...], 1064, 0, {sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, 12) = 1064
poll([{fd=4<NETLINK:[AUDIT:xxx]>, events=POLLIN}], 1, 500) = 1 ([{fd=4, revents=POLLIN}])
recvfrom(4<NETLINK:[AUDIT:xxx]>, [{nlmsg_len=36, nlmsg_type=NLMSG_ERROR, nlmsg_flags=NLM_F_CAPPED, nlmsg_seq=2, nlmsg_pid=xxx}, {error=0, msg={nlmsg_len=1064, nlmsg_type=AUDIT_ADD_RULE, nlmsg_flags=NLM_F_REQUEST|NLM_F_ACK, nlmsg_seq=2, nlmsg_pid=0}}], 8988, MSG_PEEK|MSG_DONTWAIT, {sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, [12]) = 36
recvfrom(4<NETLINK:[AUDIT:xxx]>, [{nlmsg_len=36, nlmsg_type=NLMSG_ERROR, nlmsg_flags=NLM_F_CAPPED, nlmsg_seq=2, nlmsg_pid=xxx}, {error=0, msg={nlmsg_len=1064, nlmsg_type=AUDIT_ADD_RULE, nlmsg_flags=NLM_F_REQUEST|NLM_F_ACK, nlmsg_seq=2, nlmsg_pid=0}}], 8988, MSG_DONTWAIT, {sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, [12]) = 36
close(4<NETLINK:[AUDIT:xxx]>) = 0
exit_group(0)     = ?
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

Comment 5 Steve Grubb 2022-11-08 15:15:19 UTC
Thanks for that hint. Upstream commit 2f631c32 should fix this. And fortunately, the customer can make a change in /etc to override this.

Comment 6 Renaud Métrich 2022-11-08 15:25:04 UTC
Hi Steve,

Can you explain why this doesn't work with that ProtectControlGroups=yes?

All I see comparing the code in the kernel is the rule gets pruned for some reason, due to audit_tree_freeing_mark/audit_tree_destroy_watch being called after rule is added.

Renaud.

Comment 7 Steve Grubb 2022-11-08 15:57:42 UTC
It appears that /proc gets remounted from auditd's perspective. So, the rule is likely placed on /proc that auditd sees and not the one in the init namespace.

Comment 8 Renaud Métrich 2022-11-08 16:04:33 UTC
Indeed, I can see the remount of /proc through strace, following an unshare:

47649 16:31:11.484411 mount("proc", "/proc/self/fd/4", "proc", MS_NOSUID|MS_NODEV|MS_NOEXEC, NULL) = 0 <0.000036>

Wouldn't it be possible to use an alternate mechanism than tag the "current mounts as seen by the service unit" ?

Comment 9 Steve Grubb 2022-11-08 16:12:39 UTC
Not that I know of except for separating rule loading from the auditd.service so that we have 2 services. One for rules and one for the daemon. But this is not the only systemd protection that has impacted the audit system. Well intentioned people submit pull requests asking for systemd protections which we later find out cause problems.

Comment 10 Renaud Métrich 2022-11-09 10:14:54 UTC
I understand, ideally then there should be decoupling between the two:
- auditd service
- audit rules loading

Comment 13 RHEL Program Management 2023-09-19 17:33:04 UTC
Issue migration from Bugzilla to Jira is in process at this time. This will be the last message in Jira copied from the Bugzilla bug.

Comment 14 RHEL Program Management 2023-09-19 17:35:11 UTC
This BZ has been automatically migrated to the issues.redhat.com Red Hat Issue Tracker. All future work related to this report will be managed there.

Due to differences in account names between systems, some fields were not replicated.  Be sure to add yourself to Jira issue's "Watchers" field to continue receiving updates and add others to the "Need Info From" field to continue requesting information.

To find the migrated issue, look in the "Links" section for a direct link to the new issue location. The issue key will have an icon of 2 footprints next to it, and begin with "RHEL-" followed by an integer.  You can also find this issue by visiting https://issues.redhat.com/issues/?jql= and searching the "Bugzilla Bug" field for this BZ's number, e.g. a search like:

"Bugzilla Bug" = 1234567

In the event you have trouble locating or viewing this issue, you can file an issue by sending mail to rh-issues. You can also visit https://access.redhat.com/articles/7032570 for general account information.