cgroup: fix to break the while loop in cgroup_attach_task() correctly
authorShridhar Rasal <srasal@nvidia.com>
Thu, 24 Oct 2013 03:07:51 +0000 (08:07 +0530)
committerBharat Nihalani <bnihalani@nvidia.com>
Thu, 24 Oct 2013 07:25:19 +0000 (00:25 -0700)
commit9289b72929c91cc435fd53fae3986d7fb8729146
treea2015d546159a7b3570dd60eee93006c72f2dd0d
parent8631025377302cff1f011375d2669d3b545d89d6
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 081aa458c38ba576bdd4265fc807fa95b48b9e79
("cgroup: consolidate cgroup_attach_task() and cgroup_attach_proc()")

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>
[ lizf: - fixed the first continue, pointed out by Oleg,
        - rewrote changelog. ]

Bug 1355677

Change-Id: Ifa356d9869e888a759c2be943cffd394a4102a9a
Signed-off-by: Li Zefan <lizefan@huawei.com>
Signed-off-by: Shridhar Rasal <srasal@nvidia.com>
Signed-off-by: Ajay Nandakumar <anandakumarm@nvidia.com>
Reviewed-on: http://git-master/r/303135
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
Tested-by: Bharat Nihalani <bnihalani@nvidia.com>
kernel/cgroup.c