From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Arnav Kapoor <kapoorarnav43@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
stable@vger.kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] iio: proximity: sx9324: fix out-of-bounds read of scan period table
Date: Sat, 24 Oct 2026 13:44:24 +0300 [thread overview]
Message-ID: <atyMCCJsBDPdgl2Q@ashevche-desk.local> (raw)
In-Reply-To: <20261023192700.221344-1-kapoorarnav43@gmail.com>
On Sat, Oct 24, 2026 at 12:56:51AM +0530, Arnav Kapoor wrote:
> The scan period of the SX9324 is selected by the 5 bit wide
> SX9324_REG_GNRL_CTRL0_SCANPERIOD field, so it has 32 possible values.
> sx9324_scan_period_table[] however only has 16 entries, it was copied
> over from the SX9310 driver where the field is only 4 bits wide.
>
> sx9324_wait_for_sample() indexes the table with the raw field value, so
> all the codes from 16 to 31 read past the end of the array. The default
> value of the register is SX9324_REG_GNRL_CTRL0_SCANPERIOD_100MS (0x16,
> i.e. 22), so the out-of-bounds read happens with the default
> configuration of the device. It is only avoided when the device has an
> interrupt line, as the wait is only done in the polling case.
>
> The value read is then used as the duration of an msleep() call, so the
> sensor is polled with a completely random delay.
>
> Fill the table with the scan periods of all 32 codes, which are the
> periods documented for the corresponding sx9324_samp_freq_table[]
> entries, and add a static assertion to keep both tables in sync.
...
> +/*
> + * The scan period of the SX9324 is selected by the 5 bit wide
5-bit
> + * SX9324_REG_GNRL_CTRL0_SCANPERIOD field. The values below are the scan
> + * periods in ms of the corresponding sx9324_samp_freq_table[] entries.
> + */
> static const unsigned int sx9324_scan_period_table[] = {
> - 2, 15, 30, 45, 60, 90, 120, 200,
> - 400, 600, 800, 1000, 2000, 3000, 4000, 5000,
> + 1, 2, 4, 6, 8, 10, 14, 18, /* 0x00 - 0x07 */
> + 22, 26, 30, 34, 38, 42, 46, 50, /* 0x08 - 0x0f */
> + 56, 62, 68, 74, 80, 90, 100, 200, /* 0x10 - 0x17 */
> + 300, 400, 600, 800, 1000, 2000, 3000, 4000, /* 0x18 - 0x1f */
> };
Haven't checked if this is part of any ABI. Otherwise LGTM,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-10-24 10:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 19:26 Arnav Kapoor
2026-10-24 1:57 ` Jonathan Cameron
2026-10-24 10:44 ` Andy Shevchenko [this message]
2026-10-25 23:47 ` 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=atyMCCJsBDPdgl2Q@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=kapoorarnav43@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®