lkml.org 
[lkml]   [2023]   [Sep]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] power: supply: Fix info use-after-free
Date
On Mon, 2023-09-18 at 17:04 +0200, Sebastian Reichel wrote:
> diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
> index 06e5b6b0e255..d483a81560ab 100644
> --- a/drivers/power/supply/power_supply_sysfs.c
> +++ b/drivers/power/supply/power_supply_sysfs.c
> @@ -482,6 +482,13 @@ int power_supply_uevent(const struct device *dev, struct kobj_uevent_env *env)
>         if (ret)
>                 return ret;
>  
>
> + /*
> + * Kernel generates KOBJ_REMOVE uevent in device removal path, after
> + * resources have been freed. Exit early to avoid use-after-free.
> + */
> + if (psy->removing)
> + return 0;
> +
>         prop_buf = (char *)get_zeroed_page(GFP_KERNEL);
>         if (!prop_buf)
>                 return -ENOMEM;
>
> That would also cover the no-parent-device part and avoid the
> device(s) being queried for data at device removal time, which
> wouldn't work if the device removal happens due to a hot-unplug.

Works for me.

Tested-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
\
 
 \ /
  Last update: 2023-09-19 10:46    [W:0.091 / U:0.544 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site