In case when the user exports images from current host and there is an incoming migration from a remote host, security label remembering would be possible but would attempt to remember the label allowing access to the image as the image is already used by a VM on remote host. To prevent remembering the wrong label, we'll skip the remembering of the label for any shared resource, so that the code behaves identically regardless of how the image is accessed. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_migration.c | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 2c462fd5f5..ec8b77bab9 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -533,6 +533,53 @@ qemuMigrationDstPrepareStorage(virDomainObj *vm, } +static void +qemuMigrationDstPrepareDiskSeclabels(virDomainObj *vm, + size_t nmigrate_disks, + const char **migrate_disks, + unsigned int flags) +{ + qemuDomainObjPrivate *priv = vm->privateData; + g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(priv->driver); + size_t i; + + /* In case when storage is exported from this host, security label + * remembering would behave differently compared to the host which mounts + * the exported filesystem. Specifically for incoming migration remembering + * a seclabel would remember a seclabel already allowing access to the image, + * which is not desired. Thus we skip remembering of seclabels for images + * which are local to this host but accessed in a shared way from another + * host. + */ + if (!cfg->sharedFilesystems || + cfg->sharedFilesystems[0] == NULL) + return; + + for (i = 0; i < vm->def->ndisks; i++) { + virDomainDiskDef *disk = vm->def->disks[i]; + + /* We care only about existing local storage */ + if (virStorageSourceIsEmpty(disk->src) || + !virStorageSourceIsLocalStorage(disk->src)) + continue; + + /* Only paths which are on local filesystem but shared elsewhere are + * relevant */ + if (!virFileIsSharedFSOverride(disk->src->path, cfg->sharedFilesystems)) + continue; + + /* Any storage that was migrated via NBD is technically fully local so + * we want seclabels remembered */ + if (flags & (VIR_MIGRATE_NON_SHARED_DISK | VIR_MIGRATE_NON_SHARED_INC)) { + if (qemuMigrationAnyCopyDisk(disk, nmigrate_disks, migrate_disks)) + continue; + } + + disk->src->seclabelSkipRemeber = true; + } +} + + /** * qemuMigrationDstStartNBDServer: * @driver: qemu driver @@ -3154,6 +3201,8 @@ qemuMigrationDstPrepareActive(virQEMUDriver *driver, dataFD[0]))) goto error; + qemuMigrationDstPrepareDiskSeclabels(vm, nmigrate_disks, migrate_disks, flags); + if (qemuProcessPrepareDomain(driver, vm, startFlags) < 0) goto error; -- 2.45.2