Skip to content

Commit 70e65f2

Browse files
Peter Zijlstragregkh
authored andcommitted
perf/x86: Fix possible Spectre-v1 indexing for x86_pmu::event_map()
commit 46b1b57 upstream. > arch/x86/events/intel/cstate.c:307 cstate_pmu_event_init() warn: potential spectre issue 'pkg_msr' (local cap) > arch/x86/events/intel/core.c:337 intel_pmu_event_map() warn: potential spectre issue 'intel_perfmon_event_map' > arch/x86/events/intel/knc.c:122 knc_pmu_event_map() warn: potential spectre issue 'knc_perfmon_event_map' > arch/x86/events/intel/p4.c:722 p4_pmu_event_map() warn: potential spectre issue 'p4_general_events' > arch/x86/events/intel/p6.c:116 p6_pmu_event_map() warn: potential spectre issue 'p6_perfmon_event_map' > arch/x86/events/amd/core.c:132 amd_pmu_event_map() warn: potential spectre issue 'amd_perfmon_event_map' Userspace controls @attr, sanitize @attr->config before passing it on to x86_pmu::event_map(). Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: <stable@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vince Weaver <vincent.weaver@maine.edu> Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c64ca00 commit 70e65f2

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

arch/x86/events/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/cpu.h>
2727
#include <linux/bitops.h>
2828
#include <linux/device.h>
29+
#include <linux/nospec.h>
2930

3031
#include <asm/apic.h>
3132
#include <asm/stacktrace.h>
@@ -423,6 +424,8 @@ int x86_setup_perfctr(struct perf_event *event)
423424
if (attr->config >= x86_pmu.max_events)
424425
return -EINVAL;
425426

427+
attr->config = array_index_nospec((unsigned long)attr->config, x86_pmu.max_events);
428+
426429
/*
427430
* The generic map:
428431
*/

0 commit comments

Comments
 (0)