]> git.baikalelectronics.ru Git - kernel.git/commit
cgroup: fix to break the while loop in cgroup_attach_task() correctly
authorAnjana V Kumar <anjanavk12@gmail.com>
Sat, 12 Oct 2013 02:59:17 +0000 (10:59 +0800)
committerTejun Heo <tj@kernel.org>
Sun, 13 Oct 2013 20:07:10 +0000 (16:07 -0400)
commite071e70e20707984d42f7d3803659a182206f4a8
tree5e5f08d2c9a4f7fdc434d1fc7db3f7095809dd23
parent7318dbb19301d0250a986f37869e60a7c4f36a49
cgroup: fix to break the while loop in cgroup_attach_task() correctly

Both Anjana and Eunki reported a stall in the while_each_thread loop
in cgroup_attach_task().

It's because, when we attach a single thread to a cgroup, if the cgroup
is exiting or is already in that cgroup, we won't break the loop.

If the task is already in the cgroup, the bug can lead to another thread
being attached to the cgroup unexpectedly:

  # echo 5207 > tasks
  # cat tasks
  5207
  # echo 5207 > tasks
  # cat tasks
  5207
  5215

What's worse, if the task to be attached isn't the leader of the thread
group, we might never exit the loop, hence cpu stall. Thanks for Oleg's
analysis.

This bug was introduced by commit 622223fff689033ca9eff8c48184beffe3aedaf1
("cgroup: consolidate cgroup_attach_task() and cgroup_attach_proc()")

[ lizf: - fixed the first continue, pointed out by Oleg,
        - rewrote changelog. ]

Cc: <stable@vger.kernel.org> # 3.9+
Reported-by: Eunki Kim <eunki_kim@samsung.com>
Reported-by: Anjana V Kumar <anjanavk12@gmail.com>
Signed-off-by: Anjana V Kumar <anjanavk12@gmail.com>
Signed-off-by: Li Zefan <lizefan@huawei.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup.c