From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 112DC35B120 for ; Wed, 22 Oct 2025 16:59:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761152402; cv=none; b=i5oLnIY7EbmqsL0hoTUwAj/eH9A41tPquv6EB1/OOon576aS77PtzMBpwwS3C/jW7ASd2Y4fuymV9x/AhARvPngsSFgXrAYGkYL66M015IvuzyltRqLjuMEy1nrF1rEjZGa4Blbu6LKJtcVshvA+GleSxNGOnUgPLCWYRqHuqrM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761152402; c=relaxed/simple; bh=tg3+sV6cIbsxOjpGV0ypP+7yV6rtvMxzpP/xjjXMSBE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=tGDbiqIrtZvs7WoPW65xfWSoN/xWKs0GT9U6Q8/sFKXZqUW7pIsR5Xc6/DXvTKKqnNdXzfQNDXBKLl7I/k+As24D5TILcIye6nXE8aWqZP01BaFGuF1TcuiVB+B9GDMXDrfUOsNW6ZyU8N5kn91dl3imSVMMKQULcVCtCDbKSYM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=mJP9SujQ; arc=none smtp.client-ip=209.85.160.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="mJP9SujQ" Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-3c9a42d6349so7511666fac.1 for ; Wed, 22 Oct 2025 09:59:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1761152398; x=1761757198; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=8MocBUHP0H4U2F0hQ0me7gqNWaKXOLx5jISmorrxl84=; b=mJP9SujQCiVRtLuLwAGnfVpxeSS4XvyL3IoBKqyd54ovtWsmOoKnLrQ8RWl3FFvV2G VHW28TtvO1KsCIdvrhpHDhVbJmimYlCgSCoEKJyBz7p1mPq1+sL7i67m/AzYyYCcl+Px F0Hrdzd3DsmlOOTS6+a5UgUpb9ssV/2N+xAKYNhyZIC3J9j8EuxnoRY+gl8Zm1wEL+7V cd8QdhIxCo3uqfXuWn+D2LklXfapnnywghD3asWrgEiRxxYZAl7/BJCghws/KenqDK0v 0t1jCv7v4nX2vFWjlMsfa+dQyv2mGCAv4R8gXIYY7j6klmpiAmPL0bjzPJsQDSVwuQmM ZaYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761152398; x=1761757198; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8MocBUHP0H4U2F0hQ0me7gqNWaKXOLx5jISmorrxl84=; b=avF9g7sfgqVIPWwOlXsewycEPK6G4NpPcewzhJO80oG91RqOZ6fvm5gah7U3VEMxjK wQyl8KPXQ09kqfTT92woNlZTr4Ug+Mrpq5s6a+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jTlN+ehPvAAFfh3ISTfN6iCw== X-Received: by 2002:a05:6870:24c:b0:349:de3c:bfbe with SMTP id 586e51a60fabf-3c98cf43518mr9335490fac.1.1761152398097; Wed, 22 Oct 2025 09:59:58 -0700 (PDT) Received: from ?IPV6:2600:8803:e7e4:500:4176:6994:bd72:1296? ([2600:8803:e7e4:500:4176:6994:bd72:1296]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-3c9af01b3b3sm4184066fac.11.2025.10.22.09.59.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Oct 2025 09:59:57 -0700 (PDT) Message-ID: <49c09806-0f58-4d1d-aa0c-4351fc3e7089@baylibre.com> Date: Wed, 22 Oct 2025 11:59:56 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] iio: adc: ad7124: fix possible OOB array access To: Marcelo Schmitt Cc: Michael Hennerich , Jonathan Cameron , =?UTF-8?Q?Nuno_S=C3=A1?= , Andy Shevchenko , Jonathan Cameron , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Dan Carpenter References: <20251022-iio-adc-ad7124-fix-possible-oob-array-access-v1-1-2552062cc8e6@baylibre.com> Content-Language: en-US From: David Lechner In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 10/22/25 11:54 AM, Marcelo Schmitt wrote: > Hi David, > > One minor question inline. > Nevertheless, the fix looks good to me. > > Reviewed-by: Marcelo Schmitt > > On 10/22, David Lechner 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 > What is considered using the value in this context? (see other comment below) > >> harmless, but we still should not be reading out of bounds in the first >> place. >> >> Reported-by: Dan Carpenter >> 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 >> --- >> 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) > Wasn't the value potentially read from invalid memory used above? > It's fixed now, so I guess there's no point in nitpicking on that. This code was unreachable with an undefined slot even before this change because of the check to channel >= st->num_channels before it. > >> return; > > Best regards, > Marcelo