Skip to content

Commit bd91b56

Browse files
thomastaioracleBjorn Helgaas
authored andcommitted
PCI/AER: Work around use-after-free in pcie_do_fatal_recovery()
When an fatal error is received by a non-bridge device, the device is removed, and pci_stop_and_remove_bus_device() deallocates the device structure. The freed device structure is used by subsequent code to send uevents and print messages. Hold a reference on the device until we're finished using it. This is not an ideal fix because pcie_do_fatal_recovery() should not use the device at all after removing it, but that's too big a project for right now. Fixes: 7e9084b ("PCI/AER: Handle ERR_FATAL with removal and re-enumeration of devices") Signed-off-by: Thomas Tai <thomas.tai@oracle.com> [bhelgaas: changelog, reduce get/put coverage] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 270ed73 commit bd91b56

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

‎drivers/pci/pcie/err.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ void pcie_do_fatal_recovery(struct pci_dev *dev, u32 service)
295295

296296
parent = udev->subordinate;
297297
pci_lock_rescan_remove();
298+
pci_dev_get(dev);
298299
list_for_each_entry_safe_reverse(pdev, temp, &parent->devices,
299300
bus_list) {
300301
pci_dev_get(pdev);
@@ -328,6 +329,7 @@ void pcie_do_fatal_recovery(struct pci_dev *dev, u32 service)
328329
pci_info(dev, "Device recovery from fatal error failed\n");
329330
}
330331

332+
pci_dev_put(dev);
331333
pci_unlock_rescan_remove();
332334
}
333335

0 commit comments

Comments
 (0)