vfio/pci: Fix crash when BAR has zero size
PATCH 1/1 vfio/pci: Fix crash when BAR has zero size
When the host kernel fails to assign a BAR (broken BIOS "Above 4G Decoding" or ReBAR configuration), the VFIO kernel interface reports a zero size. In that case, vfio_region_setup() skips allocating region->mem, leaving it NULL.
Then, vfio_bar_quirk_setup() calls the BAR quirk probes and passes a NULL region->mem pointer to memory_region_add_subregion_overlap(), causing a segfault in memory_region_update_container_subregions().
Skip quirk setup in vfio_realize() for zero size regions.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2732
--- hw/vfio/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/vfio/pci.c +3 -1
@@ -1852,7 +1852,9 @@ static void vfio_pci_realize(PCIDevice *pdev, Error **errp) }for (i =0 ; i <PCI_ROM_SLOT ; i++) { -vfio_bar_quirk_setup (vdev, i); +if (vdev->bars[i].size) { +vfio_bar_quirk_setup (vdev, i); + } }if (!vfio_pci_irq_setup (vdev, errp)) {
Signature · 1 line
2.56.0
Quoted 9 lines · Cédric Le Goater
When the host kernel fails to assign a BAR (broken BIOS "Above 4G Decoding" or ReBAR configuration), the VFIO kernel interface reports a zero size. In that case,
vfio_region_setup()skips allocatingregion->mem, leaving it NULL.Then,
vfio_bar_quirk_setup()calls the BAR quirk probes and passes a NULLregion->mempointer tomemory_region_add_subregion_overlap(), causing a segfault inmemory_region_update_container_subregions().
Quoted 7 lines
Skip quirk setup in
vfio_realize()for zero size regions.Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2732
Signed-off-by Cédric Le Goater <[email protected]>--- hw/vfio/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)