From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk0-f199.google.com (mail-qk0-f199.google.com [209.85.220.199]) by kanga.kvack.org (Postfix) with ESMTP id E622F6B0253 for ; Wed, 12 Oct 2016 11:54:25 -0400 (EDT) Received: by mail-qk0-f199.google.com with SMTP id v138so35270943qka.2 for ; Wed, 12 Oct 2016 08:54:25 -0700 (PDT) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com. [209.132.183.24]) by mx.google.com with ESMTPS id a80si4173566qkg.200.2016.10.12.08.54.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 12 Oct 2016 08:54:25 -0700 (PDT) Date: Wed, 12 Oct 2016 11:54:17 -0400 (EDT) From: CAI Qian Message-ID: <2086376822.528054.1476287657078.JavaMail.zimbra@redhat.com> In-Reply-To: <1476266223-14325-1-git-send-email-catalin.marinas@arm.com> References: <1476266223-14325-1-git-send-email-catalin.marinas@arm.com> Subject: Re: [PATCH] mm: kmemleak: Ensure that the task stack is not freed during scanning MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Catalin Marinas Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Andy Lutomirski ----- Original Message ----- > From: "Catalin Marinas" > To: linux-mm@kvack.org > Cc: linux-kernel@vger.kernel.org, "Andrew Morton" , "Andy Lutomirski" , > "CAI Qian" > Sent: Wednesday, October 12, 2016 5:57:03 AM > Subject: [PATCH] mm: kmemleak: Ensure that the task stack is not freed during scanning > > 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. > > Fixes: 68f24b08ee89 ("sched/core: Free the stack early if > CONFIG_THREAD_INFO_IN_TASK") > Cc: Andrew Morton > Cc: Andy Lutomirski > Cc: CAI Qian > Reported-by: CAI Qian > Signed-off-by: Catalin Marinas Tested-by: CAI Qian > --- > > 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: email@kvack.org > > > -- 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: email@kvack.org