From: Jonathan Cameron <jic23@kernel.org>
To: Sasha Levin <sashal@kernel.org>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Teng Qi <starmiku1207184332@gmail.com>,
TOTE Robot <oslab@tsinghua.edu.cn>,
Lorenzo Bianconi <lorenzo@kernel.org>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
linux-iio@vger.kernel.org
Subject: Re: [PATCH AUTOSEL 5.15 66/82] iio: imu: st_lsm6dsx: Avoid potential array overflow in st_lsm6dsx_set_odr()
Date: Fri, 12 Nov 2021 17:33:18 +0000 [thread overview]
Message-ID: <20211112173318.4369eacb@jic23-huawei> (raw)
In-Reply-To: <20211109221641.1233217-66-sashal@kernel.org>
On Tue, 9 Nov 2021 17:16:24 -0500
Sasha Levin <sashal@kernel.org> wrote:
> From: Teng Qi <starmiku1207184332@gmail.com>
>
> [ 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>
This is really just noise for stable. There wasn't a bug here though
the change is doing some hardening and improving local readability by
saving anyone having to confirm it can't occur by looking at the enum
values.
I don't mind it going into stable though if others feel it's worthwhile.
Jonathan
> ---
> 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 db45f1fc0b817..8dbf744c5651f 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) {
prev parent reply other threads:[~2021-11-12 17:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20211109221641.1233217-1-sashal@kernel.org>
2021-11-09 22:16 ` [PATCH AUTOSEL 5.15 66/82] iio: imu: st_lsm6dsx: Avoid potential array overflow in st_lsm6dsx_set_odr() Sasha Levin
2021-11-12 17:33 ` Jonathan Cameron [this message]
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=20211112173318.4369eacb@jic23-huawei \
--to=jic23@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=oslab@tsinghua.edu.cn \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox