[PATCH v2 02/12] pinctrl: nuvoton: ma35: Prevent out-of-bounds write in ma35_pinctrl_get_soc_data()
From: Lee Jones
Date: Thu Nov 19 2026 - 15:50:55 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>
---
v1 => v2: No 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 bfa743db8b13..aff2212c6278 100644
--- a/drivers/pinctrl/nuvoton/pinctrl-ma35.c
+++ b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
@@ -622,6 +622,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.750.gf70dc682cf-goog