linux/drivers
Tejun Heo 8eee1d3ed5 libata: fix sff host state machine locking while polling
The bulk of ATA host state machine is implemented by
ata_sff_hsm_move().  The function is called from either the interrupt
handler or, if polling, a work item.  Unlike from the interrupt path,
the polling path calls the function without holding the host lock and
ata_sff_hsm_move() selectively grabs the lock.

This is completely broken.  If an IRQ triggers while polling is in
progress, the two can easily race and end up accessing the hardware
and updating state machine state at the same time.  This can put the
state machine in an illegal state and lead to a crash like the
following.

  kernel BUG at drivers/ata/libata-sff.c:1302!
  invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN
  Modules linked in:
  CPU: 1 PID: 10679 Comm: syz-executor Not tainted 4.5.0-rc1+ #300
  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
  task: ffff88002bd00000 ti: ffff88002e048000 task.ti: ffff88002e048000
  RIP: 0010:[<ffffffff83a83409>]  [<ffffffff83a83409>] ata_sff_hsm_move+0x619/0x1c60
  ...
  Call Trace:
   <IRQ>
   [<ffffffff83a84c31>] __ata_sff_port_intr+0x1e1/0x3a0 drivers/ata/libata-sff.c:1584
   [<ffffffff83a85611>] ata_bmdma_port_intr+0x71/0x400 drivers/ata/libata-sff.c:2877
   [<     inline     >] __ata_sff_interrupt drivers/ata/libata-sff.c:1629
   [<ffffffff83a85bf3>] ata_bmdma_interrupt+0x253/0x580 drivers/ata/libata-sff.c:2902
   [<ffffffff81479f98>] handle_irq_event_percpu+0x108/0x7e0 kernel/irq/handle.c:157
   [<ffffffff8147a717>] handle_irq_event+0xa7/0x140 kernel/irq/handle.c:205
   [<ffffffff81484573>] handle_edge_irq+0x1e3/0x8d0 kernel/irq/chip.c:623
   [<     inline     >] generic_handle_irq_desc include/linux/irqdesc.h:146
   [<ffffffff811a92bc>] handle_irq+0x10c/0x2a0 arch/x86/kernel/irq_64.c:78
   [<ffffffff811a7e4d>] do_IRQ+0x7d/0x1a0 arch/x86/kernel/irq.c:240
   [<ffffffff86653d4c>] common_interrupt+0x8c/0x8c arch/x86/entry/entry_64.S:520
   <EOI>
   [<     inline     >] rcu_lock_acquire include/linux/rcupdate.h:490
   [<     inline     >] rcu_read_lock include/linux/rcupdate.h:874
   [<ffffffff8164b4a1>] filemap_map_pages+0x131/0xba0 mm/filemap.c:2145
   [<     inline     >] do_fault_around mm/memory.c:2943
   [<     inline     >] do_read_fault mm/memory.c:2962
   [<     inline     >] do_fault mm/memory.c:3133
   [<     inline     >] handle_pte_fault mm/memory.c:3308
   [<     inline     >] __handle_mm_fault mm/memory.c:3418
   [<ffffffff816efb16>] handle_mm_fault+0x2516/0x49a0 mm/memory.c:3447
   [<ffffffff8127dc16>] __do_page_fault+0x376/0x960 arch/x86/mm/fault.c:1238
   [<ffffffff8127e358>] trace_do_page_fault+0xe8/0x420 arch/x86/mm/fault.c:1331
   [<ffffffff8126f514>] do_async_page_fault+0x14/0xd0 arch/x86/kernel/kvm.c:264
   [<ffffffff86655578>] async_page_fault+0x28/0x30 arch/x86/entry/entry_64.S:986

