blob: c242adf6bc8578846e1cc54ad0a931b052668381 [file] [log] [blame]
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -08001#ifndef __MM_KASAN_KASAN_H
2#define __MM_KASAN_KASAN_H
3
4#include <linux/kasan.h>
5
6#define KASAN_SHADOW_SCALE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT)
7#define KASAN_SHADOW_MASK (KASAN_SHADOW_SCALE_SIZE - 1)
8
Andrey Ryabininb8c73fc2015-02-13 14:39:28 -08009#define KASAN_FREE_PAGE 0xFF /* page was freed */
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080010#define KASAN_PAGE_REDZONE 0xFE /* redzone for kmalloc_large allocations */
11#define KASAN_KMALLOC_REDZONE 0xFC /* redzone inside slub object */
12#define KASAN_KMALLOC_FREE 0xFB /* object was freed (kmem_cache_free/kfree) */
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080013#define KASAN_GLOBAL_REDZONE 0xFA /* redzone for global variable */
Andrey Ryabinin0316bec2015-02-13 14:39:42 -080014
Andrey Ryabininc420f162015-02-13 14:39:59 -080015/*
16 * Stack redzone shadow values
17 * (Those are compiler's ABI, don't change them)
18 */
19#define KASAN_STACK_LEFT 0xF1
20#define KASAN_STACK_MID 0xF2
21#define KASAN_STACK_RIGHT 0xF3
22#define KASAN_STACK_PARTIAL 0xF4
23
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080024/* Don't break randconfig/all*config builds */
25#ifndef KASAN_ABI_VERSION
26#define KASAN_ABI_VERSION 1
27#endif
Andrey Ryabininb8c73fc2015-02-13 14:39:28 -080028
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080029struct kasan_access_info {
30 const void *access_addr;
31 const void *first_bad_addr;
32 size_t access_size;
33 bool is_write;
34 unsigned long ip;
35};
36
Andrey Ryabininbebf56a2015-02-13 14:40:17 -080037/* The layout of struct dictated by compiler */
38struct kasan_source_location {
39 const char *filename;
40 int line_no;
41 int column_no;
42};
43
44/* The layout of struct dictated by compiler */
45struct kasan_global {
46 const void *beg; /* Address of the beginning of the global variable. */
47 size_t size; /* Size of the global variable. */
48 size_t size_with_redzone; /* Size of the variable + size of the red zone. 32 bytes aligned */
49 const void *name;
50 const void *module_name; /* Name of the module where the global variable is declared. */
51 unsigned long has_dynamic_init; /* This needed for C++ */
52#if KASAN_ABI_VERSION >= 4
53 struct kasan_source_location *location;
54#endif
55};
56
Andrey Ryabinin0b24bec2015-02-13 14:39:17 -080057void kasan_report_error(struct kasan_access_info *info);
58void kasan_report_user_access(struct kasan_access_info *info);
59
60static inline const void *kasan_shadow_to_mem(const void *shadow_addr)
61{
62 return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET)
63 << KASAN_SHADOW_SCALE_SHIFT);
64}
65
66static inline bool kasan_enabled(void)
67{
68 return !current->kasan_depth;
69}
70
71void kasan_report(unsigned long addr, size_t size,
72 bool is_write, unsigned long ip);
73
74#endif