]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gpio: davinci: Validate the obtained number of IRQs
authorAleksandr Mishin <amishin@t-argos.ru>
Tue, 18 Jun 2024 14:43:44 +0000 (17:43 +0300)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 24 Jun 2024 11:24:59 +0000 (13:24 +0200)
Value of pdata->gpio_unbanked is taken from Device Tree. In case of broken
DT due to any error this value can be any. Without this value validation
there can be out of chips->irqs array boundaries access in
davinci_gpio_probe().

Validate the obtained nirq value so that it won't exceed the maximum
number of IRQs per bank.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: eb3744a2dd01 ("gpio: davinci: Do not assume continuous IRQ numbering")
Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
Link: https://lore.kernel.org/r/20240618144344.16943-1-amishin@t-argos.ru
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpio-davinci.c

index bb499e362912589869213535bb46cf5d96682e2c..1d0175d6350b781665806b1f03b4de799495eea1 100644 (file)
@@ -225,6 +225,11 @@ static int davinci_gpio_probe(struct platform_device *pdev)
        else
                nirq = DIV_ROUND_UP(ngpio, 16);
 
+       if (nirq > MAX_INT_PER_BANK) {
+               dev_err(dev, "Too many IRQs!\n");
+               return -EINVAL;
+       }
+
        chips = devm_kzalloc(dev, sizeof(*chips), GFP_KERNEL);
        if (!chips)
                return -ENOMEM;