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 6/7] sched: Fix possible Spectre-v1 for sched_prio_to_weight[]
Date: Fri, 20 Apr 2018 15:14:13 +0200	[thread overview]
Message-ID: <20180420131631.977597863@infradead.org> (raw)
In-Reply-To: 20180420131407.721875616@infradead.org

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

> kernel/sched/core.c:6921 cpu_weight_nice_write_s64() warn: potential spectre issue 'sched_prio_to_weight'

Userspace controls @nice, so sanitize the value before using it to
index an array.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
---
 kernel/sched/core.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6928,11 +6928,14 @@ static int cpu_weight_nice_write_s64(str
 				     struct cftype *cft, s64 nice)
 {
 	unsigned long weight;
+	int idx;
 
 	if (nice < MIN_NICE || nice > MAX_NICE)
 		return -ERANGE;
 
-	weight = sched_prio_to_weight[NICE_TO_PRIO(nice) - MAX_RT_PRIO];
+	idx = array_index_nospec(NICE_TO_PRIO(nice) - MAX_RT_PRIO, 40);
+	weight = sched_prio_to_weight[idx];
+
 	return sched_group_set_shares(css_tg(css), scale_load(weight));
 }
 #endif

  parent reply	other threads:[~2018-04-20 13:20 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 ` [PATCH 4/7] perf,x86/msr: Fix possible Spectre-v1 for msr Peter Zijlstra
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 ` Peter Zijlstra [this message]
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.977597863@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).