Skip to contentSkip to conversation

arm64: topology: fix possible overflow in amu_fie_setup()

PATCH Applied Sergey Shtylyov 2 participants 2 messages Sep 16, 2022 – Sep 22, 2022 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: topology: fix possible overflow in amu_fie_setup()

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")

---
The patch is against the 'for-next/fixes' branch of the ARM64 repo...

 arch/arm64/kernel/topology.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/topology.c +1 -1
Index: linux/arch/arm64/kernel/topology.c
===================================================================
@@ -237,7 +237,7 @@ static void amu_fie_setup(const struct c
 	for_each_cpu(cpu, cpus) {
 		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()))
 			return;
 	}

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Applied
#1 lore raw
Quoted 9 lines · Sergey Shtylyov

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.

[...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64: topology: fix possible overflow in amu_fie_setup()

      https://git.kernel.org/arm64/c/d4955c0ad77d

Cheers,

Signature · 10 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel