mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] perf/x86: Fix integer overflow when left shifting an integer more than 32 bits
@ 2021-04-20 14:29 Colin King
  2021-04-20 15:03 ` Peter Zijlstra
  2021-04-23  7:10 ` [tip: perf/core] perf/x86: Allow for 8<num_fixed_counters<16 tip-bot2 for Colin Ian King
  0 siblings, 2 replies; 5+ messages in thread
From: Colin King @ 2021-04-20 14:29 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Thomas Gleixner, Borislav Petkov, x86, H . Peter Anvin,
	George Dunlap
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The 64 bit value read from MSR_ARCH_PERFMON_FIXED_CTR_CTRL is being
bit-wise masked with the value (0x03 << i*4). However, the shifted value
is evaluated using 32 bit arithmetic, so will overflow when i > 8.
Fix this by making 0x03 a ULL so that the shift is performed using
64 bit arithmetic.

Addresses-Coverity: ("Unintentional integer overflow")
Fixes: a5ebe0ba3dff ("perf/x86: Check all MSRs before passing hw check")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 arch/x86/events/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index bafd93c54ffa..59c665c8c2e9 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -261,7 +261,7 @@ static bool check_hw_exists(void)
 		for (i = 0; i < x86_pmu.num_counters_fixed; i++) {
 			if (fixed_counter_disabled(i))
 				continue;
-			if (val & (0x03 << i*4)) {
+			if (val & (0x03ULL << i*4)) {
 				bios_fail = 1;
 				val_fail = val;
 				reg_fail = reg;
-- 
2.30.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-23  7:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 14:29 [PATCH] perf/x86: Fix integer overflow when left shifting an integer more than 32 bits Colin King
2021-04-20 15:03 ` Peter Zijlstra
2021-04-20 15:31   ` Peter Zijlstra
2021-04-20 15:34     ` Colin Ian King
2021-04-23  7:10 ` [tip: perf/core] perf/x86: Allow for 8<num_fixed_counters<16 tip-bot2 for Colin Ian King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®