Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH] gpio: davinci: Fix potential buffer overflow
@ 2024-03-28  9:10 Aleksandr Mishin
  2024-03-28 10:32 ` Dan Carpenter
  2024-03-28 15:27 ` Alexander Lobakin
  0 siblings, 2 replies; 6+ messages in thread
From: Aleksandr Mishin @ 2024-03-28  9:10 UTC (permalink / raw)
  To: Keerthy
  Cc: Aleksandr Mishin, Linus Walleij, Bartosz Golaszewski,
	Andrew F. Davis, linux-gpio, linux-kernel, lvc-project

In davinci_gpio_probe() accessing an element of array 'chips->regs' of size 5 and
array 'offset_array' of size 5 can lead to a buffer overflow, since the index
'bank' can have an out of range value 63.
Fix this bug by limiting top index value.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: c809e37a3b5a ("gpio: davinci: Allocate the correct amount of memory for controller")
Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
---
 drivers/gpio/gpio-davinci.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index bb499e362912..b65df1f2b83f 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -257,6 +257,9 @@ static int davinci_gpio_probe(struct platform_device *pdev)
 	spin_lock_init(&chips->lock);
 
 	nbank = DIV_ROUND_UP(ngpio, 32);
+    if (nbank > MAX_REGS_BANKS || nbank > 5) {
+        nbank = MAX_REGS_BANKS < 5 ? MAX_REGS_BANKS : 5;
+	}
 	for (bank = 0; bank < nbank; bank++)
 		chips->regs[bank] = gpio_base + offset_array[bank];
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-03-28 16:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-28  9:10 [PATCH] gpio: davinci: Fix potential buffer overflow Aleksandr Mishin
2024-03-28 10:32 ` Dan Carpenter
2024-03-28 15:27 ` Alexander Lobakin
2024-03-28 16:23   ` Aleksandr Mishin
2024-03-28 16:32     ` Alexander Lobakin
2024-03-28 16:45   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox