Closed TheJags closed 1 year ago
If AppArmor is enabled on your Ubuntu system, can you please try to disable it entirely and try again.
Otherwise, can you please check the audit log in /var/log/audit/audit.log
for potential failures?
Otherwise, can you please check the audit log in
/var/log/audit/audit.log
for potential failures?
@stefanberger Thank you so much for quick replies.
(1) Somehow there is neither /var/log/audit/
directory nor audit.log
inside /var/log/
at all.
(2) Though disabling AppArmor entirely did the trick.
sudo systemctl disable apparmor
Reboot
And the virtual machine run/open just fine. Tried again after enabling AppArmor and it did not run.
So, is it advisable to (a) disable AppArmor for swtpm
or (b) edit AppArmor profile for swtpm
?
(a) Disable AppArmor for swtpm
:
Note: I have not tried this yet; just modified the commands found on this page:
https://linuxconfig.org/how-to-disable-apparmor-on-ubuntu-20-04-focal-fossa-linux
sudo ln -s /etc/apparmor.d/usr.bin.swtpm /etc/apparmor.d/disable/
apparmor_parser -R /etc/apparmor.d/disable/usr.bin.swtpm
(b) Edit AppArmor profile for swtpm
:
sudo nano /etc/apparmor.d/usr.bin.swtpm
1 # vim:syntax=apparmor
2 # AppArmor policy for swtpm
3
4 #include <tunables/global>
5
6 profile swtpm /usr/bin/swtpm {
7 #include <abstractions/base>
8 #include <abstractions/openssl>
9
10 # Site-specific additions and overrides. See local/README for details.
11 #include <local/usr.bin.swtpm>
12
13 capability chown,
14 capability dac_override,
15 capability dac_read_search,
16 capability fowner,
17 capability fsetid,
18 capability setgid,
19 capability setuid,
20
21 network inet stream,
22 network inet6 stream,
23 unix (send) type=dgram addr=none peer=(addr=none),
24 unix (send, receive) type=stream addr=none peer=(label=libvirt-*),
25
26 /usr/bin/swtpm rm,
27
28 /tmp/** rwk,
29 owner @{HOME}/** rwk,
30 owner /var/lib/libvirt/swtpm/** rwk,
31 /run/libvirt/qemu/swtpm/*.sock rwk,
32 owner /var/log/swtpm/libvirt/qemu/*.log rwk,
33 owner /run/libvirt/qemu/swtpm/*.pid rwk,
34 owner /dev/vtpmx rw,
35 owner /etc/nsswitch.conf r,
36 owner /var/lib/swtpm/** rwk,
37 owner /run/swtpm/sock rw,
38 }
39
$ sudo apparmor_status
apparmor module is loaded.
35 profiles are loaded.
33 profiles are in enforce mode.
/usr/bin/man
/usr/bin/redshift
/usr/lib/NetworkManager/nm-dhcp-client.action
/usr/lib/NetworkManager/nm-dhcp-helper
/usr/lib/connman/scripts/dhclient-script
/usr/lib/cups/backend/cups-pdf
/usr/lib/ipsec/charon
/usr/lib/ipsec/lookip
/usr/lib/ipsec/stroke
/usr/lib/lightdm/lightdm-guest-session
/usr/lib/lightdm/lightdm-guest-session//chromium
/usr/sbin/cups-browsed
/usr/sbin/cupsd
/usr/sbin/cupsd//third_party
/usr/sbin/gpsd
/usr/sbin/ntpd
/usr/sbin/unbound
/{,usr/}sbin/dhclient
ippusbxd
libreoffice-senddoc
libreoffice-soffice//gpg
libreoffice-xpdfimport
libvirt-c857b1ce-7157-4be5-ae36-29cf22a62ec8
libvirtd
libvirtd//qemu_bridge_helper
lsb_release
man_filter
man_groff
nvidia_modprobe
nvidia_modprobe//kmod
swtpm
tcpdump
virt-aa-helper
2 profiles are in complain mode.
libreoffice-oosplash
libreoffice-soffice
0 profiles are in kill mode.
0 profiles are in unconfined mode.
7 processes have profiles defined.
7 processes are in enforce mode.
/usr/bin/redshift (2013)
/usr/sbin/cups-browsed (2289)
/usr/sbin/cupsd (1347)
/usr/lib/cups/notifier/dbus (1386) /usr/sbin/cupsd
/usr/sbin/ntpd (2436)
/usr/sbin/unbound (1383)
/usr/sbin/libvirtd (1349) libvirtd
0 processes are in complain mode.
0 processes are unconfined but have a profile defined.
0 processes are in mixed mode.
0 processes are in kill mode.
$
Thanks for trying this out. At least we know what the problem is now.
Did you take my swtpm package (frpm my PPA) or is this from Ubuntu or built from repo?
It's quite possible that a recent extension to swtpm now needs additional AppArmor rules either in swtpm or libvirt -- possibly the latter, but I am not sure.
You would have to enable auditing on your system to see the failure that causes the abort of swtpm. That would help fix the profile.
Many thanks.
(1) I have installed swtpm
from your PPA:
https://launchpad.net/~stefanberger/+archive/ubuntu/swtpm-jammy
(2) The same VM used to run just fine with swtpm
, around 2 weeks ago, so as you mentioned, "a recent extension to swtpm now needs additional AppArmor rules either in swtpm or libvirt" or recent Ubuntu updates must have changed in with AppArmor/Ubuntu.
(3) I've installed auditd
sudo apt install auditd audispd-plugins
(4) Tried to run the VM again (it did not run as AppArmor is enabled), and here are entries from /var/log/audit/audit.log
:
type=AVC msg=audit(1668718959.256:68): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-c857b1ce-7157-4be5-ae36-29cf22a62ec8" pid=10085 comm="apparmor_parser"
type=SYSCALL msg=audit(1668718959.256:68): arch=c000003e syscall=1 success=yes exit=57153 a0=5 a1=55bd38e2fc50 a2=df41 a3=0 items=0 ppid=10084 pid=10085 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="apparmor_parser" exe="/usr/sbin/apparmor_parser" subj=unconfined key=(null)ARCH=x86_64 SYSCALL=write AUID="unset" UID="root" GID="root" EUID="root" SUID="root" FSUID="root" EGID="root" SGID="root" FSGID="root"
type=PROCTITLE msg=audit(1668718959.256:68): proctitle=2F7362696E2F61707061726D6F725F706172736572002D72002F6574632F61707061726D6F722E642F6C6962766972742F6C6962766972742D63383537623163652D373135372D346265352D616533362D323963663232613632656338
type=VIRT_MACHINE_ID msg=audit(1668718959.264:69): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 vm-ctx=libvirt-c857b1ce-7157-4be5-ae36-29cf22a62ec8 img-ctx=libvirt-c857b1ce-7157-4be5-ae36-29cf22a62ec8 model=apparmor exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_MACHINE_ID msg=audit(1668718959.264:70): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 vm-ctx=+64055:+108 img-ctx=+64055:+108 model=dac exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=AVC msg=audit(1668718959.492:71): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-c857b1ce-7157-4be5-ae36-29cf22a62ec8" pid=10088 comm="apparmor_parser"
type=SYSCALL msg=audit(1668718959.492:71): arch=c000003e syscall=1 success=yes exit=57177 a0=5 a1=5574c9efe100 a2=df59 a3=0 items=0 ppid=10087 pid=10088 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="apparmor_parser" exe="/usr/sbin/apparmor_parser" subj=unconfined key=(null)ARCH=x86_64 SYSCALL=write AUID="unset" UID="root" GID="root" EUID="root" SUID="root" FSUID="root" EGID="root" SGID="root" FSGID="root"
type=PROCTITLE msg=audit(1668718959.492:71): proctitle=2F7362696E2F61707061726D6F725F706172736572002D72002F6574632F61707061726D6F722E642F6C6962766972742F6C6962766972742D63383537623163652D373135372D346265352D616533362D323963663232613632656338
type=AVC msg=audit(1668718959.720:72): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-c857b1ce-7157-4be5-ae36-29cf22a62ec8" pid=10092 comm="apparmor_parser"
type=SYSCALL msg=audit(1668718959.720:72): arch=c000003e syscall=1 success=yes exit=57577 a0=5 a1=55e9da2dc530 a2=e0e9 a3=0 items=0 ppid=10091 pid=10092 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="apparmor_parser" exe="/usr/sbin/apparmor_parser" subj=unconfined key=(null)ARCH=x86_64 SYSCALL=write AUID="unset" UID="root" GID="root" EUID="root" SUID="root" FSUID="root" EGID="root" SGID="root" FSGID="root"
type=PROCTITLE msg=audit(1668718959.720:72): proctitle=2F7362696E2F61707061726D6F725F706172736572002D72002F6574632F61707061726D6F722E642F6C6962766972742F6C6962766972742D63383537623163652D373135372D346265352D616533362D323963663232613632656338
type=AVC msg=audit(1668718959.956:73): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="libvirt-c857b1ce-7157-4be5-ae36-29cf22a62ec8" pid=10096 comm="apparmor_parser"
type=SYSCALL msg=audit(1668718959.956:73): arch=c000003e syscall=1 success=yes exit=57577 a0=5 a1=55d867805990 a2=e0e9 a3=0 items=0 ppid=10095 pid=10096 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="apparmor_parser" exe="/usr/sbin/apparmor_parser" subj=unconfined key=(null)ARCH=x86_64 SYSCALL=write AUID="unset" UID="root" GID="root" EUID="root" SUID="root" FSUID="root" EGID="root" SGID="root" FSGID="root"
type=PROCTITLE msg=audit(1668718959.956:73): proctitle=2F7362696E2F61707061726D6F725F706172736572002D72002F6574632F61707061726D6F722E642F6C6962766972742F6C6962766972742D63383537623163652D373135372D346265352D616533362D323963663232613632656338
type=AVC msg=audit(1668718959.980:74): apparmor="DENIED" operation="file_inherit" profile="swtpm" name="/run/libvirt/qemu/swtpm/2-jammy-swtpm.pid" pid=10102 comm="swtpm" requested_mask="w" denied_mask="w" fsuid=135 ouid=0FSUID="swtpm" OUID="root"
type=SYSCALL msg=audit(1668718959.980:74): arch=c000003e syscall=59 success=yes exit=0 a0=7fcc5c065710 a1=7fcc5c06ab90 a2=7ffe9b4d0828 a3=0 items=0 ppid=1 pid=10102 auid=4294967295 uid=135 gid=147 euid=135 suid=135 fsuid=135 egid=147 sgid=147 fsgid=147 tty=(none) ses=4294967295 comm="swtpm" exe="/usr/bin/swtpm" subj=swtpm key=(null)ARCH=x86_64 SYSCALL=execve AUID="unset" UID="swtpm" GID="swtpm" EUID="swtpm" SUID="swtpm" FSUID="swtpm" EGID="swtpm" SGID="swtpm" FSGID="swtpm"
type=EXECVE msg=audit(1668718959.980:74): argc=10 a0="/usr/bin/swtpm" a1="socket" a2="--ctrl" a3="type=unixio,path=/run/libvirt/qemu/swtpm/2-jammy-swtpm.sock,mode=0600" a4="--tpmstate" a5="dir=/var/lib/libvirt/swtpm/c857b1ce-7157-4be5-ae36-29cf22a62ec8/tpm2,mode=0600" a6="--log" a7="file=/var/log/swtpm/libvirt/qemu/jammy-swtpm.log" a8="--terminate" a9="--tpm2"
type=PROCTITLE msg=audit(1668718959.980:74): proctitle=2F7573722F62696E2F737774706D00736F636B6574002D2D6374726C00747970653D756E6978696F2C706174683D2F72756E2F6C6962766972742F71656D752F737774706D2F322D6A616D6D792D737774706D2E736F636B2C6D6F64653D30363030002D2D74706D7374617465006469723D2F7661722F6C69622F6C69627669
type=VIRT_RESOURCE msg=audit(1668718960.012:75): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=net reason=open vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 net=52:54:00:9a:a5:93 path="macvtap1" rdev=? exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=ANOM_PROMISCUOUS msg=audit(1668718960.028:76): dev=wlxd0374547816a prom=256 old_prom=0 auid=4294967295 uid=0 gid=0 ses=4294967295AUID="unset" UID="root" GID="root"
type=AVC msg=audit(1668718960.236:77): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="libvirt-c857b1ce-7157-4be5-ae36-29cf22a62ec8" pid=10122 comm="apparmor_parser"
type=SYSCALL msg=audit(1668718960.236:77): arch=c000003e syscall=1 success=yes exit=57609 a0=5 a1=5559a97017f0 a2=e109 a3=0 items=0 ppid=10121 pid=10122 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="apparmor_parser" exe="/usr/sbin/apparmor_parser" subj=unconfined key=(null)ARCH=x86_64 SYSCALL=write AUID="unset" UID="root" GID="root" EUID="root" SUID="root" FSUID="root" EGID="root" SGID="root" FSGID="root"
type=PROCTITLE msg=audit(1668718960.236:77): proctitle=2F7362696E2F61707061726D6F725F706172736572002D72002F6574632F61707061726D6F722E642F6C6962766972742F6C6962766972742D63383537623163652D373135372D346265352D616533362D323963663232613632656338
type=VIRT_RESOURCE msg=audit(1668718960.240:78): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=net reason=open vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 net=52:54:00:9a:a5:93 path="/dev/vhost-net" rdev=0A:EE exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=BPF msg=audit(1668718960.364:79): prog-id=64 op=LOAD
type=VIRT_RESOURCE msg=audit(1668718960.364:80): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=cgroup reason=deny vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 cgroup="/sys/fs/cgroup/machine.slice/machine-qemu\x2d2\x2djammy.scope/" class=all exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.364:81): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=cgroup reason=allow vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 cgroup="/sys/fs/cgroup/machine.slice/machine-qemu\x2d2\x2djammy.scope/" class=path path="/dev/null" rdev=01:03 acl=rw exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.364:82): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=cgroup reason=allow vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 cgroup="/sys/fs/cgroup/machine.slice/machine-qemu\x2d2\x2djammy.scope/" class=path path="/dev/full" rdev=01:07 acl=rw exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.364:83): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=cgroup reason=allow vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 cgroup="/sys/fs/cgroup/machine.slice/machine-qemu\x2d2\x2djammy.scope/" class=path path="/dev/zero" rdev=01:05 acl=rw exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.364:84): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=cgroup reason=allow vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 cgroup="/sys/fs/cgroup/machine.slice/machine-qemu\x2d2\x2djammy.scope/" class=path path="/dev/random" rdev=01:08 acl=rw exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.364:85): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=cgroup reason=allow vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 cgroup="/sys/fs/cgroup/machine.slice/machine-qemu\x2d2\x2djammy.scope/" class=path path="/dev/urandom" rdev=01:09 acl=rw exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.364:86): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=cgroup reason=allow vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 cgroup="/sys/fs/cgroup/machine.slice/machine-qemu\x2d2\x2djammy.scope/" class=path path="/dev/ptmx" rdev=05:02 acl=rw exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.364:87): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=cgroup reason=allow vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 cgroup="/sys/fs/cgroup/machine.slice/machine-qemu\x2d2\x2djammy.scope/" class=path path="/dev/kvm" rdev=0A:E8 acl=rw exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.364:88): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=cgroup reason=allow vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 cgroup="/sys/fs/cgroup/machine.slice/machine-qemu\x2d2\x2djammy.scope/" class=major category=pty maj=88 acl=rw exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.364:89): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=cgroup reason=allow vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 cgroup="/sys/fs/cgroup/machine.slice/machine-qemu\x2d2\x2djammy.scope/" class=path path="/dev/urandom" rdev=01:09 acl=rw exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=ANOM_PROMISCUOUS msg=audit(1668718960.576:90): dev=wlxd0374547816a prom=0 old_prom=256 auid=4294967295 uid=0 gid=0 ses=4294967295AUID="unset" UID="root" GID="root"
type=BPF msg=audit(1668718960.636:91): prog-id=0 op=UNLOAD
type=VIRT_RESOURCE msg=audit(1668718960.636:92): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=disk reason=start vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 old-disk="?" new-disk="/media/admn/310GB/QEMU_KVM/jammy.qcow2" exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.636:93): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=disk reason=start vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 old-disk="?" new-disk="/media/admn/1-6TB/Softwares/Linux/ubuntu-mate-2022.04.30-desktop-amd64.iso" exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.636:94): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=fs reason=start vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 old-fs="?" new-fs="/media/admn/1-6TB/QEMU_Shared" exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.636:95): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=net reason=start vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 old-net="?" new-net="52:54:00:9a:a5:93" exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.636:96): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=dev reason=start vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 bus=usb device=555342207265646972646576 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.636:97): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=dev reason=start vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 bus=usb device=555342207265646972646576 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.636:98): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=rng reason=start vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 old-rng="?" new-rng="/dev/urandom" exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.636:99): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=tpm-emulator reason=start vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 device="?" exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.636:100): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=mem reason=start vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 old-mem=0 new-mem=4194304 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_RESOURCE msg=audit(1668718960.636:101): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm resrc=vcpu reason=start vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 old-vcpu=0 new-vcpu=2 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=success'UID="root" AUID="unset"
type=VIRT_CONTROL msg=audit(1668718960.636:102): pid=1349 uid=0 auid=4294967295 ses=4294967295 subj=libvirtd msg='virt=kvm op=start reason=booted vm="jammy" uuid=c857b1ce-7157-4be5-ae36-29cf22a62ec8 vm-pid=0 exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=? res=failed'UID="root" AUID="unset"
Is this the line we are looking for in audit.log
?
type=AVC msg=audit(1668718959.980:74): apparmor="DENIED" operation="file_inherit" profile="swtpm" name="/run/libvirt/qemu/swtpm/2-jammy-swtpm.pid" pid=10102 comm="swtpm" requested_mask="w" denied_mask="w" fsuid=135 ouid=0FSUID="swtpm" OUID="root"
Is this the line we are looking for in
audit.log
?
Yes!
We have been writing pid-files for a long time so this is odd that it wouldn't allow to write to /run/libvirt/qemu/swtpm/2-jammy-swtpm.pid
. The profile is swtpm
. Hm, we have this here in our profile.
From the denial we get: fsuid=135 ouid=0�FSUID="swtpm" OUID="root"
.
In the libvirt profile we have this here:
virBufferAsprintf(&buf,
" \"%s/libvirt/qemu/swtpm/%s-swtpm.pid\" rw,\n",
RUNSTATEDIR, shortName);
It's quite possible that the 'owner' part in the swtpm profile gets into the way. @lvoytek
I am actually surprised that the swtpm profile becomes active when libvirt starts the VM rather than the custom libvirt profile being used. Hm.
My next suggestion would be to run the system with AppArmor in enforcing mode but put only the swtpm profile into complain mode:
sudo aa-complain /usr/bin/swtpm
Hello, This is an issue caused by libvirt where pid files in /run/libvirt/qemu/swtpm/ are being set with root permissions rather than swtpm user permissions as they did in Jammy. I'm currently working on libvirt to get this fixed in upstream and kinetic. The Ubuntu bug is located here. In the meantime adding the line
/run/libvirt/qemu/swtpm/*.pid rwk,
to /etc/apparmor.d/local/usr.bin.swtpm
will fix the issue.
@lvoytek Thanks for letting us know!
This is an issue caused by libvirt where pid files in /run/libvirt/qemu/swtpm/ are being set with root permissions rather than swtpm user permissions as they did in Jammy.
swtpm writes its own pid file but cannot do it due to ... what? Ownership of the directory? Having to overwrite an old pid file? What has changed since Jammy?
I'm currently working on libvirt to get this fixed in upstream and kinetic. The Ubuntu bug is located here. In the meantime adding the line
Also good to know. Thanks.
@lvoytek @stefanberger
Thank you so much.
Creating (the file was not there)
sudo nano /etc/apparmor.d/local/usr.bin.swtpm
and adding:
/run/libvirt/qemu/swtpm/*.pid rwk,
did the trick. Now the VM is running just fine.
@lvoytek @stefanberger
Lastly, when I upgrade the system to say, Ubuntu MATE Lunar 23.04, or when the bug gets fixed...
should I keep this file (/etc/apparmor.d/local/usr.bin.swtpm
), or it doesn't matter? Thanks.
@stefanberger
swtpm writes its own pid file but cannot do it due to ... what? Ownership of the directory? Having to overwrite an old pid file? What has changed since Jammy?
The swtpm repository is the same between Jammy and Kinetic. libvirt has some major changes though and it seems that within its handling of swtpm it now chowns the pid file to root permissions and leaves it behind after the vm shuts down.
In Jammy (libvirt version 8.0.0), sudo ls -la /run/libvirt/qemu/swtpm
will show something like:
drwxrwx--- 2 libvirt-qemu swtpm 80 Nov 17 12:54 .
drwxr-xr-x 5 root root 180 Nov 17 12:54 ..
-rw-r--r-- 1 swtpm swtpm 5 Nov 17 12:54 14-win11-swtpm.pid
srw------- 1 libvirt-qemu kvm 0 Nov 17 12:54 14-win11-swtpm.sock
While in Kinetic (libvirt version 8.6.0) it shows something like:
drwxrwx--- 2 libvirt-qemu swtpm 80 Nov 17 13:34 .
drwxr-xr-x 5 root root 180 Nov 17 13:34 ..
-rw-r--r-- 1 root root 5 Nov 17 12:57 1-win11-swtpm.pid
-rw-r--r-- 1 root root 5 Nov 17 13:34 2-win11-swtpm.pid
srw------- 1 libvirt-qemu kvm 0 Nov 17 13:34 2-win11-swtpm.sock
where previous pid files are not removed
@TheJags You can leave it as is and nothing will break when the fix arrives in Kinetic. I'll make a note in this bug report once its actually fixed though and you can remove it then if you'd like.
@lvoytek
Thanks alot. I will keep the file as it is. You can close the issue.
Had exactly the same issue on Ubuntu 22.10 (albeit with kernel "6.1.0-060100rc5-generic") Only just encountered this thread after experimenting with many other options.
The AppArmor fix resolved the issue too. :-)
Thanks
@lvoytek @stefanberger
Thank you so much.
Creating (the file was not there)
sudo nano /etc/apparmor.d/local/usr.bin.swtpm
and adding:
/run/libvirt/qemu/swtpm/*.pid rwk,
did the trick. Now the VM is running just fine.
Met the same issue today after update libvirtd to 8.6.0. I just removed the TPM in the win11 client :- Now the VM worked with a new PIN. Host: Ubuntu20.04, Client: Win11-22H2
Hi @TheJags, just wanted to let you know the fix for this issue has been released in Ubuntu 22.04 and 22.10. Thanks!
@TheJags If this issue is resolved, can you close it?
@stefanberger @lvoytek
Yes, thank you so much.
Describe the bug: Cannot run/open a virtual machine.
When I try to run a virtual machine (which previously used to run just fine), I'm getting this error:
Required: To Reproduce (without these steps your issue may be deleted)
Steps to reproduce:
Expected behavior: Expected behavior would be a virtual machine running inside a console window.
Desktop:
Versions of relevant components:
swtpm: 0.8.0-1
libtpms: 0.9.5-1 ( libtpms0 )
openssl: 3.0.5-2ubuntu2
gnutls: 3.7.7-2ubuntu2 ( gnutls-bin )
virt-manager: 1:4.1.0-1
libvirt0: 8.6.0-0ubuntu3
qemu: 1:6.2+dfsg-2ubuntu6.5
qemu-system: 1:7.0+dfsg-7ubuntu2
qemu-system-x86: 1:7.0+dfsg-7ubuntu2
- Virtual Machine Details:
TPM Device: Type: Emulated
Advanced options: Model: CRB Version: 2.0
Log files: Please attach any log files. If using a VM and it was started with libvirt, attach the logfile found in
/var/log/swtpm/libvirt/qemu/VM-NAME-swtpm.log
.(1)
/var/log/swtpm/libvirt/qemu/jammy-swtpm.log
Additional context: (2)
/var/log/libvirt/qemu/jammy.log
(3) Guest OS XML (Ubuntu MATE Kinetic 22.10):