linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: ml-ioh: Fix buffer underwrite on probe error path
@ 2018-07-23 16:53 Anton Vasilyev
  2018-07-29 21:13 ` Linus Walleij
  0 siblings, 1 reply; 2+ messages in thread
From: Anton Vasilyev @ 2018-07-23 16:53 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Anton Vasilyev, linux-gpio, linux-kernel, ldv-project

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: Anton Vasilyev <vasilyev@ispras.ru>
---
 drivers/gpio/gpio-ml-ioh.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-ml-ioh.c b/drivers/gpio/gpio-ml-ioh.c
index b23d9a36be1f..51c7d1b84c2e 100644
--- a/drivers/gpio/gpio-ml-ioh.c
+++ b/drivers/gpio/gpio-ml-ioh.c
@@ -496,9 +496,10 @@ static int ioh_gpio_probe(struct pci_dev *pdev,
 	return 0;
 
 err_gpiochip_add:
+	chip = chip_save;
 	while (--i >= 0) {
-		chip--;
 		gpiochip_remove(&chip->gpio);
+		chip++;
 	}
 	kfree(chip_save);
 
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] gpio: ml-ioh: Fix buffer underwrite on probe error path
  2018-07-23 16:53 [PATCH] gpio: ml-ioh: Fix buffer underwrite on probe error path Anton Vasilyev
@ 2018-07-29 21:13 ` Linus Walleij
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2018-07-29 21:13 UTC (permalink / raw)
  To: vasilyev; +Cc: open list:GPIO SUBSYSTEM, linux-kernel, ldv-project

On Mon, Jul 23, 2018 at 6:54 PM Anton Vasilyev <vasilyev@ispras.ru> wrote:

> 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: Anton Vasilyev <vasilyev@ispras.ru>

Patch applied, nice work!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-07-29 21:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-23 16:53 [PATCH] gpio: ml-ioh: Fix buffer underwrite on probe error path Anton Vasilyev
2018-07-29 21:13 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).