Skip to contentSkip to conversation

spapr_pci: Fix Null pointer dereferences in spapr_dt_pci_bus()

RFC PATCH Superseded Philippe Mathieu-Daudé 3 participants 3 messages Jun 12, 2019 – Jun 13, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 spapr_pci: Fix Null pointer dereferences in spapr_dt_pci_bus()

Commit 14e714900f6 refactored the call to spapr_dt_drc(), but used an incorrect object owner as argument.

This fixes:

/hw/ppc/spapr_pci.c: 1367 in spapr_dt_pci_bus()

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1401933: Null pointer dereferences (FORWARD_NULL) Dereferencing null pointer "bus".

1367 ret = spapr_dt_drc(fdt, offset, OBJECT(bus->parent_dev),
1368 SPAPR_DR_CONNECTOR_TYPE_PCI);

Fixes 14e714900f6
Reported-by Coverity (CID 1401933)
---
 hw/ppc/spapr_pci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/ppc/spapr_pci.c +1 -2
index 957ae88bbd..e0cd3f11f1 100644
@@ -1364,8 +1364,7 @@ static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus,
         }
     }
 
-    ret = spapr_dt_drc(fdt, offset, OBJECT(bus->parent_dev),
-                       SPAPR_DR_CONNECTOR_TYPE_PCI);
+    ret = spapr_dt_drc(fdt, offset, OBJECT(sphb), SPAPR_DR_CONNECTOR_TYPE_PCI);
     if (ret) {
         return ret;
     }
Signature · 1 line
2.20.1
#1 lore raw
Quoted 6 lines · Philippe Mathieu-Daudé

Commit 14e714900f6 refactored the call to spapr_dt_drc(), but used an incorrect object owner as argument.

This fixes:

/hw/ppc/spapr_pci.c: 1367 in spapr_dt_pci_bus()

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1401933: Null pointer dereferences (FORWARD_NULL) Dereferencing null pointer "bus".

1367 ret = spapr_dt_drc(fdt, offset, OBJECT(bus->parent_dev),
1368 SPAPR_DR_CONNECTOR_TYPE_PCI);

Fixes 14e714900f6
Reported-by Coverity (CID 1401933)

Nack. The bus bridge is the correct owner in most cases here. It *used* to be that all the PCI DRCs were owned by the PHB, but that's intentionally not the case with the changes to allow hotplug under P2P bridges.

AFAICT, the bus parameter does have to be non-NULL from both callers, so I think the correct fix is to remove the test on if (bus) earlier in the function.

Quoted 18 lines
---
 hw/ppc/spapr_pci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/ppc/spapr_pci.c +1 -2
index 957ae88bbd..e0cd3f11f1 100644
@@ -1364,8 +1364,7 @@ static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus,
         }
     }
 
-    ret = spapr_dt_drc(fdt, offset, OBJECT(bus->parent_dev),
-                       SPAPR_DR_CONNECTOR_TYPE_PCI);
+    ret = spapr_dt_drc(fdt, offset, OBJECT(sphb), SPAPR_DR_CONNECTOR_TYPE_PCI);
     if (ret) {
         return ret;
     }
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 16 lines · On Thu, 13 Jun 2019 09:56:27 +1000 David Gibson <[email protected]>…
Quoted 6 lines · Philippe Mathieu-Daudé

Commit 14e714900f6 refactored the call to spapr_dt_drc(), but used an incorrect object owner as argument.

This fixes:

/hw/ppc/spapr_pci.c: 1367 in spapr_dt_pci_bus()

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1401933: Null pointer dereferences (FORWARD_NULL) Dereferencing null pointer "bus".

1367 ret = spapr_dt_drc(fdt, offset, OBJECT(bus->parent_dev),
1368 SPAPR_DR_CONNECTOR_TYPE_PCI);

Fixes 14e714900f6
Reported-by Coverity (CID 1401933)
Quoted 9 lines

Nack. The bus bridge is the correct owner in most cases here. It *used* to be that all the PCI DRCs were owned by the PHB, but that's intentionally not the case with the changes to allow hotplug under P2P bridges.

AFAICT, the bus parameter does have to be non-NULL from both callers, so I think the correct fix is to remove the test on if (bus) earlier in the function.

... and maybe make this obvious with an assert(bus) ?

Quoted 19 lines
Quoted 18 lines
---
 hw/ppc/spapr_pci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/ppc/spapr_pci.c +1 -2
index 957ae88bbd..e0cd3f11f1 100644
@@ -1364,8 +1364,7 @@ static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus,
         }
     }
 
-    ret = spapr_dt_drc(fdt, offset, OBJECT(bus->parent_dev),
-                       SPAPR_DR_CONNECTOR_TYPE_PCI);
+    ret = spapr_dt_drc(fdt, offset, OBJECT(sphb), SPAPR_DR_CONNECTOR_TYPE_PCI);
     if (ret) {
         return ret;
     }