Commit 41261b6a authored by Gerald Schaefer's avatar Gerald Schaefer Committed by Ingo Molnar

sched/autogroup: Fix race with task_groups list

In autogroup_create(), a tg is allocated and added to the task_groups
list. If CONFIG_RT_GROUP_SCHED is set, this tg is then modified while on
the list, without locking. This can race with someone walking the list,
like __enable_runtime() during CPU unplug, and result in a use-after-free
bug.

To fix this, move sched_online_group(), which adds the tg to the list,
to the end of the autogroup_create() function after the modification.
Signed-off-by: default avatarGerald Schaefer <gerald.schaefer@de.ibm.com>
Signed-off-by: default avatarPeter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1369411669-46971-2-git-send-email-gerald.schaefer@de.ibm.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent d07e75a6
...@@ -77,8 +77,6 @@ static inline struct autogroup *autogroup_create(void) ...@@ -77,8 +77,6 @@ static inline struct autogroup *autogroup_create(void)
if (IS_ERR(tg)) if (IS_ERR(tg))
goto out_free; goto out_free;
sched_online_group(tg, &root_task_group);
kref_init(&ag->kref); kref_init(&ag->kref);
init_rwsem(&ag->lock); init_rwsem(&ag->lock);
ag->id = atomic_inc_return(&autogroup_seq_nr); ag->id = atomic_inc_return(&autogroup_seq_nr);
...@@ -98,6 +96,7 @@ static inline struct autogroup *autogroup_create(void) ...@@ -98,6 +96,7 @@ static inline struct autogroup *autogroup_create(void)
#endif #endif
tg->autogroup = ag; tg->autogroup = ag;
sched_online_group(tg, &root_task_group);
return ag; return ag;
out_free: out_free:
......
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