msix: add valid.accepts methods to check address
PATCH 1/1 msix: add valid.accepts methods to check address
From: Prasad J Pandit <[email protected]>
While doing msi-x mmio operations, a guest may send an address that leads to an OOB access issue. Add valid.accepts methods to ensure that ensuing mmio r/w operation don't go beyond regions.
--- hw/pci/msix.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
hw/pci/msix.c +20 -0
@@ -193,6 +193,15 @@ static void msix_table_mmio_write(void *opaque, hwaddr addr,msix_handle_mask_update (dev, vector, was_masked); } +static bool msix_table_accepts (void *opaque,hwaddr addr,unsigned size, +bool is_write,MemTxAttrs attrs) +{ +PCIDevice *dev = opaque; +uint16_t tbl_size = dev->msix_entries_nr *PCI_MSIX_ENTRY_SIZE ; + +return dev->msix_table + addr +4 <= dev->msix_table + tbl_size; +} +static const MemoryRegionOps msix_table_mmio_ops = { .read = msix_table_mmio_read, .write = msix_table_mmio_write,
@@ -200,6 +209,7 @@ static const MemoryRegionOps msix_table_mmio_ops = { .valid = { .min_access_size = 4, .max_access_size = 4, + .accepts = msix_table_accepts }, };
@@ -221,6 +231,15 @@ static void msix_pba_mmio_write(void *opaque, hwaddr addr, { } +static bool msix_pba_accepts (void *opaque,hwaddr addr,unsigned size, +bool is_write,MemTxAttrs attrs) +{ +PCIDevice *dev = opaque; +uint16_t pba_size =QEMU_ALIGN_UP (dev->msix_entries_nr,64 ) /8 ; + +return dev->msix_pba + addr +4 <= dev->msix_pba + pba_size; +} +static const MemoryRegionOps msix_pba_mmio_ops = { .read = msix_pba_mmio_read, .write = msix_pba_mmio_write,
@@ -228,6 +247,7 @@ static const MemoryRegionOps msix_pba_mmio_ops = { .valid = { .min_access_size = 4, .max_access_size = 4, + .accepts = msix_pba_accepts }, };
Signature · 1 line
2.26.2
Quoted 6 lines · P J P
From: Prasad J Pandit <[email protected]>
While doing msi-x mmio operations, a guest may send an address that leads to an OOB access issue. Add valid.accepts methods to ensure that ensuing mmio r/w operation don't go beyond regions.
Quoted 14 lines
Reported-by Ren Ding <[email protected]>Reported-by Hanqing Zhao <[email protected]>Reported-by Anatoly Trosinenko <[email protected]>Reported-by Alexander Bulekov <[email protected]>Signed-off-by Prasad J Pandit <[email protected]>--- hw/pci/msix.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/pci/msix.c +0
-0
hw/pci/msix.c static void msix_table_mmio_write(void *opaque, hwaddr addr, · line 202
Quoted 10 lines
hw/pci/msix.c +7
-0@@ -193,6 +193,15 @@ static void msix_table_mmio_write(void *opaque, hwaddr addr,msix_handle_mask_update (dev, vector, was_masked); } +static bool msix_table_accepts (void *opaque,hwaddr addr,unsigned size, +bool is_write,MemTxAttrs attrs) +{ +PCIDevice *dev = opaque; +uint16_t tbl_size = dev->msix_entries_nr *PCI_MSIX_ENTRY_SIZE ; + +return dev->msix_table + addr +4 <= dev->msix_table + tbl_size;
Can be simplified as:
return addr + 4 <= dev->msix_entries_nr * PCI_MSIX_ENTRY_SIZE;
Quoted 14 lines
hw/pci/msix.c +3
-0+} +static const MemoryRegionOps msix_table_mmio_ops = { .read = msix_table_mmio_read, .write = msix_table_mmio_write,@@ -200,6 +209,7 @@ static const MemoryRegionOps msix_table_mmio_ops = { .valid = { .min_access_size = 4, .max_access_size = 4, + .accepts = msix_table_accepts }, };
hw/pci/msix.c static void msix_pba_mmio_write(void *opaque, hwaddr addr, · line 240
Quoted 10 lines
hw/pci/msix.c +7
-0@@ -221,6 +231,15 @@ static void msix_pba_mmio_write(void *opaque, hwaddr addr, { } +static bool msix_pba_accepts (void *opaque,hwaddr addr,unsigned size, +bool is_write,MemTxAttrs attrs) +{ +PCIDevice *dev = opaque; +uint16_t pba_size =QEMU_ALIGN_UP (dev->msix_entries_nr,64 ) /8 ; + +return dev->msix_pba + addr +4 <= dev->msix_pba + pba_size;
Can be simplified as:
return addr + 4 <= QEMU_ALIGN_UP(dev->msix_entries_nr, 64) / 8;
Quoted 14 lines
hw/pci/msix.c +3
-0+} +static const MemoryRegionOps msix_pba_mmio_ops = { .read = msix_pba_mmio_read, .write = msix_pba_mmio_write,@@ -228,6 +247,7 @@ static const MemoryRegionOps msix_pba_mmio_ops = { .valid = { .min_access_size = 4, .max_access_size = 4, + .accepts = msix_pba_accepts }, };
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 6 lines · P J P
From: Prasad J Pandit <[email protected]>
While doing msi-x mmio operations, a guest may send an address that leads to an OOB access issue. Add valid.accepts methods to ensure that ensuing mmio r/w operation don't go beyond regions.
Fixes CVE-2020-xxxxx
Oh and please also add:
Quoted 74 lines
Quoted 15 lines
Reported-by Ren Ding <[email protected]>Reported-by Hanqing Zhao <[email protected]>Reported-by Anatoly Trosinenko <[email protected]>Reported-by Alexander Bulekov <[email protected]>Signed-off-by Prasad J Pandit <[email protected]>--- hw/pci/msix.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/pci/msix.c +0
-0hw/pci/msix.c static void msix_table_mmio_write(void *opaque, hwaddr addr, · line 202
Quoted 10 lines
hw/pci/msix.c +7
-0@@ -193,6 +193,15 @@ static void msix_table_mmio_write(void *opaque, hwaddr addr,msix_handle_mask_update (dev, vector, was_masked); } +static bool msix_table_accepts (void *opaque,hwaddr addr,unsigned size, +bool is_write,MemTxAttrs attrs) +{ +PCIDevice *dev = opaque; +uint16_t tbl_size = dev->msix_entries_nr *PCI_MSIX_ENTRY_SIZE ; + +return dev->msix_table + addr +4 <= dev->msix_table + tbl_size;Can be simplified as:
return addr + 4 <= dev->msix_entries_nr * PCI_MSIX_ENTRY_SIZE;Quoted 14 lines
hw/pci/msix.c +3
-0+} +static const MemoryRegionOps msix_table_mmio_ops = { .read = msix_table_mmio_read, .write = msix_table_mmio_write,@@ -200,6 +209,7 @@ static const MemoryRegionOps msix_table_mmio_ops = { .valid = { .min_access_size = 4, .max_access_size = 4, + .accepts = msix_table_accepts }, };hw/pci/msix.c static void msix_pba_mmio_write(void *opaque, hwaddr addr, · line 240
Quoted 10 lines
hw/pci/msix.c +7
-0@@ -221,6 +231,15 @@ static void msix_pba_mmio_write(void *opaque, hwaddr addr, { } +static bool msix_pba_accepts (void *opaque,hwaddr addr,unsigned size, +bool is_write,MemTxAttrs attrs) +{ +PCIDevice *dev = opaque; +uint16_t pba_size =QEMU_ALIGN_UP (dev->msix_entries_nr,64 ) /8 ; + +return dev->msix_pba + addr +4 <= dev->msix_pba + pba_size;Can be simplified as:
return addr + 4 <= QEMU_ALIGN_UP(dev->msix_entries_nr, 64) / 8;Quoted 14 lines
hw/pci/msix.c +3
-0+} +static const MemoryRegionOps msix_pba_mmio_ops = { .read = msix_pba_mmio_read, .write = msix_pba_mmio_write,@@ -228,6 +247,7 @@ static const MemoryRegionOps msix_pba_mmio_ops = { .valid = { .min_access_size = 4, .max_access_size = 4, + .accepts = msix_pba_accepts }, };
+-- On Mon, 1 Jun 2020, Philippe Mathieu-Daudé wrote --+ | Fixes: CVE-2020-xxxxx
'CVE-2020-13754' assigned to this issue by Mitre.
-> https://bugzilla.redhat.com/show_bug.cgi?id=1842363
Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
8685 545E B54C 486B C6EB 271E E285 8B5A F050 DE8D
Quoted 11 lines · P J P
From: Prasad J Pandit <[email protected]>
While doing msi-x mmio operations, a guest may send an address that leads to an OOB access issue. Add valid.accepts methods to ensure that ensuing mmio r/w operation don't go beyond regions.
Reported-by Ren Ding <[email protected]>Reported-by Hanqing Zhao <[email protected]>Reported-by Anatoly Trosinenko <[email protected]>Reported-by Alexander Bulekov <[email protected]>Signed-off-by Prasad J Pandit <[email protected]>
IMHO this is just messed up, memory core needs to guarantee this. I'm working on a patch to do that.
Quoted 58 lines
--- hw/pci/msix.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/pci/msix.c +20
-0@@ -193,6 +193,15 @@ static void msix_table_mmio_write(void *opaque, hwaddr addr,msix_handle_mask_update (dev, vector, was_masked); } +static bool msix_table_accepts (void *opaque,hwaddr addr,unsigned size, +bool is_write,MemTxAttrs attrs) +{ +PCIDevice *dev = opaque; +uint16_t tbl_size = dev->msix_entries_nr *PCI_MSIX_ENTRY_SIZE ; + +return dev->msix_table + addr +4 <= dev->msix_table + tbl_size; +} +static const MemoryRegionOps msix_table_mmio_ops = { .read = msix_table_mmio_read, .write = msix_table_mmio_write,@@ -200,6 +209,7 @@ static const MemoryRegionOps msix_table_mmio_ops = { .valid = { .min_access_size = 4, .max_access_size = 4, + .accepts = msix_table_accepts }, };@@ -221,6 +231,15 @@ static void msix_pba_mmio_write(void *opaque, hwaddr addr, { } +static bool msix_pba_accepts (void *opaque,hwaddr addr,unsigned size, +bool is_write,MemTxAttrs attrs) +{ +PCIDevice *dev = opaque; +uint16_t pba_size =QEMU_ALIGN_UP (dev->msix_entries_nr,64 ) /8 ; + +return dev->msix_pba + addr +4 <= dev->msix_pba + pba_size; +} +static const MemoryRegionOps msix_pba_mmio_ops = { .read = msix_pba_mmio_read, .write = msix_pba_mmio_write,@@ -228,6 +247,7 @@ static const MemoryRegionOps msix_pba_mmio_ops = { .valid = { .min_access_size = 4, .max_access_size = 4, + .accepts = msix_pba_accepts }, };Signature · 1 line
2.26.2
+-- On Mon, 1 Jun 2020, Michael S. Tsirkin wrote --+ | IMHO this is just messed up, memory core needs to guarantee this. | I'm working on a patch to do that.
Okay. Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
8685 545E B54C 486B C6EB 271E E285 8B5A F050 DE8D