From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752949AbbJEKa3 (ORCPT ); Mon, 5 Oct 2015 06:30:29 -0400 Received: from mx2.parallels.com ([199.115.105.18]:54210 "EHLO mx2.parallels.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752053AbbJEKa0 (ORCPT ); Mon, 5 Oct 2015 06:30:26 -0400 From: Andrey Ryabinin To: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , CC: , Andy Lutomirski , Andrey Konovalov , Kostya Serebryany , Alexander Potapenko , kasan-dev , Borislav Petkov , Denys Vlasenko , Andi Kleen , Dmitry Vyukov , Sasha Levin , Wolfram Gloger , Andrey Ryabinin Subject: [PATCH] x86/process: Silence KASAN warnings in get_wchan() Date: Mon, 5 Oct 2015 13:28:26 +0300 Message-ID: <1444040906-6788-1-git-send-email-aryabinin@virtuozzo.com> X-Mailer: git-send-email 2.4.9 MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: US-EXCH2.sw.swsoft.com (10.255.249.46) To US-EXCH2.sw.swsoft.com (10.255.249.46) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; + 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; + } fp = READ_ONCE(*(unsigned long *)fp); } while (count++ < 16 && p->state != TASK_RUNNING); - return 0; + +out: + kasan_enable_current(); + return ret; } -- 2.4.9