Skip to content

Commit

Permalink
sched: Don't use possibly stale sched_class
Browse files Browse the repository at this point in the history
commit 83ab0aa upstream.

setscheduler() saves task->sched_class outside of the rq->lock held
region for a check after the setscheduler changes have become
effective. That might result in checking a stale value.

rtmutex_setprio() has the same problem, though it is protected by
p->pi_lock against setscheduler(), but for correctness sake (and to
avoid bad examples) it needs to be fixed as well.

Retrieve task->sched_class inside of the rq->lock held region.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Thomas Gleixner authored and Greg Kroah-Hartman committed Mar 15, 2010
1 parent 51c80d1 commit 371f1d1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -6065,14 +6065,15 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
unsigned long flags;
int oldprio, on_rq, running;
struct rq *rq;
const struct sched_class *prev_class = p->sched_class;
const struct sched_class *prev_class;

BUG_ON(prio < 0 || prio > MAX_PRIO);

rq = task_rq_lock(p, &flags);
update_rq_clock(rq);

oldprio = p->prio;
prev_class = p->sched_class;
on_rq = p->se.on_rq;
running = task_current(rq, p);
if (on_rq)
Expand Down Expand Up @@ -6292,7 +6293,7 @@ static int __sched_setscheduler(struct task_struct *p, int policy,
{
int retval, oldprio, oldpolicy = -1, on_rq, running;
unsigned long flags;
const struct sched_class *prev_class = p->sched_class;
const struct sched_class *prev_class;
struct rq *rq;
int reset_on_fork;

Expand Down Expand Up @@ -6406,6 +6407,7 @@ static int __sched_setscheduler(struct task_struct *p, int policy,
p->sched_reset_on_fork = reset_on_fork;

oldprio = p->prio;
prev_class = p->sched_class;
__setscheduler(rq, p, policy, param->sched_priority);

if (running)
Expand Down

0 comments on commit 371f1d1

Please sign in to comment.