Skip to content

Commit

Permalink
PCI: Avoid iterating through memory outside the resource window
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Edward O'Callaghan authored and Bjorn Helgaas committed Jan 8, 2016
1 parent 3460baa commit 47b975d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/pci/rom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 47b975d

Please sign in to comment.