diff options
author | Andrey Ryabinin <aryabinin@virtuozzo.com> | 2018-02-01 13:00:49 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-02-01 15:20:21 -0500 |
commit | 7f1e541fc8d57a143dd5df1d0a1276046e08c083 (patch) | |
tree | 3a56c3f3dbf30506bd47b9af085f3c20863b4dee | |
parent | bdb5ac801af3d81d36732c2f640d6a1d3df83826 (diff) |
compiler.h: Add read_word_at_a_time() function.
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>
-rw-r--r-- | include/linux/compiler.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 3035990a8070..c2cc57a2f508 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 | |||
238 | * required ordering. | 238 | * required ordering. |
239 | */ | 239 | */ |
240 | #include <asm/barrier.h> | 240 | #include <asm/barrier.h> |
241 | #include <linux/kasan-checks.h> | ||
241 | 242 | ||
242 | #define __READ_ONCE(x, check) \ | 243 | #define __READ_ONCE(x, check) \ |
243 | ({ \ | 244 | ({ \ |
@@ -257,6 +258,13 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s | |||
257 | */ | 258 | */ |
258 | #define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0) | 259 | #define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0) |
259 | 260 | ||
261 | static __no_kasan_or_inline | ||
262 | unsigned long read_word_at_a_time(const void *addr) | ||
263 | { | ||
264 | kasan_check_read(addr, 1); | ||
265 | return *(unsigned long *)addr; | ||
266 | } | ||
267 | |||
260 | #define WRITE_ONCE(x, val) \ | 268 | #define WRITE_ONCE(x, val) \ |
261 | ({ \ | 269 | ({ \ |
262 | union { typeof(x) __val; char __c[1]; } __u = \ | 270 | union { typeof(x) __val; char __c[1]; } __u = \ |