Commit 8dd710f1 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Kleber Sacilotto de Souza

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: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarPeter 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: default avatarIngo Molnar <mingo@kernel.org>

CVE-2017-5753

(backported from commit 354d7793)
[juergh:
 - Adjusted context.
 - Modified kernel/sched/auto_group.c instead of kernel/sched/autogroup.c.]
Signed-off-by: default avatarJuerg Haefliger <juergh@canonical.com>
Acked-by: default avatarStefan Bader <stefan.bader@canonical.com>
Acked-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 12ef5692
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <linux/utsname.h> #include <linux/utsname.h>
#include <linux/security.h> #include <linux/security.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/nospec.h>
unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1; unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
static struct autogroup autogroup_default; static struct autogroup autogroup_default;
...@@ -193,7 +194,7 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int nice) ...@@ -193,7 +194,7 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int nice)
{ {
static unsigned long next = INITIAL_JIFFIES; static unsigned long next = INITIAL_JIFFIES;
struct autogroup *ag; struct autogroup *ag;
int err; int err, idx;
if (nice < MIN_NICE || nice > MAX_NICE) if (nice < MIN_NICE || nice > MAX_NICE)
return -EINVAL; return -EINVAL;
...@@ -213,7 +214,9 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int nice) ...@@ -213,7 +214,9 @@ int proc_sched_autogroup_set_nice(struct task_struct *p, int nice)
ag = autogroup_task_get(p); ag = autogroup_task_get(p);
down_write(&ag->lock); down_write(&ag->lock);
err = sched_group_set_shares(ag->tg, prio_to_weight[nice + 20]);
idx = array_index_nospec(nice + 20, 40);
err = sched_group_set_shares(ag->tg, prio_to_weight[idx]);
if (!err) if (!err)
ag->nice = nice; ag->nice = nice;
up_write(&ag->lock); up_write(&ag->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment