All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Teng Qi <starmiku1207184332@gmail.com>
Cc: lorenzo.bianconi83@gmail.com, jic23@kernel.org, lars@metafoo.de,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	islituo@gmail.com, baijiaju1990@gmail.com,
	TOTE Robot <oslab@tsinghua.edu.cn>
Subject: Re: [PATCH v2] iio: imu: st_lsm6dsx: Fix an array overflow in st_lsm6dsx_set_odr()
Date: Mon, 11 Oct 2021 14:22:19 +0200	[thread overview]
Message-ID: <YWQse08lZHMBe+LX@lore-desk> (raw)
In-Reply-To: <20211011114003.976221-1-starmiku1207184332@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1932 bytes --]

> 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 catched 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 fix this array overflow, handle ST_LSM6DSX_ID_GYRO explicitly and 
> return -EINVAL for the default case.
> 
> Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
> Signed-off-by: Teng Qi <starmiku1207184332@gmail.com>

Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
> 
> ---
> v2:
> * explicitly handle ST_LSM6DSX_ID_GYRO and return -EINVAL for the default
> case instead of adding an if statement behind the switch statement.
>   Thank Lars-Peter Clausen for helpful and friendly advice.
> 
> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index db45f1fc0b81..8dbf744c5651 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -1279,6 +1279,8 @@ st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u32 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:
> @@ -1304,8 +1306,8 @@ st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u32 req_odr)
>  		}
>  		break;
>  	}
> -	default:
> -		break;
> +	default: /* should never occur */
> +		return -EINVAL;
>  	}
>  
>  	if (req_odr > 0) {
> -- 
> 2.25.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2021-10-11 12:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-11 11:40 [PATCH v2] iio: imu: st_lsm6dsx: Fix an array overflow in st_lsm6dsx_set_odr() Teng Qi
2021-10-11 12:22 ` Lorenzo Bianconi [this message]
2021-10-17 13:28   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YWQse08lZHMBe+LX@lore-desk \
    --to=lorenzo@kernel.org \
    --cc=baijiaju1990@gmail.com \
    --cc=islituo@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.bianconi83@gmail.com \
    --cc=oslab@tsinghua.edu.cn \
    --cc=starmiku1207184332@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.