pci: assert configuration access is within bounds
PATCH 1/1 pci: assert configuration access is within bounds
From: Prasad J Pandit <[email protected]>
While accessing PCI configuration bytes, assert that 'address + len' is within PCI configuration space.
Generally it is within bounds. This is more of a defensive assert, in case a buggy device was to send 'address' which may go out of bounds.
--- hw/pci/pci.c | 4 ++++ 1 file changed, 4 insertions(+)
Update v1: defensive assert as separate patch
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00957.html
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00960.html
hw/pci/pci.c +4 -0
@@ -1381,6 +1381,8 @@ uint32_t pci_default_read_config(PCIDevice *d, {uint32_t val =0 ; +assert (address + len <=pci_config_size (d)); +if (pci_is_express_downstream_port (d) &&ranges_overlap (address, len, d->exp.exp_cap +PCI_EXP_LNKSTA ,2 )) {pcie_sync_bridge_lnk (d);
@@ -1394,6 +1396,8 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val_in, intint i, was_irq_disabled =pci_irq_disabled (d);uint32_t val = val_in; +assert (addr + l <=pci_config_size (d)); +for (i =0 ; i < l; val >>=8 , ++i) {uint8_t wmask = d->wmask[addr + i];uint8_t w1cmask = d->w1cmask[addr + i];
Signature · 1 line
2.26.2
Quoted 11 lines · P J P
From: Prasad J Pandit <[email protected]>
While accessing PCI configuration bytes, assert that 'address + len' is within PCI configuration space.
Generally it is within bounds. This is more of a defensive assert, in case a buggy device was to send 'address' which may go out of bounds.
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Prasad J Pandit <[email protected]>
Quoted 32 lines
--- hw/pci/pci.c | 4 ++++ 1 file changed, 4 insertions(+)Update v1: defensive assert as separate patch
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00957.html
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00960.htmlhw/pci/pci.c +4
-0@@ -1381,6 +1381,8 @@ uint32_t pci_default_read_config(PCIDevice *d, {uint32_t val =0 ; +assert (address + len <=pci_config_size (d)); +if (pci_is_express_downstream_port (d) &&ranges_overlap (address, len, d->exp.exp_cap +PCI_EXP_LNKSTA ,2 )) {pcie_sync_bridge_lnk (d);@@ -1394,6 +1396,8 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val_in, intint i, was_irq_disabled =pci_irq_disabled (d);uint32_t val = val_in; +assert (addr + l <=pci_config_size (d)); +for (i =0 ; i < l; val >>=8 , ++i) {uint8_t wmask = d->wmask[addr + i];uint8_t w1cmask = d->w1cmask[addr + i];Signature · 1 line
2.26.2
Quoted 8 lines · * P J P ([email protected]) wrote:
From: Prasad J Pandit <[email protected]>
While accessing PCI configuration bytes, assert that 'address + len' is within PCI configuration space.
Generally it is within bounds. This is more of a defensive assert, in case a buggy device was to send 'address' which may go out of bounds.
Can a guest trigger this assert?
Dave
Quoted 36 lines
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Prasad J Pandit <[email protected]>--- hw/pci/pci.c | 4 ++++ 1 file changed, 4 insertions(+)Update v1: defensive assert as separate patch
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00957.html
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00960.htmlhw/pci/pci.c +4
-0@@ -1381,6 +1381,8 @@ uint32_t pci_default_read_config(PCIDevice *d, {uint32_t val =0 ; +assert (address + len <=pci_config_size (d)); +if (pci_is_express_downstream_port (d) &&ranges_overlap (address, len, d->exp.exp_cap +PCI_EXP_LNKSTA ,2 )) {pcie_sync_bridge_lnk (d);@@ -1394,6 +1396,8 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val_in, intint i, was_irq_disabled =pci_irq_disabled (d);uint32_t val = val_in; +assert (addr + l <=pci_config_size (d)); +for (i =0 ; i < l; val >>=8 , ++i) {uint8_t wmask = d->wmask[addr + i];uint8_t w1cmask = d->w1cmask[addr + i];Signature · 1 line
2.26.2
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 6 lines · Dr. David Alan Gilbert
Quoted 5 lines · * P J P ([email protected]) wrote:
From: Prasad J Pandit <[email protected]>
While accessing PCI configuration bytes, assert that 'address + len' is within PCI configuration space.
Quoted 7 lines
Quoted 3 lines
Generally it is within bounds. This is more of a defensive assert, in case a buggy device was to send 'address' which may go out of bounds.
Can a guest trigger this assert?
Dave
Shouldn't be able to, no.
Quoted 38 lines
Quoted 36 lines
Suggested-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Prasad J Pandit <[email protected]>--- hw/pci/pci.c | 4 ++++ 1 file changed, 4 insertions(+)Update v1: defensive assert as separate patch
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00957.html
-> https://lists.gnu.org/archive/html/qemu-devel/2020-06/msg00960.htmlhw/pci/pci.c +4
-0@@ -1381,6 +1381,8 @@ uint32_t pci_default_read_config(PCIDevice *d, {uint32_t val =0 ; +assert (address + len <=pci_config_size (d)); +if (pci_is_express_downstream_port (d) &&ranges_overlap (address, len, d->exp.exp_cap +PCI_EXP_LNKSTA ,2 )) {pcie_sync_bridge_lnk (d);@@ -1394,6 +1396,8 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val_in, intint i, was_irq_disabled =pci_irq_disabled (d);uint32_t val = val_in; +assert (addr + l <=pci_config_size (d)); +for (i =0 ; i < l; val >>=8 , ++i) {uint8_t wmask = d->wmask[addr + i];uint8_t w1cmask = d->w1cmask[addr + i];Signature · 1 line
2.26.2--
Dr. David Alan Gilbert / [email protected] / Manchester, UK