From: Ren Zhijie renzhijie2@huawei.com
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I5QQFG CVE: NA
--------------------------------
The pointer which is tg->css.cgroup may be NULL. To avoid NULL pointer dereference error, add a check in bpf_sched_entity_to_cgrpid() and bpf_sched_entity_belongs_to_cgrp().
Fixes: 628738d6a3f1 ("bpf: sched: add convenient helpers to identify sched entities") Signed-off-by: Ren Zhijie renzhijie2@huawei.com --- kernel/sched/bpf_sched.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/kernel/sched/bpf_sched.c b/kernel/sched/bpf_sched.c index 7485077d5a93..99211235a028 100644 --- a/kernel/sched/bpf_sched.c +++ b/kernel/sched/bpf_sched.c @@ -62,7 +62,7 @@ BPF_CALL_1(bpf_sched_entity_to_tgidpid, struct sched_entity *, se) BPF_CALL_1(bpf_sched_entity_to_cgrpid, struct sched_entity *, se) { #ifdef CONFIG_FAIR_GROUP_SCHED - if (!entity_is_task(se)) + if (!entity_is_task(se) && se->my_q->tg->css.cgroup) return cgroup_id(se->my_q->tg->css.cgroup); #endif return (u64) -1; @@ -82,9 +82,11 @@ BPF_CALL_2(bpf_sched_entity_belongs_to_cgrp, struct sched_entity *, se, cgrp = se->my_q->tg->css.cgroup; #endif
- for (level = cgrp->level; level; level--) - if (cgrp->ancestor_ids[level] == cgrpid) - return 1; + if (cgrp) { + for (level = cgrp->level; level; level--) + if (cgrp->ancestor_ids[level] == cgrpid) + return 1; + } #endif return 0; }