* [PATCH] x86: uv: Fix potential NULL pointer dereference of kmalloc_node
@ 2019-03-02 21:09 Aditya Pakki
2019-03-02 21:12 ` Joe Perches
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Aditya Pakki @ 2019-03-02 21:09 UTC (permalink / raw)
To: pakki001
Cc: kjlu, Darren Hart, Andy Shevchenko, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, H. Peter Anvin, x86, Nicolai Stange, Kees Cook,
Andrew Banman, Mike Travis, Colin Ian King, Varsha Rao,
platform-driver-x86, linux-kernel
kmalloc_node might fail to allocate memory for thp field. This fix
attempts to avoid a potential NULL pointer dereference.
Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
arch/x86/platform/uv/tlb_uv.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
index a4130b84d1ff..5a6d51e30a36 100644
--- a/arch/x86/platform/uv/tlb_uv.c
+++ b/arch/x86/platform/uv/tlb_uv.c
@@ -2011,6 +2011,9 @@ static void make_per_cpu_thp(struct bau_control *smaster)
size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus();
smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
+ if (!smaster->thp)
+ return;
+
memset(smaster->thp, 0, hpsz);
for_each_present_cpu(cpu) {
smaster->thp[cpu].pnode = uv_cpu_hub_info(cpu)->pnode;
--
2.17.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86: uv: Fix potential NULL pointer dereference of kmalloc_node
2019-03-02 21:09 [PATCH] x86: uv: Fix potential NULL pointer dereference of kmalloc_node Aditya Pakki
@ 2019-03-02 21:12 ` Joe Perches
2019-03-02 21:22 ` Gustavo A. R. Silva
2019-03-04 9:29 ` Peter Zijlstra
2 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2019-03-02 21:12 UTC (permalink / raw)
To: Aditya Pakki
Cc: kjlu, Darren Hart, Andy Shevchenko, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, H. Peter Anvin, x86, Nicolai Stange, Kees Cook,
Andrew Banman, Mike Travis, Colin Ian King, Varsha Rao,
platform-driver-x86, linux-kernel
On Sat, 2019-03-02 at 15:09 -0600, Aditya Pakki wrote:
> kmalloc_node might fail to allocate memory for thp field. This fix
> attempts to avoid a potential NULL pointer dereference.
right
> diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
[]
> @@ -2011,6 +2011,9 @@ static void make_per_cpu_thp(struct bau_control *smaster)
> size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus();
>
> smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
> + if (!smaster->thp)
> + return;
> +
> memset(smaster->thp, 0, hpsz);
Could use kzalloc_node as well
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86: uv: Fix potential NULL pointer dereference of kmalloc_node
2019-03-02 21:09 [PATCH] x86: uv: Fix potential NULL pointer dereference of kmalloc_node Aditya Pakki
2019-03-02 21:12 ` Joe Perches
@ 2019-03-02 21:22 ` Gustavo A. R. Silva
2019-03-04 9:29 ` Peter Zijlstra
2 siblings, 0 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2019-03-02 21:22 UTC (permalink / raw)
To: Aditya Pakki
Cc: kjlu, Darren Hart, Andy Shevchenko, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, H. Peter Anvin, x86, Nicolai Stange, Kees Cook,
Andrew Banman, Mike Travis, Colin Ian King, Varsha Rao,
platform-driver-x86, linux-kernel
Hi Aditya,
On 3/2/19 3:09 PM, Aditya Pakki wrote:
> kmalloc_node might fail to allocate memory for thp field. This fix
> attempts to avoid a potential NULL pointer dereference.
>
If this was detected by any static analyzer, please mention the
tool in the commit log.
Also, notice that this code does not apply to linux-next.
Thanks
--
Gustavo
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
> arch/x86/platform/uv/tlb_uv.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
> index a4130b84d1ff..5a6d51e30a36 100644
> --- a/arch/x86/platform/uv/tlb_uv.c
> +++ b/arch/x86/platform/uv/tlb_uv.c
> @@ -2011,6 +2011,9 @@ static void make_per_cpu_thp(struct bau_control *smaster)
> size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus();
>
> smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
> + if (!smaster->thp)
> + return;
> +
> memset(smaster->thp, 0, hpsz);
> for_each_present_cpu(cpu) {
> smaster->thp[cpu].pnode = uv_cpu_hub_info(cpu)->pnode;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86: uv: Fix potential NULL pointer dereference of kmalloc_node
2019-03-02 21:09 [PATCH] x86: uv: Fix potential NULL pointer dereference of kmalloc_node Aditya Pakki
2019-03-02 21:12 ` Joe Perches
2019-03-02 21:22 ` Gustavo A. R. Silva
@ 2019-03-04 9:29 ` Peter Zijlstra
2 siblings, 0 replies; 4+ messages in thread
From: Peter Zijlstra @ 2019-03-04 9:29 UTC (permalink / raw)
To: Aditya Pakki
Cc: kjlu, Darren Hart, Andy Shevchenko, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, H. Peter Anvin, x86, Nicolai Stange, Kees Cook,
Andrew Banman, Mike Travis, Colin Ian King, Varsha Rao,
platform-driver-x86, linux-kernel
On Sat, Mar 02, 2019 at 03:09:04PM -0600, Aditya Pakki wrote:
> kmalloc_node might fail to allocate memory for thp field. This fix
> attempts to avoid a potential NULL pointer dereference.
>
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
> arch/x86/platform/uv/tlb_uv.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/x86/platform/uv/tlb_uv.c b/arch/x86/platform/uv/tlb_uv.c
> index a4130b84d1ff..5a6d51e30a36 100644
> --- a/arch/x86/platform/uv/tlb_uv.c
> +++ b/arch/x86/platform/uv/tlb_uv.c
> @@ -2011,6 +2011,9 @@ static void make_per_cpu_thp(struct bau_control *smaster)
> size_t hpsz = sizeof(struct hub_and_pnode) * num_possible_cpus();
>
> smaster->thp = kmalloc_node(hpsz, GFP_KERNEL, smaster->osnode);
> + if (!smaster->thp)
> + return;
This is init code; memeory allocation is 'unlikely' to fail. If it were
to fail, we'd have gotten a nice crash pinpointing the failure.
Now, we boot but get weird crashes later. Note how the rest of the code
assumes smaster->thp to be set. How is that any better?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-03-04 9:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-02 21:09 [PATCH] x86: uv: Fix potential NULL pointer dereference of kmalloc_node Aditya Pakki
2019-03-02 21:12 ` Joe Perches
2019-03-02 21:22 ` Gustavo A. R. Silva
2019-03-04 9:29 ` Peter Zijlstra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome