Bug 1966492

Summary: SELinux prevents systemd-hostnamed from removing the /run/systemd/default-hostname file
Product: Red Hat Enterprise Linux 9 Reporter: Jan Stodola <jstodola>
Component: selinux-policyAssignee: Zdenek Pytela <zpytela>
Status: CLOSED CURRENTRELEASE QA Contact: Milos Malik <mmalik>
Severity: medium Docs Contact:
Priority: medium    
Version: 9.0CC: lvrabec, mmalik, plautrba, pzatko, ssekidde, xiliang
Target Milestone: betaKeywords: Triaged
Target Release: 9.0 Beta   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-34.1.7-1.el9 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-12-07 21:35:16 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:
Bug Depends On:    
Bug Blocks: 1942219    

Description Jan Stodola 2021-06-01 09:32:41 UTC
Description of problem:
The following AVC is found on the system after the default package set installation (Server with GUI) and booting the installed system:

type=AVC msg=audit(1622539307.512:194): avc:  denied  { write } for  pid=885 comm="systemd-hostnam" name="systemd" dev="tmpfs" ino=2 scontext=system_u:system_r:systemd_hostnamed_t:s0 tcontext=system_u:object_r:init_var_run_t:s0 tclass=dir permissive=0


Version-Release number of selected component (if applicable):
RHEL-9.0.0-20210531.2
selinux-policy-34.1.5-1.el9
systemd-248-5.el9

How reproducible:
always

Steps to Reproduce:
1. Run the default package set installation
2. Login to the installed system, check /var/log/audit/audit.log

Actual results:
avc:  denied  { write } for  pid=885 comm="systemd-hostnam"

Expected results:
No "systemd-hostnam" related denial.

Comment 2 Zdenek Pytela 2021-06-01 09:48:25 UTC
A commit to backport:
commit 517e50b36175e3ded1b195ec589e6bbe6f905797
Author: Zdenek Pytela <zpytela>
Date:   Tue May 18 19:17:59 2021 +0200

    Label /run/systemd/default-hostname with hostname_etc_t
    
    The /run/systemd/default-hostname file is created by systemd
    during boot time and can be removed later by systemd-hostnamed.
    Accordingly, the file transition is defined for systemd and
    systemd-hostnamed is allowed to delete pid dir entries.
    
    Resolves: rhbz#1953060

Comment 3 Milos Malik 2021-06-02 06:38:52 UTC
Here is the complete SELinux denial caught in enforcing mode:
----
type=PROCTITLE msg=audit(06/02/2021 02:36:16.136:131) : proctitle=/usr/lib/systemd/systemd-hostnamed 
type=PATH msg=audit(06/02/2021 02:36:16.136:131) : item=1 name=/run/systemd/default-hostname inode=12 dev=00:19 mode=file,644 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:init_var_run_t:s0 nametype=DELETE cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0 
type=PATH msg=audit(06/02/2021 02:36:16.136:131) : item=0 name=/run/systemd/ inode=2 dev=00:19 mode=dir,755 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:init_var_run_t:s0 nametype=PARENT cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0 
type=CWD msg=audit(06/02/2021 02:36:16.136:131) : cwd=/ 
type=SYSCALL msg=audit(06/02/2021 02:36:16.136:131) : arch=x86_64 syscall=unlink success=no exit=EACCES(Permission denied) a0=0x7f54da792445 a1=0x1 a2=0x7f54da7aff9d a3=0x7f54da5003e0 items=2 ppid=1 pid=580 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=unset comm=systemd-hostnam exe=/usr/lib/systemd/systemd-hostnamed subj=system_u:system_r:systemd_hostnamed_t:s0 key=(null) 
type=AVC msg=audit(06/02/2021 02:36:16.136:131) : avc:  denied  { write } for  pid=580 comm=systemd-hostnam name=systemd dev="tmpfs" ino=2 scontext=system_u:system_r:systemd_hostnamed_t:s0 tcontext=system_u:object_r:init_var_run_t:s0 tclass=dir permissive=0 
----

# ls -lZ /run/systemd/default-hostname 
-rw-r--r--. 1 root root system_u:object_r:init_var_run_t:s0 10 Jun  2 02:36 /run/systemd/default-hostname
#

Comment 4 Milos Malik 2021-06-02 06:43:16 UTC
Here are SELinux denials caught in permissive mode:
----
type=PROCTITLE msg=audit(06/02/2021 02:41:36.291:130) : proctitle=/usr/lib/systemd/systemd-hostnamed 
type=PATH msg=audit(06/02/2021 02:41:36.291:130) : item=1 name=/run/systemd/default-hostname inode=12 dev=00:19 mode=file,644 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:init_var_run_t:s0 nametype=DELETE cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0 
type=PATH msg=audit(06/02/2021 02:41:36.291:130) : item=0 name=/run/systemd/ inode=2 dev=00:19 mode=dir,755 ouid=root ogid=root rdev=00:00 obj=system_u:object_r:init_var_run_t:s0 nametype=PARENT cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0 
type=CWD msg=audit(06/02/2021 02:41:36.291:130) : cwd=/ 
type=SYSCALL msg=audit(06/02/2021 02:41:36.291:130) : arch=x86_64 syscall=unlink success=yes exit=0 a0=0x7f334a5ac445 a1=0x1 a2=0x7f334a5c9f9d a3=0x7f334a31a3e0 items=2 ppid=1 pid=580 auid=unset uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=unset comm=systemd-hostnam exe=/usr/lib/systemd/systemd-hostnamed subj=system_u:system_r:systemd_hostnamed_t:s0 key=(null) 
type=AVC msg=audit(06/02/2021 02:41:36.291:130) : avc:  denied  { unlink } for  pid=580 comm=systemd-hostnam name=default-hostname dev="tmpfs" ino=12 scontext=system_u:system_r:systemd_hostnamed_t:s0 tcontext=system_u:object_r:init_var_run_t:s0 tclass=file permissive=1 
type=AVC msg=audit(06/02/2021 02:41:36.291:130) : avc:  denied  { remove_name } for  pid=580 comm=systemd-hostnam name=default-hostname dev="tmpfs" ino=12 scontext=system_u:system_r:systemd_hostnamed_t:s0 tcontext=system_u:object_r:init_var_run_t:s0 tclass=dir permissive=1 
type=AVC msg=audit(06/02/2021 02:41:36.291:130) : avc:  denied  { write } for  pid=580 comm=systemd-hostnam name=systemd dev="tmpfs" ino=2 scontext=system_u:system_r:systemd_hostnamed_t:s0 tcontext=system_u:object_r:init_var_run_t:s0 tclass=dir permissive=1 
----

Comment 17 Martin Pitt 2021-08-07 05:32:14 UTC
*** Bug 1978507 has been marked as a duplicate of this bug. ***