platform: uv: fix missing checks for kcalloc
Subsystems (3)
PATCH 1/1 platform: uv: fix missing checks for kcalloc
In case kcalloc fails, the patch return an error to avoid potential NULL pointer dereference.
--- arch/x86/platform/uv/tlb_uv.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/x86/platform/uv/tlb_uv.c +6 -0
@@ -2140,7 +2140,13 @@ static int __init init_per_cpu(int nuvhubs, int base_part_pnode) timeout_us =calculate_destination_timeout (); uvhub_descs =kcalloc (nuvhubs,sizeof (struct uvhub_desc ),GFP_KERNEL ); +if (!uvhub_descs) +return 1 ; uvhub_mask =kzalloc ((nuvhubs+7 )/8 ,GFP_KERNEL ); +if (!uvhub_mask) { +kfree (uvhub_descs); +return 1 ; + }if (get_cpu_topology (base_part_pnode, uvhub_descs, uvhub_mask)) goto fail;
Signature · 1 line
2.17.1
Borislav Petkov
maintainerQuoted 13 lines · Kangjie Lu
In case kcalloc fails, the patch return an error to avoid potential NULL pointer dereference.
Signed-off-by Kangjie Lu <[email protected]>--- arch/x86/platform/uv/tlb_uv.c | 6 ++++++ 1 file changed, 6 insertions(+)arch/x86/platform/uv/tlb_uv.c +0
-0
arch/x86/platform/uv/tlb_uv.c static int __init init_per_cpu(int nuvhubs, int base_part_pnode) · line 2144
Quoted 5 lines
arch/x86/platform/uv/tlb_uv.c +2
-0@@ -2140,7 +2140,13 @@ static int __init init_per_cpu(int nuvhubs, int base_part_pnode) timeout_us =calculate_destination_timeout (); uvhub_descs =kcalloc (nuvhubs,sizeof (struct uvhub_desc ),GFP_KERNEL ); +if (!uvhub_descs) +return 1 ;
Here...
arch/x86/platform/uv/tlb_uv.c static int __init init_per_cpu(int nuvhubs, int base_part_pnode) · line 2149
Quoted 5 lines
arch/x86/platform/uv/tlb_uv.c +4
-0uvhub_mask =kzalloc ((nuvhubs+7 )/8 ,GFP_KERNEL ); +if (!uvhub_mask) { +kfree (uvhub_descs); +return 1 ; + }
... and here you can simply do
goto fail;
instead. After having initialized uvhub_descs and uvhub_mask to NULL;
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.PATCH v2 1/1 platform: uv: fix missing checks for kcalloc
In case kcalloc fails, the patch return an error to avoid potential NULL pointer dereference.
---
v2: reuse existing error path as suggested by
Borislav Petkov <[email protected]>
--- arch/x86/platform/uv/tlb_uv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/platform/uv/tlb_uv.c +5 -1
@@ -2133,14 +2133,18 @@ 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;
Signature · 1 line
2.17.1
tip-bot for Kangjie Lu
merge bot[tip:x86/cleanups] x86/platform/uv: Fix missing checks of kcalloc() return values
x86/platform/uv: Fix missing checks of kcalloc() return values
Commit-ID: 766460852cfaeca4042e5f3aeb9616b3689147bc Gitweb: https://git.kernel.org/tip/766460852cfaeca4042e5f3aeb9616b3689147bc Author: Kangjie Lu <[email protected]> AuthorDate: Mon, 25 Mar 2019 15:29:22 -0500 Committer: Borislav Petkov <[email protected]> CommitDate: Tue, 26 Mar 2019 17:01:30 +0100
x86/platform/uv: Fix missing checks of kcalloc() return values
Handle potential errors returned from kcalloc().
[ bp: rewrite commit message. ]
--- arch/x86/platform/uv/tlb_uv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/platform/uv/tlb_uv.c +6 -1
@@ -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;
Quoted 5 lines · Kangjie Lu
In case kcalloc fails, the patch return an error to avoid potential NULL pointer dereference.
Signed-off-by Kangjie Lu <[email protected]>
-Kees
Quoted 35 lines
---
v2: reuse existing error path as suggested by
Borislav Petkov <[email protected]>--- arch/x86/platform/uv/tlb_uv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/x86/platform/uv/tlb_uv.c +5
-2@@ -2133,14 +2133,18 @@ 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; --2.17.1
Signature · 1 line
Kees Cook