From 4f866f6a1073e739dde82d664bed587b51f2dca7 Mon Sep 17 00:00:00 2001 From: "Gustavo A. R. Silva" Date: Mon, 16 Oct 2023 20:25:39 +0800 Subject: [PATCH 1/2] x86/platform/UV: Replace kmalloc() and memset() with k[cz]alloc() calls mainline inclusion from mainline-v5.1-rc1 commit 2bc217c61685487987c5befd807e10936371643c category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I85XB3 CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2bc217c61685487987c5befd807e10936371643c -------------------------------- x86/platform/UV: Replace kmalloc() and memset() with k[cz]alloc() calls Replace kmalloc_node() and memset() with kzalloc_node(), and kmalloc_array() and memset() with kcalloc(). This code was detected with the help of Coccinelle. No functional changes. Signed-off-by: Gustavo A. R. Silva Signed-off-by: Borislav Petkov Cc: "H. Peter Anvin" Cc: "Peter Zijlstra (Intel)" Cc: Andrew Banman Cc: Andy Lutomirski Cc: Colin Ian King Cc: Ingo Molnar Cc: Kees Cook Cc: Nicolai Stange Cc: Thomas Gleixner Cc: Varsha Rao Cc: x86-ml Link: https://lkml.kernel.org/r/20190115173713.GA31031@embeddedor Signed-off-by: Zheng Haoran <19373368@buaa.edu.cn> --- arch/x86/platform/uv/tlb_uv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c index a4130b84d1ff..2c53b0f19329 100644 --- a/arch/x86/platform/uv/tlb_uv.c +++ b/arch/x86/platform/uv/tlb_uv.c @@ -2010,8 +2010,7 @@ static void make_per_cpu_thp(struct bau_control *smaster) int cpu; size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus(); - smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode); - memset(smaster->thp, 0, hpsz); + smaster->thp = kzalloc_node(hpsz, GFP_KERNEL, smaster->osnode); for_each_present_cpu(cpu) { smaster->thp[cpu].pnode = uv_cpu_hub_info(cpu)->pnode; smaster->thp[cpu].uvhub = uv_cpu_hub_info(cpu)->numa_blade_id; @@ -2135,15 +2134,12 @@ static int __init summarize_uvhub_sockets(int nuvhubs, static int __init init_per_cpu(int nuvhubs, int base_part_pnode) { unsigned char *uvhub_mask; - void *vp; struct uvhub_desc *uvhub_descs; if (is_uv3_hub() || is_uv2_hub() || is_uv1_hub()) timeout_us = calculate_destination_timeout(); - vp = kmalloc_array(nuvhubs, sizeof(struct uvhub_desc), GFP_KERNEL); - uvhub_descs = (struct uvhub_desc *)vp; - memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc)); + uvhub_descs = kcalloc(nuvhubs, sizeof(struct uvhub_desc), GFP_KERNEL); uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL); if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask)) -- Gitee From 8553763ec728a58313914bf8e090502ef7a95b5c Mon Sep 17 00:00:00 2001 From: Kangjie Lu Date: Mon, 16 Oct 2023 20:26:56 +0800 Subject: [PATCH 2/2] x86/platform/uv: Fix missing checks of kcalloc() return values mainline inclusion from mainline-v5.2-rc1 commit 766460852cfaeca4042e5f3aeb9616b3689147bc category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I85XB3 CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=766460852cfaeca4042e5f3aeb9616b3689147bc -------------------------------- x86/platform/uv: Fix missing checks of kcalloc() return values Handle potential errors returned from kcalloc(). [ bp: rewrite commit message. ] Signed-off-by: Kangjie Lu Signed-off-by: Borislav Petkov Cc: Andrew Banman Cc: Andy Shevchenko Cc: Colin Ian King Cc: Darren Hart Cc: "Gustavo A. R. Silva" Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Kees Cook Cc: Mike Travis Cc: Nicolai Stange Cc: pakki001@umn.edu Cc: platform-driver-x86@vger.kernel.org Cc: Thomas Gleixner Cc: Varsha Rao Cc: x86-ml Link: https://lkml.kernel.org/r/20190325202924.4624-1-kjlu@umn.edu Signed-off-by: Zheng Haoran <19373368@buaa.edu.cn> --- arch/x86/platform/uv/tlb_uv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c index 2c53b0f19329..1297e185b8c8 100644 --- a/arch/x86/platform/uv/tlb_uv.c +++ b/arch/x86/platform/uv/tlb_uv.c @@ -2133,14 +2133,19 @@ static int __init summarize_uvhub_sockets(int nuvhubs, */ static int __init init_per_cpu(int nuvhubs, int base_part_pnode) { - unsigned char *uvhub_mask; struct uvhub_desc *uvhub_descs; + unsigned char *uvhub_mask = NULL; if (is_uv3_hub() || is_uv2_hub() || is_uv1_hub()) timeout_us = calculate_destination_timeout(); uvhub_descs = kcalloc(nuvhubs, sizeof(struct uvhub_desc), GFP_KERNEL); + if (!uvhub_descs) + goto fail; + uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL); + if (!uvhub_mask) + goto fail; if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask)) goto fail; -- Gitee