[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251027142732.261607cc@jic23-huawei>
Date: Mon, 27 Oct 2025 14:27:32 +0000
From: Jonathan Cameron <jic23@...nel.org>
To: David Lechner <dlechner@...libre.com>
Cc: Michael Hennerich <Michael.Hennerich@...log.com>, Nuno Sá
<nuno.sa@...log.com>, Andy Shevchenko <andy@...nel.org>, Jonathan Cameron
<Jonathan.Cameron@...wei.com>, linux-iio@...r.kernel.org,
linux-kernel@...r.kernel.org, Dan Carpenter <dan.carpenter@...aro.org>
Subject: Re: [PATCH] iio: adc: ad7124: fix possible OOB array access
On Wed, 22 Oct 2025 10:15:05 -0500
David Lechner <dlechner@...libre.com> wrote:
> Reorder the channel bounds check before using it to index into the
> channels array in ad7124_release_config_slot(). This prevents reading
> past the end of the array.
>
> The value read from invalid memory was not used, so this was mostly
> harmless, but we still should not be reading out of bounds in the first
> place.
>
> Reported-by: Dan Carpenter <dan.carpenter@...aro.org>
> Closes: https://lore.kernel.org/linux-iio/aPi6V-hcaKReSNWK@stanley.mountain/
> Fixes: 9065197e0d41 ("iio: adc: ad7124: change setup reg allocation strategy")
> Signed-off-by: David Lechner <dlechner@...libre.com>
Applied to the togreg branch of iio.git.
thanks,
J
> ---
> drivers/iio/adc/ad7124.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> index 9d58ced7371d0af7004a81153888714e9795d4f4..ed828a82acb71342fb2eae27abfbbd86861cba53 100644
> --- a/drivers/iio/adc/ad7124.c
> +++ b/drivers/iio/adc/ad7124.c
> @@ -586,13 +586,18 @@ static int ad7124_request_config_slot(struct ad7124_state *st, u8 channel)
>
> static void ad7124_release_config_slot(struct ad7124_state *st, u8 channel)
> {
> - unsigned int slot = st->channels[channel].cfg.cfg_slot;
> + unsigned int slot;
>
> /*
> - * All of these conditions can happen at probe when all channels are
> - * disabled. Otherwise, they should not happen normally.
> + * All of these early return conditions can happen at probe when all
> + * channels are disabled. Otherwise, they should not happen normally.
> */
> - if (channel >= st->num_channels || slot == AD7124_CFG_SLOT_UNASSIGNED ||
> + if (channel >= st->num_channels)
> + return;
> +
> + slot = st->channels[channel].cfg.cfg_slot;
> +
> + if (slot == AD7124_CFG_SLOT_UNASSIGNED ||
> st->cfg_slot_use_count[slot] == 0)
> return;
>
>
> ---
> base-commit: 89cba586b8b4cde09c44b1896624720ea29f0205
> change-id: 20251022-iio-adc-ad7124-fix-possible-oob-array-access-239be24ac692
>
> Best regards,
Powered by blists - more mailing lists