From: Dmitry Osipenko <digetx@gmail.com>
To: Zhang Rui <rui.zhang@intel.com>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Amit Kucheria <amitk@kernel.org>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] thermal: core: Fix use-after-free in thermal_zone_device_unregister()
Date: Tue, 18 Aug 2020 02:54:50 +0300 [thread overview]
Message-ID: <60ffd8e3-ca65-d0ff-4a7a-067923fc5ddd@gmail.com> (raw)
In-Reply-To: <20200817234833.23954-1-digetx@gmail.com>
18.08.2020 02:48, Dmitry Osipenko пишет:
> 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>
> ---
> drivers/thermal/thermal_core.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 72bf159bcecc..56c355f684df 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)
> @@ -1560,14 +1561,13 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
> cancel_delayed_work_sync(&tz->poll_queue);
>
> thermal_set_governor(tz, NULL);
> -
Woops, this line wasn't intended to be removed. Let me send a v2.
> thermal_remove_hwmon_sysfs(tz);
> ida_simple_remove(&thermal_tz_ida, tz->id);
> ida_destroy(&tz->ida);
> 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);
>
>
prev parent reply other threads:[~2020-08-17 23:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-17 23:48 [PATCH v1] thermal: core: Fix use-after-free in thermal_zone_device_unregister() Dmitry Osipenko
2020-08-17 23:54 ` Dmitry Osipenko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=60ffd8e3-ca65-d0ff-4a7a-067923fc5ddd@gmail.com \
--to=digetx@gmail.com \
--cc=amitk@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rui.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).