From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385786; b=FkoBtAUMC7rRRFpKJYzboCFUKMHEpIMQ+dkcdj1vQ3wbejFh9JBwAP0WUvwLZ4b/bNOz qHgweCgzjmnYcNwJ0wIbrfHYLDD89+bt8smjPLb48Ki39hCz5MrYcDRpV/dJli59Tci83 HEKhOiWObcbcdNftTqGSRiGPn+lu7xnq0ZVnRmsUX/jjiV225+qc0ykI7Iww0c9FmhA+H aozhopy8bJBN0at1UYzRqaFK2tjHvVBoTdmEDnaOpcI8vvUwEo4qY1MiQfS6jkxmEWsS7 kUE47byAVoNkfGSqOL4o1LbMGPBP3b4irwmxK3m51ItAP9pvIZLLiHJF3/LqmfaN6xA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385786; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=jTolKD7DwLk/QT2ZQI+ULx9lN3Yrr45kHJ2z2TfCjKo=; b=nfC89EhgaGxGw2e8N7fODK5YDoUwfTIuxgLrsBHITO8a7l+4qLP84byVPwPDGfiZ7P3Z EwgQJRw16UAPsJoWSBp4p7SrNnhxEQi3mL9WnBHEEZ5k2DkibltuNoqFQA+5kROmBd3TV pjU0ClgvcVGjAH6uaeV8Sb9KZ0Yz9FBnKmkHUgfC0x7GU4xD5zrgA6U+gADNb+j12d3ND M0TSgFxQPGWEVGgpaNbf0stA8shBvevLo/Maq3hspnc2x6h6sBtfxNZr3ujhm1Ap43eVJ K3VIRUlR7nN4P9iJrfTXRfVuLhRlMYLJQQgpfVLLbY9rOINLLesIGtpNOAhM6RURSYw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=SHdQzHGC; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E99B2606A682; Fri, 4 Dec 2026 12:03:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=SHdQzHGC Received: by smtp.kernel.org (Postfix) with ESMTPSA id C12D01F00A0E; Fri, 4 Dec 2026 12:03:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385785; bh=jTolKD7DwLk/QT2ZQI+ULx9lN3Yrr45kHJ2z2TfCjKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SHdQzHGCyMm7RIpjzt1yiGj/WO5cRll4Nc5im7D9t0EBiB7uJbDAFgTKIdabe1ZR9 RbCgVnX4qFCvRZkYKjS7Gu6DEO1NrIun/JYvafLGnHC8CVYeKwFZegBuBYmI5ZmPr/ YgLfWH1D5vtouELv5h2qXXBC6cLqUtUTV+bjgVNg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Arnav Kapoor , Andy Shevchenko , Jonathan Cameron Subject: [PATCH 6.6 0693/1167] iio: proximity: sx9324: fix out-of-bounds read of scan period table Date: Fri, 4 Dec 2026 19:02:00 +0900 Message-ID: <20261204100720.116626370@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnav Kapoor commit 7b5f54280f8e6ef07664f6705dd005feefbe87d1 upstream. 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. Fixes: 4c18a890dff8 ("iio:proximity:sx9324: Add SX9324 support") Cc: stable@vger.kernel.org Signed-off-by: Arnav Kapoor Reviewed-by: Andy Shevchenko Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/proximity/sx9324.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/drivers/iio/proximity/sx9324.c +++ b/drivers/iio/proximity/sx9324.c @@ -280,11 +280,20 @@ static const struct { { 0, 250000 }, /* 11111: 4 s */ }; +/* + * The scan period of the SX9324 is selected by the 5-bit wide + * 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 */ }; +static_assert(ARRAY_SIZE(sx9324_scan_period_table) == ARRAY_SIZE(sx9324_samp_freq_table)); + static const struct regmap_range sx9324_writable_reg_ranges[] = { /* * To set COMPSTAT for compensation, even if datasheet says register is