All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] thermal: Add a sanity check for invalid state at stats update
@ 2020-03-30 14:08 Takashi Iwai
  2020-04-07 13:30 ` Amit Kucheria
  0 siblings, 1 reply; 5+ messages in thread
From: Takashi Iwai @ 2020-03-30 14:08 UTC (permalink / raw)
  To: Zhang Rui, Daniel Lezcano; +Cc: Amit Kucheria, linux-pm, linux-kernel

The thermal sysfs handler keeps the statistics table with the fixed
size that was determined from the initial max_states() call, and the
table entry is updated at each sysfs cur_state write call.  And, when
the driver's set_cur_state() ops accepts the value given from
user-space, the thermal sysfs core blindly applies it to the
statistics table entry, which may overflow and cause an Oops.
Although it's rather a bug in the driver's ops implementations, we
shouldn't crash but rather give a proper warning instead.

This patch adds a sanity check for avoiding such an OOB access and
warns with a stack trace to show the suspicious device in question.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---

We've hit some crash by stress tests, and this patch at least works
around the crash itself.  While the actual bug fix of the buggy driver
is still being investigated, I submit the hardening in the core side
at first.

 drivers/thermal/thermal_sysfs.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index aa99edb4dff7..a23c4e701d63 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -772,6 +772,11 @@ void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
 
 	spin_lock(&stats->lock);
 
+	if (dev_WARN_ONCE(&cdev->device, new_state >= stats->max_states,
+			  "new state %ld exceeds max_state %ld",
+			  new_state, stats->max_states))
+		goto unlock;
+
 	if (stats->state == new_state)
 		goto unlock;
 
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] thermal: Add a sanity check for invalid state at stats update
  2020-03-30 14:08 [PATCH] thermal: Add a sanity check for invalid state at stats update Takashi Iwai
@ 2020-04-07 13:30 ` Amit Kucheria
  2020-04-07 14:12   ` Takashi Iwai
  0 siblings, 1 reply; 5+ messages in thread
From: Amit Kucheria @ 2020-04-07 13:30 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Zhang Rui, Daniel Lezcano, Linux PM list, LKML

[-- Attachment #1: Type: text/plain, Size: 1954 bytes --]

On Mon, Mar 30, 2020 at 7:39 PM Takashi Iwai <tiwai@suse.de> wrote:
>
> The thermal sysfs handler keeps the statistics table with the fixed
> size that was determined from the initial max_states() call, and the
> table entry is updated at each sysfs cur_state write call.  And, when
> the driver's set_cur_state() ops accepts the value given from
> user-space, the thermal sysfs core blindly applies it to the
> statistics table entry, which may overflow and cause an Oops.
> Although it's rather a bug in the driver's ops implementations, we
> shouldn't crash but rather give a proper warning instead.
>
> This patch adds a sanity check for avoiding such an OOB access and
> warns with a stack trace to show the suspicious device in question.

Hi Takashi,

Instead of this warning, I think we should reject such input when
writing to cur_state.

See attached patch. If you think this OK, I'll submit it.

Regards,
Amit

> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
>
> We've hit some crash by stress tests, and this patch at least works
> around the crash itself.  While the actual bug fix of the buggy driver
> is still being investigated, I submit the hardening in the core side
> at first.
>
>  drivers/thermal/thermal_sysfs.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
> index aa99edb4dff7..a23c4e701d63 100644
> --- a/drivers/thermal/thermal_sysfs.c
> +++ b/drivers/thermal/thermal_sysfs.c
> @@ -772,6 +772,11 @@ void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
>
>         spin_lock(&stats->lock);
>
> +       if (dev_WARN_ONCE(&cdev->device, new_state >= stats->max_states,
> +                         "new state %ld exceeds max_state %ld",
> +                         new_state, stats->max_states))
> +               goto unlock;
> +
>         if (stats->state == new_state)
>                 goto unlock;
>
> --
> 2.16.4
>

[-- Attachment #2: 0001-thermal-Reject-invalid-cur_state-input-from-userspac.patch --]
[-- Type: text/x-patch, Size: 1808 bytes --]

From 54266260d483ab4476510dd4461a1cafc611e17d Mon Sep 17 00:00:00 2001
Message-Id: <54266260d483ab4476510dd4461a1cafc611e17d.1586266224.git.amit.kucheria@linaro.org>
From: Amit Kucheria <amit.kucheria@linaro.org>
Date: Tue, 7 Apr 2020 18:48:14 +0530
Subject: [PATCH] thermal: Reject invalid cur_state input from userspace

We don't check if the cur_state value input in sysfs is greater than the
maximum cooling state that the cooling device supports. This can cause
access to unallocated memory in case THERMAL_STATISTICS in enabled and
could also crash cooling devices that don't check for an invalid state in
their set_cur_state() callback.

Return an error if the state being requested in greater than the maximum
cooling state the device supports.

Reported-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
---
 drivers/thermal/thermal_sysfs.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index 7e1d11bdd258..8033e5a9386a 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -703,7 +703,7 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
 		const char *buf, size_t count)
 {
 	struct thermal_cooling_device *cdev = to_cooling_device(dev);
-	unsigned long state;
+	unsigned long state, max_state;
 	int result;
 
 	if (sscanf(buf, "%ld\n", &state) != 1)
@@ -712,6 +712,13 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
 	if ((long)state < 0)
 		return -EINVAL;
 
+	result = cdev->ops->get_max_state(cdev, &max_state);
+	if (result)
+		return result;
+
+	if (state >= max_state)
+		return -EINVAL;
+
 	mutex_lock(&cdev->lock);
 
 	result = cdev->ops->set_cur_state(cdev, state);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] thermal: Add a sanity check for invalid state at stats update
  2020-04-07 13:30 ` Amit Kucheria
@ 2020-04-07 14:12   ` Takashi Iwai
  2020-04-07 14:17     ` Zhang, Rui
  0 siblings, 1 reply; 5+ messages in thread
From: Takashi Iwai @ 2020-04-07 14:12 UTC (permalink / raw)
  To: Amit Kucheria
  Cc: Takashi Iwai, Zhang Rui, Daniel Lezcano, Linux PM list, LKML

On Tue, 07 Apr 2020 15:30:51 +0200,
Amit Kucheria wrote:
> 
> On Mon, Mar 30, 2020 at 7:39 PM Takashi Iwai <tiwai@suse.de> wrote:
> >
> > The thermal sysfs handler keeps the statistics table with the fixed
> > size that was determined from the initial max_states() call, and the
> > table entry is updated at each sysfs cur_state write call.  And, when
> > the driver's set_cur_state() ops accepts the value given from
> > user-space, the thermal sysfs core blindly applies it to the
> > statistics table entry, which may overflow and cause an Oops.
> > Although it's rather a bug in the driver's ops implementations, we
> > shouldn't crash but rather give a proper warning instead.
> >
> > This patch adds a sanity check for avoiding such an OOB access and
> > warns with a stack trace to show the suspicious device in question.
> 
> Hi Takashi,
> 
> Instead of this warning, I think we should reject such input when
> writing to cur_state.
> 
> See attached patch. If you think this OK, I'll submit it.

Actually the input value itself is correct, the problem is rather
about the max_states that may vary depending on other driver.  So IMO,
we don't want to refuse the input completely.

Please see the thread:
  https://lore.kernel.org/linux-acpi/s5h5zeiwd01.wl-tiwai@suse.de/


thanks,

Takashi


> 
> Regards,
> Amit
> 
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > ---
> >
> > We've hit some crash by stress tests, and this patch at least works
> > around the crash itself.  While the actual bug fix of the buggy driver
> > is still being investigated, I submit the hardening in the core side
> > at first.
> >
> >  drivers/thermal/thermal_sysfs.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
> > index aa99edb4dff7..a23c4e701d63 100644
> > --- a/drivers/thermal/thermal_sysfs.c
> > +++ b/drivers/thermal/thermal_sysfs.c
> > @@ -772,6 +772,11 @@ void thermal_cooling_device_stats_update(struct thermal_cooling_device *cdev,
> >
> >         spin_lock(&stats->lock);
> >
> > +       if (dev_WARN_ONCE(&cdev->device, new_state >= stats->max_states,
> > +                         "new state %ld exceeds max_state %ld",
> > +                         new_state, stats->max_states))
> > +               goto unlock;
> > +
> >         if (stats->state == new_state)
> >                 goto unlock;
> >
> > --
> > 2.16.4
> >
> From 54266260d483ab4476510dd4461a1cafc611e17d Mon Sep 17 00:00:00 2001
> Message-Id: <54266260d483ab4476510dd4461a1cafc611e17d.1586266224.git.amit.kucheria@linaro.org>
> From: Amit Kucheria <amit.kucheria@linaro.org>
> Date: Tue, 7 Apr 2020 18:48:14 +0530
> Subject: [PATCH] thermal: Reject invalid cur_state input from userspace
> 
> We don't check if the cur_state value input in sysfs is greater than the
> maximum cooling state that the cooling device supports. This can cause
> access to unallocated memory in case THERMAL_STATISTICS in enabled and
> could also crash cooling devices that don't check for an invalid state in
> their set_cur_state() callback.
> 
> Return an error if the state being requested in greater than the maximum
> cooling state the device supports.
> 
> Reported-by: Takashi Iwai <tiwai@suse.de>
> Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
> ---
>  drivers/thermal/thermal_sysfs.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
> index 7e1d11bdd258..8033e5a9386a 100644
> --- a/drivers/thermal/thermal_sysfs.c
> +++ b/drivers/thermal/thermal_sysfs.c
> @@ -703,7 +703,7 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
>  		const char *buf, size_t count)
>  {
>  	struct thermal_cooling_device *cdev = to_cooling_device(dev);
> -	unsigned long state;
> +	unsigned long state, max_state;
>  	int result;
>  
>  	if (sscanf(buf, "%ld\n", &state) != 1)
> @@ -712,6 +712,13 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
>  	if ((long)state < 0)
>  		return -EINVAL;
>  
> +	result = cdev->ops->get_max_state(cdev, &max_state);
> +	if (result)
> +		return result;
> +
> +	if (state >= max_state)
> +		return -EINVAL;
> +
>  	mutex_lock(&cdev->lock);
>  
>  	result = cdev->ops->set_cur_state(cdev, state);
> -- 
> 2.20.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] thermal: Add a sanity check for invalid state at stats update
  2020-04-07 14:12   ` Takashi Iwai
@ 2020-04-07 14:17     ` Zhang, Rui
  2020-04-07 15:37       ` Zhang, Rui
  0 siblings, 1 reply; 5+ messages in thread
From: Zhang, Rui @ 2020-04-07 14:17 UTC (permalink / raw)
  To: Takashi Iwai, Amit Kucheria; +Cc: Daniel Lezcano, Linux PM list, LKML

Right, I have a V2 patch series, which will be post soon.

Thanks,
rui

-----Original Message-----
From: linux-pm-owner@vger.kernel.org <linux-pm-owner@vger.kernel.org> On Behalf Of Takashi Iwai
Sent: Tuesday, April 07, 2020 10:13 PM
To: Amit Kucheria <amit.kucheria@verdurent.com>
Cc: Takashi Iwai <tiwai@suse.de>; Zhang, Rui <rui.zhang@intel.com>; Daniel Lezcano <daniel.lezcano@linaro.org>; Linux PM list <linux-pm@vger.kernel.org>; LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] thermal: Add a sanity check for invalid state at stats update
Importance: High

On Tue, 07 Apr 2020 15:30:51 +0200,
Amit Kucheria wrote:
> 
> On Mon, Mar 30, 2020 at 7:39 PM Takashi Iwai <tiwai@suse.de> wrote:
> >
> > The thermal sysfs handler keeps the statistics table with the fixed 
> > size that was determined from the initial max_states() call, and the 
> > table entry is updated at each sysfs cur_state write call.  And, 
> > when the driver's set_cur_state() ops accepts the value given from 
> > user-space, the thermal sysfs core blindly applies it to the 
> > statistics table entry, which may overflow and cause an Oops.
> > Although it's rather a bug in the driver's ops implementations, we 
> > shouldn't crash but rather give a proper warning instead.
> >
> > This patch adds a sanity check for avoiding such an OOB access and 
> > warns with a stack trace to show the suspicious device in question.
> 
> Hi Takashi,
> 
> Instead of this warning, I think we should reject such input when 
> writing to cur_state.
> 
> See attached patch. If you think this OK, I'll submit it.

Actually the input value itself is correct, the problem is rather about the max_states that may vary depending on other driver.  So IMO, we don't want to refuse the input completely.

Please see the thread:
  https://lore.kernel.org/linux-acpi/s5h5zeiwd01.wl-tiwai@suse.de/


thanks,

Takashi


> 
> Regards,
> Amit
> 
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > ---
> >
> > We've hit some crash by stress tests, and this patch at least works 
> > around the crash itself.  While the actual bug fix of the buggy 
> > driver is still being investigated, I submit the hardening in the 
> > core side at first.
> >
> >  drivers/thermal/thermal_sysfs.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/thermal/thermal_sysfs.c 
> > b/drivers/thermal/thermal_sysfs.c index aa99edb4dff7..a23c4e701d63 
> > 100644
> > --- a/drivers/thermal/thermal_sysfs.c
> > +++ b/drivers/thermal/thermal_sysfs.c
> > @@ -772,6 +772,11 @@ void thermal_cooling_device_stats_update(struct 
> > thermal_cooling_device *cdev,
> >
> >         spin_lock(&stats->lock);
> >
> > +       if (dev_WARN_ONCE(&cdev->device, new_state >= stats->max_states,
> > +                         "new state %ld exceeds max_state %ld",
> > +                         new_state, stats->max_states))
> > +               goto unlock;
> > +
> >         if (stats->state == new_state)
> >                 goto unlock;
> >
> > --
> > 2.16.4
> >
> From 54266260d483ab4476510dd4461a1cafc611e17d Mon Sep 17 00:00:00 2001
> Message-Id: 
> <54266260d483ab4476510dd4461a1cafc611e17d.1586266224.git.amit.kucheria
> @linaro.org>
> From: Amit Kucheria <amit.kucheria@linaro.org>
> Date: Tue, 7 Apr 2020 18:48:14 +0530
> Subject: [PATCH] thermal: Reject invalid cur_state input from 
> userspace
> 
> We don't check if the cur_state value input in sysfs is greater than 
> the maximum cooling state that the cooling device supports. This can 
> cause access to unallocated memory in case THERMAL_STATISTICS in 
> enabled and could also crash cooling devices that don't check for an 
> invalid state in their set_cur_state() callback.
> 
> Return an error if the state being requested in greater than the 
> maximum cooling state the device supports.
> 
> Reported-by: Takashi Iwai <tiwai@suse.de>
> Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
> ---
>  drivers/thermal/thermal_sysfs.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/thermal_sysfs.c 
> b/drivers/thermal/thermal_sysfs.c index 7e1d11bdd258..8033e5a9386a 
> 100644
> --- a/drivers/thermal/thermal_sysfs.c
> +++ b/drivers/thermal/thermal_sysfs.c
> @@ -703,7 +703,7 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
>  		const char *buf, size_t count)
>  {
>  	struct thermal_cooling_device *cdev = to_cooling_device(dev);
> -	unsigned long state;
> +	unsigned long state, max_state;
>  	int result;
>  
>  	if (sscanf(buf, "%ld\n", &state) != 1) @@ -712,6 +712,13 @@ 
> cur_state_store(struct device *dev, struct device_attribute *attr,
>  	if ((long)state < 0)
>  		return -EINVAL;
>  
> +	result = cdev->ops->get_max_state(cdev, &max_state);
> +	if (result)
> +		return result;
> +
> +	if (state >= max_state)
> +		return -EINVAL;
> +
>  	mutex_lock(&cdev->lock);
>  
>  	result = cdev->ops->set_cur_state(cdev, state);
> --
> 2.20.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] thermal: Add a sanity check for invalid state at stats update
  2020-04-07 14:17     ` Zhang, Rui
@ 2020-04-07 15:37       ` Zhang, Rui
  0 siblings, 0 replies; 5+ messages in thread
From: Zhang, Rui @ 2020-04-07 15:37 UTC (permalink / raw)
  To: Zhang, Rui, Takashi Iwai, Amit Kucheria
  Cc: Daniel Lezcano, Linux PM list, LKML

Too late for me to post it out by this midnight, will post it out tomorrow.

Thanks,
rui

-----Original Message-----
From: linux-pm-owner@vger.kernel.org <linux-pm-owner@vger.kernel.org> On Behalf Of Zhang, Rui
Sent: Tuesday, April 07, 2020 10:17 PM
To: Takashi Iwai <tiwai@suse.de>; Amit Kucheria <amit.kucheria@verdurent.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>; Linux PM list <linux-pm@vger.kernel.org>; LKML <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] thermal: Add a sanity check for invalid state at stats update

Right, I have a V2 patch series, which will be post soon.

Thanks,
rui

-----Original Message-----
From: linux-pm-owner@vger.kernel.org <linux-pm-owner@vger.kernel.org> On Behalf Of Takashi Iwai
Sent: Tuesday, April 07, 2020 10:13 PM
To: Amit Kucheria <amit.kucheria@verdurent.com>
Cc: Takashi Iwai <tiwai@suse.de>; Zhang, Rui <rui.zhang@intel.com>; Daniel Lezcano <daniel.lezcano@linaro.org>; Linux PM list <linux-pm@vger.kernel.org>; LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] thermal: Add a sanity check for invalid state at stats update
Importance: High

On Tue, 07 Apr 2020 15:30:51 +0200,
Amit Kucheria wrote:
> 
> On Mon, Mar 30, 2020 at 7:39 PM Takashi Iwai <tiwai@suse.de> wrote:
> >
> > The thermal sysfs handler keeps the statistics table with the fixed 
> > size that was determined from the initial max_states() call, and the 
> > table entry is updated at each sysfs cur_state write call.  And, 
> > when the driver's set_cur_state() ops accepts the value given from 
> > user-space, the thermal sysfs core blindly applies it to the 
> > statistics table entry, which may overflow and cause an Oops.
> > Although it's rather a bug in the driver's ops implementations, we 
> > shouldn't crash but rather give a proper warning instead.
> >
> > This patch adds a sanity check for avoiding such an OOB access and 
> > warns with a stack trace to show the suspicious device in question.
> 
> Hi Takashi,
> 
> Instead of this warning, I think we should reject such input when 
> writing to cur_state.
> 
> See attached patch. If you think this OK, I'll submit it.

Actually the input value itself is correct, the problem is rather about the max_states that may vary depending on other driver.  So IMO, we don't want to refuse the input completely.

Please see the thread:
  https://lore.kernel.org/linux-acpi/s5h5zeiwd01.wl-tiwai@suse.de/


thanks,

Takashi


> 
> Regards,
> Amit
> 
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > ---
> >
> > We've hit some crash by stress tests, and this patch at least works 
> > around the crash itself.  While the actual bug fix of the buggy 
> > driver is still being investigated, I submit the hardening in the 
> > core side at first.
> >
> >  drivers/thermal/thermal_sysfs.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/thermal/thermal_sysfs.c 
> > b/drivers/thermal/thermal_sysfs.c index aa99edb4dff7..a23c4e701d63
> > 100644
> > --- a/drivers/thermal/thermal_sysfs.c
> > +++ b/drivers/thermal/thermal_sysfs.c
> > @@ -772,6 +772,11 @@ void thermal_cooling_device_stats_update(struct
> > thermal_cooling_device *cdev,
> >
> >         spin_lock(&stats->lock);
> >
> > +       if (dev_WARN_ONCE(&cdev->device, new_state >= stats->max_states,
> > +                         "new state %ld exceeds max_state %ld",
> > +                         new_state, stats->max_states))
> > +               goto unlock;
> > +
> >         if (stats->state == new_state)
> >                 goto unlock;
> >
> > --
> > 2.16.4
> >
> From 54266260d483ab4476510dd4461a1cafc611e17d Mon Sep 17 00:00:00 2001
> Message-Id: 
> <54266260d483ab4476510dd4461a1cafc611e17d.1586266224.git.amit.kucheria
> @linaro.org>
> From: Amit Kucheria <amit.kucheria@linaro.org>
> Date: Tue, 7 Apr 2020 18:48:14 +0530
> Subject: [PATCH] thermal: Reject invalid cur_state input from 
> userspace
> 
> We don't check if the cur_state value input in sysfs is greater than 
> the maximum cooling state that the cooling device supports. This can 
> cause access to unallocated memory in case THERMAL_STATISTICS in 
> enabled and could also crash cooling devices that don't check for an 
> invalid state in their set_cur_state() callback.
> 
> Return an error if the state being requested in greater than the 
> maximum cooling state the device supports.
> 
> Reported-by: Takashi Iwai <tiwai@suse.de>
> Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
> ---
>  drivers/thermal/thermal_sysfs.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/thermal_sysfs.c 
> b/drivers/thermal/thermal_sysfs.c index 7e1d11bdd258..8033e5a9386a
> 100644
> --- a/drivers/thermal/thermal_sysfs.c
> +++ b/drivers/thermal/thermal_sysfs.c
> @@ -703,7 +703,7 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
>  		const char *buf, size_t count)
>  {
>  	struct thermal_cooling_device *cdev = to_cooling_device(dev);
> -	unsigned long state;
> +	unsigned long state, max_state;
>  	int result;
>  
>  	if (sscanf(buf, "%ld\n", &state) != 1) @@ -712,6 +712,13 @@ 
> cur_state_store(struct device *dev, struct device_attribute *attr,
>  	if ((long)state < 0)
>  		return -EINVAL;
>  
> +	result = cdev->ops->get_max_state(cdev, &max_state);
> +	if (result)
> +		return result;
> +
> +	if (state >= max_state)
> +		return -EINVAL;
> +
>  	mutex_lock(&cdev->lock);
>  
>  	result = cdev->ops->set_cur_state(cdev, state);
> --
> 2.20.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-04-07 15:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-30 14:08 [PATCH] thermal: Add a sanity check for invalid state at stats update Takashi Iwai
2020-04-07 13:30 ` Amit Kucheria
2020-04-07 14:12   ` Takashi Iwai
2020-04-07 14:17     ` Zhang, Rui
2020-04-07 15:37       ` Zhang, Rui

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.