From fae5e343fb3661ac351ca06d4629e7ed59de5129 Mon Sep 17 00:00:00 2001 From: Daniel Henrique Barboza Date: Mon, 4 Jan 2021 09:54:33 -0300 Subject: [PATCH] dac, selinux: skip setting/restoring label for absent PCI devices If the underlying PCI device of a hostdev does not exist in the host (e.g. a SR-IOV VF that was removed while the domain was running), skip security label handling for it. This will avoid errors that happens during qemuProcessStop() time, where a VF that was being used by the domain is not present anymore. The restore label functions of both DAC and SELinux drivers will trigger errors in virPCIDeviceNew(). Reviewed-by: Laine Stump Signed-off-by: Daniel Henrique Barboza --- src/security/security_dac.c | 14 ++++++++++++-- src/security/security_selinux.c | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 11f6c5c3da..344bd6fc5f 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1266,7 +1266,12 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr, } case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - g_autoptr(virPCIDevice) pci = virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci = NULL; + + if (!virPCIDeviceExists(&pcisrc->addr)) + break; + + pci = virPCIDeviceNew(&pcisrc->addr); if (!pci) return -1; @@ -1422,7 +1427,12 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr mgr, } case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - g_autoptr(virPCIDevice) pci = virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci = NULL; + + if (!virPCIDeviceExists(&pcisrc->addr)) + break; + + pci = virPCIDeviceNew(&pcisrc->addr); if (!pci) return -1; diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 1d1d9edfff..9da4e96fa6 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2103,7 +2103,12 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr, } case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - g_autoptr(virPCIDevice) pci = virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci = NULL; + + if (!virPCIDeviceExists(&pcisrc->addr)) + break; + + pci = virPCIDeviceNew(&pcisrc->addr); if (!pci) return -1; @@ -2331,7 +2336,12 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr, } case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: { - g_autoptr(virPCIDevice) pci = virPCIDeviceNew(&pcisrc->addr); + g_autoptr(virPCIDevice) pci = NULL; + + if (!virPCIDeviceExists(&pcisrc->addr)) + break; + + pci = virPCIDeviceNew(&pcisrc->addr); if (!pci) return -1;