All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vfio/pci: Fix ROM load failure handling in vfio_rom_read()
@ 2026-07-24  9:24 Cédric Le Goater
  2026-07-24 14:17 ` Alex Williamson
  2026-07-24 15:41 ` Philippe Mathieu-Daudé
  0 siblings, 2 replies; 5+ messages in thread
From: Cédric Le Goater @ 2026-07-24  9:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alex Williamson, mcasquer, Cédric Le Goater

When vfio_pci_load_rom() fails, vdev->rom is NULL but the memcpy
still computes a source pointer from it, which is undefined behavior.
Guard the access and return a 0xff pattern instead, which is what
hardware returns for an absent ROM.

Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio/pci.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index a3147d28665abd29fd804bd08bdffc3c7440033c..16d4f70ea58c9e5b174dd57950df55dc2ab91f6f 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -1176,8 +1176,13 @@ static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size)
         }
     }
 
-    memcpy(&val, vdev->rom + addr,
-           (addr < vdev->rom_size) ? MIN(size, vdev->rom_size - addr) : 0);
+    /* If ROM loading failed, return 0xff pattern */
+    if (vdev->rom_read_failed) {
+        memset(&val, 0xff, sizeof(val));
+    } else {
+        memcpy(&val, vdev->rom + addr,
+               (addr < vdev->rom_size) ? MIN(size, vdev->rom_size - addr) : 0);
+    }
 
     switch (size) {
     case 1:
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-24 21:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-24  9:24 [PATCH] vfio/pci: Fix ROM load failure handling in vfio_rom_read() Cédric Le Goater
2026-07-24 14:17 ` Alex Williamson
2026-07-24 15:25   ` Cédric Le Goater
2026-07-24 15:41 ` Philippe Mathieu-Daudé
2026-07-24 21:34   ` Alex Williamson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.