Skip to content

Commit a9c724a

Browse files
committed
cppc_cpufreq: Fix possible null pointer dereference
jira LE-1907 cve CVE-2024-38573 Rebuild_History Non-Buildable kernel-5.14.0-427.37.1.el9_4 commit-author Aleksandr Mishin <amishin@t-argos.ru> commit cf7de25 cppc_cpufreq_get_rate() and hisi_cppc_cpufreq_get_rate() can be called from different places with various parameters. So cpufreq_cpu_get() can return null as 'policy' in some circumstances. Fix this bug by adding null return check. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: a28b2bf ("cppc_cpufreq: replace per-cpu data array with a list") Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> (cherry picked from commit cf7de25) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent c3a62df commit a9c724a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

drivers/cpufreq/cppc_cpufreq.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,10 +841,15 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpu)
841841
{
842842
struct cppc_perf_fb_ctrs fb_ctrs_t0 = {0}, fb_ctrs_t1 = {0};
843843
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
844-
struct cppc_cpudata *cpu_data = policy->driver_data;
844+
struct cppc_cpudata *cpu_data;
845845
u64 delivered_perf;
846846
int ret;
847847

848+
if (!policy)
849+
return -ENODEV;
850+
851+
cpu_data = policy->driver_data;
852+
848853
cpufreq_cpu_put(policy);
849854

850855
ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t0);
@@ -924,10 +929,15 @@ static struct cpufreq_driver cppc_cpufreq_driver = {
924929
static unsigned int hisi_cppc_cpufreq_get_rate(unsigned int cpu)
925930
{
926931
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
927-
struct cppc_cpudata *cpu_data = policy->driver_data;
932+
struct cppc_cpudata *cpu_data;
928933
u64 desired_perf;
929934
int ret;
930935

936+
if (!policy)
937+
return -ENODEV;
938+
939+
cpu_data = policy->driver_data;
940+
931941
cpufreq_cpu_put(policy);
932942

933943
ret = cppc_get_desired_perf(cpu, &desired_perf);

0 commit comments

Comments
 (0)