Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/eeh: Fix a bug when pci structure is null

During a EEH recover, the pci_dev structure can be null, mainly if an
eeh event is detected during cpi config operation. In this case, the
pci_dev will not be known (and will be null) the kernel will crash
with the following message:

Unable to handle kernel paging request for data at address 0x000000a0
Faulting instruction address: 0xc00000000006b8b4
Oops: Kernel access of bad area, sig: 11 [#1]

NIP [c00000000006b8b4] .eeh_event_handler+0x10c/0x1a0
LR [c00000000006b8a8] .eeh_event_handler+0x100/0x1a0
Call Trace:
[c0000003a80dff00] [c00000000006b8a8] .eeh_event_handler+0x100/0x1a0
[c0000003a80dff90] [c000000000031f1c] .kernel_thread+0x54/0x70

The bug occurs because pci_name() tries to access a null pointer.
This patch just guarantee that pci_name() is not called on Null pointers.

Signed-off-by: Breno Leitao <leitao@linux.vnet.ibm.com>
Signed-off-by: Linas Vepstas <linasvepstas@gmail.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Breno Leitao and committed by
Benjamin Herrenschmidt
8d3d50bf e0508b15

+10 -5
+5
arch/powerpc/include/asm/ppc-pci.h
··· 137 137 void eeh_sysfs_add_device(struct pci_dev *pdev); 138 138 void eeh_sysfs_remove_device(struct pci_dev *pdev); 139 139 140 + static inline const char *eeh_pci_name(struct pci_dev *pdev) 141 + { 142 + return pdev ? pci_name(pdev) : "<null>"; 143 + } 144 + 140 145 #endif /* CONFIG_EEH */ 141 146 142 147 #else /* CONFIG_PCI */
+2 -2
arch/powerpc/platforms/pseries/eeh.c
··· 491 491 pdn->eeh_mode & EEH_MODE_NOCHECK) { 492 492 ignored_check++; 493 493 pr_debug("EEH: Ignored check (%x) for %s %s\n", 494 - pdn->eeh_mode, pci_name (dev), dn->full_name); 494 + pdn->eeh_mode, eeh_pci_name(dev), dn->full_name); 495 495 return 0; 496 496 } 497 497 ··· 515 515 printk (KERN_ERR "EEH: %d reads ignored for recovering device at " 516 516 "location=%s driver=%s pci addr=%s\n", 517 517 pdn->eeh_check_count, location, 518 - dev->driver->name, pci_name(dev)); 518 + dev->driver->name, eeh_pci_name(dev)); 519 519 printk (KERN_ERR "EEH: Might be infinite loop in %s driver\n", 520 520 dev->driver->name); 521 521 dump_stack();
+2 -2
arch/powerpc/platforms/pseries/eeh_driver.c
··· 337 337 location = location ? location : "unknown"; 338 338 printk(KERN_ERR "EEH: Error: Cannot find partition endpoint " 339 339 "for location=%s pci addr=%s\n", 340 - location, pci_name(event->dev)); 340 + location, eeh_pci_name(event->dev)); 341 341 return NULL; 342 342 } 343 343 ··· 368 368 pci_str = pci_name (frozen_pdn->pcidev); 369 369 drv_str = pcid_name (frozen_pdn->pcidev); 370 370 } else { 371 - pci_str = pci_name (event->dev); 371 + pci_str = eeh_pci_name(event->dev); 372 372 drv_str = pcid_name (event->dev); 373 373 } 374 374
+1 -1
arch/powerpc/platforms/pseries/eeh_event.c
··· 80 80 eeh_mark_slot(event->dn, EEH_MODE_RECOVERING); 81 81 82 82 printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n", 83 - pci_name(event->dev)); 83 + eeh_pci_name(event->dev)); 84 84 85 85 pdn = handle_eeh_events(event); 86 86