From: Andrey Ryabinin <aryabinin@virtuozzo.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
linux-kernel@vger.kernel.org, Dmitry Vyukov <dvyukov@google.com>,
Kees Cook <keescook@chromium.org>, Eryu Guan <eguan@redhat.com>,
Alexander Potapenko <glider@google.com>,
Chris Metcalf <metcalf@alum.mit.edu>,
David Laight <David.Laight@aculab.com>,
kasan-dev <kasan-dev@googlegroups.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Andrey Ryabinin <aryabinin@virtuozzo.com>
Subject: [PATCH 2/5] compiler.h: Add read_word_at_a_time() function.
Date: Thu, 1 Feb 2018 21:00:49 +0300 [thread overview]
Message-ID: <20180201180052.32643-2-aryabinin@virtuozzo.com> (raw)
In-Reply-To: <20180201180052.32643-1-aryabinin@virtuozzo.com>
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>
---
include/linux/compiler.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index b8414ecf9ba1..0eb5bb0902e9 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -243,6 +243,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) \
({ \
@@ -262,6 +263,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.13.6
next prev parent reply other threads:[~2018-02-01 18:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-01 18:00 [PATCH 1/5] compiler.h, kasan: Avoid duplicating __read_once_size_nocheck() Andrey Ryabinin
2018-02-01 18:00 ` Andrey Ryabinin [this message]
2018-02-01 18:00 ` [PATCH 3/5] lib/strscpy: Shut up KASAN false-positives in strscpy() Andrey Ryabinin
2018-02-01 18:00 ` [PATCH 4/5] fs/dcache: Use read_word_at_a_time() in dentry_string_cmp() Andrey Ryabinin
2018-02-01 18:00 ` [PATCH 5/5] fs: dcache: Revert "manually unpoison dname after allocation to shut up kasan's reports" Andrey Ryabinin
2018-02-01 18:28 ` [PATCH 1/5] compiler.h, kasan: Avoid duplicating __read_once_size_nocheck() Linus Torvalds
2018-02-01 20:14 ` Andrey Ryabinin
2018-02-01 20:26 ` Linus Torvalds
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=20180201180052.32643-2-aryabinin@virtuozzo.com \
--to=aryabinin@virtuozzo.com \
--cc=David.Laight@aculab.com \
--cc=akpm@linux-foundation.org \
--cc=dvyukov@google.com \
--cc=eguan@redhat.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=metcalf@alum.mit.edu \
--cc=rasmus.villemoes@prevas.dk \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®