diff mbox series

arm64: topology: fix possible overflow in amu_fie_setup()

Message ID 01493d64-2bce-d968-86dc-11a122a9c07d@omp.ru (mailing list archive)
State New, archived
Headers show
Series arm64: topology: fix possible overflow in amu_fie_setup() | expand

Commit Message

Sergey Shtylyov Sept. 16, 2022, 8:17 p.m. UTC
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 <s.shtylyov@omp.ru>

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

Comments

Will Deacon Sept. 22, 2022, 12:45 p.m. UTC | #1
On Fri, 16 Sep 2022 23:17:07 +0300, Sergey Shtylyov wrote:
> 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,
diff mbox series

Patch

Index: linux/arch/arm64/kernel/topology.c
===================================================================
--- linux.orig/arch/arm64/kernel/topology.c
+++ 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;
 	}