linux/drivers/iio
Lars-Peter Clausen e407fd655b iio: Fix potential use after free
There is no guarantee that the last reference to the iio device has already been
dropped when iio_device_free is called. This means that we can up calling
iio_dev_release after iio_device_free which will lead to a use after free. As
the general rule the struct containing the device should always be freed in the
release callback.

This is what this patch does, it moves freeing the iio device struct as well as
releasing the idr reference to the release callback. To ensure that the device
is not freed before calling iio_device_free the device_unregister call in
iio_device_unregister is broken apart. iio_device_unregister will now only call
device_del to remove the device from the system and iio_device_free will call
put_device to drop the reference we obtained in iio_devce_alloc.

We also have to take care that calling iio_device_free without having called
iio_device_register still works (i.e. this can happen if something failed during
device initialization). For this to work properly two minor changes were
necessary: channel_attr_list needs to be initialized in iio_device_alloc and we
have to check whether the chrdev has been registered before releasing it in
iio_device_release.

This change also brings iio_device_unregister and iio_device_free more in sync
with iio_device_register and iio_device_alloc which call device_add and
device_initialize respectively.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-06-04 21:15:31 -07:00
..
adc IIO: AT91: Add DT support to at91_adc driver 2012-05-14 13:25:33 -07:00
amplifiers iio: amplifiers: New driver for AD8366 Dual-Digital Variable Gain Amplifier 2012-05-14 13:15:39 -07:00
iio_core_trigger.h IIO: Move the core files to drivers/iio 2012-04-25 11:11:38 -07:00
iio_core.h IIO: Move the core files to drivers/iio 2012-04-25 11:11:38 -07:00
industrialio-buffer.c iio: Use dev_to_iio_dev() 2012-05-14 13:37:45 -07:00
industrialio-core.c iio: Fix potential use after free 2012-06-04 21:15:31 -07:00
industrialio-event.c iio: Use dev_to_iio_dev() 2012-05-14 13:37:45 -07:00
industrialio-trigger.c iio: Use dev_to_iio_dev() 2012-05-14 13:37:45 -07:00
inkern.c Merge 3.4-rc5 into staging-next 2012-05-02 11:48:07 -07:00
Kconfig ARM: AT91: IIO: Add AT91 ADC driver. 2012-05-14 13:24:09 -07:00
kfifo_buf.c IIO: Move the core files to drivers/iio 2012-04-25 11:11:38 -07:00
Makefile ARM: AT91: IIO: Add AT91 ADC driver. 2012-05-14 13:24:09 -07:00