linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bus: vexpress-config: fix device reference leak
@ 2016-11-01 10:43 Johan Hovold
  2016-11-04 11:42 ` Pawel Moll
  2016-11-16 16:48 ` Sudeep Holla
  0 siblings, 2 replies; 5+ messages in thread
From: Johan Hovold @ 2016-11-01 10:43 UTC (permalink / raw)
  To: linux-arm-kernel

Make sure to drop the reference to the parent device taken by
class_find_device() after populating the bus.

Fixes: 3b9334ac835b ("mfd: vexpress: Convert custom func API to regmap")
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/bus/vexpress-config.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/vexpress-config.c b/drivers/bus/vexpress-config.c
index 9efdf1de4035..493e7b9fc813 100644
--- a/drivers/bus/vexpress-config.c
+++ b/drivers/bus/vexpress-config.c
@@ -171,6 +171,7 @@ static int vexpress_config_populate(struct device_node *node)
 {
 	struct device_node *bridge;
 	struct device *parent;
+	int ret;
 
 	bridge = of_parse_phandle(node, "arm,vexpress,config-bridge", 0);
 	if (!bridge)
@@ -182,7 +183,11 @@ static int vexpress_config_populate(struct device_node *node)
 	if (WARN_ON(!parent))
 		return -ENODEV;
 
-	return of_platform_populate(node, NULL, NULL, parent);
+	ret = of_platform_populate(node, NULL, NULL, parent);
+
+	put_device(parent);
+
+	return ret;
 }
 
 static int __init vexpress_config_init(void)
-- 
2.7.3

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

* [PATCH] bus: vexpress-config: fix device reference leak
  2016-11-01 10:43 [PATCH] bus: vexpress-config: fix device reference leak Johan Hovold
@ 2016-11-04 11:42 ` Pawel Moll
  2016-11-04 12:21   ` Russell King - ARM Linux
  2016-11-04 13:03   ` Johan Hovold
  2016-11-16 16:48 ` Sudeep Holla
  1 sibling, 2 replies; 5+ messages in thread
From: Pawel Moll @ 2016-11-04 11:42 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, 2016-11-01 at 11:43 +0100, Johan Hovold wrote:
> Make sure to drop the reference to the parent device taken by
> class_find_device() after populating the bus.
> 
> Fixes: 3b9334ac835b ("mfd: vexpress: Convert custom func API to
> regmap")
> Signed-off-by: Johan Hovold <johan@kernel.org>

You're right. May I ask how did you figure it out? The get_device()
happening in class_find_device() is a bit obscure, so have you simply
followed places where it's being used or used some static (?) analysis
tool? If the latter, I'd be very curios to hear what was it :-)

Acked-by: Pawel Moll <pawel.moll@arm.com>

Thanks!

Pawel

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

* [PATCH] bus: vexpress-config: fix device reference leak
  2016-11-04 11:42 ` Pawel Moll
@ 2016-11-04 12:21   ` Russell King - ARM Linux
  2016-11-04 13:03   ` Johan Hovold
  1 sibling, 0 replies; 5+ messages in thread
From: Russell King - ARM Linux @ 2016-11-04 12:21 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Nov 04, 2016 at 11:42:26AM +0000, Pawel Moll wrote:
> On Tue, 2016-11-01 at 11:43 +0100, Johan Hovold wrote:
> > Make sure to drop the reference to the parent device taken by
> > class_find_device() after populating the bus.
> > 
> > Fixes: 3b9334ac835b ("mfd: vexpress: Convert custom func API to
> > regmap")
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> 
> You're right. May I ask how did you figure it out? The get_device()
> happening in class_find_device() is a bit obscure,

It's not obscure at all - all the functions that find a device do so
under a lock to ensure that the device does not go away, and they
take a reference count on the device before returning the pointer for
exactly the same reason.

If they didn't do that, the find function could locate a struct device
while another thread is deleting the struct device, and it would then
return a stale pointer - and dereferencing that pointer would then be
a use-after-free bug.

So not obscure, but rather fundamentally necessary.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

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

* [PATCH] bus: vexpress-config: fix device reference leak
  2016-11-04 11:42 ` Pawel Moll
  2016-11-04 12:21   ` Russell King - ARM Linux
@ 2016-11-04 13:03   ` Johan Hovold
  1 sibling, 0 replies; 5+ messages in thread
From: Johan Hovold @ 2016-11-04 13:03 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Nov 04, 2016 at 11:42:26AM +0000, Pawel Moll wrote:
> On Tue, 2016-11-01 at 11:43 +0100, Johan Hovold wrote:
> > Make sure to drop the reference to the parent device taken by
> > class_find_device() after populating the bus.
> > 
> > Fixes: 3b9334ac835b ("mfd: vexpress: Convert custom func API to
> > regmap")
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> 
> You're right. May I ask how did you figure it out? The get_device()
> happening in class_find_device() is a bit obscure, so have you simply
> followed places where it's being used or used some static (?) analysis
> tool? If the latter, I'd be very curios to hear what was it :-)

I stumbled over one of these leaks and grepped and searched for more.
I've submitted a few patches this week fixing some of the more obvious
ones, but there are more lurking behind various subsystem wrappers.

Thanks,
Johan

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

* [PATCH] bus: vexpress-config: fix device reference leak
  2016-11-01 10:43 [PATCH] bus: vexpress-config: fix device reference leak Johan Hovold
  2016-11-04 11:42 ` Pawel Moll
@ 2016-11-16 16:48 ` Sudeep Holla
  1 sibling, 0 replies; 5+ messages in thread
From: Sudeep Holla @ 2016-11-16 16:48 UTC (permalink / raw)
  To: linux-arm-kernel



On 01/11/16 10:43, Johan Hovold wrote:
> Make sure to drop the reference to the parent device taken by
> class_find_device() after populating the bus.
>

Thanks for the fix. I somehow missed this patch, sorry for that.
Not sure if arm-soc guys take this as a fix for v4.9, and I have already
sent PR for v4.10. I will repost this along with the ack and check with
them.

-- 
Regards,
Sudeep

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

end of thread, other threads:[~2016-11-16 16:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-01 10:43 [PATCH] bus: vexpress-config: fix device reference leak Johan Hovold
2016-11-04 11:42 ` Pawel Moll
2016-11-04 12:21   ` Russell King - ARM Linux
2016-11-04 13:03   ` Johan Hovold
2016-11-16 16:48 ` Sudeep Holla

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).