Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1499480
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] mm: kmemleak: Ensure that the task stack is not freed during scanning |
| Date | 2016-10-12 12:50 +0200 |
| Message-ID | <srpgJ-3eb-9@gated-at.bofh.it> (permalink) |
| References | <sroum-2vS-11@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Wed 12-10-16 10:57:03, Catalin Marinas wrote:
> Commit 68f24b08ee89 ("sched/core: Free the stack early if
> CONFIG_THREAD_INFO_IN_TASK") may cause the task->stack to be freed
> during kmemleak_scan() execution, leading to either a NULL pointer
> fault (if task->stack is NULL) or kmemleak accessing already freed
> memory. This patch uses the new try_get_task_stack() API to ensure that
> the task stack is not freed during kmemleak stack scanning.
Looks good to me
> Fixes: 68f24b08ee89 ("sched/core: Free the stack early if CONFIG_THREAD_INFO_IN_TASK")
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: CAI Qian <caiqian@redhat.com>
> Reported-by: CAI Qian <caiqian@redhat.com>
> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Michal Hocko <mhocko@suse.com>
> ---
>
> This was reported in a subsequent comment here:
>
> https://bugzilla.kernel.org/show_bug.cgi?id=173901
>
> However, the original bugzilla entry doesn't look related to task stack
> freeing as it was first reported on 4.8-rc8. Andy, sorry for cc'ing you
> to bugzilla, please feel free to remove your email from the bug above (I
> can't seem to be able to do it).
>
> mm/kmemleak.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index a5e453cf05c4..e5355a5b423f 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -1453,8 +1453,11 @@ static void kmemleak_scan(void)
>
> read_lock(&tasklist_lock);
> do_each_thread(g, p) {
> - scan_block(task_stack_page(p), task_stack_page(p) +
> - THREAD_SIZE, NULL);
> + void *stack = try_get_task_stack(p);
> + if (stack) {
> + scan_block(stack, stack + THREAD_SIZE, NULL);
> + put_task_stack(p);
> + }
> } while_each_thread(g, p);
> read_unlock(&tasklist_lock);
> }
>
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org. For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
--
Michal Hocko
SUSE Labs
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH] mm: kmemleak: Ensure that the task stack is not freed during scanning Catalin Marinas <catalin.marinas@arm.com> - 2016-10-12 12:00 +0200
Re: [PATCH] mm: kmemleak: Ensure that the task stack is not freed during scanning "Hillf Danton" <hillf.zj@alibaba-inc.com> - 2016-10-12 12:30 +0200
Re: [PATCH] mm: kmemleak: Ensure that the task stack is not freed during scanning Catalin Marinas <catalin.marinas@arm.com> - 2016-10-12 12:50 +0200
Re: [PATCH] mm: kmemleak: Ensure that the task stack is not freed during scanning Michal Hocko <mhocko@kernel.org> - 2016-10-12 12:50 +0200
Re: [PATCH] mm: kmemleak: Ensure that the task stack is not freed during scanning Catalin Marinas <catalin.marinas@arm.com> - 2016-10-12 18:20 +0200
Re: [PATCH] mm: kmemleak: Ensure that the task stack is not freed during scanning CAI Qian <caiqian@redhat.com> - 2016-10-12 18:40 +0200
csiph-web