linux-stable/drivers/iio
Mathias Krause b7f54894aa iio: buffer: Fix file related error handling in IIO_BUFFER_GET_FD_IOCTL
commit c72ea20503 upstream.

If we fail to copy the just created file descriptor to userland, we
try to clean up by putting back 'fd' and freeing 'ib'. The code uses
put_unused_fd() for the former which is wrong, as the file descriptor
was already published by fd_install() which gets called internally by
anon_inode_getfd().

This makes the error handling code leaving a half cleaned up file
descriptor table around and a partially destructed 'file' object,
allowing userland to play use-after-free tricks on us, by abusing
the still usable fd and making the code operate on a dangling
'file->private_data' pointer.

Instead of leaving the kernel in a partially corrupted state, don't
attempt to explicitly clean up and leave this to the process exit
path that'll release any still valid fds, including the one created
by the previous call to anon_inode_getfd(). Simply return -EFAULT to
indicate the error.

Fixes: f73f7f4da5 ("iio: buffer: add ioctl() to support opening extra buffers for IIO device")
Cc: stable@kernel.org
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Alexandru Ardelean <ardeleanalex@gmail.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Nuno Sa <Nuno.Sa@analog.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Mathias Krause <minipli@grsecurity.net>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-02-16 12:56:37 +01:00
..
accel iio: accel: kxcjk-1013: Fix possible memory leak in probe and remove 2021-12-14 10:57:21 +01:00
adc iio: adc: ti-adc081c: Partial revert of removal of ACPI IDs 2022-01-27 11:02:57 +01:00
afe iio: afe: iio-rescale: Support processed channels 2021-06-03 18:24:13 +01:00
amplifiers iio: amplifiers: hmc425a: Simplify with dev_err_probe() 2020-09-03 19:40:50 +01:00
buffer iio: core: move @id from struct iio_dev to struct iio_dev_opaque 2021-05-17 13:49:13 +01:00
cdc iio:cdc:ad7150: Fix use of uninitialized ret 2021-04-07 08:36:39 +01:00
chemical iio: chemical: Add driver support for sgp40 2021-08-08 15:19:18 +01:00
common iio: ssp_sensors: add more range checking in ssp_parse_dataframe() 2021-09-18 19:10:55 +01:00
dac iio: ad5770r: make devicetree property reading consistent 2021-11-18 19:16:07 +01:00
dummy iio: dummy: Fix build error when CONFIG_IIO_TRIGGERED_BUFFER is not set 2021-06-13 17:00:17 +01:00
frequency iio: frequency: adf4350: disable reg and clk on error in adf4350_probe() 2021-06-13 17:00:17 +01:00
gyro iio: itg3200: Call iio_trigger_notify_done() on error 2021-12-14 10:57:21 +01:00
health iio: core: move @id from struct iio_dev to struct iio_dev_opaque 2021-05-17 13:49:13 +01:00
humidity iio: humidity: hdc100x: Add margin to the conversion time 2021-07-24 18:13:02 +01:00
imu iio: imu: st_lsm6dsx: Avoid potential array overflow in st_lsm6dsx_set_odr() 2021-11-25 09:48:29 +01:00
light iio: ltr501: Don't return error code in trigger handler 2021-12-14 10:57:21 +01:00
magnetometer iio: st_sensors: disable regulators after device unregistration 2021-11-18 19:16:46 +01:00
multiplexer iio: multiplexer: iio-mux: Simplify with dev_err_probe() 2020-09-03 19:40:51 +01:00
orientation iio: hid-sensors: bind IIO channels alloc to device object 2021-07-13 18:21:53 +01:00
position iio: hid-sensors: Update header includes 2021-06-16 14:53:13 +01:00
potentiometer iio: potentiometer: Add driver support for AD5110 2021-08-15 15:38:16 +01:00
potentiostat iio: potentiostat: lmp91000: Fix alignment of buffer in iio_push_to_buffers_with_timestamp() 2021-05-17 13:54:30 +01:00
pressure iio: st_pressure_spi: Add missing entries SPI to device ID table 2021-11-18 19:16:50 +01:00
proximity iio: sx9310: Support ACPI property 2021-07-31 15:15:28 +01:00
resolver iio:resolver:ad2s1200: Drop of_match_ptr protection 2020-09-21 18:41:31 +01:00
temperature iio: ltc2983: fix device probe 2021-08-15 16:58:37 +01:00
test iio/test-format: build kunit tests without structleak plugin 2021-10-06 17:53:36 -06:00
trigger iio: trigger: stm32-timer: fix MODULE_ALIAS 2021-12-14 10:57:20 +01:00
iio_core.h iio: buffer: fix use-after-free for attached_buffers array 2021-03-25 19:13:51 +00:00
iio_core_trigger.h iio: core-trigger: make iio_device_register_trigger_consumer() an int return 2021-03-11 20:47:02 +00:00
industrialio-buffer.c iio: buffer: Fix file related error handling in IIO_BUFFER_GET_FD_IOCTL 2022-02-16 12:56:37 +01:00
industrialio-configfs.c
industrialio-core.c iio: core: check return value when calling dev_set_name() 2021-11-18 19:16:02 +01:00
industrialio-event.c iio:event: Add timeout event info type 2021-04-07 08:36:36 +01:00
industrialio-sw-device.c
industrialio-sw-trigger.c
industrialio-trigger.c iio: trigger: Fix a scheduling whilst atomic issue seen on tsc2046 2022-01-27 11:02:57 +01:00
industrialio-triggered-event.c iio: core: move @id from struct iio_dev to struct iio_dev_opaque 2021-05-17 13:49:13 +01:00
inkern.c iio: core: move @info_exist_lock to struct iio_dev_opaque 2021-05-17 13:49:13 +01:00
Kconfig iio:cdc:ad7150: Move driver out of staging. 2021-04-07 08:36:37 +01:00
Makefile iio:cdc:ad7150: Move driver out of staging. 2021-04-07 08:36:37 +01:00
TODO