RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2126583 - systemd InaccessiblePaths triggers SELinux alerts
Summary: systemd InaccessiblePaths triggers SELinux alerts
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: selinux-policy
Version: 8.6
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Zdenek Pytela
QA Contact: Milos Malik
URL:
Whiteboard:
Depends On:
Blocks: 2127972
TreeView+ depends on / blocked
 
Reported: 2022-09-14 01:50 UTC by Etienne CHAMPETIER
Modified: 2022-09-19 13:55 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: No Doc Update
Doc Text:
Clone Of:
: 2127972 (view as bug list)
Environment:
Last Closed: 2022-09-19 13:52:05 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-133895 0 None None None 2022-09-14 07:28:12 UTC

Description Etienne CHAMPETIER 2022-09-14 01:50:57 UTC
Description of problem:
I'm using systemd InaccessiblePaths directive to prevent firewalld from using iptables
this causes SELinux alerts

Version-Release number of selected component (if applicable):
selinux-policy-3.14.3-95.el8_6.4

How reproducible:
100%

Steps to Reproduce:
1. install firewalld

2. add the following systemd dropin
```
# /etc/systemd/system/firewalld.service.d/10-hide-iptables.conf
[Service]
# Hide iptables so firewalld doesn't flush tables on start/reload/stop
InaccessiblePaths=/usr/sbin/xtables-nft-multi
```

3. restart firewalld

Actual results:
type=AVC msg=audit(1663092286.961:27): avc:  denied  { getattr } for  pid=1889 comm="firewalld" path="/usr/sbin/xtables-nft-multi" dev="tmpfs" ino=16285 scontext=system_u:system_r:firewalld_t:s0 tcontext=system_u:object_r:init_var_run_t:s0 tclass=file permissive=1


Expected results:
No log spam, either allow the program to try accessing the inaccessible file, or block the access and make it silent


Additional info:

Haven't looked at the code but I think systemd does some bind mount to those inaccessible files

# ls -laZ /run/systemd/inaccessible/
total 0
d---------.  3 root root system_u:object_r:init_var_run_t:s0  160 Sep 13 20:04 .
drwxr-xr-x. 16 root root system_u:object_r:init_var_run_t:s0  420 Sep 13 20:05 ..
b---------.  1 root root system_u:object_r:init_var_run_t:s0 0, 0 Sep 13 20:04 blk
c---------.  1 root root system_u:object_r:init_var_run_t:s0 0, 0 Sep 13 20:04 chr
d---------.  2 root root system_u:object_r:init_var_run_t:s0   40 Sep 13 20:04 dir
p---------.  1 root root system_u:object_r:init_var_run_t:s0    0 Sep 13 20:04 fifo
----------.  1 root root system_u:object_r:init_var_run_t:s0    0 Sep 13 20:04 reg
s---------.  1 root root system_u:object_r:init_var_run_t:s0    0 Sep 13 20:04 sock

Comment 1 Milos Malik 2022-09-14 07:29:43 UTC
Appears multiple times in enforcing mode:
----
type=PROCTITLE msg=audit(09/14/2022 09:23:34.399:707) : proctitle=/usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid 
type=PATH msg=audit(09/14/2022 09:23:34.399:707) : item=0 name=/usr/sbin/ebtables-restore inode=1333 dev=00:18 mode=file,000 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:init_var_run_t:s0 nametype=NORMAL cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0 
type=CWD msg=audit(09/14/2022 09:23:34.399:707) : cwd=/ 
type=SYSCALL msg=audit(09/14/2022 09:23:34.399:707) : arch=x86_64 syscall=stat success=no exit=EACCES(Permission denied) a0=0x7efe609c8d50 a1=0x7ffe12af3990 a2=0x7ffe12af3990 a3=0x1 items=1 ppid=1 pid=20500 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=unset comm=firewalld exe=/usr/libexec/platform-python3.6 subj=system_u:system_r:firewalld_t:s0 key=(null) 
type=AVC msg=audit(09/14/2022 09:23:34.399:707) : avc:  denied  { getattr } for  pid=20500 comm=firewalld path=/usr/sbin/xtables-nft-multi dev="tmpfs" ino=1333 scontext=system_u:system_r:firewalld_t:s0 tcontext=system_u:object_r:init_var_run_t:s0 tclass=file permissive=0 
----

