From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751410AbbJELXs (ORCPT ); Mon, 5 Oct 2015 07:23:48 -0400 Received: from mail-wi0-f182.google.com ([209.85.212.182]:35587 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751246AbbJELXq (ORCPT ); Mon, 5 Oct 2015 07:23:46 -0400 Date: Mon, 5 Oct 2015 13:23:41 +0200 From: Ingo Molnar To: Andrey Ryabinin Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org, Andy Lutomirski , Andrey Konovalov , Kostya Serebryany , Alexander Potapenko , kasan-dev , Borislav Petkov , Denys Vlasenko , Andi Kleen , Dmitry Vyukov , Sasha Levin , Wolfram Gloger , Linus Torvalds , Andrew Morton Subject: Re: [PATCH] x86/process: Silence KASAN warnings in get_wchan() Message-ID: <20151005112341.GA1101@gmail.com> References: <1444040906-6788-1-git-send-email-aryabinin@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1444040906-6788-1-git-send-email-aryabinin@virtuozzo.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 * Andrey Ryabinin wrote: > get_wchan() is racy by design, it may access volatile stack > of running task, thus it may access redzone in a stack frame > and cause KASAN to warn about this. > > Use kasan_disable_current()/kasan_enable_current() to silence > these warnings. > > Reported-by: Sasha Levin > Signed-off-by: Andrey Ryabinin > --- > > Perhaps it would be better to add something like this: > READ_ONCE_NOCHECK() > { > kasan_disable_current(); > READ_ONCE(); > kasan_enable_current(); > } > ? > > arch/x86/kernel/process.c | 18 +++++++++++++----- > 1 file changed, 13 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c > index 39e585a..0488eb9 100644 > --- a/arch/x86/kernel/process.c > +++ b/arch/x86/kernel/process.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -514,7 +515,7 @@ unsigned long arch_randomize_brk(struct mm_struct *mm) > */ > unsigned long get_wchan(struct task_struct *p) > { > - unsigned long start, bottom, top, sp, fp, ip; > + unsigned long start, bottom, top, sp, fp, ip, ret = 0; > int count = 0; > > if (!p || p == current || p->state == TASK_RUNNING) > @@ -550,14 +551,21 @@ unsigned long get_wchan(struct task_struct *p) > if (sp < bottom || sp > top) > return 0; > > + kasan_disable_current(); > fp = READ_ONCE(*(unsigned long *)sp); > do { > if (fp < bottom || fp > top) > - return 0; > + goto out; a break would do just fine too. > + > ip = READ_ONCE(*(unsigned long *)(fp + sizeof(unsigned long))); > - if (!in_sched_functions(ip)) > - return ip; > + if (!in_sched_functions(ip)) { > + ret = ip; > + goto out; ditto. > + } > fp = READ_ONCE(*(unsigned long *)fp); > } while (count++ < 16 && p->state != TASK_RUNNING); > - return 0; > + > +out: and then the label would not be needed. > + kasan_enable_current(); > + return ret; But that's all pretty disgusting really. Cannot we do better, such as annotating the function and then KASAN sorting out its false positives, or something like that? Thanks, Ingo