SELinux AVC denial while starting Qemu VM with 3D graphics

Hello to you,

I get this every time I start the KVM/Qemu/libvirt domain (VM) described below.

This issue does not happen when I start a domain that does not have 3D graphics enabled.

Any ideas?

Thank you,

SELinux is preventing qemu-system-x86 from using the execmem access on a process.

*****  Plugin allow_execmem (53.1 confidence) suggests   *********************

If you know why qemu-system-x86 needs to map a memory region that is both executable and writable and understand that this is a potential security problem.
Then you can allow the mapping by switching one of the following booleans: virt_use_execmem
follow the advice of the catchall_boolean plugin, otherwise contact your security administrator and report this issue

*****  Plugin catchall_boolean (42.6 confidence) suggests   ******************

If you want to allow virt to use execmem
Then you must tell SELinux about this by enabling the 'virt_use_execmem' boolean.

setsebool -P virt_use_execmem 1

*****  Plugin catchall (5.76 confidence) suggests   **************************

If you believe that qemu-system-x86 should be allowed execmem access on processes labeled svirt_t by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
allow this access for now by executing:
# ausearch -c 'qemu-system-x86' --raw | audit2allow -M my-qemusystemx86
# semodule -X 300 -i my-qemusystemx86.pp

Additional Information:
Source Context                system_u:system_r:svirt_t:s0:c598,c888
Target Context                system_u:system_r:svirt_t:s0:c598,c888
Target Objects                Unknown [ process ]
Source                        qemu-system-x86
Source Path                   qemu-system-x86
Port                          <Unknown>
Host                          lakshmi.trickster.gods
Source RPM Packages           
Target RPM Packages           
SELinux Policy RPM            selinux-policy-targeted-36.15-1.fc36.noarch
Local Policy RPM              selinux-policy-targeted-36.15-1.fc36.noarch
Selinux Enabled               True
Policy Type                   targeted
Enforcing Mode                Enforcing
Host Name                     lakshmi.trickster.gods
Platform                      Linux lakshmi.trickster.gods
                              5.19.12-200.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Wed
                              Sep 28 17:11:05 UTC 2022 x86_64 x86_64
Alert Count                   1
First Seen                    2022-10-03 06:52:33 EDT
Last Seen                     2022-10-03 06:52:33 EDT
Local ID                      a4a11836-5451-4c4f-b39a-dbe978968627

Raw Audit Messages
type=AVC msg=audit(1664794353.753:542): avc:  denied  { execmem } for  pid=12076 comm="qemu-system-x86" scontext=system_u:system_r:svirt_t:s0:c598,c888 tcontext=system_u:system_r:svirt_t:s0:c598,c888 tclass=process permissive=0

