Commit 66ee32da authored by Anton Vasilyev's avatar Anton Vasilyev Committed by Kleber Sacilotto de Souza

gpio: ml-ioh: Fix buffer underwrite on probe error path

BugLink: https://bugs.launchpad.net/bugs/1798539

[ Upstream commit 4bf4eed4 ]

If ioh_gpio_probe() fails on devm_irq_alloc_descs() then chip may point
to any element of chip_save array, so reverse iteration from pointer chip
may become chip_save[-1] and gpiochip_remove() will operate with wrong
memory.

The patch fix the error path of ioh_gpio_probe() to correctly bypass
chip_save array.

Found by Linux Driver Verification project (linuxtesting.org).
Signed-off-by: default avatarAnton Vasilyev <vasilyev@ispras.ru>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 9b21421f
...@@ -495,9 +495,10 @@ static int ioh_gpio_probe(struct pci_dev *pdev, ...@@ -495,9 +495,10 @@ static int ioh_gpio_probe(struct pci_dev *pdev,
chip = chip_save; chip = chip_save;
err_gpiochip_add: err_gpiochip_add:
chip = chip_save;
while (--i >= 0) { while (--i >= 0) {
chip--;
gpiochip_remove(&chip->gpio); gpiochip_remove(&chip->gpio);
chip++;
} }
kfree(chip_save); kfree(chip_save);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment