summaryrefslogtreecommitdiffstats
path: root/drivers/pci/rom.c
diff options
context:
space:
mode:
authorEdward O'Callaghan <eocallaghan@alterapraxis.com>2016-01-08 19:16:04 +0100
committerBjorn Helgaas <bhelgaas@google.com>2016-01-08 19:16:04 +0100
commit47b975d234eac39f3a72e5496d5f6158d8b806d1 (patch)
tree4c5e429ecd4ec1a454800865345313dac73422af /drivers/pci/rom.c
parentPCI: Fix minimum allocation address overwrite (diff)
downloadlinux-47b975d234eac39f3a72e5496d5f6158d8b806d1.tar.xz
linux-47b975d234eac39f3a72e5496d5f6158d8b806d1.zip
PCI: Avoid iterating through memory outside the resource window
If the 'image' pointer has been advanced more than 'size', we've already iterated through memory outside the resource window. We have zero control over whatever we find in the option ROM, if it's even an option ROM and not just an accident of random data just happening to look like an option ROM. Signed-off-by: Edward O'Callaghan <eocallaghan@alterapraxis.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci/rom.c')
-rw-r--r--drivers/pci/rom.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index eb0ad530dc43..45987adb9eae 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -96,6 +96,9 @@ size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size)
last_image = readb(pds + 21) & 0x80;
length = readw(pds + 16);
image += length * 512;
+ /* Avoid iterating through memory outside the resource window */
+ if (image > rom + size)
+ break;
} while (length && !last_image);
/* never return a size larger than the PCI resource window */