diff options
author | Peter Zijlstra <peterz@infradead.org> | 2018-04-20 08:29:51 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2018-05-05 02:32:36 -0400 |
commit | 7281c8dec8a87685cb54d503d8cceef5a0fc2fdd (patch) | |
tree | d6297b366411ba9abe1dc8caa98f1d1fb91006ec | |
parent | b5bf9a90bbebffba888c9144c5a8a10317b04064 (diff) |
sched/core: Fix possible Spectre-v1 indexing for sched_prio_to_weight[]
> 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 (Intel) <peterz@infradead.org>
Cc: <stable@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | kernel/sched/core.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index ffde9eebc846..092f7c4de903 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include "sched.h" | 8 | #include "sched.h" |
9 | 9 | ||
10 | #include <linux/kthread.h> | 10 | #include <linux/kthread.h> |
11 | #include <linux/nospec.h> | ||
11 | 12 | ||
12 | #include <asm/switch_to.h> | 13 | #include <asm/switch_to.h> |
13 | #include <asm/tlb.h> | 14 | #include <asm/tlb.h> |
@@ -6923,11 +6924,15 @@ static int cpu_weight_nice_write_s64(struct cgroup_subsys_state *css, | |||
6923 | struct cftype *cft, s64 nice) | 6924 | struct cftype *cft, s64 nice) |
6924 | { | 6925 | { |
6925 | unsigned long weight; | 6926 | unsigned long weight; |
6927 | int idx; | ||
6926 | 6928 | ||
6927 | if (nice < MIN_NICE || nice > MAX_NICE) | 6929 | if (nice < MIN_NICE || nice > MAX_NICE) |
6928 | return -ERANGE; | 6930 | return -ERANGE; |
6929 | 6931 | ||
6930 | weight = sched_prio_to_weight[NICE_TO_PRIO(nice) - MAX_RT_PRIO]; | 6932 | idx = NICE_TO_PRIO(nice) - MAX_RT_PRIO; |
6933 | idx = array_index_nospec(idx, 40); | ||
6934 | weight = sched_prio_to_weight[idx]; | ||
6935 | |||
6931 | return sched_group_set_shares(css_tg(css), scale_load(weight)); | 6936 | return sched_group_set_shares(css_tg(css), scale_load(weight)); |
6932 | } | 6937 | } |
6933 | #endif | 6938 | #endif |