From 1ca402da88721699461877c51cf2517637397939 Mon Sep 17 00:00:00 2001 From: Sergey Shtylyov Date: Tue, 28 Feb 2023 09:22:07 +0800 Subject: [PATCH] arm64: topology: fix possible overflow in amu_fie_setup() stable inclusion from stable-v5.10.150 commit 904f881b57360cf85de962d84d8614d94431f60e category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I6D0XA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=904f881b57360cf85de962d84d8614d94431f60e -------------------------------- cpufreq_get_hw_max_freq() returns max frequency in kHz as *unsigned int*, while freq_inv_set_max_ratio() gets passed this frequency in Hz as 'u64'. Multiplying max frequency by 1000 can potentially result in overflow -- multiplying by 1000ULL instead should avoid that... Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool. Fixes: cd0ed03a8903 ("arm64: use activity monitors for frequency invariance") Signed-off-by: Sergey Shtylyov Link: https://lore.kernel.org/r/01493d64-2bce-d968-86dc-11a122a9c07d@omp.ru Signed-off-by: Will Deacon conflicts: arch/arm64/kernel/topology.c Signed-off-by: Lin Yujun Reviewed-by: Zhang Jianhua Signed-off-by: Jialin Zhang --- arch/arm64/kernel/topology.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index 3084a81250fe..0c9f986e3c6b 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -252,7 +252,7 @@ static int __init init_amu_fie(void) for_each_present_cpu(cpu) { if (!freq_counters_valid(cpu) || freq_inv_set_max_ratio(cpu, - cpufreq_get_hw_max_freq(cpu) * 1000, + cpufreq_get_hw_max_freq(cpu) * 1000ULL, arch_timer_get_rate())) continue; -- GitLab