From 5c44571bf03f55479afff1809ec9050231ab3f78 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Sat, 10 Oct 2020 15:40:28 +0800 Subject: [PATCH] percpu: use nr_groups as check condition mainline inclusion from mainline-5.1-rc1 commit 2de7852fe9096e92c5f10faa472550a2a7121cea category: bugfix bugzilla: 34611 CVE: NA ------------------------------------------------- group_cnt array is defined with NR_CPUS entries, but normally nr_groups will not reach up to NR_CPUS. So there is no issue to the current code. Checking other parts of pcpu_build_alloc_info, use nr_groups as check condition, so make it consistent to use 'group < nr_groups' as for loop check. In case we do have nr_groups equals with NR_CPUS, we could also avoid memory access out of bounds. Signed-off-by: Peng Fan Signed-off-by: Dennis Zhou (cherry picked from commit 2de7852fe9096e92c5f10faa472550a2a7121cea) Signed-off-by: Kefeng Wang Signed-off-by: Liu Shixin Reviewed-by: Kefeng Wang Signed-off-by: Yang Yingliang --- mm/percpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/percpu.c b/mm/percpu.c index 0151f276ae68..fef316942ea9 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -2387,7 +2387,7 @@ static struct pcpu_alloc_info * __init pcpu_build_alloc_info( ai->atom_size = atom_size; ai->alloc_size = alloc_size; - for (group = 0, unit = 0; group_cnt[group]; group++) { + for (group = 0, unit = 0; group < nr_groups; group++) { struct pcpu_group_info *gi = &ai->groups[group]; /* -- GitLab