Skip to contentSkip to conversation

vfio/pci: Fix information leak in vfio_rom_read()

PATCH In review Cédric Le Goater 3 participants 4 messages Jun 2 – Jun 26

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio/pci: Fix information leak in vfio_rom_read()

vfio_rom_read() can leak uninitialized stack data to the guest when a read occurs at the end boundary of the ROM BAR.

Fix this by initializing the val union to 0xff, matching the ROM initialization pattern used in vfio_pci_load_rom().

---
 hw/vfio/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/pci.c +1 -1
index 9df04fa2d76b1a78ee884d915f5a0c3c5fdb6115..de28e72519326741295c19f4a07208b95861f2ce 100644
@@ -1142,7 +1142,7 @@ static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size)
         uint16_t word;
         uint32_t dword;
         uint64_t qword;
-    } val;
+    } val = { .qword = ~0ULL };
     uint64_t data = 0;
 
     /* Load the ROM lazily when the guest tries to read it */
Signature · 1 line
2.54.0
Reviewed-by on v1 1/1
#1 lore raw

Looks good to me!

BR,
Mario

Quoted 28 lines · Cédric Le Goater

vfio_rom_read() can leak uninitialized stack data to the guest when a read occurs at the end boundary of the ROM BAR.

Fix this by initializing the val union to 0xff, matching the ROM initialization pattern used in vfio_pci_load_rom().

---
 hw/vfio/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/pci.c +1 -2
index 9df04fa2d76b1a78ee884d915f5a0c3c5fdb6115..de28e72519326741295c19f4a07208b95861f2ce 100644
@@ -1142,7 +1142,7 @@ static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size)
         uint16_t word;
         uint32_t dword;
         uint64_t qword;
-    } val;
+    } val = { .qword = ~0ULL };
     uint64_t data = 0;
 
     /* Load the ROM lazily when the guest tries to read it */
--

2.54.0

Reviewed-by on v1 1/1
#2 lore raw
In reply to Cédric Le Goater
Quoted 10 lines · Cédric Le Goater

vfio_rom_read() can leak uninitialized stack data to the guest when a read occurs at the end boundary of the ROM BAR.

Fix this by initializing the val union to 0xff, matching the ROM initialization pattern used in vfio_pci_load_rom().

---
  hw/vfio/pci.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
#3 lore raw
In reply to Cédric Le Goater
Quoted 16 lines · Cédric Le Goater

vfio_rom_read() can leak uninitialized stack data to the guest when a read occurs at the end boundary of the ROM BAR.

Fix this by initializing the val union to 0xff, matching the ROM initialization pattern used in vfio_pci_load_rom().

---
  hw/vfio/pci.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/pci.c +0 -0
index 9df04fa2d76b1a78ee884d915f5a0c3c5fdb6115..de28e72519326741295c19f4a07208b95861f2ce 100644

hw/vfio/pci.c static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size) · line 1148

Quoted 8 lines
hw/vfio/pci.c +1 -1
@@ -1142,7 +1142,7 @@ static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size)
          uint16_t word;
          uint32_t dword;
          uint64_t qword;
-    } val;
+    } val = { .qword = ~0ULL };
      uint64_t data = 0;
 
      /* Load the ROM lazily when the guest tries to read it */

Applied to

https://github.com/legoater/qemu vfio-next

Thanks,

C.