* [PATCH v2] thermal: core: Fix use-after-free in thermal_zone_device_unregister()
@ 2020-08-17 23:58 Dmitry Osipenko
2020-08-24 9:34 ` Daniel Lezcano
0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Osipenko @ 2020-08-17 23:58 UTC (permalink / raw)
To: Zhang Rui, Daniel Lezcano, Amit Kucheria; +Cc: linux-pm, linux-kernel
The user-after-free bug in thermal_zone_device_unregister() is reported by
KASAN. It happens because struct thermal_zone_device is released during of
device_unregister() invocation, and hence the "tz" variable shouldn't be
touched by thermal_notify_tz_delete(tz->id).
Fixes: 55cdf0a283b8 ("thermal: core: Add notifications call in the framework")
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
Changelog:
v2: - Don't touch lines unrelated to the actual fix.
drivers/thermal/thermal_core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 72bf159bcecc..a6616e530a84 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1516,7 +1516,7 @@ EXPORT_SYMBOL_GPL(thermal_zone_device_register);
*/
void thermal_zone_device_unregister(struct thermal_zone_device *tz)
{
- int i;
+ int i, tz_id;
const struct thermal_zone_params *tzp;
struct thermal_cooling_device *cdev;
struct thermal_zone_device *pos = NULL;
@@ -1525,6 +1525,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
return;
tzp = tz->tzp;
+ tz_id = tz->id;
mutex_lock(&thermal_list_lock);
list_for_each_entry(pos, &thermal_tz_list, node)
@@ -1567,7 +1568,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
mutex_destroy(&tz->lock);
device_unregister(&tz->device);
- thermal_notify_tz_delete(tz->id);
+ thermal_notify_tz_delete(tz_id);
}
EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);
--
2.27.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] thermal: core: Fix use-after-free in thermal_zone_device_unregister()
2020-08-17 23:58 [PATCH v2] thermal: core: Fix use-after-free in thermal_zone_device_unregister() Dmitry Osipenko
@ 2020-08-24 9:34 ` Daniel Lezcano
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Lezcano @ 2020-08-24 9:34 UTC (permalink / raw)
To: Dmitry Osipenko, Zhang Rui, Amit Kucheria; +Cc: linux-pm, linux-kernel
On 18/08/2020 01:58, Dmitry Osipenko wrote:
> The user-after-free bug in thermal_zone_device_unregister() is reported by
> KASAN. It happens because struct thermal_zone_device is released during of
> device_unregister() invocation, and hence the "tz" variable shouldn't be
> touched by thermal_notify_tz_delete(tz->id).
>
> Fixes: 55cdf0a283b8 ("thermal: core: Add notifications call in the framework")
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
Applied, thanks !
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-08-24 9:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-17 23:58 [PATCH v2] thermal: core: Fix use-after-free in thermal_zone_device_unregister() Dmitry Osipenko
2020-08-24 9:34 ` Daniel Lezcano
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).