Re: [PATCH] cgroup: fix to break the while loop incgroup_attach_task() correctly

From: Tejun Heo
Date: Sun Oct 13 2013 - 16:08:24 EST


On Sat, Oct 12, 2013 at 10:59:17AM +0800, Li Zefan wrote:
> From: Anjana V Kumar <anjanavk12@xxxxxxxxx>
>
> 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@xxxxxxxxxxxxxxx> # 3.9+
> Reported-by: Eunki Kim <eunki_kim@xxxxxxxxxxx>
> Reported-by: Anjana V Kumar <anjanavk12@xxxxxxxxx>
> Signed-off-by: Anjana V Kumar <anjanavk12@xxxxxxxxx>
> [ lizf: - fixed the first continue, pointed out by Oleg,
> - rewrote changelog. ]
> Signed-off-by: Li Zefan <lizefan@xxxxxxxxxx>

Applied to cgroup/for-3.12-fixes.

Thanks.

--
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/