But the file context does not change:

# ls -lZ /usr/sbin/xtables-*
lrwxrwxrwx. 1 root root system_u:object_r:bin_t:s0               17 Aug  5 17:31 /usr/sbin/xtables-monitor -> xtables-nft-multi
-rwxr-xr-x. 1 root root system_u:object_r:iptables_exec_t:s0 221784 Aug  5 17:31 /usr/sbin/xtables-nft-multi
#

The content of type=PATH records varies:

name=/usr/sbin/ebtables
name=/usr/sbin/ebtables-restore
name=/usr/sbin/ip6tables
name=/usr/sbin/ip6tables-restore
name=/usr/sbin/iptables
name=/usr/sbin/iptables-restore

# rpm -qa selinux\* firewalld\* | sort
firewalld-0.9.3-13.el8.noarch
firewalld-filesystem-0.9.3-13.el8.noarch
selinux-policy-3.14.3-108.el8.noarch
selinux-policy-devel-3.14.3-108.el8.noarch
selinux-policy-doc-3.14.3-108.el8.noarch
selinux-policy-minimum-3.14.3-108.el8.noarch
selinux-policy-mls-3.14.3-108.el8.noarch
selinux-policy-sandbox-3.14.3-108.el8.noarch
selinux-policy-targeted-3.14.3-108.el8.noarch
#

Comment 2 Milos Malik 2022-09-14 07:33:55 UTC
Appears only once in permissive mode:
----
type=PROCTITLE msg=audit(09/14/2022 09:30:01.429:802) : proctitle=/usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid 
type=PATH msg=audit(09/14/2022 09:30:01.429:802) : item=0 name=/usr/sbin/iptables inode=1333 dev=00:18 mode=file,000 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:init_var_run_t:s0 nametype=NORMAL cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0 
type=CWD msg=audit(09/14/2022 09:30:01.429:802) : cwd=/ 
type=SYSCALL msg=audit(09/14/2022 09:30:01.429:802) : arch=x86_64 syscall=stat success=yes exit=0 a0=0x7f06e61adf30 a1=0x7fff9e641760 a2=0x7fff9e641760 a3=0x1 items=1 ppid=1 pid=23059 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=unset comm=firewalld exe=/usr/libexec/platform-python3.6 subj=system_u:system_r:firewalld_t:s0 key=(null) 
type=AVC msg=audit(09/14/2022 09:30:01.429:802) : avc:  denied  { getattr } for  pid=23059 comm=firewalld path=/usr/sbin/xtables-nft-multi dev="tmpfs" ino=1333 scontext=system_u:system_r:firewalld_t:s0 tcontext=system_u:object_r:init_var_run_t:s0 tclass=file permissive=1 
----

# mount | grep tmpfs
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=907960k,nr_inodes=226990,mode=755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)
tmpfs on /run/stratisd/keyfiles type tmpfs (rw,relatime,seclabel,size=1024k)
tmpfs on /run/user/42 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=185592k,mode=700,uid=42,gid=42)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=185592k,mode=700)
# find /run -xdev -inum 1333
/run/systemd/inaccessible/reg
# ls -ilZ /run/systemd/inaccessible/reg 
1333 ----------. 1 root root system_u:object_r:init_var_run_t:s0 0 Sep 14 08:29 /run/systemd/inaccessible/reg
#

Comment 3 Zdenek Pytela 2022-09-19 13:52:05 UTC
Etienne,

As discussed with systemd developers, when directives like InaccessiblePaths are used, any access outside the scope should be reported since it may indicate an incorrect service behaviour or a security issue. This can be done both on systemd side as well as on selinux-policy, these layers are independent.

What we can do is to assign a different label to inaccessible files so that the issue is clear without additional audit data, but not in RHEL 8.

If you need a selinux support to your scenario, use a local policy module, e. g.

  # cat local_dontaudit_firewalld_inaccessible.cil
(dontaudit firewalld_t init_var_run_t (file (getattr)))
  # semodule -i local_dontaudit_firewalld_inaccessible.cil


Note You need to log in before you can comment on or make changes to this bug.