Skip to content

Commit 354d779

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
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 <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 7281c8d commit 354d779

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

kernel/sched/autogroup.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/*
33
* Auto-group scheduling implementation:
44
*/
5+
#include <linux/nospec.h>
56
#include "sched.h"
67

78
unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
@@ -209,7 +210,7 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int nice)
209210
static unsigned long next = INITIAL_JIFFIES;
210211
struct autogroup *ag;
211212
unsigned long shares;
212-
int err;
213+
int err, idx;
213214

214215
if (nice < MIN_NICE || nice > MAX_NICE)
215216
return -EINVAL;
@@ -227,7 +228,9 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int nice)
227228

228229
next = HZ / 10 + jiffies;
229230
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]);
231234

232235
down_write(&ag->lock);
233236
err = sched_group_set_shares(ag->tg, shares);

0 commit comments

Comments
 (0)