Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754905AbcJLQOv (ORCPT ); Wed, 12 Oct 2016 12:14:51 -0400 Received: from foss.arm.com ([217.140.101.70]:36784 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753583AbcJLQOu (ORCPT ); Wed, 12 Oct 2016 12:14:50 -0400 Date: Wed, 12 Oct 2016 17:14:41 +0100 From: Catalin Marinas To: CAI Qian Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Andy Lutomirski Subject: Re: [PATCH] mm: kmemleak: Ensure that the task stack is not freed during scanning Message-ID: <20161012161441.GC21592@e104818-lin.cambridge.arm.com> References: <1476266223-14325-1-git-send-email-catalin.marinas@arm.com> <2086376822.528054.1476287657078.JavaMail.zimbra@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2086376822.528054.1476287657078.JavaMail.zimbra@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1680 Lines: 37 On Wed, Oct 12, 2016 at 11:54:17AM -0400, CAI Qian wrote: > ----- 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 Thanks. BTW, I noticed a few false positives reported by kmemleak with the CONFIG_VMAP_STACK enabled caused by the fact that kmemleak requires two references (instead of one) to a vmalloc'ed object because of the vm_struct already containing the address. The cached_stack[] array only stores the vm_struct rather than the stack address, hence the kmemleak report. I'll work on a fix/annotation. -- Catalin