Skip to content

Commit a5f8129

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
perf/x86/cstate: Fix possible Spectre-v1 indexing for pkg_msr
> arch/x86/events/intel/cstate.c:307 cstate_pmu_event_init() warn: potential spectre issue 'pkg_msr' (local cap) Userspace controls @attr, sanitize cfg (attr->config) before using it to index an array. Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vince Weaver <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 06ce6e9 commit a5f8129

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

arch/x86/events/intel/cstate.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#include <linux/module.h>
9393
#include <linux/slab.h>
9494
#include <linux/perf_event.h>
95+
#include <linux/nospec.h>
9596
#include <asm/cpu_device_id.h>
9697
#include <asm/intel-family.h>
9798
#include "../perf_event.h"
@@ -302,6 +303,7 @@ static int cstate_pmu_event_init(struct perf_event *event)
302303
} else if (event->pmu == &cstate_pkg_pmu) {
303304
if (cfg >= PERF_CSTATE_PKG_EVENT_MAX)
304305
return -EINVAL;
306+
cfg = array_index_nospec((unsigned long)cfg, PERF_CSTATE_PKG_EVENT_MAX);
305307
if (!pkg_msr[cfg].attr)
306308
return -EINVAL;
307309
event->hw.event_base = pkg_msr[cfg].msr;

0 commit comments

Comments
 (0)