Skip to content

Commit 81082af

Browse files
Jubin Zhongksacilotto
authored andcommitted
PCI: Fix pci_slot_release() NULL pointer dereference
BugLink: https://bugs.launchpad.net/bugs/1910822 commit 4684709 upstream. If kobject_init_and_add() fails, pci_slot_release() is called to delete slot->list from parent->slots. But slot->list hasn't been initialized yet, so we dereference a NULL pointer: Unable to handle kernel NULL pointer dereference at virtual address 00000000 ... CPU: 10 PID: 1 Comm: swapper/0 Not tainted 4.4.240 #197 task: ffffeb398a45ef10 task.stack: ffffeb398a470000 PC is at __list_del_entry_valid+0x5c/0xb0 LR is at pci_slot_release+0x84/0xe4 ... __list_del_entry_valid+0x5c/0xb0 pci_slot_release+0x84/0xe4 kobject_put+0x184/0x1c4 pci_create_slot+0x17c/0x1b4 __pci_hp_initialize+0x68/0xa4 pciehp_probe+0x1a4/0x2fc pcie_port_probe_service+0x58/0x84 driver_probe_device+0x320/0x470 Initialize slot->list before calling kobject_init_and_add() to avoid this. Fixes: 8a94644 ("PCI: Fix pci_create_slot() reference count leak") Link: https://lore.kernel.org/r/1606876422-117457-1-git-send-email-zhongjubin@huawei.com Signed-off-by: Jubin Zhong <zhongjubin@huawei.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Cc: stable@vger.kernel.org # v5.9+ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
1 parent ba852ed commit 81082af

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/pci/slot.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,16 +308,16 @@ struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
308308
goto err;
309309
}
310310

311+
INIT_LIST_HEAD(&slot->list);
312+
list_add(&slot->list, &parent->slots);
313+
311314
err = kobject_init_and_add(&slot->kobj, &pci_slot_ktype, NULL,
312315
"%s", slot_name);
313316
if (err) {
314317
kobject_put(&slot->kobj);
315318
goto err;
316319
}
317320

318-
INIT_LIST_HEAD(&slot->list);
319-
list_add(&slot->list, &parent->slots);
320-
321321
down_read(&pci_bus_sem);
322322
list_for_each_entry(dev, &parent->devices, bus_list)
323323
if (PCI_SLOT(dev->devfn) == slot_nr)

0 commit comments

Comments
 (0)