From: Stephan Gerhold <stephan@gerhold.net>
To: Alexandre Bard <alexandre.bard@netmodule.com>
Cc: lorenzo.bianconi83@gmail.com, linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: imu: st_lsm6dsx: Fix reading array out of bounds
Date: Thu, 9 Apr 2020 13:01:52 +0200 [thread overview]
Message-ID: <20200409110128.GA53758@gerhold.net> (raw)
In-Reply-To: <20200409085818.9533-1-alexandre.bard@netmodule.com>
On Thu, Apr 09, 2020 at 10:58:18AM +0200, Alexandre Bard wrote:
> Former code was iterating through all possible IDs whereas only a few
> per settings array are really available. Leading to several out of
> bounds readings.
>
> Line is now longer than 80 characters. But since it is a classic for
> loop I think it is better to keep it like this than splitting it.
>
> Signed-off-by: Alexandre Bard <alexandre.bard@netmodule.com>
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 84d219ae6aee..be8882ff30eb 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -1350,7 +1350,7 @@ static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id,
> int err, i, j, data;
>
> for (i = 0; i < ARRAY_SIZE(st_lsm6dsx_sensor_settings); i++) {
> - for (j = 0; j < ST_LSM6DSX_MAX_ID; j++) {
> + for (j = 0; j < ARRAY_SIZE(st_lsm6dsx_sensor_settings[i].id); j++) {
id in st_lsm6dsx_settings is declared as:
struct {
enum st_lsm6dsx_hw_id hw_id;
const char *name;
} id[ST_LSM6DSX_MAX_ID];
so it's always ST_LSM6DSX_MAX_ID long
(additional entries are just zero-initialized).
Isn't ARRAY_SIZE(st_lsm6dsx_sensor_settings[i].id) == ST_LSM6DSX_MAX_ID
in this case?
> if (st_lsm6dsx_sensor_settings[i].id[j].name &&
> id == st_lsm6dsx_sensor_settings[i].id[j].hw_id)
> break;
> --
> 2.20.1
>
next prev parent reply other threads:[~2020-04-09 11:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-09 8:58 [PATCH] iio: imu: st_lsm6dsx: Fix reading array out of bounds Alexandre Bard
2020-04-09 9:17 ` Andy Shevchenko
2020-04-09 11:01 ` Stephan Gerhold [this message]
2020-04-09 11:50 ` Alexandre Bard
2020-04-09 11:58 ` Lorenzo Bianconi
2020-04-09 12:09 ` Stephan Gerhold
2020-04-09 12:14 ` Alexandre Bard
2020-04-09 16:44 ` Martin Kepplinger
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=20200409110128.GA53758@gerhold.net \
--to=stephan@gerhold.net \
--cc=alexandre.bard@netmodule.com \
--cc=linux-iio@vger.kernel.org \
--cc=lorenzo.bianconi83@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