android_kernel_oneplus_msm8998/drivers/pci/hotplug
Lukas Wunner 131412f4f6 PCI: pciehp: Fix use-after-free on unplug
commit 281e878eab191cce4259abbbf1a0322e3adae02c upstream.

When pciehp is unbound (e.g. on unplug of a Thunderbolt device), the
hotplug_slot struct is deregistered and thus freed before freeing the
IRQ.  The IRQ handler and the work items it schedules print the slot
name referenced from the freed structure in various informational and
debug log messages, each time resulting in a quadruple dereference of
freed pointers (hotplug_slot -> pci_slot -> kobject -> name).

At best the slot name is logged as "(null)", at worst kernel memory is
exposed in logs or the driver crashes:

  pciehp 0000:10:00.0:pcie204: Slot((null)): Card not present

An attacker may provoke the bug by unplugging multiple devices on a
Thunderbolt daisy chain at once.  Unplugging can also be simulated by
powering down slots via sysfs.  The bug is particularly easy to trigger
in poll mode.

It has been present since the driver's introduction in 2004:
https://git.kernel.org/tglx/history/c/c16b4b14d980

Fix by rearranging teardown such that the IRQ is freed first.  Run the
work items queued by the IRQ handler to completion before freeing the
hotplug_slot struct by draining the work queue from the ->release_slot
callback which is invoked by pci_hp_deregister().

Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: stable@vger.kernel.org # v2.6.4
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-08-24 13:27:01 +02:00
..
acpi_pcihp.c
acpiphp.h
acpiphp_core.c
acpiphp_glue.c ACPI / hotplug / PCI: Check presence of slot itself in get_slot_status() 2018-04-24 09:32:06 +02:00
acpiphp_ibm.c
cpci_hotplug.h
cpci_hotplug_core.c PCI: Delete unnecessary NULL pointer checks 2014-12-26 16:28:08 -07:00
cpci_hotplug_pci.c PCI: cpcihp: Add missing curly braces in cpci_configure_slot() 2015-03-12 11:22:10 -05:00
cpcihp_generic.c
cpcihp_zt5550.c
cpcihp_zt5550.h
cpqphp.h
cpqphp_core.c
cpqphp_ctrl.c
cpqphp_nvram.c
cpqphp_nvram.h
cpqphp_pci.c
cpqphp_sysfs.c
ibmphp.h
ibmphp_core.c PCI: Assign resources before drivers claim devices (pci_scan_bus()) 2015-03-12 15:04:01 -05:00
ibmphp_ebda.c
ibmphp_hpc.c
ibmphp_pci.c
ibmphp_res.c
Kconfig
Makefile PCI: pciehp: Drop pointless ACPI-based "slot detection" check 2015-05-21 11:01:12 -05:00
pci_hotplug_core.c PCI: hotplug: Don't leak pci_slot on registration failure 2018-08-24 13:27:01 +02:00
pciehp.h PCI: pciehp: Fix use-after-free on unplug 2018-08-24 13:27:01 +02:00
pciehp_core.c PCI: pciehp: Fix use-after-free on unplug 2018-08-24 13:27:01 +02:00
pciehp_ctrl.c PCI: pciehp: Queue power work requests in dedicated function 2015-10-21 13:55:37 -05:00
pciehp_hpc.c PCI: pciehp: Fix use-after-free on unplug 2018-08-24 13:27:01 +02:00
pciehp_pci.c
pcihp_skeleton.c
rpadlpar.h
rpadlpar_core.c powerpc/pci/rpadlpar: Fix device reference leaks 2017-01-12 11:22:50 +01:00
rpadlpar_sysfs.c
rpaphp.h
rpaphp_core.c
rpaphp_pci.c
rpaphp_slot.c
s390_pci_hpc.c
sgi_hotplug.c ACPI: Introduce acpi_unload_parent_table() usages in Linux kernel 2015-01-26 16:08:49 +01:00
shpchp.h
shpchp_core.c
shpchp_ctrl.c
shpchp_hpc.c PCI: shpchp: Enable bridge bus mastering if MSI is enabled 2017-09-27 11:00:16 +02:00
shpchp_pci.c
shpchp_sysfs.c