Skip to content

Commit 3cc4e13

Browse files
Xiu Jianfenghtejun
authored andcommitted
cgroup: Fix potential overflow issue when checking max_depth
cgroup.max.depth is the maximum allowed descent depth below the current cgroup. If the actual descent depth is equal or larger, an attempt to create a new child cgroup will fail. However due to the cgroup->max_depth is of int type and having the default value INT_MAX, the condition 'level > cgroup->max_depth' will never be satisfied, and it will cause an overflow of the level after it reaches to INT_MAX. Fix it by starting the level from 0 and using '>=' instead. It's worth mentioning that this issue is unlikely to occur in reality, as it's impossible to have a depth of INT_MAX hierarchy, but should be be avoided logically. Fixes: 1a926e0 ("cgroup: implement hierarchy limits") Signed-off-by: Xiu Jianfeng <[email protected]> Reviewed-by: Michal Koutný <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 117932e commit 3cc4e13

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/cgroup/cgroup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5789,15 +5789,15 @@ static bool cgroup_check_hierarchy_limits(struct cgroup *parent)
57895789
{
57905790
struct cgroup *cgroup;
57915791
int ret = false;
5792-
int level = 1;
5792+
int level = 0;
57935793

57945794
lockdep_assert_held(&cgroup_mutex);
57955795

57965796
for (cgroup = parent; cgroup; cgroup = cgroup_parent(cgroup)) {
57975797
if (cgroup->nr_descendants >= cgroup->max_descendants)
57985798
goto fail;
57995799

5800-
if (level > cgroup->max_depth)
5800+
if (level >= cgroup->max_depth)
58015801
goto fail;
58025802

58035803
level++;

0 commit comments

Comments
 (0)