Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759157AbcLBODK (ORCPT ); Fri, 2 Dec 2016 09:03:10 -0500 Received: from mail-lf0-f44.google.com ([209.85.215.44]:34543 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750900AbcLBODJ (ORCPT ); Fri, 2 Dec 2016 09:03:09 -0500 MIME-Version: 1.0 In-Reply-To: <20161202140147.gvj452hmlbxnstrg@treble> References: <20161201145821.imkcgizo4thmiei2@treble> <20161201164551.52xlcftamleam6vq@treble> <20161201171306.swnvi4f2ezavloxd@treble> <20161201173438.bfe5eq23i6ezfxsq@treble> <20161201175611.gf63mwzomt4wrlxy@treble> <20161201203154.mwt5x736g7z6jh3o@treble> <5144d695-7ac4-f992-5239-91c772b0c121@virtuozzo.com> <20161202140147.gvj452hmlbxnstrg@treble> From: Dmitry Vyukov Date: Fri, 2 Dec 2016 15:02:46 +0100 Message-ID: Subject: Re: [PATCH v2] x86/suspend: fix false positive KASAN warning on suspend/resume To: Josh Poimboeuf Cc: Andrey Ryabinin , "Rafael J. Wysocki" , Len Brown , Pavel Machek , linux-pm@vger.kernel.org, LKML , Peter Zijlstra , Ingo Molnar , Andy Lutomirski , Scott Bauer , "x86@kernel.org" , Alexander Potapenko , kasan-dev Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2062 Lines: 56 On Fri, Dec 2, 2016 at 3:01 PM, Josh Poimboeuf wrote: > On Fri, Dec 02, 2016 at 04:41:09PM +0300, Andrey Ryabinin wrote: >> >> >> On 12/01/2016 11:31 PM, Josh Poimboeuf wrote: >> >> > arch/x86/kernel/acpi/wakeup_64.S | 16 ++++++++++++++++ >> > 1 file changed, 16 insertions(+) >> > >> > diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S >> > index 169963f..1df9b75 100644 >> > --- a/arch/x86/kernel/acpi/wakeup_64.S >> > +++ b/arch/x86/kernel/acpi/wakeup_64.S >> > @@ -109,6 +109,22 @@ ENTRY(do_suspend_lowlevel) >> > movq pt_regs_r14(%rax), %r14 >> > movq pt_regs_r15(%rax), %r15 >> > >> > +#ifdef CONFIG_KASAN >> > + /* >> > + * The suspend path may have poisoned some areas deeper in the stack, >> > + * which we now need to unpoison. >> > + * >> > + * We can't call kasan_unpoison_task_stack_below() because it uses %gs >> > + * for 'current', which hasn't been set up yet. Instead, calculate the >> > + * stack range manually and call kasan_unpoison_shadow(). >> > + */ >> > + movq %rsp, %rdi >> > + andq $CURRENT_MASK, %rdi >> > + movq %rsp, %rsi >> > + xorq %rdi, %rsi >> > + call kasan_unpoison_shadow >> > +#endif >> > + >> >> Looks good, but in fact we can use kasan_unpoison_task_stack_below(). We just need to change it a little: >> >> diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c >> index 70c0097..e779236 100644 >> --- a/mm/kasan/kasan.c >> +++ b/mm/kasan/kasan.c >> @@ -80,7 +80,9 @@ 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); >> + void *base = (void *)((unsigned long)watermark & ~(THREAD_SIZE - 1)); >> + >> + kasan_unpoison_shadow(base, watermark - base); >> } >> >> >> With this we don't have to calculate stack range in assembly. > > That is better indeed, will do a v3. agree