Fix it by ensuring that the polling path is holding the host lock
before entering ata_sff_hsm_move() so that all hardware accesses and
state updates are performed under the host lock.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-and-tested-by: Dmitry Vyukov <dvyukov@google.com>
Link: http://lkml.kernel.org/g/CACT4Y+b_JsOxJu2EZyEf+mOXORc_zid5V1-pLZSroJVxyWdSpw@mail.gmail.com
Cc: stable@vger.kernel.org
2016-02-01 11:33:21 -05:00
..
accessibility
acpi tree wide: use kvfree() than conditional kfree()/vfree() 2016-01-22 17:02:18 -08:00
amba
android
ata libata: fix sff host state machine locking while polling 2016-02-01 11:33:21 -05:00
atm
auxdisplay
base wrappers for ->i_mutex access 2016-01-22 18:04:28 -05:00
bcma GPIO bulk updates for the v4.5 kernel cycle: 2016-01-17 12:32:01 -08:00
block Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client 2016-01-24 12:34:13 -08:00
bluetooth
bus ARM: SoC driver updates for v4.5 2016-01-20 18:42:30 -08:00
cdrom
char Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2016-01-23 12:24:56 -08:00
clk ARM: DT updates for v4.5 2016-01-20 18:16:29 -08:00
clocksource ARM: SoC cleanups for v4.5 2016-01-20 17:55:20 -08:00
connector
cpufreq powerpc updates for 4.5 2016-01-15 13:18:47 -08:00
cpuidle More power management and ACPI updates for v4.5-rc1 2016-01-20 19:06:49 -08:00
crypto Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6 2016-01-22 11:58:43 -08:00
dca
devfreq PM / devfreq: Do not show statistics if it's not ready. 2016-01-13 17:30:33 +09:00
dio
dma dmaengine fixes for 4.5-rc1 2016-01-20 10:15:21 -08:00
dma-buf
edac
eisa
extcon
firewire
firmware UBSAN: run-time undefined behavior sanity checker 2016-01-20 17:09:18 -08:00
fmc
fpga
gpio ARM: SoC multiplatform code changes for v4.5 2016-01-20 18:03:56 -08:00
gpu tree wide: use kvfree() than conditional kfree()/vfree() 2016-01-22 17:02:18 -08:00
hid asm-generic changes for 4.5 2016-01-20 17:30:20 -08:00
hsi HSI: omap_ssi_port: fix handling of_get_named_gpio result 2016-01-07 16:07:54 +01:00
hv char/misc patches for 4.5-rc1 2016-01-13 10:23:36 -08:00
hwmon Merge git://www.linux-watchdog.org/linux-watchdog 2016-01-17 12:15:38 -08:00
hwspinlock
hwtracing
i2c Merge branch 'i2c/for-4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux 2016-01-14 11:25:37 -08:00
ide drivers/ide: make ide-scan-pci.c driver explicitly non-modular 2016-01-18 14:12:33 -05:00
idle
iio Merge branch 'akpm' (patches from Andrew) 2016-01-21 12:32:08 -08:00
infiniband Initial roundup of 4.5 merge window patches 2016-01-23 18:45:06 -08:00
input Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input 2016-01-22 17:20:30 -08:00
iommu IOMMU Updates for Linux v4.5 2016-01-19 09:35:06 -08:00
ipack
irqchip Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus 2016-01-24 12:50:56 -08:00
isdn Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2016-01-11 23:55:43 -05:00
leds GPIO bulk updates for the v4.5 kernel cycle: 2016-01-17 12:32:01 -08:00
lguest lguest: Map switcher text R/O 2016-01-12 12:17:28 +01:00
lightnvm lightnvm: introduce factory reset 2016-01-12 08:21:18 -07:00
macintosh
mailbox
mcb
md Merge branch 'for-4.5/drivers' of git://git.kernel.dk/linux-block 2016-01-21 18:19:38 -08:00
media dma-mapping: always provide the dma_map_ops based implementation 2016-01-20 17:09:18 -08:00
memory ARM: SoC driver updates for v4.5 2016-01-20 18:42:30 -08:00
memstick memstick: use sector_div instead of do_div 2016-01-20 17:09:18 -08:00
message
mfd GPIO bulk updates for the v4.5 kernel cycle: 2016-01-17 12:32:01 -08:00
misc Merge branch 'akpm' (patches from Andrew) 2016-01-21 12:32:08 -08:00
mmc MMC core: 2016-01-22 12:04:21 -08:00
mtd Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/ralf/upstream-linus 2016-01-24 12:50:56 -08:00
net Initial roundup of 4.5 merge window patches 2016-01-23 18:45:06 -08:00
nfc
ntb NTB: Fix macro parameter conflict with field name 2016-01-21 19:53:10 -05:00
nubus
nvdimm mm, dax, pmem: introduce {get|put}_dev_pagemap() for dax-gup 2016-01-15 17:56:32 -08:00
nvme Merge branch 'for-4.5/nvme' of git://git.kernel.dk/linux-block 2016-01-21 19:58:02 -08:00
nvmem
of DeviceTree updates for 4.5: 2016-01-14 11:13:28 -08:00
oprofile wrappers for ->i_mutex access 2016-01-22 18:04:28 -05:00
parisc parisc: convert to dma_map_ops 2016-01-20 17:09:18 -08:00
parport
pci PCI changes for the v4.5 merge window: 2016-01-21 11:52:16 -08:00
pcmcia
perf
phy
pinctrl GPIO bulk updates for the v4.5 kernel cycle: 2016-01-17 12:32:01 -08:00
platform ideapad-laptop: Add Lenovo Yoga 700 to no_hw_rfkill dmi list 2016-01-24 10:15:01 -08:00
pnp
power power: bq27xxx_battery: Fix bq27541 AveragePower register address 2016-01-14 01:03:18 +01:00
powercap Merge branch 'powercap' 2016-01-12 01:12:40 +01:00
pps
ps3
ptp
pwm pwm: Mark all devices as "might sleep" 2016-01-21 15:04:59 +01:00
rapidio rapidio: use kobj_to_dev() 2016-01-20 17:09:18 -08:00
ras
regulator regulator: Update for v4.5 2016-01-15 12:14:47 -08:00
remoteproc virtio: make find_vqs() checkpatch.pl-friendly 2016-01-12 20:47:06 +02:00
reset
rpmsg virtio: make find_vqs() checkpatch.pl-friendly 2016-01-12 20:47:06 +02:00
rtc RTC for 4.5 2016-01-18 12:10:45 -08:00
s390 virtio: barrier rework+fixes 2016-01-18 16:44:24 -08:00
sbus
scsi Initial roundup of 4.5 merge window patches 2016-01-23 18:45:06 -08:00
sfi
sh
sn
soc ARM: SoC support for Tegra platforms for v4.5 2016-01-22 17:30:52 -08:00
spi powerpc updates for 4.5 2016-01-15 13:18:47 -08:00
spmi
ssb
staging Initial roundup of 4.5 merge window patches 2016-01-23 18:45:06 -08:00
target Merge branch 'for-4.5/nvme' of git://git.kernel.dk/linux-block 2016-01-21 19:58:02 -08:00
tc
thermal Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux 2016-01-24 12:43:06 -08:00
thunderbolt
tty ARM: SoC driver updates for v4.5 2016-01-20 18:42:30 -08:00
uio
usb Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2016-01-23 12:24:56 -08:00
uwb
vfio
vhost
video wrappers for ->i_mutex access 2016-01-22 18:04:28 -05:00
virt
virtio virtio: make find_vqs() checkpatch.pl-friendly 2016-01-12 20:47:06 +02:00
vlynq
vme
w1
watchdog watchdog: asm9260: remove __init and __exit annotations 2016-01-11 22:48:05 +01:00
xen virtio: barrier rework+fixes 2016-01-18 16:44:24 -08:00
zorro
Kconfig
Makefile