Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0bdba580 authored by Tomasz Buchert's avatar Tomasz Buchert Committed by Linus Torvalds
Browse files

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: default avatarTomasz 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d5de4ddb
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -173,24 +173,25 @@ static int freezer_can_attach(struct cgroup_subsys *ss,

	/*
	 * Anything frozen can't move or be moved to/from.
	 *
	 * Since orig_freezer->state == FROZEN means that @task has been
	 * frozen, so it's sufficient to check the latter condition.
	 */

	if (is_task_frozen_enough(task))
	freezer = cgroup_freezer(new_cgroup);
	if (freezer->state != CGROUP_THAWED)
		return -EBUSY;

	freezer = cgroup_freezer(new_cgroup);
	if (freezer->state == CGROUP_FROZEN)
	rcu_read_lock();
	if (__cgroup_freezing_or_frozen(task)) {
		rcu_read_unlock();
		return -EBUSY;
	}
	rcu_read_unlock();

	if (threadgroup) {
		struct task_struct *c;

		rcu_read_lock();
		list_for_each_entry_rcu(c, &task->thread_group, thread_group) {
			if (is_task_frozen_enough(c)) {
			if (__cgroup_freezing_or_frozen(c)) {
				rcu_read_unlock();
				return -EBUSY;
			}