linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf/x86/intel: fix integer overflow when shifting 32 places
@ 2017-01-11 11:43 Colin King
  2017-01-11 15:46 ` [tip:perf/urgent] perf/x86/intel: Use ULL constant to prevent undefined shift behaviour tip-bot for Colin King
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2017-01-11 11:43 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H . Peter Anvin, x86,
	Peter Zijlstra, Andi Kleen, Stephane Eranian, Kan Liang,
	Alexander Shishkin
  Cc: linux-kernel

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

When x86_pmu.num_counters is set to INTEL_PMC_MAX_GENERIC we end up
with the 32 bit integer constant 1 being shifted 32 places leading to
undefined behaviour.  Fix this by shifting 1ULL instead of 1.

Fixes CoverityScan CID#1192105 ("Bad bit shift operation")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 arch/x86/events/intel/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 8613826..d611cab 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3987,7 +3987,7 @@ __init int intel_pmu_init(void)
 		     x86_pmu.num_counters, INTEL_PMC_MAX_GENERIC);
 		x86_pmu.num_counters = INTEL_PMC_MAX_GENERIC;
 	}
-	x86_pmu.intel_ctrl = (1 << x86_pmu.num_counters) - 1;
+	x86_pmu.intel_ctrl = (1ULL << x86_pmu.num_counters) - 1;
 
 	if (x86_pmu.num_counters_fixed > INTEL_PMC_MAX_FIXED) {
 		WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!",
-- 
2.10.2

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

* [tip:perf/urgent] perf/x86/intel: Use ULL constant to prevent undefined shift behaviour
  2017-01-11 11:43 [PATCH] perf/x86/intel: fix integer overflow when shifting 32 places Colin King
@ 2017-01-11 15:46 ` tip-bot for Colin King
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Colin King @ 2017-01-11 15:46 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, colin.king, mingo, peterz, kan.liang, linux-kernel,
	alexander.shishkin, ak, eranian, hpa

Commit-ID:  ad5013d5699d30ded0cdbbc68b93b2aa28222c6e
Gitweb:     http://git.kernel.org/tip/ad5013d5699d30ded0cdbbc68b93b2aa28222c6e
Author:     Colin King <colin.king@canonical.com>
AuthorDate: Wed, 11 Jan 2017 11:43:10 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Wed, 11 Jan 2017 16:43:30 +0100

perf/x86/intel: Use ULL constant to prevent undefined shift behaviour

When x86_pmu.num_counters is 32 the shift of the integer constant 1 is
exceeding 32bit and therefor undefined behaviour.

Fix this by shifting 1ULL instead of 1.

Reported-by: CoverityScan CID#1192105 ("Bad bit shift operation")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Link: http://lkml.kernel.org/r/20170111114310.17928-1-colin.king@canonical.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/events/intel/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 8613826..d611cab 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3987,7 +3987,7 @@ __init int intel_pmu_init(void)
 		     x86_pmu.num_counters, INTEL_PMC_MAX_GENERIC);
 		x86_pmu.num_counters = INTEL_PMC_MAX_GENERIC;
 	}
-	x86_pmu.intel_ctrl = (1 << x86_pmu.num_counters) - 1;
+	x86_pmu.intel_ctrl = (1ULL << x86_pmu.num_counters) - 1;
 
 	if (x86_pmu.num_counters_fixed > INTEL_PMC_MAX_FIXED) {
 		WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!",

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

end of thread, other threads:[~2017-01-11 15:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-11 11:43 [PATCH] perf/x86/intel: fix integer overflow when shifting 32 places Colin King
2017-01-11 15:46 ` [tip:perf/urgent] perf/x86/intel: Use ULL constant to prevent undefined shift behaviour tip-bot for Colin King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).