All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Keerthy <j-keerthy@ti.com>,
	Linus Walleij <linusw@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>,
	"Software, Inc" <source@mvista.com>, Jan Kotas <jank@cadence.com>,
	Grygorii Strashko <grygorii.strashko@ti.com>,
	linux-gpio@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 01/10] gpio: davinci: Validate ngpio against MAX_REGS_BANKS in davinci_gpio_probe()
Date: Thu,  3 Dec 2026 20:54:59 +0000	[thread overview]
Message-ID: <20261203205606.3905705-2-lee@kernel.org> (raw)
In-Reply-To: <20261203205606.3905705-1-lee@kernel.org>

davinci_gpio_probe() validates nirq against MAX_INT_PER_BANK (32) but
never bounds ngpio against MAX_REGS_BANKS (5, supporting at most 160
GPIOs).  A larger ti,ngpio value causes out-of-bounds reads past
offset_array[] and out-of-bounds writes past chips->regs[] and
chips->context[].

Reject ngpio values greater than MAX_REGS_BANKS * 32 with -EINVAL and
size offset_array with MAX_REGS_BANKS.

Fixes: 8f7cf8c65746 ("gpio: davinci: Remove gpio2regs function")
Closes: https://sashiko.dev/#/bug/linux-59cf1b6f-2241-467c-a82a-93a3d1bf5d16
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/gpio/gpio-davinci.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index 5f24367ad9af..f1f2b8f75761 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -43,7 +43,9 @@ typedef struct irq_chip *(*gpio_get_irq_chip_cb_t)(unsigned int irq);
 
 #define BINTEN	0x8 /* GPIO Interrupt Per-Bank Enable Register */
 
-static unsigned int offset_array[5] = {0x10, 0x38, 0x60, 0x88, 0xb0};
+static unsigned int offset_array[MAX_REGS_BANKS] = {
+	0x10, 0x38, 0x60, 0x88, 0xb0,
+};
 
 struct davinci_gpio_irq_data {
 	void __iomem			*regs;
@@ -179,6 +181,8 @@ static int davinci_gpio_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, ret, "Failed to get the number of GPIOs\n");
 	if (ngpio == 0)
 		return dev_err_probe(dev, -EINVAL, "How many GPIOs?\n");
+	if (ngpio > MAX_REGS_BANKS * 32)
+		return dev_err_probe(dev, -EINVAL, "Too many GPIOs\n");
 
 	/*
 	 * If there are unbanked interrupts then the number of
-- 
2.56.1.911.g883d8bcb20-goog


  reply	other threads:[~2026-12-03 20:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 20:54 [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-03 20:54 ` Lee Jones
2026-12-03 20:54 ` Lee Jones [this message]
2026-12-03 20:55 ` [PATCH 02/10] gpiolib: acpi: Hold gpio_device reference in acpi_dev_gpio_irq_wake_get_by() Lee Jones
2026-12-04 11:35   ` Andy Shevchenko
2026-12-03 20:55 ` [PATCH 03/10] gpio: mvebu: Clear chained IRQ handlers on unbind Lee Jones
2026-12-03 21:13   ` sashiko-bot
2026-12-03 22:10   ` Andrew Lunn
2026-12-04  0:05     ` Rosen Penev
2026-12-04  1:17       ` Andrew Lunn
2026-12-05  3:12         ` Rosen Penev
2026-12-03 20:55 ` [PATCH 04/10] gpio: rockchip: Unregister gpiochip on pin-range lookup errors Lee Jones
2026-12-03 20:55   ` Lee Jones
2026-12-03 20:55 ` [PATCH 05/10] gpiolib: Avoid undersized array bitmap in set fastpath Lee Jones
2026-12-03 20:55 ` [PATCH 06/10] gpio: mlxbf2: Embed context save registers to prevent suspend NULL dereference Lee Jones
2026-12-03 20:55 ` [PATCH 07/10] gpio: regmap: Use resolved chip->ngpio for default ngpio_per_reg Lee Jones
2026-12-04 11:36   ` Andy Shevchenko
2026-12-03 20:55 ` [PATCH 08/10] gpio: mpc8xxx: Drop stale remove callback clearing chained handler Lee Jones
2026-12-03 21:17   ` sashiko-bot
2026-12-03 20:55 ` [PATCH 09/10] gpio: mpsse: Allocate DMA-safe buffer in mpsse_write() Lee Jones
2026-12-03 20:55 ` [PATCH 10/10] gpio: pcie-idio-24: Fix COS_ENABLE_RISING bit definition Lee Jones
2026-12-04 21:02   ` William Breathitt Gray

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203205606.3905705-2-lee@kernel.org \
    --to=lee@kernel.org \
    --cc=brgl@kernel.org \
    --cc=grygorii.strashko@ti.com \
    --cc=j-keerthy@ti.com \
    --cc=jank@cadence.com \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=source@mvista.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.