diff options
author | Andrea Arcangeli <aarcange@redhat.com> | 2019-06-28 12:07:14 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-01-27 14:50:58 +0100 |
commit | fde68698dde71ee5bf209e9931ee3188861d3b3a (patch) | |
tree | bcefe08210fd71d40c1386e49245860e3464956f /kernel/fork.c | |
parent | 5105593b6e56c799eb7b6699251c41bebe8d816c (diff) | |
download | linux-stable-fde68698dde71ee5bf209e9931ee3188861d3b3a.tar.gz linux-stable-fde68698dde71ee5bf209e9931ee3188861d3b3a.tar.bz2 linux-stable-fde68698dde71ee5bf209e9931ee3188861d3b3a.zip |
fork,memcg: alloc_thread_stack_node needs to set tsk->stack
[ Upstream commit 1bf4580e00a248a2c86269125390eb3648e1877c ]
Commit 5eed6f1dff87 ("fork,memcg: fix crash in free_thread_stack on
memcg charge fail") 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.
Link: http://lkml.kernel.org/r/20190619011450.28048-1-aarcange@redhat.com
Fixes: 9b6f7e163cd0 ("mm: rework memcg kernel stack accounting")
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
Reviewed-by: Rik van Riel <riel@surriel.com>
Acked-by: Roman Gushchin <guro@fb.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'kernel/fork.c')
-rw-r--r-- | kernel/fork.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index 1bd119530a49..1a2d18e98bf9 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -240,7 +240,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 } |