Bug 1927551

Summary: SELinux block systemd from running scripts in /usr/lib/systemd/system-sleep
Product: Red Hat Enterprise Linux 8 Reporter: Orion Poplawski <orion>
Component: selinux-policyAssignee: Zdenek Pytela <zpytela>
Status: CLOSED ERRATA QA Contact: Milos Malik <mmalik>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.3CC: lvrabec, mmalik, plautrba, ssekidde
Target Milestone: rcKeywords: Triaged
Target Release: 8.5   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-3.14.3-69.el8 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-09 19:42:58 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 Orion Poplawski 2021-02-11 00:09:16 UTC
Description of problem:

I placed a script in /usr/lib/systemd/system-sleep but it does not get executed:

type=AVC msg=audit(1612929018.423:559): avc:  denied  { execute } for  pid=69804 comm="(direxec)" name="bitdefender-sleep" dev="dm-1" ino=138514047 scontext=system_u:system_r:systemd_sleep_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=file permissive=0

Feb 09 07:17:28 systemd[1]: Starting Suspend...
Feb 09 07:17:28 [133863]: Failed to execute /usr/lib/systemd/system-sleep/bitdefender-sleep: Permission denied
Feb 09 07:17:28 [133862]: /usr/lib/systemd/system-sleep/bitdefender-sleep failed with exit status 1.

Version-Release number of selected component (if applicable):
selinux-policy-3.14.3-54.el8_3.2.noarch

# ls -lZa /usr/lib/systemd/system-sleep
total 12
drwxr-xr-x.  2 root root system_u:object_r:bin_t:s0   31 Dec 17 16:30 ./
drwxr-xr-x. 16 root root system_u:object_r:lib_t:s0 4096 Jan  8 07:18 ../
-rwxr-xr-x.  1 root root system_u:object_r:bin_t:s0  150 Sep  5 10:49 bitdefender-sleep*


allow systemd_sleep_t systemd_sleep_exec_t:file { entrypoint execute getattr ioctl lock map open read };

Perhaps /usr/lib/systemd/system-sleep and it's contents should get labeled systemd_sleep_exec_t ?

FWIW - /usr/lib/systemd/system-shutdown is labeled lib_t instead of bin_t.

restorecon doesn't change any of these labels.

Comment 1 Orion Poplawski 2021-02-11 15:56:36 UTC
Changing to lib_t doesn't help.  Changing to systemd_sleed_exec_t leads to a different denial:

avc:  denied  { getattr } for  pid=144222 comm="(sd-executor)" path="/usr/lib/systemd/system-sleep" dev="dm-1" ino=134845448 scontext=system_u:system_r:systemd_sleep_t:s0 tcontext=system_u:object_r:systemd_sleep_exec_t:s0 tclass=dir permissive=0

Comment 2 Zdenek Pytela 2021-04-19 20:56:33 UTC
I've submitted a Fedora PR to address the issue:
https://github.com/fedora-selinux/selinux-policy/pull/612

Comment 13 errata-xmlrpc 2021-11-09 19:42:58 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (selinux-policy bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:4420