Bug 2169262

Summary: Security context of swtpm.log of vm with shared tpmstate was not restored after migration failed and shutdown
Product: Red Hat Enterprise Linux 9 Reporter: Yanqiu Zhang <yanqzhan>
Component: libvirtAssignee: Michal Privoznik <mprivozn>
libvirt sub component: General QA Contact: Yanqiu Zhang <yanqzhan>
Status: CLOSED MIGRATED Docs Contact:
Severity: unspecified    
Priority: unspecified CC: lmen, mprivozn, virt-maint, xuzhang, yanqzhan
Version: 9.2Keywords: MigratedToJIRA, Triaged
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-09-22 17:47:45 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 Yanqiu Zhang 2023-02-13 05:46:05 UTC
Description of problem:
For vm with shared tpmstate(/var/lib/libvirt/swtpm), security context of swtpm.log was not restored after migration failed and vm shutdown
Later start vm will meet error:
    'error: Requested operation is not valid: Setting different SELinux label on /var/log/swtpm/libvirt/qemu/vm2-swtpm.log which is already in use'

Version-Release number of selected component (if applicable):
libvirt-9.0.0-4.el9.x86_64
qemu-kvm-7.2.0-8.el9.x86_64
swtpm-0.8.0-1.el9.x86_64
libtpms-0.9.1-2.20211126git1ff6fe1f43.el9.x86_64

How reproducible:
100%

Steps to Reproduce:
1. mount /var/lib/libvirt/swtpm on a shared storage(on both hosts), e.g. NFS:
# df -hT
10.*.*:/test/swtpm               nfs4       70G   14G   57G  20% /var/lib/libvirt/swtpm
# ls /var/lib/libvirt/swtpm/
(nothing)

2. Define vm with vtpm from an xml
# cat vm2.xml
...
  <cpu mode='host-model' check='partial'>
    <feature policy='disable' name='vmx'/>
  </cpu>
...
    <tpm model='tpm-crb'>
      <backend type='emulator' version='2.0'/>
    </tpm>
...
# virsh define vm2.xml
Domain 'vm2' defined from vm2.xml
# ls /var/lib/libvirt/swtpm/
44db1abb-17eb-4b8e-ac9e-c18549741b65

3. Start vm and check seclabel:
# virsh start vm2
Domain 'vm2' started
# ll -hZ /var/log/swtpm/libvirt/qemu/vm2-swtpm.log
-rw-r--r--. 1 tss tss system_u:object_r:svirt_image_t:s0:c62,c987 19K Feb 12 09:36 /var/log/swtpm/libvirt/qemu/vm2-swtpm.log

4. migrate to a host with different cpu features, to cause failure:
# virsh migrate vm2 --live qemu+ssh://hostB/system --verbose
root@hostB's password:
error: operation failed: guest CPU doesn't match specification: missing features: ds,dtes64,avx512ifma,sha-ni,avx512vbmi,avx512vbmi2,gfni,vaes,vpclmulqdq,avx512bitalg,avx512-vpopcntdq,la57,rdpid,fsrm,wbnoinvd

# ll -hZ /var/log/swtpm/libvirt/qemu/vm2-swtpm.log
-rw-r--r--. 1 tss tss system_u:object_r:svirt_image_t:s0:c62,c987 19K Feb 12 09:36 /var/log/swtpm/libvirt/qemu/vm2-swtpm.log

5. Shutdown vm and check seclabel again:
# virsh shutdown vm2
Domain 'vm2' is being shutdown
# virsh list --all
 Id   Name           State
-------------------------------
 -    avocado-vtpm   shut off
 -    vm2            shut off

# ll -hZ /var/log/swtpm/libvirt/qemu/vm2-swtpm.log
-rw-r--r--. 1 tss tss system_u:object_r:svirt_image_t:s0:c62,c987 20K Feb 12 09:37 /var/log/swtpm/libvirt/qemu/vm2-swtpm.log

6. Try to start vm again:
# virsh start vm2
error: Failed to start domain 'vm2'
error: Requested operation is not valid: Setting different SELinux label on /var/log/swtpm/libvirt/qemu/vm2-swtpm.log which is already in use

# ll -hZ /var/log/swtpm/libvirt/qemu/vm2-swtpm.log
-rw-r--r--. 1 tss tss system_u:object_r:virt_log_t:s0 23K Feb 12 09:38 /var/log/swtpm/libvirt/qemu/vm2-swtpm.log

Actual results:
In step5, swtpm.log seclable wasn't restored. Then later start will encounter error.

Expected results:
selinux context of swtpm.log should be restored to system_u:object_r:virt_log_t:s0, like step6 shows.

Additional info:
1. Not reproduced for local tpmstate(/var/lib/libvirt/swtpm not mounted).
2. The vm must be freshly defined on shared tpmstate, otherwise only starting a vm defined on local tpmstate before can not reproduce this issue.
3. Not all kinds of migration failure can reproduce, e.g. migrate with local disk failure can not.

Comment 2 RHEL Program Management 2023-09-22 17:47:18 UTC
Issue migration from Bugzilla to Jira is in process at this time. This will be the last message in Jira copied from the Bugzilla bug.

Comment 3 RHEL Program Management 2023-09-22 17:47:45 UTC
This BZ has been automatically migrated to the issues.redhat.com Red Hat Issue Tracker. All future work related to this report will be managed there.

Due to differences in account names between systems, some fields were not replicated.  Be sure to add yourself to Jira issue's "Watchers" field to continue receiving updates and add others to the "Need Info From" field to continue requesting information.

To find the migrated issue, look in the "Links" section for a direct link to the new issue location. The issue key will have an icon of 2 footprints next to it, and begin with "RHEL-" followed by an integer.  You can also find this issue by visiting https://issues.redhat.com/issues/?jql= and searching the "Bugzilla Bug" field for this BZ's number, e.g. a search like:

"Bugzilla Bug" = 1234567

In the event you have trouble locating or viewing this issue, you can file an issue by sending mail to rh-issues. You can also visit https://access.redhat.com/articles/7032570 for general account information.