Skip to content

Commit

Permalink
sched: Use dl_bw_of() under RCU read lock
Browse files Browse the repository at this point in the history
dl_bw_of() dereferences rq->rd which has to have RCU read lock held.
Probability of use-after-free isn't zero here.

Also add lockdep assert into dl_bw_cpus().

Signed-off-by: Kirill Tkhai <ktkhai@parallels.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: <stable@vger.kernel.org> # v3.14+
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/20140922183624.11015.71558.stgit@localhost
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Kirill Tkhai authored and Ingo Molnar committed Sep 24, 2014
1 parent 7a96c23 commit 66339c3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,8 @@ unsigned long to_ratio(u64 period, u64 runtime)
#ifdef CONFIG_SMP
inline struct dl_bw *dl_bw_of(int i)
{
rcu_lockdep_assert(rcu_read_lock_sched_held(),
"sched RCU must be held");
return &cpu_rq(i)->rd->dl_bw;
}

Expand All @@ -2029,6 +2031,8 @@ static inline int dl_bw_cpus(int i)
struct root_domain *rd = cpu_rq(i)->rd;
int cpus = 0;

rcu_lockdep_assert(rcu_read_lock_sched_held(),
"sched RCU must be held");
for_each_cpu_and(i, rd->span, cpu_active_mask)
cpus++;

Expand Down Expand Up @@ -7645,6 +7649,8 @@ static int sched_dl_global_constraints(void)
int cpu, ret = 0;
unsigned long flags;

rcu_read_lock();

/*
* Here we want to check the bandwidth not being set to some
* value smaller than the currently allocated bandwidth in
Expand All @@ -7666,6 +7672,8 @@ static int sched_dl_global_constraints(void)
break;
}

rcu_read_unlock();

return ret;
}

Expand All @@ -7681,6 +7689,7 @@ static void sched_dl_do_global(void)
if (global_rt_runtime() != RUNTIME_INF)
new_bw = to_ratio(global_rt_period(), global_rt_runtime());

rcu_read_lock();
/*
* FIXME: As above...
*/
Expand All @@ -7691,6 +7700,7 @@ static void sched_dl_do_global(void)
dl_b->bw = new_bw;
raw_spin_unlock_irqrestore(&dl_b->lock, flags);
}
rcu_read_unlock();
}

static int sched_rt_global_validate(void)
Expand Down

0 comments on commit 66339c3

Please sign in to comment.