kernel_samsung_a53x/drivers/pci
Lukas Wunner bc2bb965ce PCI/DPC: Fix use-after-free on concurrent DPC and hot-removal
commit 11a1f4bc47362700fcbde717292158873fb847ed upstream.

Keith reports a use-after-free when a DPC event occurs concurrently to
hot-removal of the same portion of the hierarchy:

The dpc_handler() awaits readiness of the secondary bus below the
Downstream Port where the DPC event occurred.  To do so, it polls the
config space of the first child device on the secondary bus.  If that
child device is concurrently removed, accesses to its struct pci_dev
cause the kernel to oops.

That's because pci_bridge_wait_for_secondary_bus() neglects to hold a
reference on the child device.  Before v6.3, the function was only
called on resume from system sleep or on runtime resume.  Holding a
reference wasn't necessary back then because the pciehp IRQ thread
could never run concurrently.  (On resume from system sleep, IRQs are
not enabled until after the resume_noirq phase.  And runtime resume is
always awaited before a PCI device is removed.)

However starting with v6.3, pci_bridge_wait_for_secondary_bus() is also
called on a DPC event.  Commit 53b54ad074de ("PCI/DPC: Await readiness
of secondary bus after reset"), which introduced that, failed to
appreciate that pci_bridge_wait_for_secondary_bus() now needs to hold a
reference on the child device because dpc_handler() and pciehp may
indeed run concurrently.  The commit was backported to v5.10+ stable
kernels, so that's the oldest one affected.

Add the missing reference acquisition.

Abridged stack trace:

  BUG: unable to handle page fault for address: 00000000091400c0
  CPU: 15 PID: 2464 Comm: irq/53-pcie-dpc 6.9.0
  RIP: pci_bus_read_config_dword+0x17/0x50
  pci_dev_wait()
  pci_bridge_wait_for_secondary_bus()
  dpc_reset_link()
  pcie_do_recovery()
  dpc_handler()

Fixes: 53b54ad074de ("PCI/DPC: Await readiness of secondary bus after reset")
Closes: https://lore.kernel.org/r/20240612181625.3604512-3-kbusch@meta.com/
Link: https://lore.kernel.org/linux-pci/8e4bcd4116fd94f592f2bf2749f168099c480ddf.1718707743.git.lukas@wunner.de
Reported-by: Keith Busch <kbusch@kernel.org>
Tested-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: stable@vger.kernel.org # v5.10+
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-11-23 23:20:30 +01:00
..
controller PCI: rockchip: Use GPIOD_OUT_LOW flag while requesting ep_gpio 2024-11-23 23:20:14 +01:00
endpoint
hotplug Revert "PCI: acpiphp: Reassign resources on bridge if necessary" 2024-11-18 12:11:50 +01:00
pcie PCI/EDR: Align EDR_PORT_LOCATE_DSM with PCI Firmware r3.3 2024-11-19 12:27:04 +01:00
switch PCI: switchtec: Fix an error handling path in switchtec_pci_probe() 2024-11-19 08:44:52 +01:00
access.c
ats.c
bus.c
ecam.c
host-bridge.c
iov.c
irq.c
Kconfig
Makefile
mmap.c
msi.c PCI/MSI: Prevent MSI hardware interrupt number truncation 2024-11-18 22:25:37 +01:00
of.c
p2pdma.c
pci-acpi.c
pci-bridge-emul.c
pci-bridge-emul.h
pci-driver.c Manual Revert: PCI: Drop pci_device_remove() test of pci_dev->driver 2024-11-19 10:17:16 +01:00
pci-label.c
pci-mid.c
pci-pf-stub.c
pci-stub.c
pci-sysfs.c
pci.c PCI/DPC: Fix use-after-free on concurrent DPC and hot-removal 2024-11-23 23:20:30 +01:00
pci.h PCI/ERR: Cache RCEC EA Capability offset in pci_init_capabilities() 2024-11-19 09:22:18 +01:00
probe.c PCI/ERR: Cache RCEC EA Capability offset in pci_init_capabilities() 2024-11-19 09:22:18 +01:00
proc.c
quirks.c Manual Revert: PCI/ASPM: Make Intel DG2 L1 acceptable latency unlimited 2024-11-19 10:37:22 +01:00
remove.c
rom.c
search.c
setup-bus.c PCI: Fix resource double counting on remove & rescan 2024-11-23 23:20:10 +01:00
setup-irq.c
setup-res.c PCI: Work around Intel I210 ROM BAR overlap defect 2024-11-19 09:22:33 +01:00
slot.c
syscall.c
vc.c
vpd.c
xen-pcifront.c