Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753725AbcLBV5m (ORCPT ); Fri, 2 Dec 2016 16:57:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56710 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751311AbcLBV5k (ORCPT ); Fri, 2 Dec 2016 16:57:40 -0500 Date: Fri, 2 Dec 2016 15:57:38 -0600 From: Josh Poimboeuf To: Pavel Machek Cc: Andrey Ryabinin , Dmitry Vyukov , "Rafael J. Wysocki" , Len Brown , linux-pm@vger.kernel.org, LKML , Peter Zijlstra , Ingo Molnar , Andy Lutomirski , Scott Bauer , "x86@kernel.org" , Alexander Potapenko , kasan-dev Subject: Re: [PATCH v4] x86/suspend: fix false positive KASAN warning on suspend/resume Message-ID: <20161202215738.hsdchaxtpinvru3n@treble> References: <20161201175611.gf63mwzomt4wrlxy@treble> <20161201203154.mwt5x736g7z6jh3o@treble> <5144d695-7ac4-f992-5239-91c772b0c121@virtuozzo.com> <20161202140147.gvj452hmlbxnstrg@treble> <20161202144240.3tect4hx4cks44iu@treble> <20161202150819.2h25oyoj7qsvrw77@treble> <20161202174221.sfcvvddbvl5uz4f4@treble> <20161202210903.GB15126@amd> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20161202210903.GB15126@amd> User-Agent: Mutt/1.6.0.1 (2016-04-01) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 02 Dec 2016 21:57:40 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1823 Lines: 50 On Fri, Dec 02, 2016 at 10:09:03PM +0100, Pavel Machek wrote: > On Fri 2016-12-02 11:42:21, Josh Poimboeuf wrote: > > Resuming from a suspend operation is showing a KASAN false positive > > warning: > > > > > > Reported-by: Scott Bauer > > Signed-off-by: Josh Poimboeuf > > Acked-by: Pavel Machek > > > diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c > > index 0e9505f..b2a0cff 100644 > > --- a/mm/kasan/kasan.c > > +++ b/mm/kasan/kasan.c > > @@ -80,7 +80,14 @@ void kasan_unpoison_task_stack(struct task_struct *task) > > /* Unpoison the stack for the current task beyond a watermark sp value. */ > > asmlinkage void kasan_unpoison_task_stack_below(const void *watermark) > > { > > - __kasan_unpoison_stack(current, watermark); > > + /* > > + * Calculate the task stack base address. Avoid using 'current' > > + * because this function is called by early resume code which hasn't > > + * yet set up the percpu register (%gs). > > + */ > > + void *base = (void *)((unsigned long)watermark & ~(THREAD_SIZE - 1)); > > + > > + kasan_unpoison_shadow(base, watermark - base); > > } > > > > I know you modified this code to be arch-independend... but is it > really? I guess it is portable enough across architectures that run > kasan today.. Yes, it's arch-independent as far as I know. All the implementations of alloc_thread_stack_node() in kernel/fork.c create THREAD_SIZE sized/aligned stacks. ia64 has its own implementation of alloc_thread_stack_node(), which also has a THREAD_SIZE sized/aligned stack, with task_struct stored at the beginning. For those architectures for which stack grows up, they would need to call a different helper which unpoisons the stack above the watermark, but that was also the case before my patch. -- Josh