pci: check address before reading configuration bytes
PATCH 1/1 pci: check address before reading configuration bytes
From: Prasad J Pandit <[email protected]>
While reading PCI configuration bytes, a guest may send an address towards the end of the configuration space. It may lead to an OOB access issue. Add check to ensure 'address + len' is within PCI configuration space.
--- hw/pci/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/pci/pci.c +3 -1
@@ -1385,7 +1385,9 @@ uint32_t pci_default_read_config(PCIDevice *d, ranges_overlap(address, len, d->exp.exp_cap + PCI_EXP_LNKSTA, 2)) {pcie_sync_bridge_lnk (d); } -memcpy (&val, d->config + address, len); +if (address + len <=pci_config_size (d)) { +memcpy (&val, d->config + address, len); + }return le32_to_cpu (val); }
Signature · 1 line
2.26.2
Quoted 6 lines · P J P
From: Prasad J Pandit <[email protected]>
While reading PCI configuration bytes, a guest may send an address towards the end of the configuration space. It may lead to an OOB access issue. Add check to ensure 'address + len' is within PCI configuration space.
A malicious guest triggering an OOB access in the host QEMU sounds like a significant security flaw. Do we have a CVE assigned for this ?
Quoted 28 lines
Reported-by Ren Ding <[email protected]>Reported-by Hanqing Zhao <[email protected]>Reported-by Yi Ren <[email protected]>Signed-off-by Prasad J Pandit <[email protected]>--- hw/pci/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/pci/pci.c +3
-1@@ -1385,7 +1385,9 @@ uint32_t pci_default_read_config(PCIDevice *d, ranges_overlap(address, len, d->exp.exp_cap + PCI_EXP_LNKSTA, 2)) {pcie_sync_bridge_lnk (d); } -memcpy (&val, d->config + address, len); +if (address + len <=pci_config_size (d)) { +memcpy (&val, d->config + address, len); + }return le32_to_cpu (val); }Signature · 1 line
2.26.2
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 20 lines · P J P
From: Prasad J Pandit <[email protected]>
While reading PCI configuration bytes, a guest may send an address towards the end of the configuration space. It may lead to an OOB access issue. Add check to ensure 'address + len' is within PCI configuration space.
Reported-by Ren Ding <[email protected]>Reported-by Hanqing Zhao <[email protected]>Reported-by Yi Ren <[email protected]>Signed-off-by Prasad J Pandit <[email protected]>--- hw/pci/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/pci/pci.c +0
-0
hw/pci/pci.c uint32_t pci_default_read_config(PCIDevice *d, · line 1388
Quoted 5 lines
hw/pci/pci.c +1
-1@@ -1385,7 +1385,9 @@ uint32_t pci_default_read_config(PCIDevice *d, ranges_overlap(address, len, d->exp.exp_cap + PCI_EXP_LNKSTA, 2)) {pcie_sync_bridge_lnk (d); } -memcpy (&val, d->config + address, len); +if (address + len <=pci_config_size (d)) {
We don't want to hide/ignore earlier bugs, so IMO the caller should check for access in range, and this function abort() as it should never been called with such arguments.
Quoted 6 lines
hw/pci/pci.c +2
-0+memcpy (&val, d->config + address, len); + }return le32_to_cpu (val); }