Skip to contentSkip to conversation

pinctrl: at91: Fix possible out-of-boundary access

PATCH In review Andy Shevchenko 3 participants 3 messages May 8, 2025 – May 13, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: at91: Fix possible out-of-boundary access

at91_gpio_probe() doesn't check that given OF alias is not available or something went wrong when trying to get it. This might have consequences when accessing gpio_chips array with that value as an index. Note, that BUG() can be compiled out and hence won't actually perform the required checks.

Fixes 6732ae5cb47c ("ARM: at91: add pinctrl support")
---
 drivers/pinctrl/pinctrl-at91.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pinctrl/pinctrl-at91.c +5 -1
index 442dd8c80b65..6c2727bd55bc 100644
@@ -1822,12 +1822,16 @@ static int at91_gpio_probe(struct platform_device *pdev)
 	struct at91_gpio_chip *at91_chip = NULL;
 	struct gpio_chip *chip;
 	struct pinctrl_gpio_range *range;
+	int alias_idx;
 	int ret = 0;
 	int irq, i;
-	int alias_idx = of_alias_get_id(np, "gpio");
 	uint32_t ngpio;
 	char **names;
 
+	alias_idx = of_alias_get_id(np, "gpio");
+	if (alias_idx < 0)
+		return alias_idx;
+
 	BUG_ON(alias_idx >= ARRAY_SIZE(gpio_chips));
 	if (gpio_chips[alias_idx])
 		return dev_err_probe(dev, -EBUSY, "%d slot is occupied.\n", alias_idx);
Signature · 1 line
2.47.2
#1 lore raw

Thu, May 08, 2025 at 11:08:07PM +0300, Andy Shevchenko kirjoitti:

Quoted 5 lines

at91_gpio_probe() doesn't check that given OF alias is not available or something went wrong when trying to get it. This might have consequences when accessing gpio_chips array with that value as an index. Note, that BUG() can be compiled out and hence won't actually perform the required checks.

Also

Quoted 2 lines
Fixes 6732ae5cb47c ("ARM: at91: add pinctrl support")
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko

at91_gpio_probe() doesn't check that given OF alias is not available or something went wrong when trying to get it. This might have consequences when accessing gpio_chips array with that value as an index. Note, that BUG() can be compiled out and hence won't actually perform the required checks.

Fixes 6732ae5cb47c ("ARM: at91: add pinctrl support")

Patch applied and hey, b4 just picked up all the extra tags for me! Love this tool.

Yours,
Linus Walleij