Skip to content

Commit

Permalink
sched/autogroup: Fix race with task_groups list
Browse files Browse the repository at this point in the history
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: Gerald Schaefer <[email protected]>
Signed-off-by: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
gerald-schaefer authored and Ingo Molnar committed May 28, 2013
1 parent d07e75a commit 41261b6
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions kernel/sched/auto_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ static inline struct autogroup *autogroup_create(void)
if (IS_ERR(tg))
goto out_free;

sched_online_group(tg, &root_task_group);

kref_init(&ag->kref);
init_rwsem(&ag->lock);
ag->id = atomic_inc_return(&autogroup_seq_nr);
Expand All @@ -98,6 +96,7 @@ static inline struct autogroup *autogroup_create(void)
#endif
tg->autogroup = ag;

sched_online_group(tg, &root_task_group);
return ag;

out_free:
Expand Down

0 comments on commit 41261b6

Please sign in to comment.