From: Matthieu Baerts <matthieu.baerts@tessares.net>
To: stable@vger.kernel.org
Cc: asmadeus@codewreck.org, sashal@kernel.org,
Andrey Ryabinin <aryabinin@virtuozzo.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Matthieu Baerts <matthieu.baerts@tessares.net>
Subject: [PATCH 2/3] compiler.h: Add read_word_at_a_time() function.
Date: Wed, 24 Jul 2019 22:55:56 +0200 [thread overview]
Message-ID: <20190724205557.30913-3-matthieu.baerts@tessares.net> (raw)
In-Reply-To: <20190724205557.30913-1-matthieu.baerts@tessares.net>
From: Andrey Ryabinin <aryabinin@virtuozzo.com>
commit 7f1e541fc8d57a143dd5df1d0a1276046e08c083 upstream.
Sometimes we know that it's safe to do potentially out-of-bounds access
because we know it won't cross a page boundary. Still, KASAN will
report this as a bug.
Add read_word_at_a_time() function which is supposed to be used in such
cases. In read_word_at_a_time() KASAN performs relaxed check - only the
first byte of access is validated.
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
---
include/linux/compiler.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index f490d8d93ec3..f84d332085c3 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -238,6 +238,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
* required ordering.
*/
#include <asm/barrier.h>
+#include <linux/kasan-checks.h>
#define __READ_ONCE(x, check) \
({ \
@@ -257,6 +258,13 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
*/
#define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0)
+static __no_kasan_or_inline
+unsigned long read_word_at_a_time(const void *addr)
+{
+ kasan_check_read(addr, 1);
+ return *(unsigned long *)addr;
+}
+
#define WRITE_ONCE(x, val) \
({ \
union { typeof(x) __val; char __c[1]; } __u = \
--
2.20.1
next prev parent reply other threads:[~2019-07-24 20:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-24 20:55 [PATCH 0/3] Backport request for v4.14 to fix KASAN issues Matthieu Baerts
2019-07-24 20:55 ` [PATCH 1/3] compiler.h, kasan: Avoid duplicating __read_once_size_nocheck() Matthieu Baerts
2019-07-24 20:55 ` Matthieu Baerts [this message]
2019-07-24 20:55 ` [PATCH 3/3] lib/strscpy: Shut up KASAN false-positives in strscpy() Matthieu Baerts
2019-07-25 4:18 ` [PATCH 0/3] Backport request for v4.14 to fix KASAN issues Sasha Levin
2019-07-25 9:38 ` Matthieu Baerts
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=20190724205557.30913-3-matthieu.baerts@tessares.net \
--to=matthieu.baerts@tessares.net \
--cc=aryabinin@virtuozzo.com \
--cc=asmadeus@codewreck.org \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.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