Skip to content

Commit 688d5d9

Browse files
Peter Zijlstragregkh
authored andcommitted
perf/x86/cstate: Fix possible Spectre-v1 indexing for pkg_msr
commit a5f8129 upstream. > 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 <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 662218f commit 688d5d9

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

arch/x86/events/intel/cstate.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
#include <linux/module.h>
9191
#include <linux/slab.h>
9292
#include <linux/perf_event.h>
93+
#include <linux/nospec.h>
9394
#include <asm/cpu_device_id.h>
9495
#include <asm/intel-family.h>
9596
#include "../perf_event.h"
@@ -300,6 +301,7 @@ static int cstate_pmu_event_init(struct perf_event *event)
300301
} else if (event->pmu == &cstate_pkg_pmu) {
301302
if (cfg >= PERF_CSTATE_PKG_EVENT_MAX)
302303
return -EINVAL;
304+
cfg = array_index_nospec((unsigned long)cfg, PERF_CSTATE_PKG_EVENT_MAX);
303305
if (!pkg_msr[cfg].attr)
304306
return -EINVAL;
305307
event->hw.event_base = pkg_msr[cfg].msr;

0 commit comments

Comments
 (0)