Skip to content

Commit 339df13

Browse files
Xiu Jianfenggregkh
authored andcommitted
cgroup: Fix potential overflow issue when checking max_depth
[ Upstream commit 3cc4e13 ] 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 <xiujianfeng@huawei.com> Reviewed-by: Michal Koutný <mkoutny@suse.com> Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 7c47d87 commit 339df13

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

kernel/cgroup/cgroup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5104,15 +5104,15 @@ static bool cgroup_check_hierarchy_limits(struct cgroup *parent)
51045104
{
51055105
struct cgroup *cgroup;
51065106
int ret = false;
5107-
int level = 1;
5107+
int level = 0;
51085108

51095109
lockdep_assert_held(&cgroup_mutex);
51105110

51115111
for (cgroup = parent; cgroup; cgroup = cgroup_parent(cgroup)) {
51125112
if (cgroup->nr_descendants >= cgroup->max_descendants)
51135113
goto fail;
51145114

5115-
if (level > cgroup->max_depth)
5115+
if (level >= cgroup->max_depth)
51165116
goto fail;
51175117

51185118
level++;

0 commit comments

Comments
 (0)