Skip to content

Commit 33ef6b6

Browse files
bblumtorvalds
authored andcommitted
cgroups: more safe tasklist locking in cgroup_attach_proc
Fix unstable tasklist locking in cgroup_attach_proc. According to this thread - https://lkml.org/lkml/2011/7/27/243 - RCU is not sufficient to guarantee the tasklist is stable w.r.t. de_thread and exit. Taking tasklist_lock for reading, instead of rcu_read_lock, ensures proper exclusion. Signed-off-by: Ben Blum <bblum@andrew.cmu.edu> Acked-by: Paul Menage <paul@paulmenage.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> Cc: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 434a964 commit 33ef6b6

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎kernel/cgroup.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,7 +2027,7 @@ int cgroup_attach_proc(struct cgroup *cgrp, struct task_struct *leader)
20272027
goto out_free_group_list;
20282028

20292029
/* prevent changes to the threadgroup list while we take a snapshot. */
2030-
rcu_read_lock();
2030+
read_lock(&tasklist_lock);
20312031
if (!thread_group_leader(leader)) {
20322032
/*
20332033
* a race with de_thread from another thread's exec() may strip
@@ -2036,7 +2036,7 @@ int cgroup_attach_proc(struct cgroup *cgrp, struct task_struct *leader)
20362036
* throw this task away and try again (from cgroup_procs_write);
20372037
* this is "double-double-toil-and-trouble-check locking".
20382038
*/
2039-
rcu_read_unlock();
2039+
read_unlock(&tasklist_lock);
20402040
retval = -EAGAIN;
20412041
goto out_free_group_list;
20422042
}
@@ -2057,7 +2057,7 @@ int cgroup_attach_proc(struct cgroup *cgrp, struct task_struct *leader)
20572057
} while_each_thread(leader, tsk);
20582058
/* remember the number of threads in the array for later. */
20592059
group_size = i;
2060-
rcu_read_unlock();
2060+
read_unlock(&tasklist_lock);
20612061

20622062
/*
20632063
* step 1: check that we can legitimately attach to the cgroup.

0 commit comments

Comments
 (0)