* [PATCH] iio: adc: mcp3911: Fix out of bounds access of array mcp3911_osr_table
@ 2022-10-12 13:42 Colin Ian King
2022-10-12 13:52 ` Marcus Folkesson
0 siblings, 1 reply; 2+ messages in thread
From: Colin Ian King @ 2022-10-12 13:42 UTC (permalink / raw)
To: Marcus Folkesson, Kent Gustavsson, Jonathan Cameron,
Lars-Peter Clausen, Andy Shevchenko, linux-iio
Cc: kernel-janitors, linux-kernel
Currently the for-loop is using the size of the array mcp3911_osr_table
as the upper bounds which is 0..31 which is causing an out of bounds
access to the array at indexes 8..31. Fix this using the ARRAY_SIZE
macro to get the size of the array in elements rather than bytes.
Fixes: 6d965885f4ea ("iio: adc: mcp3911: add support for oversampling ratio")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
drivers/iio/adc/mcp3911.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/adc/mcp3911.c b/drivers/iio/adc/mcp3911.c
index b35fd2c9c3c0..015a9ffdb26a 100644
--- a/drivers/iio/adc/mcp3911.c
+++ b/drivers/iio/adc/mcp3911.c
@@ -248,7 +248,7 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev,
break;
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
- for (int i = 0; i < sizeof(mcp3911_osr_table); i++) {
+ for (int i = 0; i < ARRAY_SIZE(mcp3911_osr_table); i++) {
if (val == mcp3911_osr_table[i]) {
val = FIELD_PREP(MCP3911_CONFIG_OSR, i);
ret = mcp3911_update(adc, MCP3911_REG_CONFIG, MCP3911_CONFIG_OSR,
--
2.37.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: adc: mcp3911: Fix out of bounds access of array mcp3911_osr_table
2022-10-12 13:42 [PATCH] iio: adc: mcp3911: Fix out of bounds access of array mcp3911_osr_table Colin Ian King
@ 2022-10-12 13:52 ` Marcus Folkesson
0 siblings, 0 replies; 2+ messages in thread
From: Marcus Folkesson @ 2022-10-12 13:52 UTC (permalink / raw)
To: Colin Ian King
Cc: Kent Gustavsson, Jonathan Cameron, Lars-Peter Clausen,
Andy Shevchenko, linux-iio, kernel-janitors, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 691 bytes --]
Hi Colin,
On Wed, Oct 12, 2022 at 02:42:45PM +0100, Colin Ian King wrote:
> Currently the for-loop is using the size of the array mcp3911_osr_table
> as the upper bounds which is 0..31 which is causing an out of bounds
> access to the array at indexes 8..31. Fix this using the ARRAY_SIZE
> macro to get the size of the array in elements rather than bytes.
>
> Fixes: 6d965885f4ea ("iio: adc: mcp3911: add support for oversampling ratio")
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Thank you for the patch!
Dan was a little bit earlier to catch this though
https://lore.kernel.org/all/20221002132053.113f595f@jic23-huawei/
Best regards,
Marcus Folkesson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-12 13:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-12 13:42 [PATCH] iio: adc: mcp3911: Fix out of bounds access of array mcp3911_osr_table Colin Ian King
2022-10-12 13:52 ` Marcus Folkesson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).