Hello everyone!
For context, I have a computer that was running Fedora 39 and I recently upgraded to Fedora 40.
There appears to be an issue with Virt-Manager / libvirt in Fedora 40. SELinux is preventing me from creating a new guest image if I try to emulate a TPM 2.0. Digging into it, I eventually find a log file that reports “swtpm at /usr/bin/swtpm does not support TPM 2” and there will be exceptions in SELinux indicating that it blocked stuff.
If I disable SELinux I have no issues, I can create the guest, suggesting the issue is with SELinux.
I tried doing a “touch /.autorelabel” and rebooting the system as I found other posts suggesting that the context labels were wrong after the upgrade but this did not correct the issue for me. Just for clarification, I don’t have an issue with running guest VMs, I only have an issue if the guest VM is emulating a TPM.
Running “ausearch -m AVC,USER_AVC -ts recent” I get entries that look like this:
time->Thu Apr 25 18:01:14 2024
type=AVC msg=audit(1714093274.173:279): avc: denied { relabelfrom } for pid=6652 comm="rpc-virtqemud" name="1-fedora39-40-TPM-Upg" dev="tmpfs" ino=2915 scontext=system_u:system_r:virtqemud_t:s0 tcontext=system_u:object_r:virt_var_run_t:s0 tclass=dir permissive=1
----
time->Thu Apr 25 18:01:14 2024
type=AVC msg=audit(1714093274.226:281): avc: denied { add_name } for pid=6422 comm="rpc-virtqemud" name="fedora39-40-TPM-Upg-swtpm.log" scontext=system_u:system_r:virtqemud_t:s0 tcontext=system_u:object_r:var_log_t:s0 tclass=dir permissive=1
----
time->Thu Apr 25 18:01:14 2024
type=AVC msg=audit(1714093274.226:282): avc: denied { create } for pid=6422 comm="rpc-virtqemud" name="fedora39-40-TPM-Upg-swtpm.log" scontext=system_u:system_r:virtqemud_t:s0 tcontext=system_u:object_r:var_log_t:s0 tclass=file permissive=1
----
time->Thu Apr 25 18:01:14 2024
type=AVC msg=audit(1714093274.226:283): avc: denied { write } for pid=6422 comm="rpc-virtqemud" path="/var/log/swtpm/libvirt/qemu/fedora39-40-TPM-Upg-swtpm.log" dev="dm-0" ino=878537 scontext=system_u:system_r:virtqemud_t:s0 tcontext=system_u:object_r:var_log_t:s0 tclass=file permissive=1
----
time->Thu Apr 25 18:01:14 2024
type=AVC msg=audit(1714093274.226:284): avc: denied { setattr } for pid=6422 comm="rpc-virtqemud" name="fedora39-40-TPM-Upg-swtpm.log" dev="dm-0" ino=878537 scontext=system_u:system_r:virtqemud_t:s0 tcontext=system_u:object_r:var_log_t:s0 tclass=file permissive=1
----
time->Thu Apr 25 18:01:14 2024
type=AVC msg=audit(1714093274.272:286): avc: denied { getattr } for pid=6422 comm="rpc-virtqemud" name="/" dev="dm-0" ino=256 scontext=system_u:system_r:virtqemud_t:s0 tcontext=system_u:object_r:fs_t:s0 tclass=filesystem permissive=1
----
time->Thu Apr 25 18:01:14 2024
type=AVC msg=audit(1714093274.283:287): avc: denied { open } for pid=6659 comm="swtpm" path="/var/log/swtpm/libvirt/qemu/fedora39-40-TPM-Upg-swtpm.log" dev="dm-0" ino=878537 scontext=system_u:system_r:swtpm_t:s0 tcontext=system_u:object_r:var_log_t:s0 tclass=file permissive=0
----
Running “sealert -l “*”” I get the following output:
SELinux is preventing rpc-virtqemud from relabelfrom access on the directory 2-fedora39-TPM.
***** Plugin catchall (100. confidence) suggests **************************
If you believe that rpc-virtqemud should be allowed relabelfrom access on the 2-fedora39-TPM directory by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c 'rpc-virtqemud' --raw | audit2allow -M my-rpcvirtqemud
# semodule -X 300 -i my-rpcvirtqemud.pp
Additional Information:
Source Context system_u:system_r:virtqemud_t:s0
Target Context system_u:object_r:virt_var_run_t:s0
Target Objects 2-fedora39-TPM [ dir ]
Source rpc-virtqemud
Source Path rpc-virtqemud
Port <Unknown>
Host bartlebyvi
Source RPM Packages
Target RPM Packages
SELinux Policy RPM selinux-policy-targeted-40.16-1.fc40.noarch
Local Policy RPM selinux-policy-targeted-40.16-1.fc40.noarch
Selinux Enabled True
Policy Type targeted
Enforcing Mode Enforcing
Host Name bartlebyvi
Platform Linux bartlebyvi 6.8.7-300.fc40.x86_64 #1 SMP
PREEMPT_DYNAMIC Wed Apr 17 19:21:08 UTC 2024
x86_64
Alert Count 1
First Seen 2024-04-25 19:25:29 PDT
Last Seen 2024-04-25 19:25:29 PDT
Local ID f0329c26-325e-4097-a2b2-331d53c6cc3d
Raw Audit Messages
type=AVC msg=audit(1714098329.840:387): avc: denied { relabelfrom } for pid=7646 comm="rpc-virtqemud" name="2-fedora39-TPM" dev="tmpfs" ino=3634 scontext=system_u:system_r:virtqemud_t:s0 tcontext=system_u:object_r:virt_var_run_t:s0 tclass=dir permissive=1
Hash: rpc-virtqemud,virtqemud_t,virt_var_run_t,dir,relabelfrom
SELinux is preventing rpc-virtqemud from setattr access on the file fedora39-TPM-swtpm.log.
***** Plugin catchall (100. confidence) suggests **************************
If you believe that rpc-virtqemud should be allowed setattr access on the fedora39-TPM-swtpm.log file by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c 'rpc-virtqemud' --raw | audit2allow -M my-rpcvirtqemud
# semodule -X 300 -i my-rpcvirtqemud.pp
Additional Information:
Source Context system_u:system_r:virtqemud_t:s0
Target Context system_u:object_r:var_log_t:s0
Target Objects fedora39-TPM-swtpm.log [ file ]
Source rpc-virtqemud
Source Path rpc-virtqemud
Port <Unknown>
Host bartlebyvi
Source RPM Packages
Target RPM Packages
SELinux Policy RPM selinux-policy-targeted-40.16-1.fc40.noarch
Local Policy RPM selinux-policy-targeted-40.16-1.fc40.noarch
Selinux Enabled True
Policy Type targeted
Enforcing Mode Enforcing
Host Name bartlebyvi
Platform Linux bartlebyvi 6.8.7-300.fc40.x86_64 #1 SMP
PREEMPT_DYNAMIC Wed Apr 17 19:21:08 UTC 2024
x86_64
Alert Count 1
First Seen 2024-04-25 19:25:29 PDT
Last Seen 2024-04-25 19:25:29 PDT
Local ID 1449b9d7-ec71-4985-aea0-57193d9e38ae
Raw Audit Messages
type=AVC msg=audit(1714098329.851:388): avc: denied { setattr } for pid=3334 comm="rpc-virtqemud" name="fedora39-TPM-swtpm.log" dev="dm-0" ino=537436 scontext=system_u:system_r:virtqemud_t:s0 tcontext=system_u:object_r:var_log_t:s0 tclass=file permissive=1
Hash: rpc-virtqemud,virtqemud_t,var_log_t,file,setattr
SELinux is preventing rpc-virtqemud from getattr access on the filesystem /.
***** Plugin catchall (100. confidence) suggests **************************
If you believe that rpc-virtqemud should be allowed getattr access on the filesystem by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c 'rpc-virtqemud' --raw | audit2allow -M my-rpcvirtqemud
# semodule -X 300 -i my-rpcvirtqemud.pp
Additional Information:
Source Context system_u:system_r:virtqemud_t:s0
Target Context system_u:object_r:fs_t:s0
Target Objects / [ filesystem ]
Source rpc-virtqemud
Source Path rpc-virtqemud
Port <Unknown>
Host bartlebyvi
Source RPM Packages
Target RPM Packages
SELinux Policy RPM selinux-policy-targeted-40.16-1.fc40.noarch
Local Policy RPM selinux-policy-targeted-40.16-1.fc40.noarch
Selinux Enabled True
Policy Type targeted
Enforcing Mode Enforcing
Host Name bartlebyvi
Platform Linux bartlebyvi 6.8.7-300.fc40.x86_64 #1 SMP
PREEMPT_DYNAMIC Wed Apr 17 19:21:08 UTC 2024
x86_64
Alert Count 1
First Seen 2024-04-25 19:25:29 PDT
Last Seen 2024-04-25 19:25:29 PDT
Local ID 4b0a82d7-77c9-4578-9478-92c03f9b5ef7
Raw Audit Messages
type=AVC msg=audit(1714098329.852:389): avc: denied { getattr } for pid=3334 comm="rpc-virtqemud" name="/" dev="dm-0" ino=256 scontext=system_u:system_r:virtqemud_t:s0 tcontext=system_u:object_r:fs_t:s0 tclass=filesystem permissive=1
Hash: rpc-virtqemud,virtqemud_t,fs_t,filesystem,getattr
SELinux is preventing rpc-virtqemud from write access on the file fedora39-TPM-swtpm.log.
***** Plugin catchall (100. confidence) suggests **************************
If you believe that rpc-virtqemud should be allowed write access on the fedora39-TPM-swtpm.log file by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c 'rpc-virtqemud' --raw | audit2allow -M my-rpcvirtqemud
# semodule -X 300 -i my-rpcvirtqemud.pp
Additional Information:
Source Context system_u:system_r:virtqemud_t:s0
Target Context system_u:object_r:var_log_t:s0
Target Objects fedora39-TPM-swtpm.log [ file ]
Source rpc-virtqemud
Source Path rpc-virtqemud
Port <Unknown>
Host bartlebyvi
Source RPM Packages
Target RPM Packages
SELinux Policy RPM selinux-policy-targeted-40.16-1.fc40.noarch
Local Policy RPM selinux-policy-targeted-40.16-1.fc40.noarch
Selinux Enabled True
Policy Type targeted
Enforcing Mode Enforcing
Host Name bartlebyvi
Platform Linux bartlebyvi 6.8.7-300.fc40.x86_64 #1 SMP
PREEMPT_DYNAMIC Wed Apr 17 19:21:08 UTC 2024
x86_64
Alert Count 1
First Seen 2024-04-25 19:25:29 PDT
Last Seen 2024-04-25 19:25:29 PDT
Local ID 58f8d3f2-0ace-4400-b7c7-9f42d4dcccb2
Raw Audit Messages
type=AVC msg=audit(1714098329.853:390): avc: denied { write } for pid=7651 comm="rpc-virtqemud" name="fedora39-TPM-swtpm.log" dev="dm-0" ino=537436 scontext=system_u:system_r:virtqemud_t:s0 tcontext=system_u:object_r:var_log_t:s0 tclass=file permissive=1
Hash: rpc-virtqemud,virtqemud_t,var_log_t,file,write
SELinux is preventing rpc-virtqemud from relabelfrom access on the directory tpm2.
***** Plugin catchall (100. confidence) suggests **************************
If you believe that rpc-virtqemud should be allowed relabelfrom access on the tpm2 directory by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c 'rpc-virtqemud' --raw | audit2allow -M my-rpcvirtqemud
# semodule -X 300 -i my-rpcvirtqemud.pp
Additional Information:
Source Context system_u:system_r:virtqemud_t:s0
Target Context system_u:object_r:virt_var_lib_t:s0
Target Objects tpm2 [ dir ]
Source rpc-virtqemud
Source Path rpc-virtqemud
Port <Unknown>
Host bartlebyvi
Source RPM Packages
Target RPM Packages
SELinux Policy RPM selinux-policy-targeted-40.16-1.fc40.noarch
Local Policy RPM selinux-policy-targeted-40.16-1.fc40.noarch
Selinux Enabled True
Policy Type targeted
Enforcing Mode Enforcing
Host Name bartlebyvi
Platform Linux bartlebyvi 6.8.7-300.fc40.x86_64 #1 SMP
PREEMPT_DYNAMIC Wed Apr 17 19:21:08 UTC 2024
x86_64
Alert Count 1
First Seen 2024-04-25 19:25:29 PDT
Last Seen 2024-04-25 19:25:29 PDT
Local ID be797438-9c1b-474d-afc0-680ad6cceeeb
Raw Audit Messages
type=AVC msg=audit(1714098329.853:391): avc: denied { relabelfrom } for pid=7651 comm="rpc-virtqemud" name="tpm2" dev="dm-0" ino=538166 scontext=system_u:system_r:virtqemud_t:s0 tcontext=system_u:object_r:virt_var_lib_t:s0 tclass=dir permissive=1
Hash: rpc-virtqemud,virtqemud_t,virt_var_lib_t,dir,relabelfrom
If I create a local policy using the suggested commands I’m able to overcome the issue and I can confirm that the process is indeed trying to relabel the SE-Linux tags.
I suspect this is a bug in Fedora 40, it doesn’t make sense to me that a process would need to relabel the SELinux context of an object it’s working with. Does this sound correct? Should this be filed in the Bugzilla?