Commit 5edbd2d8 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Greg Kroah-Hartman

perf/x86/msr: Fix possible Spectre-v1 indexing in the MSR driver

commit 06ce6e9b upstream.

> arch/x86/events/msr.c:178 msr_event_init() warn: potential spectre issue 'msr' (local cap)

Userspace controls @attr, sanitize cfg (attr->config) before using it
to index an array.
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarPeter 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: default avatarIngo Molnar <mingo@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 688d5d91
#include <linux/perf_event.h> #include <linux/perf_event.h>
#include <linux/nospec.h>
#include <asm/intel-family.h> #include <asm/intel-family.h>
enum perf_msr_id { enum perf_msr_id {
...@@ -136,9 +137,6 @@ static int msr_event_init(struct perf_event *event) ...@@ -136,9 +137,6 @@ static int msr_event_init(struct perf_event *event)
if (event->attr.type != event->pmu->type) if (event->attr.type != event->pmu->type)
return -ENOENT; return -ENOENT;
if (cfg >= PERF_MSR_EVENT_MAX)
return -EINVAL;
/* unsupported modes and filters */ /* unsupported modes and filters */
if (event->attr.exclude_user || if (event->attr.exclude_user ||
event->attr.exclude_kernel || event->attr.exclude_kernel ||
...@@ -149,6 +147,11 @@ static int msr_event_init(struct perf_event *event) ...@@ -149,6 +147,11 @@ static int msr_event_init(struct perf_event *event)
event->attr.sample_period) /* no sampling */ event->attr.sample_period) /* no sampling */
return -EINVAL; return -EINVAL;
if (cfg >= PERF_MSR_EVENT_MAX)
return -EINVAL;
cfg = array_index_nospec((unsigned long)cfg, PERF_MSR_EVENT_MAX);
if (!msr[cfg].attr) if (!msr[cfg].attr)
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment