linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: linux-kernel@vger.kernel.org, mingo@kernel.org
Cc: tglx@linutronix.de, dan.j.williams@intel.com,
	torvalds@linux-foundation.org,
	Dan Carpenter <dan.carpenter@oracle.com>,
	"Peter Zijlstra" <peterz@infradead.org>
Subject: [PATCH 4/7] perf,x86/msr: Fix possible Spectre-v1 for msr
Date: Fri, 20 Apr 2018 15:14:11 +0200	[thread overview]
Message-ID: <20180420131631.875020804@infradead.org> (raw)
In-Reply-To: 20180420131407.721875616@infradead.org

[-- Attachment #1: peterz-spectre1-4.patch --]
[-- Type: text/plain, Size: 1016 bytes --]

> 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: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
---
 arch/x86/events/msr.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

--- a/arch/x86/events/msr.c
+++ b/arch/x86/events/msr.c
@@ -158,9 +158,6 @@ static int msr_event_init(struct perf_ev
 	if (event->attr.type != event->pmu->type)
 		return -ENOENT;
 
-	if (cfg >= PERF_MSR_EVENT_MAX)
-		return -EINVAL;
-
 	/* unsupported modes and filters */
 	if (event->attr.exclude_user   ||
 	    event->attr.exclude_kernel ||
@@ -171,6 +168,11 @@ static int msr_event_init(struct perf_ev
 	    event->attr.sample_period) /* no sampling */
 		return -EINVAL;
 
+	if (cfg >= PERF_MSR_EVENT_MAX)
+		return -EINVAL;
+
+	cfg = array_index_nospec(cfg, PERF_MSR_EVENT_MAX);
+
 	if (!msr[cfg].attr)
 		return -EINVAL;
 

  parent reply	other threads:[~2018-04-20 13:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-20 13:14 [PATCH 0/7] Various Spectre-v1 fixes Peter Zijlstra
2018-04-20 13:14 ` [PATCH 1/7] perf: Fix possible Spectre-v1 for aux_pages Peter Zijlstra
2018-04-20 13:14 ` [PATCH 2/7] perf,x86: Fix possible Spectre-v1 for hw_perf_event Peter Zijlstra
2018-04-20 13:14 ` [PATCH 3/7] perf,x86: Fix possible Spectre-v1 for x86_pmu::event_map() Peter Zijlstra
2018-04-20 13:14 ` Peter Zijlstra [this message]
2018-04-20 13:14 ` [PATCH 5/7] perf,x86/cstate: Fix possible Spectre-v1 for pkg_msr Peter Zijlstra
2018-04-20 13:14 ` [PATCH 6/7] sched: Fix possible Spectre-v1 for sched_prio_to_weight[] Peter Zijlstra
2018-04-20 13:14 ` [PATCH 7/7] sched,autogroup: Fix possible Spectre-v1 for sched_prio_to_weight Peter Zijlstra
2018-04-23  1:03 ` [PATCH 0/7] Various Spectre-v1 fixes Michal Hocko
2018-04-23  9:33   ` Peter Zijlstra
2018-04-23 13:50     ` Dan Williams
2018-04-23 16:47     ` Michal Hocko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180420131631.875020804@infradead.org \
    --to=peterz@infradead.org \
    --cc=dan.carpenter@oracle.com \
    --cc=dan.j.williams@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).