spapr_pci: Fix potential NULL pointer dereference in spapr_dt_pci_bus()
PATCH v2 1/1 spapr_pci: Fix potential NULL pointer dereference in spapr_dt_pci_bus()
Commit 14e714900f6 refactored the call to spapr_dt_drc(), introducing a potential NULL pointer dereference while accessing bus->parent_dev.
A trivial audit show 'bus' is not null in the two places the static function spapr_dt_drc() is called.
Since the 'bus' parameter is not NULL in both callers, remove remove the test on if (bus), and add an assert() to silent static analyzers.
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);
--- hw/ppc/spapr_pci.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
hw/ppc/spapr_pci.c +5 -6
@@ -1356,12 +1356,11 @@ static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus,_FDT (fdt_setprop_cell (fdt, offset,"#size-cells" ,RESOURCE_CELLS_SIZE )); -if (bus) { -pci_for_each_device_reverse (bus,pci_bus_num (bus), - spapr_dt_pci_device_cb, &cbinfo); -if (cbinfo.err) { -return cbinfo.err; - } +assert (bus); +pci_for_each_device_reverse (bus,pci_bus_num (bus), + spapr_dt_pci_device_cb, &cbinfo); +if (cbinfo.err) { +return cbinfo.err; } ret = spapr_dt_drc(fdt, offset, OBJECT(bus->parent_dev),
Signature · 1 line
2.20.1
David Gibson
AppliedQuoted 15 lines · Philippe Mathieu-Daudé
Commit
14e714900f6refactored the call tospapr_dt_drc(), introducing a potential NULL pointer dereference while accessingbus->parent_dev.
A trivial audit show 'bus' is not null in the two places the static functionspapr_dt_drc()is called.Since the 'bus' parameter is not NULL in both callers, remove remove the test on if (bus), and add an
assert()to silent static analyzers.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".
Quoted 8 lines
1367 ret = spapr_dt_drc(fdt, offset,
OBJECT(bus->parent_dev),
1368SPAPR_DR_CONNECTOR_TYPE_PCI);Fixes 14e714900f6Reported-by Coverity (CID 1401933)Suggested-by Greg Kurz <[email protected]>Suggested-by David Gibson <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Applied, thanks.
Quoted 26 lines
--- hw/ppc/spapr_pci.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)hw/ppc/spapr_pci.c +5
-6@@ -1356,12 +1356,11 @@ static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus,_FDT (fdt_setprop_cell (fdt, offset,"#size-cells" ,RESOURCE_CELLS_SIZE )); -if (bus) { -pci_for_each_device_reverse (bus,pci_bus_num (bus), - spapr_dt_pci_device_cb, &cbinfo); -if (cbinfo.err) { -return cbinfo.err; - } +assert (bus); +pci_for_each_device_reverse (bus,pci_bus_num (bus), + spapr_dt_pci_device_cb, &cbinfo); +if (cbinfo.err) { +return cbinfo.err; } ret = spapr_dt_drc(fdt, offset, OBJECT(bus->parent_dev),
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