Commit 9f9b438384 for qemu.org

commit 9f9b43838440bae2d117069fae18e209b9b2b907
Author: Cédric Le Goater <clg@redhat.com>
Date:   Mon Nov 9 13:14:01 2026 +0100

    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
    Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
    Link: https://lore.kernel.org/qemu-devel/20261109121401.973836-1-clg@redhat.com
    Signed-off-by: Cédric Le Goater <clg@redhat.com>

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 9607866077..cb7cc011fc 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -3658,7 +3658,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_interrupt_setup(vdev, errp)) {