Skip to content

Commit 140ab64

Browse files
QiuMikebjorn-helgaas
authored andcommitted
powerpc/PCI: Fix NULL dereference in sys_pciconfig_iobase() list traversal
3bc9559 ("powerpc/PCI: Use list_for_each_entry() for bus traversal") caused a NULL pointer dereference because the loop body set the iterator to NULL: Unable to handle kernel paging request for data at address 0x00000000 Faulting instruction address: 0xc000000000041d78 Oops: Kernel access of bad area, sig: 11 [alexander-zimmermann#1] ... NIP [c000000000041d78] .sys_pciconfig_iobase+0x68/0x1f0 LR [c000000000041e0c] .sys_pciconfig_iobase+0xfc/0x1f0 Call Trace: [c0000003b4787db0] [c000000000041e0c] .sys_pciconfig_iobase+0xfc/0x1f0 (unreliable) [c0000003b4787e30] [c000000000009ed8] syscall_exit+0x0/0x98 Fix it by using a temporary variable for the iterator. [bhelgaas: changelog, drop tmp_bus initialization] Fixes: 3bc9559 powerpc/PCI: Use list_for_each_entry() for bus traversal Signed-off-by: Mike Qiu <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent c9eaa44 commit 140ab64

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

arch/powerpc/kernel/pci_64.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ long sys_pciconfig_iobase(long which, unsigned long in_bus,
208208
unsigned long in_devfn)
209209
{
210210
struct pci_controller* hose;
211-
struct pci_bus *bus = NULL;
211+
struct pci_bus *tmp_bus, *bus = NULL;
212212
struct device_node *hose_node;
213213

214214
/* Argh ! Please forgive me for that hack, but that's the
@@ -229,10 +229,12 @@ long sys_pciconfig_iobase(long which, unsigned long in_bus,
229229
* used on pre-domains setup. We return the first match
230230
*/
231231

232-
list_for_each_entry(bus, &pci_root_buses, node) {
233-
if (in_bus >= bus->number && in_bus <= bus->busn_res.end)
232+
list_for_each_entry(tmp_bus, &pci_root_buses, node) {
233+
if (in_bus >= tmp_bus->number &&
234+
in_bus <= tmp_bus->busn_res.end) {
235+
bus = tmp_bus;
234236
break;
235-
bus = NULL;
237+
}
236238
}
237239
if (bus == NULL || bus->dev.of_node == NULL)
238240
return -ENODEV;

0 commit comments

Comments
 (0)