pci: Add boundary check for hose->regions
authorThierry Reding <treding@nvidia.com>
Fri, 15 Mar 2019 15:32:32 +0000 (16:32 +0100)
committerTom Rini <trini@konsulko.com>
Tue, 23 Apr 2019 21:57:23 +0000 (17:57 -0400)
Make sure that we don't overflow the hose->regions array, otherwise we
would end up overwriting the hose->region_count field and cause mayhem
to ensue. Also print an error message when we'd be overflowing because
it indicates that there aren't enough regions available and the number
needs to be increased.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/pci/pci-uclass.c

index 824fa11907472c0bed5332c9614ae4eed7d7348e..cf1e7617ae3522599b1f0ca2b7ece743920af330 100644 (file)
@@ -918,6 +918,11 @@ static void decode_regions(struct pci_controller *hose, ofnode parent_node,
                return;
 
        for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
+               if (hose->region_count == MAX_PCI_REGIONS) {
+                       pr_err("maximum number of regions parsed, aborting\n");
+                       break;
+               }
+
                if (bd->bi_dram[i].size) {
                        pci_set_region(hose->regions + hose->region_count++,
                                       bd->bi_dram[i].start,