All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] platform: uv: fix missing checks for kcalloc
@ 2019-03-24 22:57 Kangjie Lu
  2019-03-25 12:55 ` Borislav Petkov
  0 siblings, 1 reply; 5+ messages in thread
From: Kangjie Lu @ 2019-03-24 22:57 UTC (permalink / raw)
  To: kjlu
  Cc: pakki001, Darren Hart, Andy Shevchenko, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, H. Peter Anvin, x86, Mike Travis,
	Kees Cook, Gustavo A. R. Silva, Varsha Rao, Nicolai Stange,
	Andrew Banman, Colin Ian King, platform-driver-x86, linux-kernel

In case kcalloc fails, the patch return an error to avoid
potential NULL pointer dereference.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 arch/x86/platform/uv/tlb_uv.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
index 2c53b0f19329..1ac777f14846 100644
--- a/arch/x86/platform/uv/tlb_uv.c
+++ b/arch/x86/platform/uv/tlb_uv.c
@@ -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;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] platform: uv: fix missing checks for kcalloc
  2019-03-24 22:57 [PATCH] platform: uv: fix missing checks for kcalloc Kangjie Lu
@ 2019-03-25 12:55 ` Borislav Petkov
  2019-03-25 20:29   ` [PATCH v2] " Kangjie Lu
  0 siblings, 1 reply; 5+ messages in thread
From: Borislav Petkov @ 2019-03-25 12:55 UTC (permalink / raw)
  To: Kangjie Lu
  Cc: pakki001, Darren Hart, Andy Shevchenko, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin, x86, Mike Travis, Kees Cook,
	Gustavo A. R. Silva, Varsha Rao, Nicolai Stange, Andrew Banman,
	Colin Ian King, platform-driver-x86, linux-kernel

On Sun, Mar 24, 2019 at 05:57:53PM -0500, Kangjie Lu wrote:
> In case kcalloc fails, the patch return an error to avoid
> potential NULL pointer dereference.
> 
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>
> ---
>  arch/x86/platform/uv/tlb_uv.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
> index 2c53b0f19329..1ac777f14846 100644
> --- a/arch/x86/platform/uv/tlb_uv.c
> +++ b/arch/x86/platform/uv/tlb_uv.c
> @@ -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...

>  	uvhub_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.

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] platform: uv: fix missing checks for kcalloc
  2019-03-25 12:55 ` Borislav Petkov
@ 2019-03-25 20:29   ` Kangjie Lu
  2019-03-26 16:10     ` [tip:x86/cleanups] x86/platform/uv: Fix missing checks of kcalloc() return values tip-bot for Kangjie Lu
  2019-04-23 20:02     ` [PATCH v2] platform: uv: fix missing checks for kcalloc Kees Cook
  0 siblings, 2 replies; 5+ messages in thread
From: Kangjie Lu @ 2019-03-25 20:29 UTC (permalink / raw)
  To: kjlu
  Cc: pakki001, Darren Hart, Andy Shevchenko, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, H. Peter Anvin, x86, Kees Cook,
	Andrew Banman, Varsha Rao, Colin Ian King, Gustavo A. R. Silva,
	Nicolai Stange, platform-driver-x86, linux-kernel

In case kcalloc fails, the patch return an error to avoid
potential NULL pointer dereference.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>

---
v2: reuse existing error path as suggested by
Borislav Petkov <bp@alien8.de>
---
 arch/x86/platform/uv/tlb_uv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
index 2c53b0f19329..7b41b51b9a86 100644
--- a/arch/x86/platform/uv/tlb_uv.c
+++ b/arch/x86/platform/uv/tlb_uv.c
@@ -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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [tip:x86/cleanups] x86/platform/uv: Fix missing checks of kcalloc() return values
  2019-03-25 20:29   ` [PATCH v2] " Kangjie Lu
@ 2019-03-26 16:10     ` tip-bot for Kangjie Lu
  2019-04-23 20:02     ` [PATCH v2] platform: uv: fix missing checks for kcalloc Kees Cook
  1 sibling, 0 replies; 5+ messages in thread
From: tip-bot for Kangjie Lu @ 2019-03-26 16:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: nstange, kjlu, hpa, dvhart, x86, andy, bp, colin.king,
	linux-kernel, gustavo, mingo, keescook, mingo, tglx, rvarsha016,
	abanman, mike.travis

Commit-ID:  766460852cfaeca4042e5f3aeb9616b3689147bc
Gitweb:     https://git.kernel.org/tip/766460852cfaeca4042e5f3aeb9616b3689147bc
Author:     Kangjie Lu <kjlu@umn.edu>
AuthorDate: Mon, 25 Mar 2019 15:29:22 -0500
Committer:  Borislav Petkov <bp@suse.de>
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. ]

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Andrew Banman <abanman@hpe.com>
Cc: Andy Shevchenko <andy@infradead.org>
Cc: Colin Ian King <colin.king@canonical.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Mike Travis <mike.travis@hpe.com>
Cc: Nicolai Stange <nstange@suse.de>
Cc: pakki001@umn.edu
Cc: platform-driver-x86@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Varsha Rao <rvarsha016@gmail.com>
Cc: x86-ml <x86@kernel.org>
Link: https://lkml.kernel.org/r/20190325202924.4624-1-kjlu@umn.edu
---
 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;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] platform: uv: fix missing checks for kcalloc
  2019-03-25 20:29   ` [PATCH v2] " Kangjie Lu
  2019-03-26 16:10     ` [tip:x86/cleanups] x86/platform/uv: Fix missing checks of kcalloc() return values tip-bot for Kangjie Lu
@ 2019-04-23 20:02     ` Kees Cook
  1 sibling, 0 replies; 5+ messages in thread
From: Kees Cook @ 2019-04-23 20:02 UTC (permalink / raw)
  To: Kangjie Lu
  Cc: pakki001, Darren Hart, Andy Shevchenko, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, H. Peter Anvin, X86 ML, Kees Cook,
	Andrew Banman, Varsha Rao, Colin Ian King, Gustavo A. R. Silva,
	Nicolai Stange, Platform Driver, LKML

On Mon, Mar 25, 2019 at 1:29 PM Kangjie Lu <kjlu@umn.edu> wrote:
>
> In case kcalloc fails, the patch return an error to avoid
> potential NULL pointer dereference.
>
> Signed-off-by: Kangjie Lu <kjlu@umn.edu>

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

>
> ---
> v2: reuse existing error path as suggested by
> Borislav Petkov <bp@alien8.de>
> ---
>  arch/x86/platform/uv/tlb_uv.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
> index 2c53b0f19329..7b41b51b9a86 100644
> --- a/arch/x86/platform/uv/tlb_uv.c
> +++ b/arch/x86/platform/uv/tlb_uv.c
> @@ -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
>


-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-04-23 20:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-24 22:57 [PATCH] platform: uv: fix missing checks for kcalloc Kangjie Lu
2019-03-25 12:55 ` Borislav Petkov
2019-03-25 20:29   ` [PATCH v2] " Kangjie Lu
2019-03-26 16:10     ` [tip:x86/cleanups] x86/platform/uv: Fix missing checks of kcalloc() return values tip-bot for Kangjie Lu
2019-04-23 20:02     ` [PATCH v2] platform: uv: fix missing checks for kcalloc Kees Cook

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.