Bug 2225418 - the /run/dhclient.* files are mislabeled when dhclient is executed by the cloud-init-local service
Summary: the /run/dhclient.* files are mislabeled when dhclient is executed by the clo...
Keywords:
Status: VERIFIED
Alias: None
Deadline: 2023-08-08
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: selinux-policy
Version: 9.3
Hardware: Unspecified
OS: Linux
high
high
Target Milestone: rc
: ---
Assignee: Nikola Knazekova
QA Contact: Milos Malik
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-07-25 09:36 UTC by Petr Sklenar
Modified: 2023-08-16 06:44 UTC (History)
4 users (show)

Fixed In Version: selinux-policy-38.1.20-1.el9
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-163268 0 None None None 2023-07-25 09:37:45 UTC

Internal Links: 2229726

Description Petr Sklenar 2023-07-25 09:36:38 UTC
Description of problem:
dhclient has avc denial

Version-Release number of selected component (if applicable):
dhcp-client-4.4.2-19.b1.el9.x86_64
selinux-policy-38.1.17-1.el9.noarch

How reproducible:
always 

Steps to Reproduce:
1. just run dhclient and you will see denial
2. ls -laZ /var/run/dhclient.pid
-rw-r--r--. 1 root root system_u:object_r:var_run_t:s0 4 Jul 25 05:25 /var/run/dhclient.pid
3.

Actual results:
$ tail -f /var/log/audit/audit.log | grep den &
[1] 5267
$ dhclient
type=AVC msg=audit(1690277578.888:432): avc:  denied  { read } for  pid=5269 comm="dhclient" name="dhclient.pid" dev="tmpfs" ino=778 scontext=unconfined_u:system_r:dhcpc_t:s0-s0:c0.c1023 tcontext=system_u:object_r:var_run_t:s0 tclass=file permissive=0
type=AVC msg=audit(1690277578.889:433): avc:  denied  { write } for  pid=5269 comm="dhclient" name="dhclient.pid" dev="tmpfs" ino=778 scontext=unconfined_u:system_r:dhcpc_t:s0-s0:c0.c1023 tcontext=system_u:object_r:var_run_t:s0 tclass=file permissive=0
Can't create /var/run/dhclient.pid: Permission denied

type=AVC msg=audit(1690277580.959:434): avc:  denied  { write } for  pid=5269 comm="dhclient" name="dhclient.pid" dev="tmpfs" ino=778 scontext=unconfined_u:system_r:dhcpc_t:s0-s0:c0.c1023 tcontext=system_u:object_r:var_run_t:s0 tclass=file permissive=0


Expected results:
no denial

Additional info:

Comment 1 Milos Malik 2023-07-25 11:35:21 UTC
Seen on 1MT-RHEL-9.3.0-20230718.0 machine:

# restorecon -Rv /run/
Relabeled /run/dhclient.lease from system_u:object_r:var_run_t:s0 to system_u:object_r:dhcpc_var_run_t:s0
Relabeled /run/dhclient.pid from system_u:object_r:var_run_t:s0 to system_u:object_r:dhcpc_var_run_t:s0
Relabeled /run/NetworkManager/no-stub-resolv.conf from system_u:object_r:NetworkManager_var_run_t:s0 to system_u:object_r:net_conf_t:s0
#

The dhclient.pid file must have been created by something else, because the following sequence works correctly:

# rm -f /run/dhclient.*
# ls -Z /var/run/dhclient.*
ls: cannot access '/var/run/dhclient.*': No such file or directory
# dhclient
# ls -Z /var/run/dhclient.*
unconfined_u:object_r:dhcpc_var_run_t:s0 /var/run/dhclient.pid
#

Comment 2 Milos Malik 2023-07-25 16:37:27 UTC
Based on SELinux denials shown in comment#0, the /var/run/dhclient.pid file is mislabeled and that's the reason why SELinux denials appear. If it was labeled correctly, no SELinux denials would have appeared.

Correct SELinux context defined by SELinux policy is:

# matchpathcon /var/run/dhclient.pid
/var/run/dhclient.pid	system_u:object_r:dhcpc_var_run_t:s0
#

Comment#1 shows that execution of the dhclient program is not the cause.

In order to fix the issue, we need to find out what process created the mislabeled file: /var/run/dhclient.pid

Comment 3 Nikola Knazekova 2023-07-26 20:07:59 UTC
This is from the cloud-init.log: 
- subp.py[DEBUG]: Running command ['/usr/sbin/dhclient', '-1', '-v', '-lf', '/run/dhclient.lease', '-pf', '/run/dhclient.pid', 'eth0', '-sf', '/bin/true'] with allowed return codes [0] (shell=False, capture=True)

After restorecon and rebooting 1mt machine, the /var/run/dhclient.* got wrong label var_run_t.

So I added type transition rule for cloud_init when creating dhclient.pid/lease, and after reboot it has correct label dhcpd_var_run_t.
Can you please retest it, and confirm the fix with selinux-policy version 38.22-1.fc39.101?
# dnf copr enable nknazeko/selinux-policy 

Thank you

Nikola

Comment 8 Nikola Knazekova 2023-07-28 14:34:40 UTC
Fixed in other copr build, version 38.22-1.fc39.201, can you please test it?

Comment 14 Nikola Knazekova 2023-08-10 13:06:42 UTC
PR: https://github.com/fedora-selinux/selinux-policy/pull/1800


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