linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] fork,memcg: alloc_thread_stack_node needs to set tsk->stack
@ 2019-06-19  1:14 Andrea Arcangeli
  2019-06-19  1:22 ` Rik van Riel
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrea Arcangeli @ 2019-06-19  1:14 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, Rik van Riel, Roman Gushchin, Michal Hocko

Commit 5eed6f1dff87bfb5e545935def3843edf42800f2 corrected two
instances, but there was a third instance of this bug.

Without setting tsk->stack, if memcg_charge_kernel_stack fails, it'll
execute free_thread_stack() on a dangling pointer.

Enterprise kernels are compiled with VMAP_STACK=y so this isn't
critical, but custom VMAP_STACK=n builds should have some performance
advantage, with the drawback of risking to fail fork because
compaction didn't succeed. So as long as VMAP_STACK=n is a supported
option it's worth fixing it upstream.

Fixes: 9b6f7e163cd0 ("mm: rework memcg kernel stack accounting")
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
---
 kernel/fork.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index d6c324b1b29e..9ee28dfe7c21 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -248,7 +248,11 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node)
 	struct page *page = alloc_pages_node(node, THREADINFO_GFP,
 					     THREAD_SIZE_ORDER);
 
-	return page ? page_address(page) : NULL;
+	if (likely(page)) {
+		tsk->stack = page_address(page);
+		return tsk->stack;
+	}
+	return NULL;
 #endif
 }
 


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

* Re: [PATCH 1/1] fork,memcg: alloc_thread_stack_node needs to set tsk->stack
  2019-06-19  1:14 [PATCH 1/1] fork,memcg: alloc_thread_stack_node needs to set tsk->stack Andrea Arcangeli
@ 2019-06-19  1:22 ` Rik van Riel
  2019-06-19  3:49 ` Roman Gushchin
  2019-06-19  5:18 ` Michal Hocko
  2 siblings, 0 replies; 4+ messages in thread
From: Rik van Riel @ 2019-06-19  1:22 UTC (permalink / raw)
  To: Andrea Arcangeli, Andrew Morton; +Cc: linux-mm, Roman Gushchin, Michal Hocko

