All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: mvebu: fix potential user-after-free on probe
@ 2020-11-30 13:33 ` Baruch Siach
  0 siblings, 0 replies; 8+ messages in thread
From: Baruch Siach @ 2020-11-30 13:33 UTC (permalink / raw)
  To: Thierry Reding, Uwe Kleine-König, Lee Jones, Linus Walleij,
	Bartosz Golaszewski
  Cc: Baruch Siach, Andrew Lunn, Gregory Clement,
	Sebastian Hesselbarth, Thomas Petazzoni, Chris Packham,
	Sascha Hauer, Ralph Sennhauser, linux-pwm, linux-gpio,
	linux-arm-kernel

When mvebu_pwm_probe() fails IRQ domain is not released. Move
mvebu_pwm_probe() before IRQ domain registration.

Fixes: 757642f9a584 ("gpio: mvebu: Add limited PWM support")
Reported-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---

This is split out of the "gpio: mvebu: Armada 8K/7K PWM support" series.
I'll rebase the series v2 on top on this fix.
---
 drivers/gpio/gpio-mvebu.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 433e2c3f3fd5..4a331c8f6b06 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -1197,6 +1197,13 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
 
 	devm_gpiochip_add_data(&pdev->dev, &mvchip->chip, mvchip);
 
+	/* Some MVEBU SoCs have simple PWM support for GPIO lines */
+	if (IS_ENABLED(CONFIG_PWM)) {
+		err = mvebu_pwm_probe(pdev, mvchip, id);
+		if (err)
+			return err;
+	}
+
 	/* Some gpio controllers do not provide irq support */
 	if (!have_irqs)
 		return 0;
@@ -1254,10 +1261,6 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
 						 mvchip);
 	}
 
-	/* Some MVEBU SoCs have simple PWM support for GPIO lines */
-	if (IS_ENABLED(CONFIG_PWM))
-		return mvebu_pwm_probe(pdev, mvchip, id);
-
 	return 0;
 
 err_domain:
-- 
2.29.2


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

* [PATCH] gpio: mvebu: fix potential user-after-free on probe
@ 2020-11-30 13:33 ` Baruch Siach
  0 siblings, 0 replies; 8+ messages in thread
From: Baruch Siach @ 2020-11-30 13:33 UTC (permalink / raw)
  To: Thierry Reding, Uwe Kleine-König, Lee Jones, Linus Walleij,
	Bartosz Golaszewski
  Cc: Andrew Lunn, Baruch Siach, linux-pwm, Gregory Clement,
	linux-gpio, Chris Packham, Thomas Petazzoni, Ralph Sennhauser,
	Sascha Hauer, linux-arm-kernel, Sebastian Hesselbarth

When mvebu_pwm_probe() fails IRQ domain is not released. Move
mvebu_pwm_probe() before IRQ domain registration.

Fixes: 757642f9a584 ("gpio: mvebu: Add limited PWM support")
Reported-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
---

This is split out of the "gpio: mvebu: Armada 8K/7K PWM support" series.
I'll rebase the series v2 on top on this fix.
---
 drivers/gpio/gpio-mvebu.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 433e2c3f3fd5..4a331c8f6b06 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -1197,6 +1197,13 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
 
 	devm_gpiochip_add_data(&pdev->dev, &mvchip->chip, mvchip);
 
+	/* Some MVEBU SoCs have simple PWM support for GPIO lines */
+	if (IS_ENABLED(CONFIG_PWM)) {
+		err = mvebu_pwm_probe(pdev, mvchip, id);
+		if (err)
+			return err;
+	}
+
 	/* Some gpio controllers do not provide irq support */
 	if (!have_irqs)
 		return 0;
@@ -1254,10 +1261,6 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
 						 mvchip);
 	}
 
-	/* Some MVEBU SoCs have simple PWM support for GPIO lines */
-	if (IS_ENABLED(CONFIG_PWM))
-		return mvebu_pwm_probe(pdev, mvchip, id);
-
 	return 0;
 
 err_domain:
-- 
2.29.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] gpio: mvebu: fix potential user-after-free on probe
  2020-11-30 13:33 ` Baruch Siach
@ 2020-11-30 13:51   ` Uwe Kleine-König
  -1 siblings, 0 replies; 8+ messages in thread
From: Uwe Kleine-König @ 2020-11-30 13:51 UTC (permalink / raw)
  To: Baruch Siach
  Cc: Thierry Reding, Lee Jones, Linus Walleij, Bartosz Golaszewski,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Thomas Petazzoni, Chris Packham, Sascha Hauer, Ralph Sennhauser,
	linux-pwm, linux-gpio, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 448 bytes --]

On Mon, Nov 30, 2020 at 03:33:23PM +0200, Baruch Siach wrote:
> When mvebu_pwm_probe() fails IRQ domain is not released. Move
> mvebu_pwm_probe() before IRQ domain registration.

And now if something with IRQ domain registration fails the pwm stuff
isn't freed?

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] gpio: mvebu: fix potential user-after-free on probe
@ 2020-11-30 13:51   ` Uwe Kleine-König
  0 siblings, 0 replies; 8+ messages in thread
From: Uwe Kleine-König @ 2020-11-30 13:51 UTC (permalink / raw)
  To: Baruch Siach
  Cc: Andrew Lunn, Sascha Hauer, linux-pwm, Linus Walleij,
	Chris Packham, Bartosz Golaszewski, Thierry Reding,
	Thomas Petazzoni, linux-gpio, Ralph Sennhauser, Lee Jones,
	Gregory Clement, linux-arm-kernel, Sebastian Hesselbarth


[-- Attachment #1.1: Type: text/plain, Size: 448 bytes --]

On Mon, Nov 30, 2020 at 03:33:23PM +0200, Baruch Siach wrote:
> When mvebu_pwm_probe() fails IRQ domain is not released. Move
> mvebu_pwm_probe() before IRQ domain registration.

And now if something with IRQ domain registration fails the pwm stuff
isn't freed?

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] gpio: mvebu: fix potential user-after-free on probe
  2020-11-30 13:51   ` Uwe Kleine-König
