Skip to content

Commit d1897c9

Browse files
committed
cgroup: fix rule checking for threaded mode switching
A domain cgroup isn't allowed to be turned threaded if its subtree is populated or domain controllers are enabled. cgroup_enable_threaded() depended on cgroup_can_be_thread_root() test to enforce this rule. A parent which has populated domain descendants or have domain controllers enabled can't become a thread root, so the above rules are enforced automatically. However, for the root cgroup which can host mixed domain and threaded children, cgroup_can_be_thread_root() doesn't check any of those conditions and thus first level cgroups ends up escaping those rules. This patch fixes the bug by adding explicit checks for those rules in cgroup_enable_threaded(). Reported-by: Michael Kerrisk (man-pages) <[email protected]> Signed-off-by: Tejun Heo <[email protected]> Fixes: 8cfd814 ("cgroup: implement cgroup v2 thread support") Cc: [email protected] # v4.14+
1 parent c53593e commit d1897c9

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

kernel/cgroup/cgroup.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,6 +3183,16 @@ static int cgroup_enable_threaded(struct cgroup *cgrp)
31833183
if (cgroup_is_threaded(cgrp))
31843184
return 0;
31853185

3186+
/*
3187+
* If @cgroup is populated or has domain controllers enabled, it
3188+
* can't be switched. While the below cgroup_can_be_thread_root()
3189+
* test can catch the same conditions, that's only when @parent is
3190+
* not mixable, so let's check it explicitly.
3191+
*/
3192+
if (cgroup_is_populated(cgrp) ||
3193+
cgrp->subtree_control & ~cgrp_dfl_threaded_ss_mask)
3194+
return -EOPNOTSUPP;
3195+
31863196
/* we're joining the parent's domain, ensure its validity */
31873197
if (!cgroup_is_valid_domain(dom_cgrp) ||
31883198
!cgroup_can_be_thread_root(dom_cgrp))

0 commit comments

Comments
 (0)