summaryrefslogtreecommitdiffstats
path: root/kernel/sched
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2018-04-20 09:03:45 -0400
committerIngo Molnar <mingo@kernel.org>2018-05-05 02:34:42 -0400
commit354d7793070611b4df5a79fbb0f12752d0ed0cc5 (patch)
tree3efb40ae7133e4bb2dfc6c27cb72a82e9a2465b4 /kernel/sched
parent7281c8dec8a87685cb54d503d8cceef5a0fc2fdd (diff)
sched/autogroup: Fix possible Spectre-v1 indexing for sched_prio_to_weight[]
> kernel/sched/autogroup.c:230 proc_sched_autogroup_set_nice() warn: potential spectre issue 'sched_prio_to_weight' Userspace controls @nice, sanitize the array index. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: <stable@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/sched')
-rw-r--r--kernel/sched/autogroup.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/kernel/sched/autogroup.c b/kernel/sched/autogroup.c
index 6be6c575b6cd..2d4ff5353ded 100644
--- a/kernel/sched/autogroup.c
+++ b/kernel/sched/autogroup.c
@@ -2,6 +2,7 @@
2/* 2/*
3 * Auto-group scheduling implementation: 3 * Auto-group scheduling implementation:
4 */ 4 */
5#include <linux/nospec.h>
5#include "sched.h" 6#include "sched.h"
6 7
7unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1; 8unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
@@ -209,7 +210,7 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int nice)
209 static unsigned long next = INITIAL_JIFFIES; 210 static unsigned long next = INITIAL_JIFFIES;
210 struct autogroup *ag; 211 struct autogroup *ag;
211 unsigned long shares; 212 unsigned long shares;
212 int err; 213 int err, idx;
213 214
214 if (nice < MIN_NICE || nice > MAX_NICE) 215 if (nice < MIN_NICE || nice > MAX_NICE)
215 return -EINVAL; 216 return -EINVAL;
@@ -227,7 +228,9 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int nice)
227 228
228 next = HZ / 10 + jiffies; 229 next = HZ / 10 + jiffies;
229 ag = autogroup_task_get(p); 230 ag = autogroup_task_get(p);
230 shares = scale_load(sched_prio_to_weight[nice + 20]); 231
232 idx = array_index_nospec(nice + 20, 40);
233 shares = scale_load(sched_prio_to_weight[idx]);
231 234
232 down_write(&ag->lock); 235 down_write(&ag->lock);
233 err = sched_group_set_shares(ag->tg, shares); 236 err = sched_group_set_shares(ag->tg, shares);