* [PATCH] thermal: Fix NULL pointer dereference issue
@ 2020-11-16 16:29 Mukesh Ojha
2020-11-17 7:18 ` Zhang Rui
0 siblings, 1 reply; 5+ messages in thread
From: Mukesh Ojha @ 2020-11-16 16:29 UTC (permalink / raw)
To: linux-pm, linux-kernel; +Cc: rui.zhang, daniel.lezcano, amitk, Mukesh Ojha
Cooling stats variable inside thermal_cooling_device_stats_update()
can get NULL. We should add a NULL check on stat inside for sanity.
Signed-off-by: Mukesh Ojha <mojha@codeaurora.org>
---
drivers/thermal/thermal_sysfs.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index a6f371f..f52708f 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -754,6 +754,9 @@ void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
{
struct cooling_dev_stats *stats = cdev->stats;
+ if (!stats)
+ return;
+
spin_lock(&stats->lock);
if (stats->state == new_state)
--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center,
Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] thermal: Fix NULL pointer dereference issue
2020-11-16 16:29 [PATCH] thermal: Fix NULL pointer dereference issue Mukesh Ojha
@ 2020-11-17 7:18 ` Zhang Rui
2020-11-17 8:57 ` Daniel Lezcano
0 siblings, 1 reply; 5+ messages in thread
From: Zhang Rui @ 2020-11-17 7:18 UTC (permalink / raw)
To: Mukesh Ojha, linux-pm, linux-kernel; +Cc: daniel.lezcano, amitk
On Mon, 2020-11-16 at 21:59 +0530, Mukesh Ojha wrote:
> Cooling stats variable inside thermal_cooling_device_stats_update()
> can get NULL. We should add a NULL check on stat inside for sanity.
>
> Signed-off-by: Mukesh Ojha <mojha@codeaurora.org>
> ---
> drivers/thermal/thermal_sysfs.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/thermal/thermal_sysfs.c
> b/drivers/thermal/thermal_sysfs.c
> index a6f371f..f52708f 100644
> --- a/drivers/thermal/thermal_sysfs.c
> +++ b/drivers/thermal/thermal_sysfs.c
> @@ -754,6 +754,9 @@ void thermal_cooling_device_stats_update(struct
> thermal_cooling_device *cdev,
> {
> struct cooling_dev_stats *stats = cdev->stats;
>
> + if (!stats)
> + return;
> +
May I know in which case stats can be NULL?
The only possibility I can see is that cdev->ops->get_max_state() fails
in cooling_device_stats_setup(), right?
thanks,
rui
> spin_lock(&stats->lock);
>
> if (stats->state == new_state)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] thermal: Fix NULL pointer dereference issue
2020-11-17 7:18 ` Zhang Rui
@ 2020-11-17 8:57 ` Daniel Lezcano
2020-11-17 11:27 ` Zhang Rui
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Lezcano @ 2020-11-17 8:57 UTC (permalink / raw)
To: Zhang Rui, Mukesh Ojha, linux-pm, linux-kernel; +Cc: amitk
On 17/11/2020 08:18, Zhang Rui wrote:
> On Mon, 2020-11-16 at 21:59 +0530, Mukesh Ojha wrote:
>> Cooling stats variable inside thermal_cooling_device_stats_update()
>> can get NULL. We should add a NULL check on stat inside for sanity.
>>
>> Signed-off-by: Mukesh Ojha <mojha@codeaurora.org>
>> ---
>> drivers/thermal/thermal_sysfs.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/thermal/thermal_sysfs.c
>> b/drivers/thermal/thermal_sysfs.c
>> index a6f371f..f52708f 100644
>> --- a/drivers/thermal/thermal_sysfs.c
>> +++ b/drivers/thermal/thermal_sysfs.c
>> @@ -754,6 +754,9 @@ void thermal_cooling_device_stats_update(struct
>> thermal_cooling_device *cdev,
>> {
>> struct cooling_dev_stats *stats = cdev->stats;
>>
>> + if (!stats)
>> + return;
>> +
> May I know in which case stats can be NULL?
> The only possibility I can see is that cdev->ops->get_max_state() fails
> in cooling_device_stats_setup(), right?
A few lines below, the allocation could fail.
stats = kzalloc(var, GFP_KERNEL);
if (!stats)
return;
Some drivers define themselves as a cooling device state to let the
userspace to act on their power. The screen brightness is one example
with a cdev with 1024 states, the resulting stats table to be allocated
is very big and the kzalloc is prone to fail.
> thanks,
> rui
>
>> spin_lock(&stats->lock);
>>
>> if (stats->state == new_state)
>
--
<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] 5+ messages in thread
* Re: [PATCH] thermal: Fix NULL pointer dereference issue
2020-11-17 8:57 ` Daniel Lezcano
@ 2020-11-17 11:27 ` Zhang Rui
2020-11-17 12:08 ` Daniel Lezcano
0 siblings, 1 reply; 5+ messages in thread
From: Zhang Rui @ 2020-11-17 11:27 UTC (permalink / raw)
To: Daniel Lezcano, Mukesh Ojha, linux-pm, linux-kernel; +Cc: amitk
On Tue, 2020-11-17 at 09:57 +0100, Daniel Lezcano wrote:
> On 17/11/2020 08:18, Zhang Rui wrote:
> > On Mon, 2020-11-16 at 21:59 +0530, Mukesh Ojha wrote:
> > > Cooling stats variable inside
> > > thermal_cooling_device_stats_update()
> > > can get NULL. We should add a NULL check on stat inside for
> > > sanity.
> > >
> > > Signed-off-by: Mukesh Ojha <mojha@codeaurora.org>
> > > ---
> > > drivers/thermal/thermal_sysfs.c | 3 +++
> > > 1 file changed, 3 insertions(+)
> > >
> > > diff --git a/drivers/thermal/thermal_sysfs.c
> > > b/drivers/thermal/thermal_sysfs.c
> > > index a6f371f..f52708f 100644
> > > --- a/drivers/thermal/thermal_sysfs.c
> > > +++ b/drivers/thermal/thermal_sysfs.c
> > > @@ -754,6 +754,9 @@ void
> > > thermal_cooling_device_stats_update(struct
> > > thermal_cooling_device *cdev,
> > > {
> > > struct cooling_dev_stats *stats = cdev->stats;
> > >
> > > + if (!stats)
> > > + return;
> > > +
> >
> > May I know in which case stats can be NULL?
> > The only possibility I can see is that cdev->ops->get_max_state()
> > fails
> > in cooling_device_stats_setup(), right?
>
> A few lines below, the allocation could fail.
>
> stats = kzalloc(var, GFP_KERNEL);
> if (!stats)
> return;
>
> Some drivers define themselves as a cooling device state to let the
> userspace to act on their power. The screen brightness is one example
> with a cdev with 1024 states, the resulting stats table to be
> allocated
> is very big and the kzalloc is prone to fail.
>
Oh, right.
As we're not going to fix the cdev, so I think we do need this patch,
right?
thanks,
rui
> > thanks,
> > rui
> >
> > > spin_lock(&stats->lock);
> > >
> > > if (stats->state == new_state)
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] thermal: Fix NULL pointer dereference issue
2020-11-17 11:27 ` Zhang Rui
@ 2020-11-17 12:08 ` Daniel Lezcano
0 siblings, 0 replies; 5+ messages in thread
From: Daniel Lezcano @ 2020-11-17 12:08 UTC (permalink / raw)
To: Zhang Rui, Mukesh Ojha, linux-pm, linux-kernel; +Cc: amitk
On 17/11/2020 12:27, Zhang Rui wrote:
> On Tue, 2020-11-17 at 09:57 +0100, Daniel Lezcano wrote:
>> On 17/11/2020 08:18, Zhang Rui wrote:
>>> On Mon, 2020-11-16 at 21:59 +0530, Mukesh Ojha wrote:
>>>> Cooling stats variable inside
>>>> thermal_cooling_device_stats_update()
>>>> can get NULL. We should add a NULL check on stat inside for
>>>> sanity.
>>>>
>>>> Signed-off-by: Mukesh Ojha <mojha@codeaurora.org>
>>>> ---
>>>> drivers/thermal/thermal_sysfs.c | 3 +++
>>>> 1 file changed, 3 insertions(+)
>>>>
>>>> diff --git a/drivers/thermal/thermal_sysfs.c
>>>> b/drivers/thermal/thermal_sysfs.c
>>>> index a6f371f..f52708f 100644
>>>> --- a/drivers/thermal/thermal_sysfs.c
>>>> +++ b/drivers/thermal/thermal_sysfs.c
>>>> @@ -754,6 +754,9 @@ void
>>>> thermal_cooling_device_stats_update(struct
>>>> thermal_cooling_device *cdev,
>>>> {
>>>> struct cooling_dev_stats *stats = cdev->stats;
>>>>
>>>> + if (!stats)
>>>> + return;
>>>> +
>>>
>>> May I know in which case stats can be NULL?
>>> The only possibility I can see is that cdev->ops->get_max_state()
>>> fails
>>> in cooling_device_stats_setup(), right?
>>
>> A few lines below, the allocation could fail.
>>
>> stats = kzalloc(var, GFP_KERNEL);
>> if (!stats)
>> return;
>>
>> Some drivers define themselves as a cooling device state to let the
>> userspace to act on their power. The screen brightness is one example
>> with a cdev with 1024 states, the resulting stats table to be
>> allocated
>> is very big and the kzalloc is prone to fail.
>>
> Oh, right.
> As we're not going to fix the cdev, so I think we do need this patch,
> right?
If the allocation fails at this level if initialization there is clearly
something wrong. I'm wondering if it would make sense to report back an
error and make thermal_cooling_device_register to fail.
Having an allocation failing and silently ignore it sounds like not very
robust IMO.
--
<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] 5+ messages in thread
end of thread, other threads:[~2020-11-17 12:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-16 16:29 [PATCH] thermal: Fix NULL pointer dereference issue Mukesh Ojha
2020-11-17 7:18 ` Zhang Rui
2020-11-17 8:57 ` Daniel Lezcano
2020-11-17 11:27 ` Zhang Rui
2020-11-17 12:08 ` 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).