Skip to contentSkip to conversation

pseries: Fix array overrun bug in PCI code

PATCH Applied David Gibson 3 participants 6 messages Nov 29, 2011 – Dec 19, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pseries: Fix array overrun bug in PCI code

spapr_populate_pci_devices() containd a loop with PCI_NUM_REGIONS (7) iterations. However this overruns the 'bars' global array, which only has 6 elements. In fact we only want to run this loop for things listed in the bars array, so this patch corrects the loop bounds to reflect that.

---
 hw/spapr_pci.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/spapr_pci.c +1 -1
index 7162588..9b6a032 100644
@@ -454,7 +454,7 @@ int spapr_populate_pci_devices(sPAPRPHBState *phb,
         reg[0].size = 0;
 
         n = 0;
-        for (i = 0; i < PCI_NUM_REGIONS; ++i) {
+        for (i = 0; i < ARRAY_SIZE(bars); ++i) {
             if (0 == dev->io_regions[i].size) {
                 continue;
             }
Signature · 1 line
1.7.7.3
#1 lore raw
Quoted 6 lines · David Gibson

spapr_populate_pci_devices() containd a loop with PCI_NUM_REGIONS (7) iterations. However this overruns the 'bars' global array, which only has 6 elements. In fact we only want to run this loop for things listed in the bars array, so this patch corrects the loop bounds to reflect that.

As a bugfix for a bad memory access, this is definitely for 1.0

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#2 lore raw
Quoted 9 lines · David Gibson
Quoted 6 lines · David Gibson

spapr_populate_pci_devices() containd a loop with PCI_NUM_REGIONS (7) iterations.  However this overruns the 'bars' global array, which only has 6 elements. In fact we only want to run this loop for things listed in the bars array, so this patch corrects the loop bounds to reflect that.

As a bugfix for a bad memory access, this is definitely for 1.0

Now applied. Indeed it would probably have been better done before the release.

Cheers

#3 lore raw
Quoted 7 lines · andrzej zaborowski
Quoted 6 lines · David Gibson
Quoted 5 lines · David Gibson

spapr_populate_pci_devices() containd a loop with PCI_NUM_REGIONS (7) iterations. However this overruns the 'bars' global array, which only has 6 elements. In fact we only want to run this loop for things listed in the bars array, so this patch corrects the loop bounds to reflect that.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

As a bugfix for a bad memory access, this is definitely for 1.0

Now applied. Indeed it would probably have been better done before the release.

Well, that's why we aligned to have 1.0.1 around christmas - because there will be more issues exposed soon, I'm fairly sure :)

Thanks for applying btw.

Alex

#4 lore raw
In reply to David Gibson
Quoted 6 lines · David Gibson

spapr_populate_pci_devices() containd a loop with PCI_NUM_REGIONS (7) iterations. However this overruns the 'bars' global array, which only has 6 elements. In fact we only want to run this loop for things listed in the bars array, so this patch corrects the loop bounds to reflect that.

Thanks, applied to ppc-next and queued for 1.0.

Alex

Quoted 20 lines

---
hw/spapr_pci.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
hw/spapr_pci.c +1 -1
index 7162588..9b6a032 100644
@@ -454,7 +454,7 @@ int spapr_populate_pci_devices(sPAPRPHBState *phb,
        reg[0].size = 0;
 
        n = 0;
-        for (i = 0; i < PCI_NUM_REGIONS; ++i) {
+        for (i = 0; i < ARRAY_SIZE(bars); ++i) {
            if (0 == dev->io_regions[i].size) {
                continue;
            }
Signature · 1 line
1.7.7.3
#5 lore raw
Quoted 11 lines · Alexander Graf
Quoted 6 lines · David Gibson

spapr_populate_pci_devices() containd a loop with PCI_NUM_REGIONS (7) iterations. However this overruns the 'bars' global array, which only has 6 elements. In fact we only want to run this loop for things listed in the bars array, so this patch corrects the loop bounds to reflect that.

Thanks, applied to ppc-next and queued for 1.0.

Call me stupid. Only queued for 1.0 of course.

Alex