* [PATCH] cgroup: Fix potential overflow issue when checking max_depth
@ 2024-10-12 7:22 Xiu Jianfeng
2024-10-14 13:37 ` Michal Koutný
2024-10-14 23:40 ` Tejun Heo
0 siblings, 2 replies; 4+ messages in thread
From: Xiu Jianfeng @ 2024-10-12 7:22 UTC (permalink / raw)
To: tj, lizefan.x, hannes, mkoutny, roman.gushchin
Cc: cgroups, linux-kernel, wangweiyang2
From: Xiu Jianfeng <xiujianfeng@huawei.com>
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: 1a926e0bbab8 ("cgroup: implement hierarchy limits")
Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
kernel/cgroup/cgroup.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 5886b95c6eae..044c7ba1cc48 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -5789,7 +5789,7 @@ static bool cgroup_check_hierarchy_limits(struct cgroup *parent)
{
struct cgroup *cgroup;
int ret = false;
- int level = 1;
+ int level = 0;
lockdep_assert_held(&cgroup_mutex);
@@ -5797,7 +5797,7 @@ static bool cgroup_check_hierarchy_limits(struct cgroup *parent)
if (cgroup->nr_descendants >= cgroup->max_descendants)
goto fail;
- if (level > cgroup->max_depth)
+ if (level >= cgroup->max_depth)
goto fail;
level++;
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cgroup: Fix potential overflow issue when checking max_depth
2024-10-12 7:22 [PATCH] cgroup: Fix potential overflow issue when checking max_depth Xiu Jianfeng
@ 2024-10-14 13:37 ` Michal Koutný
2024-10-14 14:17 ` Xiu Jianfeng
2024-10-14 23:40 ` Tejun Heo
1 sibling, 1 reply; 4+ messages in thread
From: Michal Koutný @ 2024-10-14 13:37 UTC (permalink / raw)
To: Xiu Jianfeng
Cc: tj, lizefan.x, hannes, roman.gushchin, cgroups, linux-kernel,
wangweiyang2
[-- Attachment #1: Type: text/plain, Size: 773 bytes --]
Hello.
On Sat, Oct 12, 2024 at 07:22:46AM GMT, Xiu Jianfeng <xiujianfeng@huaweicloud.com> wrote:
> 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.
Strictly speaking the overflow would be undefined behavior (Out of curiousity --
have you figured this out with a checker tool or code reading?)
Logically (neglecting UB), max_depth=INT_MAX would behave like intended
(no limit).
> Fixes: 1a926e0bbab8 ("cgroup: implement hierarchy limits")
> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
> ---
> kernel/cgroup/cgroup.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Michal Koutný <mkoutny@suse.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cgroup: Fix potential overflow issue when checking max_depth
2024-10-14 13:37 ` Michal Koutný
@ 2024-10-14 14:17 ` Xiu Jianfeng
0 siblings, 0 replies; 4+ messages in thread
From: Xiu Jianfeng @ 2024-10-14 14:17 UTC (permalink / raw)
To: Michal Koutný
Cc: tj, lizefan.x, hannes, roman.gushchin, cgroups, linux-kernel,
wangweiyang2
Hi Michal,
On 2024/10/14 21:37, Michal Koutný wrote:
> Hello.
>
> On Sat, Oct 12, 2024 at 07:22:46AM GMT, Xiu Jianfeng <xiujianfeng@huaweicloud.com> wrote:
>> 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.
>
> Strictly speaking the overflow would be undefined behavior (Out of curiousity --
> have you figured this out with a checker tool or code reading?)
Thanks for your review, I figured it out with code reading.
> Logically (neglecting UB), max_depth=INT_MAX would behave like intended
> (no limit).
Agreed, this is the real 'no limit'.
>
>> Fixes: 1a926e0bbab8 ("cgroup: implement hierarchy limits")
>> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
>> ---
>> kernel/cgroup/cgroup.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> Reviewed-by: Michal Koutný <mkoutny@suse.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cgroup: Fix potential overflow issue when checking max_depth
2024-10-12 7:22 [PATCH] cgroup: Fix potential overflow issue when checking max_depth Xiu Jianfeng
2024-10-14 13:37 ` Michal Koutný
@ 2024-10-14 23:40 ` Tejun Heo
1 sibling, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2024-10-14 23:40 UTC (permalink / raw)
To: Xiu Jianfeng
Cc: lizefan.x, hannes, mkoutny, roman.gushchin, cgroups,
linux-kernel, wangweiyang2
On Sat, Oct 12, 2024 at 07:22:46AM +0000, Xiu Jianfeng wrote:
> From: Xiu Jianfeng <xiujianfeng@huawei.com>
>
> 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: 1a926e0bbab8 ("cgroup: implement hierarchy limits")
> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
Applied to cgroup/for-6.12-fixes.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-14 23:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-12 7:22 [PATCH] cgroup: Fix potential overflow issue when checking max_depth Xiu Jianfeng
2024-10-14 13:37 ` Michal Koutný
2024-10-14 14:17 ` Xiu Jianfeng
2024-10-14 23:40 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®