Skip to contentSkip to conversation

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

PATCH New Xiangyu Chen 3 participants 5 messages Nov 15, 2024 Stable branch

lore
Share & tools
lore
#0 lore raw

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

From: Xiangyu Chen <[email protected]>

[ Upstream commit 5493f9714e4cdaf0ee7cec15899a231400cb1a9f ]

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.

[Xiangyu: Bp to fix CVE: CVE-2024-50009 resolved minor conflicts]
---
 drivers/cpufreq/amd-pstate.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/cpufreq/amd-pstate.c +6 -1
index 90dcf26f0973..106aef210003 100644
@@ -309,9 +309,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;
+
 	cap_perf = READ_ONCE(cpudata->highest_perf);
 	lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);
 	max_freq = READ_ONCE(cpudata->max_freq);
Signature · 1 line
2.43.0
#1 lore raw

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

From: Xiangyu Chen <[email protected]>

[ Upstream commit 5493f9714e4cdaf0ee7cec15899a231400cb1a9f ]

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.

[Xiangyu: Bp to fix CVE: CVE-2024-50009 resolved minor conflicts]
---
 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.43.0
#2 lore raw

Hi!

If I'm not mistaken, the line From: should contain the name of the original commit author. Also I’ve already sent same back-port [1]. However, I didn’t get an answer yet.

[1] https://lore.kernel.org/lkml/[email protected]/

Anastasia Belova

15.11.2024 11:33, Xiangyu Chen пишет:

Quoted 38 lines

From: Xiangyu Chen <[email protected]>

[ Upstream commit 5493f9714e4cdaf0ee7cec15899a231400cb1a9f ]

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.

[Xiangyu: Bp to fix CVE: CVE-2024-50009 resolved minor conflicts]
---
  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

Hi,

Thanks for your info, I've solved the conflicts in a local commit and forgot to

update the commit author, thanks, and please ignore this patch.

Let's wait for the patch you sent to merge the stable branch :)

Thanks!

Br,

Xiangyu

Quoted 55 lines · Anastasia Belova

CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.

Hi!

If I'm not mistaken, the line From: should contain the name of the original commit author. Also I’ve already sent same back-port [1]. However, I didn’t get an answer yet.

[1]
https://lore.kernel.org/lkml/[email protected]/

Anastasia Belova

15.11.2024 11:33, Xiangyu Chen пишет:

Quoted 39 lines

From: Xiangyu Chen <[email protected]>

[ Upstream commit 5493f9714e4cdaf0ee7cec15899a231400cb1a9f ]

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.

[Xiangyu:  Bp to fix CVE: CVE-2024-50009 resolved minor conflicts]

---
  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);
#4 lore raw
In reply to Anastasia Belova

Hi,

Thanks for your info, I've solved the conflicts in a local commit and forgot to

update the commit author, thanks, and please ignore this patch.

Let's wait for the patch you sent to merge the stable branch :)

Thanks!

Br,

Xiangyu

在 2024年11月15日 星期五 下午05:17:52 [GMT+8], Anastasia Belova<[email protected]> 寫道:

Hi!

If I'm not mistaken, the line From: should contain the name of the original commit author. Also I’ve already sent same back-port [1]. However, I didn’t get an answer yet.

[1]
https://lore.kernel.org/lkml/[email protected]/

Anastasia Belova

15.11.2024 11:33, Xiangyu Chen пишет:

Quoted 38 lines

From: Xiangyu Chen <[email protected]>

[ Upstream commit 5493f9714e4cdaf0ee7cec15899a231400cb1a9f ]

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.

[Xiangyu:  Bp to fix CVE: CVE-2024-50009 resolved minor conflicts]

---
  drivers/cpufreq/amd-pstate.c | 7 ++++++-

  1 file changed, 6 insertions(+), 1 deletion(-)
drivers/cpufreq/amd-pstate.c +1 -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;

drivers/cpufreq/amd-pstate.c +3 -0
+
+    cpudata = policy->driver_data;
+

      if (policy->min != cpudata->min_limit_freq || policy->max != cpudata->max_limit_freq) amd_pstate_update_min_max_limit(policy);