[PATCH v3 02/12] pinctrl: nuvoton: ma35: Prevent out-of-bounds write in ma35_pinctrl_get_soc_data()
From: Lee Jones
Date: Fri Nov 27 2026 - 09:06:26 EST
ma35_pinctrl_get_soc_data() allocates ctrl->pin_banks with
ctrl->nr_banks (MA35_GPIO_BANK_MAX) entries and populates them while
iterating over child GPIO controller nodes with
for_each_gpiochip_node(). If the Device Tree contains more than
MA35_GPIO_BANK_MAX GPIO controller child nodes, id exceeds
ctrl->nr_banks and writes past the end of ctrl->pin_banks.
Check that id is within ctrl->nr_banks before indexing ctrl->pin_banks.
Fixes: f805e356313b ("pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver")
Closes: https://sashiko.dev/#/bug/linux-7f04e7c5-6691-4586-b0f9-392f1285514c
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
v2 => v3:
- Rebase onto pinctrl/for-next; no functional changes.
drivers/pinctrl/nuvoton/pinctrl-ma35.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/pinctrl/nuvoton/pinctrl-ma35.c b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
index 872769db244b..ddd3f4329f67 100644
--- a/drivers/pinctrl/nuvoton/pinctrl-ma35.c
+++ b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
@@ -623,6 +623,12 @@ static int ma35_pinctrl_get_soc_data(struct ma35_pinctrl *pctl, struct platform_
}
for_each_gpiochip_node(&pdev->dev, child) {
+ if (id >= ctrl->nr_banks) {
+ dev_err(&pdev->dev, "Exceeded max GPIO banks (%u)\n",
+ ctrl->nr_banks);
+ fwnode_handle_put(child);
+ return -EINVAL;
+ }
bank = &ctrl->pin_banks[id];
bank->fwnode = child;
bank->regmap = pctl->regmap;
--
2.56.1.839.g22a8290db9-goog