[-- Attachment #1: Type: text/plain, Size: 841 bytes --]

On Tue, 2019-06-18 at 21:14 -0400, Andrea Arcangeli wrote:
> Commit 5eed6f1dff87bfb5e545935def3843edf42800f2 corrected two
> instances, but there was a third instance of this bug.
> 
> Without setting tsk->stack, if memcg_charge_kernel_stack fails, it'll
> execute free_thread_stack() on a dangling pointer.
> 
> Enterprise kernels are compiled with VMAP_STACK=y so this isn't
> critical, but custom VMAP_STACK=n builds should have some performance
> advantage, with the drawback of risking to fail fork because
> compaction didn't succeed. So as long as VMAP_STACK=n is a supported
> option it's worth fixing it upstream.
> 
> Fixes: 9b6f7e163cd0 ("mm: rework memcg kernel stack accounting")
> Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>

Reviewed-by: Rik van Riel <riel@surriel.com>

-- 
All Rights Reversed.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH 1/1] fork,memcg: alloc_thread_stack_node needs to set tsk->stack
  2019-06-19  1:14 [PATCH 1/1] fork,memcg: alloc_thread_stack_node needs to set tsk->stack Andrea Arcangeli
  2019-06-19  1:22 ` Rik van Riel
@ 2019-06-19  3:49 ` Roman Gushchin
  2019-06-19  5:18 ` Michal Hocko
  2 siblings, 0 replies; 4+ messages in thread
From: Roman Gushchin @ 2019-06-19  3:49 UTC (permalink / raw)
  To: Andrea Arcangeli; +Cc: Andrew Morton, linux-mm, Rik van Riel, Michal Hocko

Acked-by: Roman Gushchin <guro@fb.com>

Thank you, Andrea!

> On Jun 18, 2019, at 18:15, Andrea Arcangeli <aarcange@redhat.com> wrote:
> 
> Commit 5eed6f1dff87bfb5e545935def3843edf42800f2 corrected two
> instances, but there was a third instance of this bug.
> 
> Without setting tsk->stack, if memcg_charge_kernel_stack fails, it'll
> execute free_thread_stack() on a dangling pointer.
> 
> Enterprise kernels are compiled with VMAP_STACK=y so this isn't
> critical, but custom VMAP_STACK=n builds should have some performance
> advantage, with the drawback of risking to fail fork because
> compaction didn't succeed. So as long as VMAP_STACK=n is a supported
> option it's worth fixing it upstream.
> 
> Fixes: 9b6f7e163cd0 ("mm: rework memcg kernel stack accounting")
> Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
> ---
> kernel/fork.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/fork.c b/kernel/fork.c
> index d6c324b1b29e..9ee28dfe7c21 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -248,7 +248,11 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node)
>    struct page *page = alloc_pages_node(node, THREADINFO_GFP,
>                         THREAD_SIZE_ORDER);
> 
> -    return page ? page_address(page) : NULL;
> +    if (likely(page)) {
> +        tsk->stack = page_address(page);
> +        return tsk->stack;
> +    }
> +    return NULL;
> #endif
> }
> 
> 


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

* Re: [PATCH 1/1] fork,memcg: alloc_thread_stack_node needs to set tsk->stack
  2019-06-19  1:14 [PATCH 1/1] fork,memcg: alloc_thread_stack_node needs to set tsk->stack Andrea Arcangeli
  2019-06-19  1:22 ` Rik van Riel
  2019-06-19  3:49 ` Roman Gushchin
@ 2019-06-19  5:18 ` Michal Hocko
  2 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2019-06-19  5:18 UTC (permalink / raw)
  To: Andrea Arcangeli; +Cc: Andrew Morton, linux-mm, Rik van Riel, Roman Gushchin

On Tue 18-06-19 21:14:50, Andrea Arcangeli wrote:
> Commit 5eed6f1dff87bfb5e545935def3843edf42800f2 corrected two
> instances, but there was a third instance of this bug.

Sigh. I should have noticed when reviewing the above. My bad.

> Without setting tsk->stack, if memcg_charge_kernel_stack fails, it'll
> execute free_thread_stack() on a dangling pointer.
> 
> Enterprise kernels are compiled with VMAP_STACK=y so this isn't
> critical, but custom VMAP_STACK=n builds should have some performance
> advantage, with the drawback of risking to fail fork because
> compaction didn't succeed. So as long as VMAP_STACK=n is a supported
> option it's worth fixing it upstream.
> 
> Fixes: 9b6f7e163cd0 ("mm: rework memcg kernel stack accounting")
> Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>

Acked-by: Michal Hocko <mhocko@suse.com>

I have double checked now and it seems we have covered all the cases
finally.

Thanks!
> ---
>  kernel/fork.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/fork.c b/kernel/fork.c
> index d6c324b1b29e..9ee28dfe7c21 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -248,7 +248,11 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node)
>  	struct page *page = alloc_pages_node(node, THREADINFO_GFP,
>  					     THREAD_SIZE_ORDER);
>  
> -	return page ? page_address(page) : NULL;
> +	if (likely(page)) {
> +		tsk->stack = page_address(page);
> +		return tsk->stack;
> +	}
> +	return NULL;
>  #endif
>  }
>  

-- 
Michal Hocko
SUSE Labs


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

end of thread, other threads:[~2019-06-19  5:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-19  1:14 [PATCH 1/1] fork,memcg: alloc_thread_stack_node needs to set tsk->stack Andrea Arcangeli
2019-06-19  1:22 ` Rik van Riel
2019-06-19  3:49 ` Roman Gushchin
2019-06-19  5:18 ` Michal Hocko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox