linux/drivers/iio/imu
Teng Qi 94be878c88 iio: imu: st_lsm6dsx: Avoid potential array overflow in st_lsm6dsx_set_odr()
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>
2021-10-20 14:43:53 +01:00
..
bmi160 iio: Drop Duplicated "mount-matrix" parameter 2021-06-03 18:24:13 +01:00
inv_icm42600 iio: Drop Duplicated "mount-matrix" parameter 2021-06-03 18:24:13 +01:00
inv_mpu6050 iio: imu: inv_mpu6050: Mark acpi match table as maybe unused 2021-10-17 11:05:53 +01:00
st_lsm6dsx iio: imu: st_lsm6dsx: Avoid potential array overflow in st_lsm6dsx_set_odr() 2021-10-20 14:43:53 +01:00
st_lsm9ds0 iio: st_lsm9ds0: Make use of the helper function dev_err_probe() 2021-10-19 08:30:44 +01:00
adis16400.c iio: imu: adis16400: Fix buffer alignment requirements. 2021-10-19 08:29:22 +01:00
adis16460.c iio: adis16460: make use of the new unmasked_drdy flag 2021-10-19 08:27:34 +01:00
adis16475.c First set of IIO new device and feature support for the 5.16 cycle 2021-10-19 11:44:28 +02:00
adis16480.c iio: adis16480: fix devices that do not support sleep mode 2021-09-26 16:22:25 +01:00
adis_buffer.c iio: adis: add burst_max_speed_hz variable 2021-05-17 13:49:09 +01:00
adis_trigger.c iio: adis: handle devices that cannot unmask the drdy pin 2021-10-19 08:27:34 +01:00
adis.c iio: adis: handle devices that cannot unmask the drdy pin 2021-10-19 08:27:34 +01:00
fxos8700_core.c iio: remove explicit IIO device parent assignment 2020-06-14 11:49:59 +01:00
fxos8700_i2c.c iio: imu: fxos8700: Drop unneeded explicit castings 2021-03-25 19:13:50 +00:00
fxos8700_spi.c iio: imu: fxos8700: Drop unneeded explicit castings 2021-03-25 19:13:50 +00:00
fxos8700.h iio: imu: Add support for the FXOS8700 IMU 2019-10-22 10:24:50 +01:00
Kconfig iio: st_sensors: Add lsm9ds0 IMU support 2021-05-17 13:54:22 +01:00
kmx61.c iio: imu: kmx61: Balance runtime pm + use pm_runtime_resume_and_get() 2021-05-17 13:54:26 +01:00
Makefile iio: st_sensors: Add lsm9ds0 IMU support 2021-05-17 13:54:22 +01:00