Skip to contentSkip to conversation

cpufreq: amd-pstate: add check for cpufreq_cpu_get's return value

PATCH In review Anastasia Belova 1 participant 4 messages Nov 6, 2024 – Dec 12, 2024 Stable branch

lore
Share & tools
lore
#0 lore raw

cover cpufreq: amd-pstate: add check for cpufreq_cpu_get's return value

NULL-dereference is possible in amd_pstate_adjust_perf in 6.6 stable release.

The problem has been fixed by the following upstream patch that was adapted to 6.6. The patch couldn't be applied clearly but the changes made are minor.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

#1 lore raw

PATCH 1/1 cpufreq: amd-pstate: add check for cpufreq_cpu_get's return value

From: Anastasia Belova <[email protected]>

commit 5493f9714e4cdaf0ee7cec15899a231400cb1a9f upstream.

cpufreq_cpu_get may return NULL. To avoid NULL-dereference check it and return in case of error.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 drivers/cpufreq/amd-pstate.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/cpufreq/amd-pstate.c +6 -1
index 8c16d67b98bf..0fc5495c935a 100644
@@ -579,9 +579,14 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
 	unsigned long max_perf, min_perf, des_perf,
 		      cap_perf, lowest_nonlinear_perf, max_freq;
 	struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
-	struct amd_cpudata *cpudata = policy->driver_data;
+	struct amd_cpudata *cpudata;
 	unsigned int target_freq;
 
+	if (!policy)
+		return;
+
+	cpudata = policy->driver_data;
+
 	if (policy->min != cpudata->min_limit_freq || policy->max != cpudata->max_limit_freq)
 		amd_pstate_update_min_max_limit(policy);
 
Signature · 1 line
2.47.0
#2 lore raw

Just a friendly reminder.

Cc'ing Mario Limonciello and Gautham Ranjal Shenoy.

Quoted 36 lines · Anastasia Belova

From: Anastasia Belova <[email protected]>

commit 5493f9714e4cdaf0ee7cec15899a231400cb1a9f upstream.

cpufreq_cpu_get may return NULL. To avoid NULL-dereference check it and return in case of error.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
  drivers/cpufreq/amd-pstate.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
drivers/cpufreq/amd-pstate.c +6 -1
index 8c16d67b98bf..0fc5495c935a 100644
@@ -579,9 +579,14 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
  	unsigned long max_perf, min_perf, des_perf,
  		      cap_perf, lowest_nonlinear_perf, max_freq;
  	struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
-	struct amd_cpudata *cpudata = policy->driver_data;
+	struct amd_cpudata *cpudata;
  	unsigned int target_freq;
 
+	if (!policy)
+		return;
+
+	cpudata = policy->driver_data;
+
  	if (policy->min != cpudata->min_limit_freq || policy->max != cpudata->max_limit_freq)
  		amd_pstate_update_min_max_limit(policy);
 
#3 lore raw
In reply to Anastasia Belova

Just a friendly reminder.

Quoted 8 lines · Anastasia Belova

NULL-dereference is possible in amd_pstate_adjust_perf in 6.6 stable release.

The problem has been fixed by the following upstream patch that was adapted to 6.6. The patch couldn't be applied clearly but the changes made are minor.

Found by Linux Verification Center (linuxtesting.org) with SVACE.