From: Raffaele Tranfaglia via B4 Relay <devnull+raffaele.tranfaglia.gmail.com@kernel.org>
To: "Nuno Sá" <nuno.sa@analog.com>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Andy Shevchenko" <andy@kernel.org>
Cc: linux@analog.com, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org,
Raffaele Tranfaglia <raffaele.tranfaglia@gmail.com>
Subject: [PATCH] iio: light: adux1020: harden sampling frequency table lookup
Date: Wed, 04 Nov 2026 10:28:22 +0000 [thread overview]
Message-ID: <20261104-adux1020-rate-bounds-v1-1-2db71ad2cc21@gmail.com> (raw)
From: Raffaele Tranfaglia <raffaele.tranfaglia@gmail.com>
The proximity frequency field read from the FREQUENCY register is four
bits wide, so it can hold values from 0 to 15, but adux1020_rates[] only
has 14 entries. The driver never programs values 14 or 15, but if a
misbehaving device reports one of them, reading the sampling frequency
indexes past the end of the table and returns garbage.
Reject such values with -EINVAL instead of indexing past the end of
the table.
Signed-off-by: Raffaele Tranfaglia <raffaele.tranfaglia@gmail.com>
---
Found with LLM-assisted static analysis of drivers/iio, looking for
table lookups indexed by unchecked register fields; the fix was drafted
with the same assistant and reviewed and tested by me.
Tested on arm64 QEMU with i2c-stub and CONFIG_UBSAN_BOUNDS=y. After
setting the frequency field in FREQUENCY (0x40) to 14, reading
in_proximity_sampling_frequency:
- before: two array-index-out-of-bounds reports, and the attribute
reads 0.025000
- after: the read fails with -EINVAL and no report is printed
---
drivers/iio/light/adux1020.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/iio/light/adux1020.c b/drivers/iio/light/adux1020.c
index 0ea282ecc99a..d4281b9754c3 100644
--- a/drivers/iio/light/adux1020.c
+++ b/drivers/iio/light/adux1020.c
@@ -414,6 +414,10 @@ static int adux1020_read_raw(struct iio_dev *indio_dev,
goto fail;
regval = FIELD_GET(ADUX1020_PROX_FREQ_MASK, regval);
+ if (regval >= ARRAY_SIZE(adux1020_rates)) {
+ ret = -EINVAL;
+ goto fail;
+ }
*val = adux1020_rates[regval][0];
*val2 = adux1020_rates[regval][1];
---
base-commit: 20ce8ef9c9e04cd6c5ae0422e251a9b5936c6b7c
change-id: 20261104-adux1020-rate-bounds-61e3ff96e0f3
Best regards,
--
Raffaele Tranfaglia <raffaele.tranfaglia@gmail.com>
next reply other threads:[~2026-11-04 10:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 10:28 Raffaele Tranfaglia via B4 Relay [this message]
2026-11-07 22:29 ` 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=20261104-adux1020-rate-bounds-v1-1-2db71ad2cc21@gmail.com \
--to=devnull+raffaele.tranfaglia.gmail.com@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@analog.com \
--cc=nuno.sa@analog.com \
--cc=raffaele.tranfaglia@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
all inboxes | Powered by JetHome®