OpenCloudOS-Kernel/drivers/iio/imu/st_lsm6dsx
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
..
Kconfig iio: imu: st_lsm6dsx: add support to LSM6DSOP 2020-12-03 19:40:24 +00:00
Makefile
st_lsm6dsx.h iio: imu: st_lsm6dsx: move max_fifo_size in st_lsm6dsx_fifo_ops 2021-10-19 08:27:34 +01:00
st_lsm6dsx_buffer.c iio: make use of devm_iio_kfifo_buffer_setup() helper 2021-03-11 20:47:01 +00:00
st_lsm6dsx_core.c iio: imu: st_lsm6dsx: Avoid potential array overflow in st_lsm6dsx_set_odr() 2021-10-20 14:43:53 +01:00
st_lsm6dsx_i2c.c iio: imu: st_lsm6dsx: Drop unneeded explicit castings 2021-03-25 19:13:50 +00:00
st_lsm6dsx_i3c.c iio: imu: st_lsm6dsx: Drop unneeded explicit castings 2021-03-25 19:13:50 +00:00
st_lsm6dsx_shub.c iio: imu: st_lsm6dsx: set 10ms as min shub slave timeout 2020-11-01 20:54:15 +00:00
st_lsm6dsx_spi.c iio: imu: st_lsm6dsx: Drop unneeded explicit castings 2021-03-25 19:13:50 +00:00