From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: Ido Schimmel <idosch@idosch.org>
Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
lukasz.luba@arm.com, Jiri Pirko <jiri@nvidia.com>,
Ido Schimmel <idosch@nvidia.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Zhang Rui <rui.zhang@intel.com>,
Amit Kucheria <amitk@kernel.org>,
"open list:MELLANOX ETHERNET SWITCH DRIVERS"
<netdev@vger.kernel.org>
Subject: Re: [PATCH v2 1/5] thermal/drivers/core: Use a char pointer for the cooling device name
Date: Sun, 14 Mar 2021 11:48:53 +0100 [thread overview]
Message-ID: <f4d7d072-2c4f-2d9d-8628-0c8c83b76f4d@linaro.org> (raw)
In-Reply-To: <YE3dMM7tqk5BbD/l@shredder.lan>
Hi Ido,
On 14/03/2021 10:53, Ido Schimmel wrote:
> On Fri, Mar 12, 2021 at 06:03:12PM +0100, Daniel Lezcano wrote:
>> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
>> index 996c038f83a4..9ef8090eb645 100644
>> --- a/drivers/thermal/thermal_core.c
>> +++ b/drivers/thermal/thermal_core.c
>> @@ -960,10 +960,7 @@ __thermal_cooling_device_register(struct device_node *np,
[ ... ]
>> /**
>> @@ -1172,6 +1177,7 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
>> device_del(&cdev->device);
>> thermal_cooling_device_destroy_sysfs(cdev);
>> put_device(&cdev->device);
>> + kfree(cdev->type);
>> }
>> EXPORT_SYMBOL_GPL(thermal_cooling_device_unregister);
>
> I'm getting the following user-after-free with this patch [1]. Fixed by:
>
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 9ef8090eb645..c8d4010940ef 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -1176,8 +1176,8 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
> ida_simple_remove(&thermal_cdev_ida, cdev->id);
> device_del(&cdev->device);
> thermal_cooling_device_destroy_sysfs(cdev);
> - put_device(&cdev->device);
> kfree(cdev->type);
> + put_device(&cdev->device);
Indeed 'thermal_release' frees the cdev pointer and is called by
put_device, then kfree use the pointer right after.
Thanks for the fix
-- Daniel
--
<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
prev parent reply other threads:[~2021-03-14 10:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-12 17:03 [PATCH v2 1/5] thermal/drivers/core: Use a char pointer for the cooling device name Daniel Lezcano
2021-03-12 18:49 ` Lukasz Luba
2021-03-12 21:01 ` Daniel Lezcano
2021-03-15 9:40 ` Lukasz Luba
2021-03-15 9:58 ` Lukasz Luba
2021-03-14 9:53 ` Ido Schimmel
2021-03-14 10:48 ` Daniel Lezcano [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=f4d7d072-2c4f-2d9d-8628-0c8c83b76f4d@linaro.org \
--to=daniel.lezcano@linaro.org \
--cc=amitk@kernel.org \
--cc=davem@davemloft.net \
--cc=idosch@idosch.org \
--cc=idosch@nvidia.com \
--cc=jiri@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=netdev@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).