Skip to content

Commit 97a6136

Browse files
rgushchinhtejun
authored andcommitted
cgroup: freezer: fix frozen state inheritance
If a new child cgroup is created in the frozen cgroup hierarchy (one or more of ancestor cgroups is frozen), the CGRP_FREEZE cgroup flag should be set. Otherwise if a process will be attached to the child cgroup, it won't become frozen. The problem can be reproduced with the test_cgfreezer_mkdir test. This is the output before this patch: ~/test_freezer ok 1 test_cgfreezer_simple ok 2 test_cgfreezer_tree ok 3 test_cgfreezer_forkbomb Cgroup /sys/fs/cgroup/cg_test_mkdir_A/cg_test_mkdir_B isn't frozen not ok 4 test_cgfreezer_mkdir ok 5 test_cgfreezer_rmdir ok 6 test_cgfreezer_migrate ok 7 test_cgfreezer_ptrace ok 8 test_cgfreezer_stopped ok 9 test_cgfreezer_ptraced ok 10 test_cgfreezer_vfork And with this patch: ~/test_freezer ok 1 test_cgfreezer_simple ok 2 test_cgfreezer_tree ok 3 test_cgfreezer_forkbomb ok 4 test_cgfreezer_mkdir ok 5 test_cgfreezer_rmdir ok 6 test_cgfreezer_migrate ok 7 test_cgfreezer_ptrace ok 8 test_cgfreezer_stopped ok 9 test_cgfreezer_ptraced ok 10 test_cgfreezer_vfork Reported-by: Mark Crossen <[email protected]> Signed-off-by: Roman Gushchin <[email protected]> Fixes: 76f969e ("cgroup: cgroup v2 freezer") Cc: Tejun Heo <[email protected]> Cc: [email protected] # v5.2+ Signed-off-by: Tejun Heo <[email protected]>
1 parent 44e9d30 commit 97a6136

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

kernel/cgroup/cgroup.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5255,8 +5255,16 @@ static struct cgroup *cgroup_create(struct cgroup *parent)
52555255
* if the parent has to be frozen, the child has too.
52565256
*/
52575257
cgrp->freezer.e_freeze = parent->freezer.e_freeze;
5258-
if (cgrp->freezer.e_freeze)
5258+
if (cgrp->freezer.e_freeze) {
5259+
/*
5260+
* Set the CGRP_FREEZE flag, so when a process will be
5261+
* attached to the child cgroup, it will become frozen.
5262+
* At this point the new cgroup is unpopulated, so we can
5263+
* consider it frozen immediately.
5264+
*/
5265+
set_bit(CGRP_FREEZE, &cgrp->flags);
52595266
set_bit(CGRP_FROZEN, &cgrp->flags);
5267+
}
52605268

52615269
spin_lock_irq(&css_set_lock);
52625270
for (tcgrp = cgrp; tcgrp; tcgrp = cgroup_parent(tcgrp)) {

0 commit comments

Comments
 (0)