Patch "iio: imu: st_lsm6dsx: Avoid potential array overflow in st_lsm6dsx_set_odr()" has been added to the 5.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    iio: imu: st_lsm6dsx: Avoid potential array overflow in st_lsm6dsx_set_odr()

to the 5.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     iio-imu-st_lsm6dsx-avoid-potential-array-overflow-in.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit ea411f5cd8eeda9165f2489647b11987af62db8e
Author: Teng Qi <starmiku1207184332@xxxxxxxxx>
Date:   Mon Oct 11 19:40:03 2021 +0800

    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@xxxxxxxxxxxxxxx>
    Signed-off-by: Teng Qi <starmiku1207184332@xxxxxxxxx>
    Acked-by: Lorenzo Bianconi <lorenzo@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20211011114003.976221-1-starmiku1207184332@xxxxxxxxx
    Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 057a4b0100106..8850da8e25d69 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1015,6 +1015,8 @@ static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 req_odr)
 	int err;
 
 	switch (sensor->id) {
+	case ST_LSM6DSX_ID_GYRO:
+		break;
 	case ST_LSM6DSX_ID_EXT0:
 	case ST_LSM6DSX_ID_EXT1:
 	case ST_LSM6DSX_ID_EXT2:
@@ -1040,8 +1042,8 @@ static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 req_odr)
 		}
 		break;
 	}
-	default:
-		break;
+	default: /* should never occur */
+		return -EINVAL;
 	}
 
 	if (req_odr > 0) {



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux