* [PATCH] thermal: intel: powerclamp: Fix NULL pointer access issue
@ 2023-05-03 23:38 Srinivas Pandruvada
2023-05-04 18:31 ` Rafael J. Wysocki
0 siblings, 1 reply; 2+ messages in thread
From: Srinivas Pandruvada @ 2023-05-03 23:38 UTC (permalink / raw)
To: rafael, rui.zhang, daniel.lezcano
Cc: linux-pm, linux-kernel, Srinivas Pandruvada, Risto A . Paju, stable
If the cur_state for the powerclamp cooling device is set to the default
minimum state of 0, without setting first to cur_state > 0, this results
in NULL pointer access.
This NULL pointer access happens in the powercap core idle-inject function
idle_inject_set_duration() as there is no NULL check for idle_inject_device
pointer. This pointer must be allocated by calling idle_inject_register()
or idle_inject_register_full().
In the function powerclamp_set_cur_state(), idle_inject_device pointer is
allocated only when the cur_state > 0. But setting 0 without changing to
any other state, idle_inject_set_duration() will be called with a NULL
idle_inject_device pointer.
To address this just return from powerclamp_set_cur_state(), if the
current cooling device state is same as the last one. Since the powerup
default cooling device state is 0, changing the state to 0 again here
will return without calling idle_inject_set_duration().
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Fixes: 8526eb7fc75a ("thermal: intel: powerclamp: Use powercap idle-inject feature")
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=217386
Tested-by: Risto A. Paju <teknohog@iki.fi>
Cc: stable@kernel.org
---
This issue is can be reproduced from 6.3-rc1 kernel.
drivers/thermal/intel/intel_powerclamp.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/thermal/intel/intel_powerclamp.c b/drivers/thermal/intel/intel_powerclamp.c
index 91fc7e239497..36243a3972fd 100644
--- a/drivers/thermal/intel/intel_powerclamp.c
+++ b/drivers/thermal/intel/intel_powerclamp.c
@@ -703,6 +703,10 @@ static int powerclamp_set_cur_state(struct thermal_cooling_device *cdev,
new_target_ratio = clamp(new_target_ratio, 0UL,
(unsigned long) (max_idle - 1));
+
+ if (powerclamp_data.target_ratio == new_target_ratio)
+ goto exit_set;
+
if (!powerclamp_data.target_ratio && new_target_ratio > 0) {
pr_info("Start idle injection to reduce power\n");
powerclamp_data.target_ratio = new_target_ratio;
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] thermal: intel: powerclamp: Fix NULL pointer access issue
2023-05-03 23:38 [PATCH] thermal: intel: powerclamp: Fix NULL pointer access issue Srinivas Pandruvada
@ 2023-05-04 18:31 ` Rafael J. Wysocki
0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2023-05-04 18:31 UTC (permalink / raw)
To: Srinivas Pandruvada
Cc: rafael, rui.zhang, daniel.lezcano, linux-pm, linux-kernel,
Risto A . Paju, stable
On Thu, May 4, 2023 at 1:38 AM Srinivas Pandruvada
<srinivas.pandruvada@linux.intel.com> wrote:
>
> If the cur_state for the powerclamp cooling device is set to the default
> minimum state of 0, without setting first to cur_state > 0, this results
> in NULL pointer access.
>
> This NULL pointer access happens in the powercap core idle-inject function
> idle_inject_set_duration() as there is no NULL check for idle_inject_device
> pointer. This pointer must be allocated by calling idle_inject_register()
> or idle_inject_register_full().
>
> In the function powerclamp_set_cur_state(), idle_inject_device pointer is
> allocated only when the cur_state > 0. But setting 0 without changing to
> any other state, idle_inject_set_duration() will be called with a NULL
> idle_inject_device pointer.
>
> To address this just return from powerclamp_set_cur_state(), if the
> current cooling device state is same as the last one. Since the powerup
> default cooling device state is 0, changing the state to 0 again here
> will return without calling idle_inject_set_duration().
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> Fixes: 8526eb7fc75a ("thermal: intel: powerclamp: Use powercap idle-inject feature")
> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=217386
> Tested-by: Risto A. Paju <teknohog@iki.fi>
> Cc: stable@kernel.org
> ---
> This issue is can be reproduced from 6.3-rc1 kernel.
>
> drivers/thermal/intel/intel_powerclamp.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/thermal/intel/intel_powerclamp.c b/drivers/thermal/intel/intel_powerclamp.c
> index 91fc7e239497..36243a3972fd 100644
> --- a/drivers/thermal/intel/intel_powerclamp.c
> +++ b/drivers/thermal/intel/intel_powerclamp.c
> @@ -703,6 +703,10 @@ static int powerclamp_set_cur_state(struct thermal_cooling_device *cdev,
>
> new_target_ratio = clamp(new_target_ratio, 0UL,
> (unsigned long) (max_idle - 1));
> +
> + if (powerclamp_data.target_ratio == new_target_ratio)
> + goto exit_set;
> +
> if (!powerclamp_data.target_ratio && new_target_ratio > 0) {
> pr_info("Start idle injection to reduce power\n");
> powerclamp_data.target_ratio = new_target_ratio;
> --
Applied as 6.4-rc material, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-05-04 18:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-03 23:38 [PATCH] thermal: intel: powerclamp: Fix NULL pointer access issue Srinivas Pandruvada
2023-05-04 18:31 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®