]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: tpm: Avoid security labels on incoming migration with shared storage
authorStefan Berger <stefanb@linux.ibm.com>
Mon, 24 Oct 2022 10:28:47 +0000 (06:28 -0400)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 9 Nov 2022 11:26:38 +0000 (12:26 +0100)
When using shared storage there is no need to apply security labels on the
storage since the files have to have been labeled already on the source
side and we must assume that the source and destination side have been
setup to use the same uid and gid for running swtpm as well as share the
same security labels. Whether the security labels can be used at all
depends on the shared storage and whether and how it supports them.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_tpm.c

index ae9b2c9fec16e5f85a2377295068f9bb3389c42d..0c3775a913fe409f5168baddb4e200748d5287c6 100644 (file)
@@ -932,10 +932,19 @@ qemuTPMEmulatorStart(virQEMUDriver *driver,
     virCommandSetPidFile(cmd, pidfile);
     virCommandSetErrorFD(cmd, &errfd);
 
-    if (qemuSecurityStartTPMEmulator(driver, vm, cmd,
-                                     cfg->swtpm_user, cfg->swtpm_group,
-                                     NULL, &cmdret) < 0)
-        return -1;
+    if (incomingMigration &&
+        virFileIsSharedFS(tpm->data.emulator.storagepath) == 1) {
+        /* security labels must have been set up on source already */
+        if (qemuSecurityCommandRun(driver, vm, cmd,
+                                   cfg->swtpm_user, cfg->swtpm_group,
+                                   NULL, &cmdret) < 0) {
+            goto error;
+        }
+    } else if (qemuSecurityStartTPMEmulator(driver, vm, cmd,
+                                            cfg->swtpm_user, cfg->swtpm_group,
+                                            NULL, &cmdret) < 0) {
+        goto error;
+    }
 
     if (cmdret < 0) {
         /* virCommandRun() hidden in qemuSecurityStartTPMEmulator()