From: Nikhil Kumar Singh <[email protected]>
A guest-triggerable assertion crash (DoS) exists in pnv_phb4_config_write()
and pnv_phb4_config_read(). When a guest performs an 8-byte access to
PHB_CONFIG_DATA (offset 0x130), QEMU aborts because the switch(size)
statement in the config accessors only handles 1, 2, and 4-byte accesses,
hitting g_assert_not_reached() in the default case.
Since guest input is untrusted, an invalid access size should not crash
the host. Fix this by adding a size > 4 guard in pnv_phb4_reg_write() and
pnv_phb4_reg_read() before the config accessor calls, and by replacing
the g_assert_not_reached() in pnv_phb4_config_write() and
pnv_phb4_config_read() with phb_error() to cover any other callers.
Invalid reads now return ~0ull, maintaining PCI conventions.
Fixes: 4f9924c4d4cf ("ppc/pnv: Add models for POWER9 PHB4 PCIe Host bridge")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3591
Signed-off-by: Nikhil Kumar Singh <[email protected]>
Reviewed-by: Aditya Gupta <[email protected]>
Link:
https://lore.kernel.org/qemu-devel/[email protected]
Signed-off-by: Harsh Prateek Bora <[email protected]>
(cherry picked from commit 0b76df366bfd9f25b0f01d66c96e8e5d81984d01)
Signed-off-by: Michael Tokarev <[email protected]>
diff --git a/hw/pci-host/pnv_phb4.c b/hw/pci-host/pnv_phb4.c
index 178c73f519b..d597dd1d49f 100644
--- a/hw/pci-host/pnv_phb4.c
+++ b/hw/pci-host/pnv_phb4.c
@@ -83,7 +83,9 @@ static void pnv_phb4_config_write(PnvPHB4 *phb, unsigned off,
val = bswap32(val);
break;
default:
- g_assert_not_reached();
+ phb_error(phb, "invalid config write size %u at offset 0x%x\n",
+ size, off);
+ return;
}
pci_host_config_write_common(pdev, cfg_addr, limit, val, size);
}
@@ -118,7 +120,9 @@ static uint64_t pnv_phb4_config_read(PnvPHB4 *phb, unsigned
off,
case 4:
return bswap32(val);
default:
- g_assert_not_reached();
+ phb_error(phb, "invalid config read size %u at offset 0x%x\n",
+ size, off);
+ return ~0ull;
}
}
@@ -506,6 +510,11 @@ static void pnv_phb4_reg_write(void *opaque, hwaddr off,
uint64_t val,
/* Special case outbound configuration data */
if ((off & 0xfffc) == PHB_CONFIG_DATA) {
+ if (size > 4) {
+ phb_error(phb, "invalid config write size %u at 0x%"PRIx64"\n",
+ size, off);
+ return;
+ }
pnv_phb4_config_write(phb, off & 0x3, size, val);
return;
}
@@ -643,6 +652,11 @@ static uint64_t pnv_phb4_reg_read(void *opaque, hwaddr
off, unsigned size)
uint64_t val;
if ((off & 0xfffc) == PHB_CONFIG_DATA) {
+ if (size > 4) {
+ phb_error(phb, "invalid config read size %u at 0x%"PRIx64"\n",
+ size, off);
+ return ~0ull;
+ }
return pnv_phb4_config_read(phb, off & 0x3, size);
}
--
2.47.3