From: Daniel Paziyski <[email protected]>
pcie_sriov_pf_init is only used to initialize PFs for device created VFs, and
as such, it is checked that the PF has not been referenced by a user created VF
by means of the sriov-pf parameter.
This check crashes if it is performed for a PF that does not have an ID, and
there are already user created VFs in the system.
Example:
qemu-system-x86_64 -M q35 \
-device pcie-root-port,id=rp1,chassis=1,slot=1 \
-device virtio-net-pci,sriov-pf=f,addr=0.1,bus=rp1 \
-device virtio-net-pci,id=f,addr=0.0,bus=rp1 \
-device pcie-root-port,id=rp2,chassis=1,slot=2 \
-device nvme-subsys,id=subsys0 \
-device
nvme,sriov_max_vfs=1,serial=s,sriov_vq_flexible=2,sriov_vi_flexible=1,bus=rp2,subsys=subsys0
ASAN message:
The signal is caused by a READ memory access.
Hint: address points to the zero page.
#0 in g_str_hash (/usr/lib/libglib-2.0.so.0+0x49954)
#1 in g_hash_table_contains (/usr/lib/libglib-2.0.so.0+0x4ad3b)
#2 in pcie_sriov_pf_init ../hw/pci/pcie_sriov.c:161
#3 in nvme_init_sriov ../hw/nvme/ctrl.c:9088
#4 in nvme_init_pci ../hw/nvme/ctrl.c:9218
#5 in nvme_realize ../hw/nvme/ctrl.c:9696
Cc: [email protected]
Fixes: 19e55471d4e8 ("pcie_sriov: Allow user to create SR-IOV device")
Signed-off-by: Daniel Paziyski <[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Message-ID: <[email protected]>
---
hw/pci/pcie_sriov.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c
index 63d19ea488..9ba14d46c4 100644
--- a/hw/pci/pcie_sriov.c
+++ b/hw/pci/pcie_sriov.c
@@ -158,7 +158,7 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset,
BusState *bus = qdev_get_parent_bus(&dev->qdev);
int32_t devfn = dev->devfn + vf_offset;
- if (pfs && g_hash_table_contains(pfs, dev->qdev.id)) {
+ if (pfs && dev->qdev.id && g_hash_table_contains(pfs, dev->qdev.id)) {
error_setg(errp, "attaching user-created SR-IOV VF unsupported");
return false;
}
--
MST