gpio: brcmstb: fix UAF after IRQ domain setup failure
PATCH 1/1 gpio: brcmstb: fix UAF after IRQ domain setup failure
When devm_request_irq() fails in brcmstb_gpio_irq_setup(), the error path removes the IRQ domain but leaves priv->irq_domain non-NULL.
The probe error path subsequently calls brcmstb_gpio_remove(), which checks priv->irq_domain and attempts to access the already-freed domain through irq_find_mapping(). It also attempts to remove the domain again, resulting in a use-after-free and potentially further memory corruption.
Set priv->irq_domain to NULL after removing it so that the common cleanup path skips the already-freed IRQ domain.
This issue was found by our static analysis tool under development.
--- drivers/gpio/gpio-brcmstb.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpio/gpio-brcmstb.c +1 -0
@@ -513,6 +513,7 @@ static int brcmstb_gpio_irq_setup(struct platform_device *pdev, out_free_domain:irq_domain_remove (priv->irq_domain); + priv->irq_domain =NULL ;return err; }
Signature · 1 line
2.43.0
Quoted 9 lines · Guangshuo Li
When
devm_request_irq()fails inbrcmstb_gpio_irq_setup(), the error path removes the IRQ domain but leavespriv->irq_domainnon-NULL.The probe error path subsequently calls
brcmstb_gpio_remove(), which checkspriv->irq_domainand attempts to access the already-freed domain throughirq_find_mapping(). It also attempts to remove the domain again, resulting in a use-after-free and potentially further memory corruption.
Quoted 8 lines
Set
priv->irq_domainto NULL after removing it so that the common cleanup path skips the already-freed IRQ domain.This issue was found by our static analysis tool under development.
Fixes 0ba31dc201de ("gpio: brcmstb: consolidate interrupt domains")Signed-off-by Guangshuo Li <[email protected]>
Signature · 1 line
Florian
Bartosz Golaszewski
AppliedQuoted 10 lines · Guangshuo Li
When
devm_request_irq()fails inbrcmstb_gpio_irq_setup(), the error path removes the IRQ domain but leavespriv->irq_domainnon-NULL.The probe error path subsequently calls
brcmstb_gpio_remove(), which checkspriv->irq_domainand attempts to access the already-freed domain throughirq_find_mapping(). It also attempts to remove the domain again, resulting in a use-after-free and potentially further memory corruption.[...]
Applied, thanks!
[1/1] gpio: brcmstb: fix UAF after IRQ domain setup failure
https://git.kernel.org/brgl/c/baa14758afb3e2828de1f76511edc1de50216f39
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>