android_kernel_samsung_msm8976/drivers/iio
Martin Kelly fbc53c3874 iio:kfifo_buf: check for uint overflow
commit 3d13de4b027d5f6276c0f9d3a264f518747d83f2 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>
2019-07-27 21:52:28 +02:00
..
accel
adc iio:ad7793: Fix ad7785 product ID 2016-02-25 11:57:48 -08:00
amplifiers
common
dac iio: dac: mcp4725: set iio name property in sysfs 2016-02-25 11:57:48 -08:00
frequency
grip Import latest Samsung release 2017-04-18 03:43:52 +02:00
gyro Import latest Samsung release 2017-04-18 03:43:52 +02:00
imu iio: adis_lib: Initialize trigger before requesting interrupt 2019-07-27 21:46:10 +02:00
inv_test Import latest Samsung release 2017-04-18 03:43:52 +02:00
light Import latest Samsung release 2017-04-18 03:43:52 +02:00
magnetometer Import latest Samsung release 2017-04-18 03:43:52 +02:00
Kconfig Import latest Samsung release 2017-04-18 03:43:52 +02:00
Makefile Import latest Samsung release 2017-04-18 03:43:52 +02:00
buffer_cb.c
iio_core.h
iio_core_trigger.h
industrialio-buffer.c
industrialio-core.c Import latest Samsung release 2017-04-18 03:43:52 +02:00
industrialio-event.c
industrialio-trigger.c iio: Fix error handling in iio_trigger_attach_poll_func 2019-07-27 21:41:56 +02:00
industrialio-triggered-buffer.c
inkern.c
kfifo_buf.c iio:kfifo_buf: check for uint overflow 2019-07-27 21:52:28 +02:00