* [PATCH 1/7] USB: core: fix device node leak
[not found] <20170530162554.26159-1-johan@kernel.org>
@ 2017-05-30 16:25 ` Johan Hovold
2017-05-30 22:55 ` Tyrel Datwyler
2017-06-05 3:35 ` Peter Chen
2017-05-30 16:25 ` [PATCH 6/7] thermal: max77620: fix device-node reference imbalance Johan Hovold
1 sibling, 2 replies; 7+ messages in thread
From: Johan Hovold @ 2017-05-30 16:25 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
linux-kernel, Johan Hovold, stable, Peter Chen
Make sure to release any OF device-node reference taken when creating
the USB device.
Note that we currently do not hold a reference to the root hub
device-tree node (i.e. the parent controller node).
Fixes: 69bec7259853 ("USB: core: let USB device know device node")
Cc: stable <stable@vger.kernel.org> # v4.6
Cc: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/usb/core/usb.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 28b053cacc90..62e1906bb2f3 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -416,6 +416,8 @@ static void usb_release_dev(struct device *dev)
usb_destroy_configuration(udev);
usb_release_bos_descriptor(udev);
+ if (udev->parent)
+ of_node_put(dev->of_node);
usb_put_hcd(hcd);
kfree(udev->product);
kfree(udev->manufacturer);
--
2.13.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 6/7] thermal: max77620: fix device-node reference imbalance
[not found] <20170530162554.26159-1-johan@kernel.org>
2017-05-30 16:25 ` [PATCH 1/7] USB: core: fix device node leak Johan Hovold
@ 2017-05-30 16:25 ` Johan Hovold
2017-05-30 22:59 ` Tyrel Datwyler
1 sibling, 1 reply; 7+ messages in thread
From: Johan Hovold @ 2017-05-30 16:25 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
linux-kernel, Johan Hovold, stable, Laxman Dewangan
The thermal child device reuses the parent MFD-device device-tree node
when registering a thermal zone, but did not take a reference to the
node.
This leads to a reference imbalance, and potential use-after-free, when
the node reference is dropped by the platform-bus device destructor
(once for the child and later again for the parent).
Fix this by dropping any reference already held to a device-tree node
and getting a reference to the parent's node which will be balanced on
reprobe or on platform-device release, whichever comes first.
Note that simply clearing the of_node pointer on probe errors and on
driver unbind would not allow the use of device-managed resources as
specifically thermal_zone_of_sensor_unregister() claims that a valid
device-tree node pointer is needed during deregistration (even if it
currently does not seem to use it).
Fixes: ec4664b3fd6d ("thermal: max77620: Add thermal driver for reporting junction temp")
Cc: stable <stable@vger.kernel.org> # 4.9
Cc: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/thermal/max77620_thermal.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c
index e9a1fe342760..71d35f3c9215 100644
--- a/drivers/thermal/max77620_thermal.c
+++ b/drivers/thermal/max77620_thermal.c
@@ -104,8 +104,6 @@ static int max77620_thermal_probe(struct platform_device *pdev)
return -EINVAL;
}
- pdev->dev.of_node = pdev->dev.parent->of_node;
-
mtherm->dev = &pdev->dev;
mtherm->rmap = dev_get_regmap(pdev->dev.parent, NULL);
if (!mtherm->rmap) {
@@ -113,6 +111,14 @@ static int max77620_thermal_probe(struct platform_device *pdev)
return -ENODEV;
}
+ /*
+ * Drop any current reference to a device-tree node and get a
+ * reference to the parent's node which will be balanced on reprobe or
+ * on platform-device release.
+ */
+ of_node_put(pdev->dev.of_node);
+ pdev->dev.of_node = of_node_get(pdev->dev.parent->of_node);
+
mtherm->tz_device = devm_thermal_zone_of_sensor_register(&pdev->dev, 0,
mtherm, &max77620_thermal_ops);
if (IS_ERR(mtherm->tz_device)) {
--
2.13.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/7] USB: core: fix device node leak
2017-05-30 16:25 ` [PATCH 1/7] USB: core: fix device node leak Johan Hovold
@ 2017-05-30 22:55 ` Tyrel Datwyler
2017-05-31 8:25 ` Johan Hovold
2017-06-05 3:35 ` Peter Chen
1 sibling, 1 reply; 7+ messages in thread
From: Tyrel Datwyler @ 2017-05-30 22:55 UTC (permalink / raw)
To: Johan Hovold, Greg Kroah-Hartman
Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
linux-kernel, stable, Peter Chen
On 05/30/2017 09:25 AM, Johan Hovold wrote:
> Make sure to release any OF device-node reference taken when creating
> the USB device.
>
> Note that we currently do not hold a reference to the root hub
> device-tree node (i.e. the parent controller node).
>
> Fixes: 69bec7259853 ("USB: core: let USB device know device node")
> Cc: stable <stable@vger.kernel.org> # v4.6
> Cc: Peter Chen <peter.chen@nxp.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
> drivers/usb/core/usb.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> index 28b053cacc90..62e1906bb2f3 100644
> --- a/drivers/usb/core/usb.c
> +++ b/drivers/usb/core/usb.c
> @@ -416,6 +416,8 @@ static void usb_release_dev(struct device *dev)
>
> usb_destroy_configuration(udev);
> usb_release_bos_descriptor(udev);
> + if (udev->parent)
> + of_node_put(dev->of_node);
If I'm following the root hub doesn't hold an of_node reference, so does that guarantee
that dev->of_node is NULL for the root hub? If so of_node_put() is safely called with a
NULL reference, making the if(udev->parent) unnecessary, and further no need to remove it
in follow-up patch #5.
-Tyrel
> usb_put_hcd(hcd);
> kfree(udev->product);
> kfree(udev->manufacturer);
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 6/7] thermal: max77620: fix device-node reference imbalance
2017-05-30 16:25 ` [PATCH 6/7] thermal: max77620: fix device-node reference imbalance Johan Hovold
@ 2017-05-30 22:59 ` Tyrel Datwyler
2017-05-31 8:28 ` Johan Hovold
0 siblings, 1 reply; 7+ messages in thread
From: Tyrel Datwyler @ 2017-05-30 22:59 UTC (permalink / raw)
To: Johan Hovold, Greg Kroah-Hartman
Cc: Linus Walleij, Peter Chen, Rob Herring, Arnd Bergmann,
Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm, linux-usb,
linux-kernel, stable, Laxman Dewangan
On 05/30/2017 09:25 AM, Johan Hovold wrote:
> The thermal child device reuses the parent MFD-device device-tree node
> when registering a thermal zone, but did not take a reference to the
> node.
>
> This leads to a reference imbalance, and potential use-after-free, when
> the node reference is dropped by the platform-bus device destructor
> (once for the child and later again for the parent).
>
> Fix this by dropping any reference already held to a device-tree node
> and getting a reference to the parent's node which will be balanced on
> reprobe or on platform-device release, whichever comes first.
>
> Note that simply clearing the of_node pointer on probe errors and on
> driver unbind would not allow the use of device-managed resources as
> specifically thermal_zone_of_sensor_unregister() claims that a valid
> device-tree node pointer is needed during deregistration (even if it
> currently does not seem to use it).
>
> Fixes: ec4664b3fd6d ("thermal: max77620: Add thermal driver for reporting junction temp")
> Cc: stable <stable@vger.kernel.org> # 4.9
> Cc: Laxman Dewangan <ldewangan@nvidia.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
> drivers/thermal/max77620_thermal.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c
> index e9a1fe342760..71d35f3c9215 100644
> --- a/drivers/thermal/max77620_thermal.c
> +++ b/drivers/thermal/max77620_thermal.c
> @@ -104,8 +104,6 @@ static int max77620_thermal_probe(struct platform_device *pdev)
> return -EINVAL;
> }
>
> - pdev->dev.of_node = pdev->dev.parent->of_node;
> -
> mtherm->dev = &pdev->dev;
> mtherm->rmap = dev_get_regmap(pdev->dev.parent, NULL);
> if (!mtherm->rmap) {
> @@ -113,6 +111,14 @@ static int max77620_thermal_probe(struct platform_device *pdev)
> return -ENODEV;
> }
>
> + /*
> + * Drop any current reference to a device-tree node and get a
> + * reference to the parent's node which will be balanced on reprobe or
> + * on platform-device release.
> + */
> + of_node_put(pdev->dev.of_node);
> + pdev->dev.of_node = of_node_get(pdev->dev.parent->of_node);
> +
This seems like needless churn. Can't this just be squashed into patch #7?
-Tyrel
> mtherm->tz_device = devm_thermal_zone_of_sensor_register(&pdev->dev, 0,
> mtherm, &max77620_thermal_ops);
> if (IS_ERR(mtherm->tz_device)) {
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/7] USB: core: fix device node leak
2017-05-30 22:55 ` Tyrel Datwyler
@ 2017-05-31 8:25 ` Johan Hovold
0 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2017-05-31 8:25 UTC (permalink / raw)
To: Tyrel Datwyler
Cc: Johan Hovold, Greg Kroah-Hartman, Linus Walleij, Peter Chen,
Rob Herring, Arnd Bergmann, Sricharan R, Zhang Rui,
Eduardo Valentin, linux-pm, linux-usb, linux-kernel, stable,
Peter Chen
On Tue, May 30, 2017 at 03:55:56PM -0700, Tyrel Datwyler wrote:
> On 05/30/2017 09:25 AM, Johan Hovold wrote:
> > Make sure to release any OF device-node reference taken when creating
> > the USB device.
> >
> > Note that we currently do not hold a reference to the root hub
> > device-tree node (i.e. the parent controller node).
> >
> > Fixes: 69bec7259853 ("USB: core: let USB device know device node")
> > Cc: stable <stable@vger.kernel.org> # v4.6
> > Cc: Peter Chen <peter.chen@nxp.com>
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> > ---
> > drivers/usb/core/usb.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> > index 28b053cacc90..62e1906bb2f3 100644
> > --- a/drivers/usb/core/usb.c
> > +++ b/drivers/usb/core/usb.c
> > @@ -416,6 +416,8 @@ static void usb_release_dev(struct device *dev)
> >
> > usb_destroy_configuration(udev);
> > usb_release_bos_descriptor(udev);
> > + if (udev->parent)
> > + of_node_put(dev->of_node);
>
> If I'm following the root hub doesn't hold an of_node reference, so
> does that guarantee that dev->of_node is NULL for the root hub?
No, it may be non-NULL.
> If so of_node_put() is safely called with a NULL reference, making the
> if(udev->parent) unnecessary, and further no need to remove it in
> follow-up patch #5.
So this one is still needed.
Thanks,
Johan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 6/7] thermal: max77620: fix device-node reference imbalance
2017-05-30 22:59 ` Tyrel Datwyler
@ 2017-05-31 8:28 ` Johan Hovold
0 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2017-05-31 8:28 UTC (permalink / raw)
To: Tyrel Datwyler
Cc: Johan Hovold, Greg Kroah-Hartman, Linus Walleij, Peter Chen,
Rob Herring, Arnd Bergmann, Sricharan R, Zhang Rui,
Eduardo Valentin, linux-pm, linux-usb, linux-kernel, stable,
Laxman Dewangan
On Tue, May 30, 2017 at 03:59:10PM -0700, Tyrel Datwyler wrote:
> On 05/30/2017 09:25 AM, Johan Hovold wrote:
> > The thermal child device reuses the parent MFD-device device-tree node
> > when registering a thermal zone, but did not take a reference to the
> > node.
> >
> > This leads to a reference imbalance, and potential use-after-free, when
> > the node reference is dropped by the platform-bus device destructor
> > (once for the child and later again for the parent).
> >
> > Fix this by dropping any reference already held to a device-tree node
> > and getting a reference to the parent's node which will be balanced on
> > reprobe or on platform-device release, whichever comes first.
> >
> > Note that simply clearing the of_node pointer on probe errors and on
> > driver unbind would not allow the use of device-managed resources as
> > specifically thermal_zone_of_sensor_unregister() claims that a valid
> > device-tree node pointer is needed during deregistration (even if it
> > currently does not seem to use it).
> >
> > Fixes: ec4664b3fd6d ("thermal: max77620: Add thermal driver for reporting junction temp")
> > Cc: stable <stable@vger.kernel.org> # 4.9
> > Cc: Laxman Dewangan <ldewangan@nvidia.com>
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> > ---
> > drivers/thermal/max77620_thermal.c | 10 ++++++++--
> > 1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/thermal/max77620_thermal.c b/drivers/thermal/max77620_thermal.c
> > index e9a1fe342760..71d35f3c9215 100644
> > --- a/drivers/thermal/max77620_thermal.c
> > +++ b/drivers/thermal/max77620_thermal.c
> > @@ -104,8 +104,6 @@ static int max77620_thermal_probe(struct platform_device *pdev)
> > return -EINVAL;
> > }
> >
> > - pdev->dev.of_node = pdev->dev.parent->of_node;
> > -
> > mtherm->dev = &pdev->dev;
> > mtherm->rmap = dev_get_regmap(pdev->dev.parent, NULL);
> > if (!mtherm->rmap) {
> > @@ -113,6 +111,14 @@ static int max77620_thermal_probe(struct platform_device *pdev)
> > return -ENODEV;
> > }
> >
> > + /*
> > + * Drop any current reference to a device-tree node and get a
> > + * reference to the parent's node which will be balanced on reprobe or
> > + * on platform-device release.
> > + */
> > + of_node_put(pdev->dev.of_node);
> > + pdev->dev.of_node = of_node_get(pdev->dev.parent->of_node);
> > +
>
> This seems like needless churn. Can't this just be squashed into patch
> #7?
As I just replied to Eduardo, I'm fixing two separate issues here of
which this one might qualify for stable while the other (7/7) does not.
Thanks,
Johan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/7] USB: core: fix device node leak
2017-05-30 16:25 ` [PATCH 1/7] USB: core: fix device node leak Johan Hovold
2017-05-30 22:55 ` Tyrel Datwyler
@ 2017-06-05 3:35 ` Peter Chen
1 sibling, 0 replies; 7+ messages in thread
From: Peter Chen @ 2017-06-05 3:35 UTC (permalink / raw)
To: Johan Hovold
Cc: Greg Kroah-Hartman, Linus Walleij, Peter Chen, Rob Herring,
Arnd Bergmann, Sricharan R, Zhang Rui, Eduardo Valentin, linux-pm,
linux-usb, linux-kernel, stable, Peter Chen
On Tue, May 30, 2017 at 06:25:48PM +0200, Johan Hovold wrote:
> Make sure to release any OF device-node reference taken when creating
> the USB device.
>
> Note that we currently do not hold a reference to the root hub
> device-tree node (i.e. the parent controller node).
>
> Fixes: 69bec7259853 ("USB: core: let USB device know device node")
> Cc: stable <stable@vger.kernel.org> # v4.6
> Cc: Peter Chen <peter.chen@nxp.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
> drivers/usb/core/usb.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> index 28b053cacc90..62e1906bb2f3 100644
> --- a/drivers/usb/core/usb.c
> +++ b/drivers/usb/core/usb.c
> @@ -416,6 +416,8 @@ static void usb_release_dev(struct device *dev)
>
> usb_destroy_configuration(udev);
> usb_release_bos_descriptor(udev);
> + if (udev->parent)
> + of_node_put(dev->of_node);
> usb_put_hcd(hcd);
> kfree(udev->product);
> kfree(udev->manufacturer);
Acked-by: Peter Chen <peter.chen@nxp.com>
--
Best Regards,
Peter Chen
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-06-05 3:35 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20170530162554.26159-1-johan@kernel.org>
2017-05-30 16:25 ` [PATCH 1/7] USB: core: fix device node leak Johan Hovold
2017-05-30 22:55 ` Tyrel Datwyler
2017-05-31 8:25 ` Johan Hovold
2017-06-05 3:35 ` Peter Chen
2017-05-30 16:25 ` [PATCH 6/7] thermal: max77620: fix device-node reference imbalance Johan Hovold
2017-05-30 22:59 ` Tyrel Datwyler
2017-05-31 8:28 ` Johan Hovold
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).