2010-11-19 18:42:23

by Vasily Kulikov

[permalink] [raw]
Subject: [PATCH] power: power_supply_core: fix use after free and memory leak

device_unregister() might free its argument. This leads to freed
memory use in kfree(). Also use put_device() instead of kfree()
as dev may be already used in another layer after call to device_add().

Signed-off-by: Vasiliy Kulikov <[email protected]>
---
Compile tested only.

drivers/power/power_supply_core.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index 91606bb..f06bad0 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -190,10 +190,10 @@ int power_supply_register(struct device *parent, struct power_supply *psy)
goto success;

create_triggers_failed:
- device_unregister(psy->dev);
+ device_del(dev);
kobject_set_name_failed:
device_add_failed:
- kfree(dev);
+ put_device(dev);
success:
return rc;
}
--
1.7.0.4


2010-12-22 00:05:51

by Anton Vorontsov

[permalink] [raw]
Subject: Re: [PATCH] power: power_supply_core: fix use after free and memory leak

On Fri, Nov 19, 2010 at 09:41:58PM +0300, Vasiliy Kulikov wrote:
> device_unregister() might free its argument. This leads to freed
> memory use in kfree(). Also use put_device() instead of kfree()
> as dev may be already used in another layer after call to device_add().
>
> Signed-off-by: Vasiliy Kulikov <[email protected]>

Applied, thanks!

> ---
> Compile tested only.
>
> drivers/power/power_supply_core.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
> index 91606bb..f06bad0 100644
> --- a/drivers/power/power_supply_core.c
> +++ b/drivers/power/power_supply_core.c
> @@ -190,10 +190,10 @@ int power_supply_register(struct device *parent, struct power_supply *psy)
> goto success;
>
> create_triggers_failed:
> - device_unregister(psy->dev);
> + device_del(dev);
> kobject_set_name_failed:
> device_add_failed:
> - kfree(dev);
> + put_device(dev);
> success:
> return rc;
> }
> --
> 1.7.0.4

--
Anton Vorontsov
Email: [email protected]