2022-05-17 09:04:41

by Stephen Zhang

[permalink] [raw]
Subject: [PATCH] cgroup: fix potential null pointer risk

We previously assumed 'parent' could be null,
so null pointer judgment should be added.

Signed-off-by: Shida Zhang <[email protected]>
---
kernel/cgroup/cgroup.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index adb820e98f24..7f230b0ab644 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -5701,7 +5701,8 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
}
spin_unlock_irq(&css_set_lock);

- cgroup1_check_for_release(parent);
+ if (parent)
+ cgroup1_check_for_release(parent);

cgroup_bpf_offline(cgrp);

--
2.25.1



2022-05-18 03:35:17

by Stephen Zhang

[permalink] [raw]
Subject: Re: [PATCH] cgroup: fix potential null pointer risk

Tejun Heo <[email protected]> 于2022年5月18日周三 01:07写道:
>
> The function is never called for a root cgroup. The parent check up above in
> the same function is superflous. So, maybe remove that?
>
> Thanks.
>
> --
> tejun

Thanks. I will remake a patch based on this.


--
Stephen

2022-05-18 04:35:25

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH] cgroup: fix potential null pointer risk

On Tue, May 17, 2022 at 03:31:06PM +0800, Shida Zhang wrote:
> We previously assumed 'parent' could be null,
> so null pointer judgment should be added.
>
> Signed-off-by: Shida Zhang <[email protected]>
> ---
> kernel/cgroup/cgroup.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
> index adb820e98f24..7f230b0ab644 100644
> --- a/kernel/cgroup/cgroup.c
> +++ b/kernel/cgroup/cgroup.c
> @@ -5701,7 +5701,8 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
> }
> spin_unlock_irq(&css_set_lock);
>
> - cgroup1_check_for_release(parent);
> + if (parent)
> + cgroup1_check_for_release(parent);

The function is never called for a root cgroup. The parent check up above in
the same function is superflous. So, maybe remove that?

Thanks.

--
tejun