path: root/include/linux/kasan.h
diff options
authorAndrey Ryabinin <>2015-02-13 14:40:17 -0800
committerLinus Torvalds <>2015-02-13 21:21:42 -0800
commitbebf56a1b176c2e1c9efe44e7e6915532cc682cf (patch)
tree4b967827878142197f2b62cd0b89652873631192 /include/linux/kasan.h
parent6301939d97d079f0d3dbe71e750f4daf5d39fc33 (diff)
kasan: enable instrumentation of global variables
This feature let us to detect accesses out of bounds of global variables. This will work as for globals in kernel image, so for globals in modules. Currently this won't work for symbols in user-specified sections (e.g. __init, __read_mostly, ...) The idea of this is simple. Compiler increases each global variable by redzone size and add constructors invoking __asan_register_globals() function. Information about global variable (address, size, size with redzone ...) passed to __asan_register_globals() so we could poison variable's redzone. This patch also forces module_alloc() to return 8*PAGE_SIZE aligned address making shadow memory handling ( kasan_module_alloc()/kasan_module_free() ) more simple. Such alignment guarantees that each shadow page backing modules address space correspond to only one module_alloc() allocation. Signed-off-by: Andrey Ryabinin <> Cc: Dmitry Vyukov <> Cc: Konstantin Serebryany <> Cc: Dmitry Chernenkov <> Signed-off-by: Andrey Konovalov <> Cc: Yuri Gribov <> Cc: Konstantin Khlebnikov <> Cc: Sasha Levin <> Cc: Christoph Lameter <> Cc: Joonsoo Kim <> Cc: Dave Hansen <> Cc: Andi Kleen <> Cc: Ingo Molnar <> Cc: Thomas Gleixner <> Cc: "H. Peter Anvin" <> Cc: Christoph Lameter <> Cc: Pekka Enberg <> Cc: David Rientjes <> Signed-off-by: Andrew Morton <> Signed-off-by: Linus Torvalds <>
Diffstat (limited to 'include/linux/kasan.h')
1 files changed, 10 insertions, 0 deletions
diff --git a/include/linux/kasan.h b/include/linux/kasan.h
index d5310eef3e38..72ba725ddf9c 100644
--- a/include/linux/kasan.h
+++ b/include/linux/kasan.h
@@ -49,8 +49,15 @@ void kasan_krealloc(const void *object, size_t new_size);
void kasan_slab_alloc(struct kmem_cache *s, void *object);
void kasan_slab_free(struct kmem_cache *s, void *object);
+int kasan_module_alloc(void *addr, size_t size);
+void kasan_module_free(void *addr);
#else /* CONFIG_KASAN */
+#define MODULE_ALIGN 1
static inline void kasan_unpoison_shadow(const void *address, size_t size) {}
static inline void kasan_enable_current(void) {}
@@ -74,6 +81,9 @@ static inline void kasan_krealloc(const void *object, size_t new_size) {}
static inline void kasan_slab_alloc(struct kmem_cache *s, void *object) {}
static inline void kasan_slab_free(struct kmem_cache *s, void *object) {}
+static inline int kasan_module_alloc(void *addr, size_t size) { return 0; }
+static inline void kasan_module_free(void *addr) {}
#endif /* CONFIG_KASAN */
#endif /* LINUX_KASAN_H */