aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup_freezer.c
diff options
context:
space:
mode:
authorTomasz Buchert <tomasz.buchert@inria.fr>2010-10-27 18:33:33 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-10-27 21:03:08 -0400
commit0bdba580ab052a21e3eda2764ed22d9ee962392b (patch)
tree9d8fb958c8612a9c72b8662d9b51c12c76ccd0bb /kernel/cgroup_freezer.c
parentd5de4ddb1bc430289bede76c0d87cabee93f749a (diff)
cgroup_freezer: fix can_attach() to prohibit moving from/to freezing/frozen cgroups
It is possible to move a task from its cgroup even if this group is 'FREEZING'. This results in a nasty bug - the moved task will become frozen OUTSIDE its original cgroup and will remain in a permanent 'D' state. This patch allows to migrate the task only between THAWED cgroups. This behavior was observed and easily reproduced on a single core laptop. Notice that reproducibility depends highly on the machine used. Program and instructions how to reproduce the bug can be fetched from: http://pentium.hopto.org/~thinred/repos/linux-misc/freezer_bug.c Signed-off-by: Tomasz Buchert <tomasz.buchert@inria.fr> Cc: Matt Helsley <matthltc@us.ibm.com> Cc: Paul Menage <menage@google.com> Cc: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/cgroup_freezer.c')
-rw-r--r--kernel/cgroup_freezer.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
index 321e2a007d25..c287627bed3d 100644
--- a/kernel/cgroup_freezer.c
+++ b/kernel/cgroup_freezer.c
@@ -173,24 +173,25 @@ static int freezer_can_attach(struct cgroup_subsys *ss,
173 173
174 /* 174 /*
175 * Anything frozen can't move or be moved to/from. 175 * Anything frozen can't move or be moved to/from.
176 *
177 * Since orig_freezer->state == FROZEN means that @task has been
178 * frozen, so it's sufficient to check the latter condition.
179 */ 176 */
180 177
181 if (is_task_frozen_enough(task)) 178 freezer = cgroup_freezer(new_cgroup);
179 if (freezer->state != CGROUP_THAWED)
182 return -EBUSY; 180 return -EBUSY;
183 181
184 freezer = cgroup_freezer(new_cgroup); 182 rcu_read_lock();
185 if (freezer->state == CGROUP_FROZEN) 183 if (__cgroup_freezing_or_frozen(task)) {
184 rcu_read_unlock();
186 return -EBUSY; 185 return -EBUSY;
186 }
187 rcu_read_unlock();
187 188
188 if (threadgroup) { 189 if (threadgroup) {
189 struct task_struct *c; 190 struct task_struct *c;
190 191
191 rcu_read_lock(); 192 rcu_read_lock();
192 list_for_each_entry_rcu(c, &task->thread_group, thread_group) { 193 list_for_each_entry_rcu(c, &task->thread_group, thread_group) {
193 if (is_task_frozen_enough(c)) { 194 if (__cgroup_freezing_or_frozen(c)) {
194 rcu_read_unlock(); 195 rcu_read_unlock();
195 return -EBUSY; 196 return -EBUSY;
196 } 197 }