All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnav Kapoor <kapoorarnav43@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Andy Shevchenko" <andriy.shevchenko@intel.com>,
	"Yasin Lee" <yasin.lee.x@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Arnav Kapoor" <kapoorarnav43@gmail.com>
Subject: [PATCH 2/5] iio: proximity: hx9023s: check the sampling frequency index
Date: Mon, 23 Nov 2026 22:22:48 +0530	[thread overview]
Message-ID: <20261123165255.239490-3-kapoorarnav43@gmail.com> (raw)
In-Reply-To: <20261123165255.239490-1-kapoorarnav43@gmail.com>

hx9023s_get_samp_freq() uses the PRF_CFG register value as an index
into hx9023s_samp_freq_table[], which has 32 entries, without checking
it. The driver only writes valid indexes itself, but the configuration
file loaded by hx9023s_bin_load() writes arbitrary register/value pairs,
so PRF_CFG can hold any 8-bit value. Reading sampling_frequency then
reads past the end of the table and divides KILO by whatever it finds
there, which may be zero.

Return -EINVAL if the index is outside the table.

Fixes: e9ed97be4fcc ("iio: proximity: hx9023s: Added firmware file parsing functionality")
Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com>
---
 drivers/iio/proximity/hx9023s.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/iio/proximity/hx9023s.c b/drivers/iio/proximity/hx9023s.c
index eaf962c29256..364ad2fd6095 100644
--- a/drivers/iio/proximity/hx9023s.c
+++ b/drivers/iio/proximity/hx9023s.c
@@ -681,6 +681,9 @@ static int hx9023s_get_samp_freq(struct hx9023s_data *data, int *val, int *val2)
 	if (ret)
 		return ret;
 
+	if (index >= ARRAY_SIZE(hx9023s_samp_freq_table))
+		return -EINVAL;
+
 	odr = hx9023s_samp_freq_table[index];
 	*val = KILO / odr;
 	*val2 = div_u64((KILO % odr) * MICRO, odr);
-- 
2.53.0


  parent reply	other threads:[~2026-11-23 16:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 16:52 [PATCH 0/5] iio: proximity: hx9023s: fix sampling frequency, resume and event value handling Arnav Kapoor
2026-11-23 16:52 ` [PATCH 1/5] iio: proximity: hx9023s: fix division by zero in set_samp_freq Arnav Kapoor
2026-11-23 19:14   ` Andy Shevchenko
2026-11-23 16:52 ` Arnav Kapoor [this message]
2026-11-23 19:15   ` [PATCH 2/5] iio: proximity: hx9023s: check the sampling frequency index Andy Shevchenko
2026-11-23 16:52 ` [PATCH 3/5] iio: proximity: hx9023s: re-enable interrupts on resume for events Arnav Kapoor
2026-11-23 16:52 ` [PATCH 4/5] iio: proximity: hx9023s: reject out-of-range threshold values Arnav Kapoor
2026-11-23 19:26   ` Andy Shevchenko
2026-11-23 16:52 ` [PATCH 5/5] iio: proximity: hx9023s: reject out-of-range debounce values Arnav Kapoor

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=20261123165255.239490-3-kapoorarnav43@gmail.com \
    --to=kapoorarnav43@gmail.com \
    --cc=andriy.shevchenko@intel.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=nuno.sa@analog.com \
    --cc=yasin.lee.x@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.