Commit b8dc7781 authored by Anastasia Belova's avatar Anastasia Belova Committed by Bowen You
Browse files

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

mainline inclusion
from mainline-v6.12-rc1
commit 5493f9714e4cdaf0ee7cec15899a231400cb1a9f
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IAYRBF
CVE: CVE-2024-50009

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=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.

Signed-off-by: default avatarAnastasia Belova <abelova@astralinux.ru>
Reviewed-by: default avatarPerry Yuan <perry.yuan@amd.com>
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Conflicts:
        drivers/cpufreq/amd-pstate.c
[amd_pstate_update_limits is not involved, target_freq isn't removed]
Signed-off-by: default avatarBowen You <youbowen2@huawei.com>
parent ebf321fb
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -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);