blob: 049dab914d5191c2785529dffe7f6c2f6ce819b3 [file] [log] [blame]
Andrew Geisslerb7d28612020-07-24 16:15:54 -05001From f7d6a635fa3b7797f9d072e280f065bf3cfcd24d Mon Sep 17 00:00:00 2001
2From: Prasad J Pandit <pjp@fedoraproject.org>
3Date: Thu, 4 Jun 2020 17:05:25 +0530
4Subject: [PATCH] pci: assert configuration access is within bounds
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9While accessing PCI configuration bytes, assert that
10'address + len' is within PCI configuration space.
11
12Generally it is within bounds. This is more of a defensive
13assert, in case a buggy device was to send 'address' which
14may go out of bounds.
15
16Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
17Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
18Message-Id: <20200604113525.58898-1-ppandit@redhat.com>
19Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
20Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
21
22Upstream-Status: Backport [f7d6a635fa3b7797f9d072e280f065bf3cfcd24d]
23CVE: CVE-2020-13791
24Signed-off-by: Sakib Sajal <sakib.sajal@windriver.com>
25---
26 hw/pci/pci.c | 4 ++++
27 1 file changed, 4 insertions(+)
28
29diff --git a/hw/pci/pci.c b/hw/pci/pci.c
30index 70c66965f5..7bf2ae6d92 100644
31--- a/hw/pci/pci.c
32+++ b/hw/pci/pci.c
33@@ -1381,6 +1381,8 @@ uint32_t pci_default_read_config(PCIDevice *d,
34 {
35 uint32_t val = 0;
36
37+ assert(address + len <= pci_config_size(d));
38+
39 if (pci_is_express_downstream_port(d) &&
40 ranges_overlap(address, len, d->exp.exp_cap + PCI_EXP_LNKSTA, 2)) {
41 pcie_sync_bridge_lnk(d);
42@@ -1394,6 +1396,8 @@ void pci_default_write_config(PCIDevice *d, uint32_t addr, uint32_t val_in, int
43 int i, was_irq_disabled = pci_irq_disabled(d);
44 uint32_t val = val_in;
45
46+ assert(addr + l <= pci_config_size(d));
47+
48 for (i = 0; i < l; val >>= 8, ++i) {
49 uint8_t wmask = d->wmask[addr + i];
50 uint8_t w1cmask = d->w1cmask[addr + i];
51--
522.20.1
53