Bug 2368360

Summary: Outdated selinux file labelling generates selinux alert
Product: [Fedora] Fedora Reporter: John Fawcett <john>
Component: selinux-policyAssignee: Zdenek Pytela <zpytela>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: 42CC: daan.j.demeyer, dwalsh, fedoraproject, lnykryn, lvrabec, mmalik, msekleta, omosnacek, pkoncity, suraj.ghimire7, systemd-maint, vmojzis, yuwatana, zbyszek, zpytela
Target Milestone: ---Flags: zpytela: mirror+
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: selinux-policy-41.43-1.fc42 Doc Type: ---
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2025-06-07 06:46:29 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 John Fawcett 2025-05-24 12:00:25 UTC
Description of problem:
-----------------------
following alert is generated at boot time after upgrade to fedora 42

type=AVC msg=audit(1748083304.513:71043): avc:  denied  { write } for  pid=82926 comm="systemd-random-" name="random-seed" dev="sda5" ino=34945 scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:unlabeled_t:s0 tclass=file permissive=0


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

Name           : systemd
Epoch          : 0
Version        : 257.5
Release        : 6.fc42
Architecture   : i686


How reproducible:
-----------------

I have this alert on two different systems and it is reproducible. Other systems don't give the alert. 

On systems where reproducible the label is:
ls -lZ /var/lib/systemd/random-seed
-rw------- 1 root root ? 512 May 19 16:05 /var/lib/systemd/random-seed

On system where not reproducible the label is
ls -lZ /var/lib/systemd/random-seed
-rw-------. 1 root root system_u:object_r:init_var_lib_t:s0 32 May 19 15:51 /var/lib/systemd/random-seed

Steps to Reproduce:
-------------------

Reboot system and then run command
ausearch -m avc

Actual results:
---------------

Result is the message shown above in bug description

Expected results:
-----------------

<no matches>

Additional info:
----------------

solved by

semanage fcontext --add --type random_seed_t "/var/lib/systemd/random-seed"
restorecon var/lib/systemd/random-seed

Label is now correct
ls -lZ /var/lib/systemd/random-seed
-rw-------. 1 root root system_u:object_r:random_seed_t:s0 512 May 24 13:00 /var/lib/systemd/random-seed

Also prior to running the above I checked existing labelling specifications and it seems that the specifications include /usr/var/lib/random-seed which does not exist on the system. I therefore wonder if the location was changed to /usr/var/lib/systemd/random-seed without updating the selinux labelling. Potentially the labelling for the presumably old location /usr/var/lib/random-seed could be removed.

semanage fcontext --list | grep random-seed
/run/random-seed                                   regular file       system_u:object_r:initrc_var_run_t:s0 
/usr/var/lib/random-seed                           all files          system_u:object_r:random_seed_t:s0 
/var/lib/random-seed                               all files          system_u:object_r:random_seed_t:s0

Comment 1 John Fawcett 2025-05-24 14:16:58 UTC
Just noticed while fixing on another system that above labelling did not work. Had to do

semanage fcontext --add --type init_var_lib_t "/var/lib/systemd/random-seed"
restorecon /var/lib/systemd/random-seed

Comment 2 Zbigniew Jędrzejewski-Szmek 2025-05-31 12:39:54 UTC
Yeah, there is some confusion here. I'm not sure why you'd have a file that is unlabelled.
systemd-random-seed doesn't do anything special about the file: it rewrites the
existing file in place, or opens it for writing if it doesn't exist yet. So the
label should be created correctly.

It seems that init_var_lib_t works, but random_seem_t seems more correct. There is an
explicit policy for that context. I filed
https://github.com/fedora-selinux/selinux-policy/pull/2712 to update the locations.

Comment 3 Fedora Update System 2025-06-04 19:42:58 UTC
FEDORA-2025-f9f097f491 (selinux-policy-41.43-1.fc42) has been submitted as an update to Fedora 42.
https://bodhi.fedoraproject.org/updates/FEDORA-2025-f9f097f491

Comment 4 Fedora Update System 2025-06-05 02:35:58 UTC
FEDORA-2025-f9f097f491 has been pushed to the Fedora 42 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2025-f9f097f491`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2025-f9f097f491

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 5 Fedora Update System 2025-06-07 06:46:29 UTC
FEDORA-2025-f9f097f491 (selinux-policy-41.43-1.fc42) has been pushed to the Fedora 42 stable repository.
If problem still persists, please make note of it in this bug report.