linux/drivers/iio
Lars-Peter Clausen f027e0b3a7 iio: adis_lib: Initialize trigger before requesting interrupt
The adis_probe_trigger() creates a new IIO trigger and requests an
interrupt associated with the trigger. The interrupt uses the generic
iio_trigger_generic_data_rdy_poll() function as its interrupt handler.

Currently the driver initializes some fields of the trigger structure after
the interrupt has been requested. But an interrupt can fire as soon as it
has been requested. This opens up a race condition.

iio_trigger_generic_data_rdy_poll() will access the trigger data structure
and dereference the ops field. If the ops field is not yet initialized this
will result in a NULL pointer deref.

It is not expected that the device generates an interrupt at this point, so
typically this issue did not surface unless e.g. due to a hardware
misconfiguration (wrong interrupt number, wrong polarity, etc.).

But some newer devices from the ADIS family start to generate periodic
interrupts in their power-on reset configuration and unfortunately the
interrupt can not be masked in the device.  This makes the race condition
much more visible and the following crash has been observed occasionally
when booting a system using the ADIS16460.

	Unable to handle kernel NULL pointer dereference at virtual address 00000008
	pgd = c0004000
	[00000008] *pgd=00000000
	Internal error: Oops: 5 [#1] PREEMPT SMP ARM
	Modules linked in:
	CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.9.0-04126-gf9739f0-dirty #257
	Hardware name: Xilinx Zynq Platform
	task: ef04f640 task.stack: ef050000
	PC is at iio_trigger_notify_done+0x30/0x68
	LR is at iio_trigger_generic_data_rdy_poll+0x18/0x20
	pc : [<c042d868>]    lr : [<c042d924>]    psr: 60000193
	sp : ef051bb8  ip : 00000000  fp : ef106400
	r10: c081d80a  r9 : ef3bfa00  r8 : 00000087
	r7 : ef051bec  r6 : 00000000  r5 : ef3bfa00  r4 : ee92ab00
	r3 : 00000000  r2 : 00000000  r1 : 00000000  r0 : ee97e400
	Flags: nZCv  IRQs off  FIQs on  Mode SVC_32  ISA ARM  Segment none
	Control: 18c5387d  Table: 0000404a  DAC: 00000051
	Process swapper/0 (pid: 1, stack limit = 0xef050210)
	[<c042d868>] (iio_trigger_notify_done) from [<c0065b10>] (__handle_irq_event_percpu+0x88/0x118)
	[<c0065b10>] (__handle_irq_event_percpu) from [<c0065bbc>] (handle_irq_event_percpu+0x1c/0x58)
	[<c0065bbc>] (handle_irq_event_percpu) from [<c0065c30>] (handle_irq_event+0x38/0x5c)
	[<c0065c30>] (handle_irq_event) from [<c0068e28>] (handle_level_irq+0xa4/0x130)
	[<c0068e28>] (handle_level_irq) from [<c0064e74>] (generic_handle_irq+0x24/0x34)
	[<c0064e74>] (generic_handle_irq) from [<c021ab7c>] (zynq_gpio_irqhandler+0xb8/0x13c)
	[<c021ab7c>] (zynq_gpio_irqhandler) from [<c0064e74>] (generic_handle_irq+0x24/0x34)
	[<c0064e74>] (generic_handle_irq) from [<c0065370>] (__handle_domain_irq+0x5c/0xb4)
	[<c0065370>] (__handle_domain_irq) from [<c000940c>] (gic_handle_irq+0x48/0x8c)
	[<c000940c>] (gic_handle_irq) from [<c0013e8c>] (__irq_svc+0x6c/0xa8)

To fix this make sure that the trigger is fully initialized before
requesting the interrupt.

Fixes: ccd2b52f4a ("staging:iio: Add common ADIS library")
Reported-by: Robin Getz <Robin.Getz@analog.com>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-02-17 14:16:35 +00:00
..
accel iio: mma8452: replace license description with SPDX specifier 2018-01-08 16:03:41 +01:00
adc iio: adc: stm32: fix stm32h7_adc_enable error handling 2018-01-28 08:18:49 +00:00
amplifiers iio:amplifiers:ad8366 drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:24:50 +01:00
buffer License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
chemical iio: chemical: ccs811: Fix output of IIO_CONCENTRATION channels 2018-01-08 16:03:44 +01:00
common iio: common: ssp_sensors: account for const type of of_device_id.data 2018-01-08 16:03:43 +01:00
counter iio: stm32: Adopt SPDX identifier 2018-01-08 16:03:41 +01:00
dac iio: dac: mcp4725: Remove unneeded conversions to bool 2018-01-08 16:03:41 +01:00
dummy iio: dummy_evgen: modify the return value check for irq_sim_init() 2018-01-08 16:03:41 +01:00
frequency iio:frequency: drop assign iio_info.driver_module 2017-08-22 21:28:20 +01:00
gyro gyro:adis16136: fix debugfs_simple_attr.cocci warnings 2018-01-08 16:03:44 +01:00
health Merge Linus's staging merge point into staging-next 2017-12-06 15:27:17 +01:00
humidity iio: humidity: hts221: move common code in hts221_core 2018-01-08 16:03:43 +01:00
imu iio: adis_lib: Initialize trigger before requesting interrupt 2018-02-17 14:16:35 +00:00
light iio: light: make a couple of config structures static 2018-01-08 16:03:41 +01:00
magnetometer iio: magnetometer: ak8975: Add another ACPI ID 2017-12-02 10:40:02 +00:00
multiplexer iio: multiplexer: add NULL check on devm_kzalloc() and devm_kmemdup() return values 2017-09-03 18:10:29 +01:00
orientation iio:orientation: drop assign iio_info.driver_module 2017-08-22 21:33:36 +01:00
potentiometer Staging/IIO patches for 4.15-rc1 2017-11-13 20:53:28 -08:00
potentiostat iio:potentiostat:lmp91000 drop assign iio_info.driver_module and iio_trigger_ops.owner 2017-08-22 21:34:48 +01:00
pressure iio:pressure:bmp280: Read calibration data in probe 2018-01-08 16:03:43 +01:00
proximity iio: srf08: fix link error "devm_iio_triggered_buffer_setup" undefined 2018-02-04 11:13:00 +00:00
temperature Staging/IIO patches for 4.15-rc1 2017-11-13 20:53:28 -08:00
trigger iio: stm32: Adopt SPDX identifier 2018-01-08 16:03:41 +01:00
iio_core.h
iio_core_trigger.h
industrialio-buffer.c iio: buffer: Expose data available 2018-01-08 16:03:41 +01:00
industrialio-configfs.c iio: make function argument and some structures const 2017-10-19 16:15:24 +02:00
industrialio-core.c Merge Linus's staging merge point into staging-next 2017-12-06 15:27:17 +01:00
industrialio-event.c
industrialio-sw-device.c iio: make function argument and some structures const 2017-10-19 16:15:24 +02:00
industrialio-sw-trigger.c iio: make function argument and some structures const 2017-10-19 16:15:24 +02:00
industrialio-trigger.c iio:trigger: Remove necessity to have a trig->ops structure. 2017-08-22 21:20:28 +01:00
industrialio-triggered-event.c
inkern.c First round of IIO new device support, features and cleanups for the 4.14 cycle. 2017-07-27 21:29:49 -07:00
Kconfig iio: multiplexer: new iio category and iio-mux driver 2017-06-03 19:29:26 +09:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00