@ 2020-11-30 13:55     ` Baruch Siach
  -1 siblings, 0 replies; 8+ messages in thread
From: Baruch Siach @ 2020-11-30 13:55 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Thierry Reding, Lee Jones, Linus Walleij, Bartosz Golaszewski,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Thomas Petazzoni, Chris Packham, Sascha Hauer, Ralph Sennhauser,
	linux-pwm, linux-gpio, linux-arm-kernel

Hi Uwe,

On Mon, Nov 30 2020, Uwe Kleine-König wrote:
> On Mon, Nov 30, 2020 at 03:33:23PM +0200, Baruch Siach wrote:
>> When mvebu_pwm_probe() fails IRQ domain is not released. Move
>> mvebu_pwm_probe() before IRQ domain registration.
>
> And now if something with IRQ domain registration fails the pwm stuff
> isn't freed?

As far as I can see mvebu_pwm_probe() uses devres exclusively to
allocate resources.

baruch

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -

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

* Re: [PATCH] gpio: mvebu: fix potential user-after-free on probe
@ 2020-11-30 13:55     ` Baruch Siach
  0 siblings, 0 replies; 8+ messages in thread
From: Baruch Siach @ 2020-11-30 13:55 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Andrew Lunn, Sascha Hauer, linux-pwm, Linus Walleij,
	Chris Packham, Bartosz Golaszewski, Thierry Reding,
	Thomas Petazzoni, linux-gpio, Ralph Sennhauser, Lee Jones,
	Gregory Clement, linux-arm-kernel, Sebastian Hesselbarth

Hi Uwe,

On Mon, Nov 30 2020, Uwe Kleine-König wrote:
> On Mon, Nov 30, 2020 at 03:33:23PM +0200, Baruch Siach wrote:
>> When mvebu_pwm_probe() fails IRQ domain is not released. Move
>> mvebu_pwm_probe() before IRQ domain registration.
>
> And now if something with IRQ domain registration fails the pwm stuff
> isn't freed?

As far as I can see mvebu_pwm_probe() uses devres exclusively to
allocate resources.

baruch

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] gpio: mvebu: fix potential user-after-free on probe
  2020-11-30 13:55     ` Baruch Siach
@ 2020-11-30 14:43       ` Uwe Kleine-König
  -1 siblings, 0 replies; 8+ messages in thread
From: Uwe Kleine-König @ 2020-11-30 14:43 UTC (permalink / raw)
  To: Baruch Siach
  Cc: Thierry Reding, Lee Jones, Linus Walleij, Bartosz Golaszewski,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Thomas Petazzoni, Chris Packham, Sascha Hauer, Ralph Sennhauser,
	linux-pwm, linux-gpio, linux-arm-kernel

[-- Attachment #1: Type: text/plain, Size: 733 bytes --]

Hi Baruch,

On Mon, Nov 30, 2020 at 03:55:28PM +0200, Baruch Siach wrote:
> On Mon, Nov 30 2020, Uwe Kleine-König wrote:
> > On Mon, Nov 30, 2020 at 03:33:23PM +0200, Baruch Siach wrote:
> >> When mvebu_pwm_probe() fails IRQ domain is not released. Move
> >> mvebu_pwm_probe() before IRQ domain registration.
> >
> > And now if something with IRQ domain registration fails the pwm stuff
> > isn't freed?
> 
> As far as I can see mvebu_pwm_probe() uses devres exclusively to
> allocate resources.

there is no devm magic in pwmchip_add().

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] gpio: mvebu: fix potential user-after-free on probe
@ 2020-11-30 14:43       ` Uwe Kleine-König
  0 siblings, 0 replies; 8+ messages in thread
From: Uwe Kleine-König @ 2020-11-30 14:43 UTC (permalink / raw)
  To: Baruch Siach
  Cc: Andrew Lunn, Sascha Hauer, linux-pwm, Linus Walleij,
	Chris Packham, Bartosz Golaszewski, Thierry Reding,
	Thomas Petazzoni, linux-gpio, Ralph Sennhauser, Lee Jones,
	Gregory Clement, linux-arm-kernel, Sebastian Hesselbarth


[-- Attachment #1.1: Type: text/plain, Size: 733 bytes --]

Hi Baruch,

On Mon, Nov 30, 2020 at 03:55:28PM +0200, Baruch Siach wrote:
> On Mon, Nov 30 2020, Uwe Kleine-König wrote:
> > On Mon, Nov 30, 2020 at 03:33:23PM +0200, Baruch Siach wrote:
> >> When mvebu_pwm_probe() fails IRQ domain is not released. Move
> >> mvebu_pwm_probe() before IRQ domain registration.
> >
> > And now if something with IRQ domain registration fails the pwm stuff
> > isn't freed?
> 
> As far as I can see mvebu_pwm_probe() uses devres exclusively to
> allocate resources.

there is no devm magic in pwmchip_add().

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2020-11-30 14:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-30 13:33 [PATCH] gpio: mvebu: fix potential user-after-free on probe Baruch Siach
2020-11-30 13:33 ` Baruch Siach
2020-11-30 13:51 ` Uwe Kleine-König
2020-11-30 13:51   ` Uwe Kleine-König
2020-11-30 13:55   ` Baruch Siach
2020-11-30 13:55     ` Baruch Siach
2020-11-30 14:43     ` Uwe Kleine-König
2020-11-30 14:43       ` Uwe Kleine-König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.