From: Michal Privoznik Date: Thu, 19 Mar 2020 11:51:55 +0000 (+0100) Subject: qemu: Don't crash when getting targets for a multipath X-Git-Tag: v6.2.0-rc1~124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aeb909bf9b4c3fa48d017475545df94f7c5d3b3a;p=thirdparty%2Flibvirt.git qemu: Don't crash when getting targets for a multipath In one of my previous commits I've introduced code that creates all devices for given (possible) multipath target. But I've made a mistake there - the code accesses 'next->path' without checking if the disk source is local. Note that the 'next->path' is NULL/doesn't make sense for VIR_STORAGE_TYPE_NVME. Fixes: a30078cb832646177defd256e77c632905f1e6d0 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1814947 Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa Reviewed-by: Ján Tomko --- diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0e2252f6cf..6b70f457ca 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -15846,7 +15846,6 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, bool hasNVMe = false; for (next = src; virStorageSourceIsBacking(next); next = next->backingStore) { - VIR_AUTOSTRINGLIST targetPaths = NULL; g_autofree char *tmpPath = NULL; if (next->type == VIR_STORAGE_TYPE_NVME) { @@ -15855,6 +15854,8 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, if (!(tmpPath = virPCIDeviceAddressGetIOMMUGroupDev(&next->nvme->pciAddr))) return -1; } else { + VIR_AUTOSTRINGLIST targetPaths = NULL; + if (virStorageSourceIsEmpty(next) || !virStorageSourceIsLocalStorage(next)) { /* Not creating device. Just continue. */ @@ -15862,20 +15863,20 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, } tmpPath = g_strdup(next->path); - } - if (virStringListAdd(&paths, tmpPath) < 0) - return -1; + if (virDevMapperGetTargets(next->path, &targetPaths) < 0 && + errno != ENOSYS && errno != EBADF) { + virReportSystemError(errno, + _("Unable to get devmapper targets for %s"), + next->path); + return -1; + } - if (virDevMapperGetTargets(next->path, &targetPaths) < 0 && - errno != ENOSYS && errno != EBADF) { - virReportSystemError(errno, - _("Unable to get devmapper targets for %s"), - next->path); - return -1; + if (virStringListMerge(&paths, &targetPaths) < 0) + return -1; } - if (virStringListMerge(&paths, &targetPaths) < 0) + if (virStringListAdd(&paths, tmpPath) < 0) return -1; }