android_kernel_samsung_msm8976/drivers
Sebastian Andrzej Siewior dcc121e02f PCI/AER: Flush workqueue on device remove to avoid use-after-free
commit 4ae2182b1e3407de369f8c5d799543b7db74221b upstream.

A Root Port's AER structure (rpc) contains a queue of events.  aer_irq()
enqueues AER status information and schedules aer_isr() to dequeue and
process it.  When we remove a device, aer_remove() waits for the queue to
be empty, then frees the rpc struct.

But aer_isr() references the rpc struct after dequeueing and possibly
emptying the queue, which can cause a use-after-free error as in the
following scenario with two threads, aer_isr() on the left and a
concurrent aer_remove() on the right:

  Thread A                      Thread B
  --------                      --------
  aer_irq():
    rpc->prod_idx++
                                aer_remove():
                                  wait_event(rpc->prod_idx == rpc->cons_idx)
                                  # now blocked until queue becomes empty
  aer_isr():                      # ...
    rpc->cons_idx++               # unblocked because queue is now empty
    ...                           kfree(rpc)
    mutex_unlock(&rpc->rpc_mutex)

To prevent this problem, use flush_work() to wait until the last scheduled
instance of aer_isr() has completed before freeing the rpc struct in
aer_remove().

I reproduced this use-after-free by flashing a device FPGA and
re-enumerating the bus to find the new device.  With SLUB debug, this
crashes with 0x6b bytes (POISON_FREE, the use-after-free magic number) in
GPR25:

  pcieport 0000:00:00.0: AER: Multiple Corrected error received: id=0000
  Unable to handle kernel paging request for data at address 0x27ef9e3e
  Workqueue: events aer_isr
  GPR24: dd6aa000 6b6b6b6b 605f8378 605f8360 d99b12c0 604fc674 606b1704 d99b12c0
  NIP [602f5328] pci_walk_bus+0xd4/0x104

