linux/drivers/iio
Teng Qi 3a9eae47a5 iio: imu: st_lsm6dsx: Avoid potential array overflow in st_lsm6dsx_set_odr()
[ Upstream commit 94be878c882d8d784ff44c639bf55f3b029f85af ]

The length of hw->settings->odr_table is 2 and ref_sensor->id is an enum
variable whose value is between 0 and 5.
However, the value ST_LSM6DSX_ID_MAX (i.e. 5) is not caught properly in
 switch (sensor->id) {

If ref_sensor->id is ST_LSM6DSX_ID_MAX, an array overflow will ocurrs in
function st_lsm6dsx_check_odr():
  odr_table = &sensor->hw->settings->odr_table[sensor->id];

and in function st_lsm6dsx_set_odr():
  reg = &hw->settings->odr_table[ref_sensor->id].reg;

To avoid this array overflow, handle ST_LSM6DSX_ID_GYRO explicitly and
return -EINVAL for the default case.

The enum value ST_LSM6DSX_ID_MAX is only present as an easy way to check
the limit and as such is never used, however this is not locally obvious.

Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Teng Qi <starmiku1207184332@gmail.com>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
Link: https://lore.kernel.org/r/20211011114003.976221-1-starmiku1207184332@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-11-26 10:47:16 +01:00
..
accel
adc iio: mtk-auxadc: fix case IIO_CHAN_INFO_PROCESSED 2021-10-20 11:40:15 +02:00
afe
amplifiers
buffer
chemical
common iio: ssp_sensors: fix error code in ssp_print_mcu_debug() 2021-10-20 11:40:15 +02:00
dac iio: dac: ad5446: Fix ad5622_write() return value 2021-11-17 09:48:26 +01:00
dummy
frequency
gyro
health
humidity
imu iio: imu: st_lsm6dsx: Avoid potential array overflow in st_lsm6dsx_set_odr() 2021-11-26 10:47:16 +01:00
light iio: light: opt3001: Fixed timeout error when 0 lux 2021-10-20 11:40:15 +02:00
magnetometer
multiplexer
orientation
potentiometer
potentiostat
pressure
proximity
resolver
temperature
trigger
iio_core_trigger.h
iio_core.h
industrialio-buffer.c
industrialio-configfs.c
industrialio-core.c
industrialio-event.c
industrialio-sw-device.c
industrialio-sw-trigger.c
industrialio-trigger.c
industrialio-triggered-event.c
inkern.c
Kconfig
Makefile