Hash: qemu-system-x86,svirt_t,svirt_t,process,execmem
$ sudo virsh dumpxml Jammy
<domain type='kvm' id='4'>
    <libosinfo:libosinfo xmlns:libosinfo="">
      <libosinfo:os id=""/>
  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <vcpu placement='static'>2</vcpu>
    <type arch='x86_64' machine='pc-q35-5.2'>hvm</type>
    <boot dev='hd'/>
    <vmport state='off'/>
  <cpu mode='custom' match='exact' check='full'>
    <model fallback='forbid'>Skylake-Client-IBRS</model>
    <feature policy='require' name='ss'/>
    <feature policy='require' name='vmx'/>
    <feature policy='require' name='pdcm'/>
    <feature policy='require' name='hypervisor'/>
    <feature policy='require' name='tsc_adjust'/>
    <feature policy='require' name='clflushopt'/>
    <feature policy='require' name='umip'/>
    <feature policy='require' name='md-clear'/>
    <feature policy='require' name='stibp'/>
    <feature policy='require' name='arch-capabilities'/>
    <feature policy='require' name='ssbd'/>
    <feature policy='require' name='xsaves'/>
    <feature policy='require' name='pdpe1gb'/>
    <feature policy='require' name='ibpb'/>
    <feature policy='require' name='ibrs'/>
    <feature policy='require' name='amd-stibp'/>
    <feature policy='require' name='amd-ssbd'/>
    <feature policy='require' name='rsba'/>
    <feature policy='require' name='skip-l1dfl-vmentry'/>
    <feature policy='require' name='pschange-mc-no'/>
    <feature policy='disable' name='hle'/>
    <feature policy='disable' name='rtm'/>
    <feature policy='disable' name='mpx'/>
  <clock offset='utc'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/Jammy.qcow2' index='2'/>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
    <disk type='file' device='cdrom'>
      <driver name='qemu'/>
      <target dev='sda' bus='sata'/>
      <alias name='sata0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    <controller type='usb' index='0' model='qemu-xhci' ports='15'>
      <alias name='usb'/>
      <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
    <controller type='sata' index='0'>
      <alias name='ide'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
    <controller type='pci' index='0' model='pcie-root'>
      <alias name='pcie.0'/>
    <controller type='pci' index='1' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='1' port='0x10'/>
      <alias name='pci.1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0' multifunction='on'/>
    <controller type='pci' index='2' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='2' port='0x11'/>
      <alias name='pci.2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/>
    <controller type='pci' index='3' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='3' port='0x12'/>
      <alias name='pci.3'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x2'/>
    <controller type='pci' index='4' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='4' port='0x13'/>
      <alias name='pci.4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x3'/>
    <controller type='pci' index='5' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='5' port='0x14'/>
      <alias name='pci.5'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x4'/>
    <controller type='pci' index='6' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='6' port='0x15'/>
      <alias name='pci.6'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x5'/>
    <controller type='pci' index='7' model='pcie-root-port'>
      <model name='pcie-root-port'/>
      <target chassis='7' port='0x16'/>
      <alias name='pci.7'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x6'/>
    <controller type='virtio-serial' index='0'>
      <alias name='virtio-serial0'/>
      <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
    <interface type='bridge'>
      <mac address='52:54:00:f4:76:4f'/>
      <source bridge='br0'/>
      <target dev='vnet3'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    <serial type='pty'>
      <source path='/dev/pts/2'/>
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      <alias name='serial0'/>
    <console type='pty' tty='/dev/pts/2'>
      <source path='/dev/pts/2'/>
      <target type='serial' port='0'/>
      <alias name='serial0'/>
    <channel type='unix'>
      <source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-4-Jammy/org.qemu.guest_agent.0'/>
      <target type='virtio' name='org.qemu.guest_agent.0' state='disconnected'/>
      <alias name='channel0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    <channel type='spicevmc'>
      <target type='virtio' name='com.redhat.spice.0' state='connected'/>
      <alias name='channel1'/>
      <address type='virtio-serial' controller='0' bus='0' port='2'/>
    <input type='tablet' bus='usb'>
      <alias name='input0'/>
      <address type='usb' bus='0' port='1'/>
    <input type='mouse' bus='ps2'>
      <alias name='input1'/>
    <input type='keyboard' bus='ps2'>
      <alias name='input2'/>
    <graphics type='spice'>
      <listen type='none'/>
      <image compression='off'/>
      <gl enable='yes' rendernode='/dev/dri/by-path/pci-0000:00:02.0-render'/>
    <sound model='ich9'>
      <alias name='sound0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x1b' function='0x0'/>
    <audio id='1' type='spice'/>
      <model type='virtio' heads='1' primary='yes'>
        <acceleration accel3d='yes'/>
      <alias name='video0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
    <redirdev bus='usb' type='spicevmc'>
      <alias name='redir0'/>
      <address type='usb' bus='0' port='2'/>
    <redirdev bus='usb' type='spicevmc'>
      <alias name='redir1'/>
      <address type='usb' bus='0' port='3'/>
    <memballoon model='virtio'>
      <alias name='balloon0'/>
      <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
    <rng model='virtio'>
      <backend model='random'>/dev/urandom</backend>
      <alias name='rng0'/>
      <address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>
  <seclabel type='dynamic' model='selinux' relabel='yes'>
  <seclabel type='dynamic' model='dac' relabel='yes'>
$ lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	Fedora
Description:	Fedora release 36 (Thirty Six)
Release:	36
Codename:	ThirtySix
$ uname -srv
Linux 5.19.12-200.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Sep 28 17:11:05 UTC 2022
$ rpm -q libvirt-daemon qemu-system-x86
$ sudo rpm -qV libvirt-daemon qemu-system-x86 qemu-kvm qemu-kvm-core
.M.......  g /run/libvirt/common

Mostly I want to know if I should configure SELinux to allow the execwrite operation or not.
Any ideas?

Well, this should not happen unless you run ARM hardware (which you do not have). In the ARM case, the suggested setsebool -P virt_use_execmem 1 would be the solution.

It is very likely that this would solve your problem here as well, but I cannot find documentation of this phenomenon in these circumstances and therefore, cannot say for sure if there is an intended reason or not for SELinux doing that. Actions like this should be done only if you have explicit information that suggests to do so because we cannot fully exclude atm if there is a security impact. It is good that you do not just follow such outputs!

The formally correct way would be to file a bug before changing the boolean in such circumstances unless we can identify the cause in this thread: some more information would help to indicate what this is all about. First, do sudo dnf update and reboot if you have not already done so. Then, test again. If the problem remains:

Can you provide logs with and without the issue? So, provoke the problem once and then get the output of sudo journalctl --since "5 minutes ago" (or 2 or 3 minutes, just ensure that everything related to the occurrance is contained!).

Then, do the same again, but without provoking the problem (such as without 3D graphics). It would be helpful if we can compare the logs.

Also, do you have PCI passthrough enabled? Please provide the output of cat /boot/loader/entries/*-5.19.12* | grep options

Is your kernel tainted? Please provide the output of cat /proc/sys/kernel/tainted → if the value is not 0, then your kernel is tainted and the next step will be to evaluate if this is the cause of your problem. If you use nvidia driver, disable the driver, check the /tainted file again (let us know the output!), and also try again to use your virtual machine without the nvidia driver! Does it work then?

Also, please let us know lscpu | grep name

What exactly do you mean with that? Which option? Where to set it? Please elaborate.