From 4928d2dfe87274440a7a198290c787f6b5d634b0 Mon Sep 17 00:00:00 2001 From: Miaohe Lin Date: Wed, 29 Mar 2023 11:20:05 +0800 Subject: [PATCH] mm: compaction: avoid possible NULL pointer dereference in kcompactd_cpu_online mainline inclusion from mainline-v6.3-rc1 commit 3109de308987ceae413ee015038d51e2a86c7806 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I6POXN CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3109de308987ceae413ee015038d51e2a86c7806 -------------------------------- It's possible that kcompactd_run could fail to run kcompactd for a hot added node and leave pgdat->kcompactd as NULL. So pgdat->kcompactd should be checked here to avoid possible NULL pointer dereference. Link: https://lkml.kernel.org/r/20220418141253.24298-10-linmiaohe@huawei.com Signed-off-by: Miaohe Lin Cc: Charan Teja Kalla Cc: David Hildenbrand Cc: Pintu Kumar Cc: Vlastimil Babka Signed-off-by: Andrew Morton Signed-off-by: Ze Zuo Reviewed-by: Kefeng Wang Signed-off-by: Jialin Zhang --- mm/compaction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index 509dee7c2f38..8e8017d909b7 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2949,7 +2949,8 @@ static int kcompactd_cpu_online(unsigned int cpu) if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids) /* One of our CPUs online: restore mask */ - set_cpus_allowed_ptr(pgdat->kcompactd, mask); + if (pgdat->kcompactd) + set_cpus_allowed_ptr(pgdat->kcompactd, mask); } return 0; } -- GitLab