[bhelgaas: changelog, stable tag]
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2016-03-03 15:06:24 -08:00
..
accessibility
acpi ACPICA: Tables: Fix an issue that FACS initialization is performed twice 2015-08-03 09:29:46 -07:00
amba
ata libata: fix sff host state machine locking while polling 2016-03-03 15:06:24 -08:00
atm
auxdisplay auxdisplay: ks0108: fix refcount 2015-09-21 10:00:09 -07:00
base regmap: debugfs: Don't bother actually printing when calculating max length 2015-10-22 14:37:51 -07:00
bcma
block xen-blkfront: check for null drvdata in blkback_changed (XenbusStateClosing) 2015-11-09 10:12:58 -08:00
bluetooth Bluetooth: btusb: Fix memory leak in Intel setup routine 2015-08-03 09:29:42 -07:00
bus bus: mvebu: pass the coherency availability information at init time 2015-07-03 19:48:09 -07:00
cdrom
char vTPM: fix memory allocation flag for rtce buffer at kernel boot 2016-02-19 14:22:38 -08:00
clk clk: versatile: off by one in clk_sp810_timerclken_of_get() 2015-09-21 10:00:07 -07:00
clocksource clocksource/drivers/vt8500: Increase the minimum delta 2016-03-03 15:06:20 -08:00
connector connector: bump skb->users before callback invocation 2016-01-28 21:49:33 -08:00
cpufreq cpufreq: speedstep-smi: enable interrupts when waiting 2015-03-06 14:40:48 -08:00
cpuidle cpuidle / menu: Return (-1) if there are no suitable states 2015-08-03 09:29:41 -07:00
crypto crypto: caam - fix memory corruption in ahash_final_ctx 2015-09-13 09:07:59 -07:00
dca
devfreq
dio
dma dmaengine: mv_xor: bug fix for racing condition in descriptors cleanup 2015-08-03 09:29:46 -07:00
edac EDAC, ppc4xx: Access mci->csrows array elements properly 2015-09-13 09:07:59 -07:00
eisa
extcon extcon: max77693: Fix two NULL pointer exceptions on missing pdata 2014-07-06 18:54:15 -07:00
firewire firewire: ohci: fix JMicron JMB38x IT context discovery 2016-01-22 19:47:53 -08:00
firmware efi-pstore: Make efi-pstore return a unique id 2015-02-05 22:35:40 -08:00
gpio gpio: sysfs: fix memory leaks and device hotplug 2015-05-17 09:51:32 -07:00
gpu drm/radeon: use post-decrement in error handling 2016-03-03 15:06:24 -08:00
hid HID: usbhid: fix recursive deadlock 2016-02-19 14:22:37 -08:00
hsi
hv Drivers: hv: vmbus: Don't wait after requesting offers 2015-05-13 05:15:43 -07:00
hwmon hwmon: (mcp3021) Fix broken output scaling 2015-08-03 09:29:46 -07:00
hwspinlock
i2c i2c: rcar: enable RuntimePM before registering to the core 2015-10-27 09:44:50 +09:00
ide
idle
iio iio: dac: mcp4725: set iio name property in sysfs 2016-02-25 11:57:48 -08:00
infiniband IB/qib: fix mcast detach when qp not attached 2016-03-03 15:06:24 -08:00
input Input: i8042 - add Fujitsu Lifebook U745 to the nomux list 2016-02-25 11:57:49 -08:00
iommu iommu/vt-d: Fix 64-bit accesses to 32-bit DMAR_GSTS_REG 2016-02-25 11:57:49 -08:00
ipack
irqchip irqchip: gic: Fix core ID calculation when topology is read from DT 2014-07-28 08:00:06 -07:00
isdn ppp, slip: Validate VJ compression slot parameters completely 2016-01-28 21:49:35 -08:00
leds leds: leds-pwm: properly clean up after probe failure 2014-06-07 13:25:34 -07:00
lguest lguest: fix out-by-one error in address checking. 2015-06-05 23:19:54 -07:00
macintosh windfarm: decrement client count when unregistering 2015-10-22 14:37:49 -07:00
mailbox
md dm snapshot: fix hung bios when copy error occurs 2016-03-03 15:06:23 -08:00
media tda1004x: only update the frontend properties if locked 2016-03-03 15:06:23 -08:00
memory
memstick memstick: mspro_block: add missing curly braces 2015-05-06 21:56:28 +02:00
message mptfusion: enable no_write_same for vmware scsi disks 2014-10-30 09:35:10 -07:00
mfd mfd: sm501: dbg_regs attribute must be read-only 2015-08-16 20:51:37 -07:00
misc mei: bus: fix possible boundaries violation 2014-11-21 09:22:55 -08:00
mmc mmc: mmci: fix an ages old detection error 2016-03-03 15:06:23 -08:00
mtd mtd: mtdpart: fix add_mtd_partitions error path 2016-02-19 14:22:38 -08:00
net can: sja1000: clear interrupts on start 2016-03-03 15:06:21 -08:00
nfc NFC: microread: Potential overflows in microread_target_discovered() 2014-10-05 14:54:12 -07:00
ntb
nubus
of of/address: Don't loop forever in of_find_matching_node_by_address(). 2015-09-21 10:00:09 -07:00
oprofile
parisc parisc iommu: fix panic due to trying to allocate too large region 2016-01-28 21:49:36 -08:00
parport drivers: parport: Kconfig: exclude arm64 for PARPORT_PC 2015-05-06 21:56:26 +02:00
pci PCI/AER: Flush workqueue on device remove to avoid use-after-free 2016-03-03 15:06:24 -08:00
pcmcia Disable write buffering on Toshiba ToPIC95 2015-08-03 09:29:41 -07:00
pinctrl pinctrl: mvebu: armada-xp: fix functions of MPP48 2015-08-03 09:29:42 -07:00
platform intel_scu_ipcutil: underflow in scu_reg_access() 2016-02-25 11:57:49 -08:00
pnp PNP / ACPI: proper handling of ACPI IO/Memory resource parsing failures 2014-03-23 21:38:22 -07:00
power wm831x_power: Use IRQF_ONESHOT to request threaded IRQs 2016-03-03 15:06:20 -08:00
pps
ps3
ptp
pwm
rapidio rapidio/tsi721_dma: fix failure to obtain transaction descriptor 2014-08-07 14:30:25 -07:00
regulator regulator: core: fix constraints output buffer 2015-08-03 09:29:41 -07:00
remoteproc remoteproc: avoid stack overflow in debugfs file 2016-02-19 14:22:37 -08:00
reset
rpmsg
rtc rtc: rtc-at91rm9200: fix infinite wait for ACKUPD irq 2014-06-26 15:12:37 -04:00
s390 s390/dasd: fix refcount for PAV reassignment 2016-03-03 15:06:23 -08:00
sbus bbc-i2c: Fix BBC I2C envctrl on SunBlade 2000 2014-08-14 09:24:16 +08:00
scsi ses: fix additional element traversal bug 2016-03-03 15:06:22 -08:00
sfi
sh
sn
spi spi: fix parent-device reference leak 2016-02-19 14:22:38 -08:00
ssb
ssbi
staging iio: lpc32xx_adc: fix warnings caused by enabling unprepared clock 2016-02-25 11:57:48 -08:00
target iscsi-target: Fix potential dead-lock during node acl delete 2016-02-25 11:57:47 -08:00
tc
thermal
tty pty: make sure super_block is still valid in final /dev/tty close 2016-02-25 11:57:46 -08:00
uio
usb cdc-acm:exclude Samsung phone 04e8:685d 2016-03-03 15:06:24 -08:00
uwb
vfio vfio-pci: Fix the check on pci device type in vfio_pci_probe() 2015-01-27 07:52:32 -08:00
vhost vhost/scsi: potential memory corruption 2015-10-01 12:07:34 +02:00
video video: vgacon: Don't build on arm64 2015-05-06 21:56:25 +02:00
virt
virtio virtio: fix memory leak of virtio ida cache layers 2016-03-03 15:06:21 -08:00
vlynq
vme
w1 w1: fix w1_send_slave dropping a slave id 2014-05-06 07:55:28 -07:00
watchdog watchdog: omap: assert the counter being stopped before reprogramming 2015-08-03 09:29:47 -07:00
xen xen/gntdev: Grant maps should not be subject to NUMA balancing 2016-01-28 21:49:28 -08:00
zorro
Kconfig
Makefile