From: Andrey Ryabinin <aryabinin@virtuozzo.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
<x86@kernel.org>
Cc: <linux-kernel@vger.kernel.org>,
Andy Lutomirski <luto@amacapital.net>,
Andrey Konovalov <andreyknvl@google.com>,
Kostya Serebryany <kcc@google.com>,
Alexander Potapenko <glider@google.com>,
kasan-dev <kasan-dev@googlegroups.com>,
Borislav Petkov <bp@alien8.de>,
Denys Vlasenko <dvlasenk@redhat.com>,
Andi Kleen <ak@linux.intel.com>,
Dmitry Vyukov <dvyukov@google.com>,
Sasha Levin <sasha.levin@oracle.com>,
Wolfram Gloger <wmglo@dent.med.uni-muenchen.de>,
Andrey Ryabinin <aryabinin@virtuozzo.com>
Subject: [PATCH] x86/process: Silence KASAN warnings in get_wchan()
Date: Mon, 5 Oct 2015 13:28:26 +0300 [thread overview]
Message-ID: <1444040906-6788-1-git-send-email-aryabinin@virtuozzo.com> (raw)
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 <sasha.levin@oracle.com>
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
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 <linux/random.h>
#include <linux/user-return-notifier.h>
#include <linux/dmi.h>
+#include <linux/kasan.h>
#include <linux/utsname.h>
#include <linux/stackprotector.h>
#include <linux/tick.h>
@@ -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
next reply other threads:[~2015-10-05 10:30 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-05 10:28 Andrey Ryabinin [this message]
2015-10-05 10:38 ` Dmitry Vyukov
2015-10-05 11:18 ` Borislav Petkov
2015-10-05 11:23 ` Ingo Molnar
2015-10-05 11:39 ` Dmitry Vyukov
2015-10-05 11:46 ` Andrey Ryabinin
2015-10-05 13:15 ` Borislav Petkov
2015-10-05 18:42 ` Andy Lutomirski
2015-10-05 16:39 ` Andi Kleen
2015-10-05 16:59 ` Andrey Ryabinin
2015-10-05 18:58 ` Andi Kleen
2015-10-06 7:26 ` Ingo Molnar
2015-10-06 7:38 ` Andrey Ryabinin
2015-10-06 18:11 ` Andy Lutomirski
2015-10-07 7:22 ` Ingo Molnar
2015-10-07 8:54 ` Andrey Ryabinin
2015-10-07 9:11 ` Andrey Ryabinin
2015-10-07 16:27 ` Andi Kleen
2015-10-07 18:48 ` Andrey Ryabinin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1444040906-6788-1-git-send-email-aryabinin@virtuozzo.com \
--to=aryabinin@virtuozzo.com \
--cc=ak@linux.intel.com \
--cc=andreyknvl@google.com \
--cc=bp@alien8.de \
--cc=dvlasenk@redhat.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=hpa@zytor.com \
--cc=kasan-dev@googlegroups.com \
--cc=kcc@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@redhat.com \
--cc=sasha.levin@oracle.com \
--cc=tglx@linutronix.de \
--cc=wmglo@dent.med.uni-muenchen.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome