[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <11d30081b64935c2c3d45e5197cabbc25082a3fe.camel@axis.com>
Date: Tue, 19 Sep 2023 07:33:01 +0000
From: Vincent Whitchurch <Vincent.Whitchurch@...s.com>
To: "sre@...nel.org" <sre@...nel.org>,
Vincent Whitchurch <Vincent.Whitchurch@...s.com>
CC: "mazziesaccount@...il.com" <mazziesaccount@...il.com>,
"linux-pm@...r.kernel.org" <linux-pm@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
kernel <kernel@...s.com>,
"linus.walleij@...aro.org" <linus.walleij@...aro.org>
Subject: Re: [PATCH] power: supply: Fix info use-after-free
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@...s.com>
Powered by blists - more mailing lists