linux/drivers/iio
Martin Kelly f5a5651517 iio:kfifo_buf: check for uint overflow
commit 3d13de4b02 upstream.

Currently, the following causes a kernel OOPS in memcpy:

echo 1073741825 > buffer/length
echo 1 > buffer/enable

Note that using 1073741824 instead of 1073741825 causes "write error:
Cannot allocate memory" but no OOPS.

This is because 1073741824 == 2^30 and 1073741825 == 2^30+1. Since kfifo
rounds up to the nearest power of 2, it will actually call kmalloc with
roundup_pow_of_two(length) * bytes_per_datum.

Using length == 1073741825 and bytes_per_datum == 2, we get:

kmalloc(roundup_pow_of_two(1073741825) * 2
or kmalloc(2147483648 * 2)
or kmalloc(4294967296)
or kmalloc(UINT_MAX + 1)

so this overflows to 0, causing kmalloc to return ZERO_SIZE_PTR and
subsequent memcpy to fail once the device is enabled.

Fix this by checking for overflow prior to allocating a kfifo. With this
check added, the above code returns -EINVAL when enabling the buffer,
rather than causing an OOPS.

Signed-off-by: Martin Kelly <mkelly@xevo.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
[bwh: Backported to 3.16: adjust filename]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
History 2018-10-21 08:45:05 +01:00
..
accel iio: accel: st_accel: fix data-ready line configuration 2017-11-26 13:50:19 +00:00
adc iio: ad7793: Fix the serial interface reset 2018-01-01 20:51:38 +00:00
amplifiers iio: amplifiers: ad8366: Remove regulator_put 2013-09-28 11:49:45 +01:00
common iio: hid-sensor-attributes: Fix sensor property setting failure. 2017-07-18 18:40:29 +01:00
dac iio: dac: ad7303: fix channel description 2017-08-26 02:14:32 +01:00
frequency Merge 3.12-rc6 into staging-next. 2013-10-19 13:14:34 -07:00
gyro iio:st_sensors: Fix oops when probing SPI devices 2015-05-28 09:59:58 +01:00
humidity iio: dht11: Use usleep_range instead of msleep for start signal 2017-03-16 02:27:04 +00:00
imu iio: adis_lib: Initialize trigger before requesting interrupt 2018-06-16 22:22:19 +01:00
light iio: light: tsl2563: use correct event code 2017-11-11 13:32:52 +00:00
magnetometer iio: magnetometer: st_magn_core: enable multiread by default for LIS3MDL 2017-11-26 13:50:13 +00:00
orientation iio: hid-sensors: Inclinometer 3D: Raw read support 2014-05-05 10:59:52 +01:00
pressure iio: pressure: st_pressure: fix drdy configuration for LPS22HB and LPS25H 2017-11-26 13:50:19 +00:00
proximity iio: proximity: as3935: fix iio_trigger_poll issue 2017-09-15 18:29:33 +01:00
temperature iio: tmp006: Check channel info on write 2015-08-10 09:54:08 +01:00
trigger iio:trigger: fix sysfs name on list mutex 2013-09-28 11:51:16 +01:00
buffer_cb.c iio get rid of unneccessary error_ret 2014-02-18 08:46:36 +00:00
iio_core.h IIO: core: Introduce read_raw_multi 2014-04-29 22:05:32 +01:00
iio_core_trigger.h iio: fix semicolon in io_core_trigger.h 2013-08-03 18:40:32 +01:00
industrialio-buffer.c iio: buffer: check if a buffer has been set up when poll is called 2018-06-16 22:22:19 +01:00
industrialio-core.c iio: core: Return error for failed read_reg 2018-01-01 20:51:38 +00:00
industrialio-event.c iio: event: Remove negative error code from iio_event_poll 2015-09-28 10:21:38 +01:00
industrialio-trigger.c iio: Fix error handling in iio_trigger_attach_poll_func 2016-08-22 22:38:13 +01:00
industrialio-triggered-buffer.c iio:triggered-buffer: Remove redundant call to iio_sw_buffer_preenable(). 2013-10-16 19:12:47 +01:00
inkern.c iio: inkern: fix a NULL dereference on error 2016-02-25 00:18:38 +00:00
Kconfig iio: always select ANON_INODES 2014-05-10 11:39:57 +01:00
kfifo_buf.c iio:kfifo_buf: check for uint overflow 2018-10-21 08:45:05 +01:00
Makefile iio: Add AS3935 lightning sensor support 2014-03-16 18:00:32 +00:00