Commit | Line | Data |
---|---|---|
0b24becc AR |
1 | #ifndef __MM_KASAN_KASAN_H |
2 | #define __MM_KASAN_KASAN_H | |
3 | ||
4 | #include <linux/kasan.h> | |
cd11016e | 5 | #include <linux/stackdepot.h> |
0b24becc AR |
6 | |
7 | #define KASAN_SHADOW_SCALE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) | |
8 | #define KASAN_SHADOW_MASK (KASAN_SHADOW_SCALE_SIZE - 1) | |
9 | ||
0316bec2 AR |
10 | #define KASAN_FREE_PAGE 0xFF /* page was freed */ |
11 | #define KASAN_PAGE_REDZONE 0xFE /* redzone for kmalloc_large allocations */ | |
12 | #define KASAN_KMALLOC_REDZONE 0xFC /* redzone inside slub object */ | |
13 | #define KASAN_KMALLOC_FREE 0xFB /* object was freed (kmem_cache_free/kfree) */ | |
bebf56a1 | 14 | #define KASAN_GLOBAL_REDZONE 0xFA /* redzone for global variable */ |
0316bec2 | 15 | |
c420f167 AR |
16 | /* |
17 | * Stack redzone shadow values | |
18 | * (Those are compiler's ABI, don't change them) | |
19 | */ | |
20 | #define KASAN_STACK_LEFT 0xF1 | |
21 | #define KASAN_STACK_MID 0xF2 | |
22 | #define KASAN_STACK_RIGHT 0xF3 | |
23 | #define KASAN_STACK_PARTIAL 0xF4 | |
24 | ||
bebf56a1 AR |
25 | /* Don't break randconfig/all*config builds */ |
26 | #ifndef KASAN_ABI_VERSION | |
27 | #define KASAN_ABI_VERSION 1 | |
28 | #endif | |
b8c73fc2 | 29 | |
0b24becc AR |
30 | struct kasan_access_info { |
31 | const void *access_addr; | |
32 | const void *first_bad_addr; | |
33 | size_t access_size; | |
34 | bool is_write; | |
35 | unsigned long ip; | |
36 | }; | |
37 | ||
bebf56a1 AR |
38 | /* The layout of struct dictated by compiler */ |
39 | struct kasan_source_location { | |
40 | const char *filename; | |
41 | int line_no; | |
42 | int column_no; | |
43 | }; | |
44 | ||
45 | /* The layout of struct dictated by compiler */ | |
46 | struct kasan_global { | |
47 | const void *beg; /* Address of the beginning of the global variable. */ | |
48 | size_t size; /* Size of the global variable. */ | |
49 | size_t size_with_redzone; /* Size of the variable + size of the red zone. 32 bytes aligned */ | |
50 | const void *name; | |
51 | const void *module_name; /* Name of the module where the global variable is declared. */ | |
52 | unsigned long has_dynamic_init; /* This needed for C++ */ | |
53 | #if KASAN_ABI_VERSION >= 4 | |
54 | struct kasan_source_location *location; | |
55 | #endif | |
56 | }; | |
57 | ||
7ed2f9e6 AP |
58 | /** |
59 | * Structures to keep alloc and free tracks * | |
60 | */ | |
61 | ||
cd11016e AP |
62 | #define KASAN_STACK_DEPTH 64 |
63 | ||
7ed2f9e6 | 64 | struct kasan_track { |
cd11016e AP |
65 | u32 pid; |
66 | depot_stack_handle_t stack; | |
7ed2f9e6 AP |
67 | }; |
68 | ||
69 | struct kasan_alloc_meta { | |
b3cbd9bf AR |
70 | struct kasan_track alloc_track; |
71 | struct kasan_track free_track; | |
7ed2f9e6 AP |
72 | }; |
73 | ||
55834c59 AP |
74 | struct qlist_node { |
75 | struct qlist_node *next; | |
76 | }; | |
7ed2f9e6 | 77 | struct kasan_free_meta { |
55834c59 AP |
78 | /* This field is used while the object is in the quarantine. |
79 | * Otherwise it might be used for the allocator freelist. | |
80 | */ | |
81 | struct qlist_node quarantine_link; | |
7ed2f9e6 AP |
82 | }; |
83 | ||
84 | struct kasan_alloc_meta *get_alloc_info(struct kmem_cache *cache, | |
85 | const void *object); | |
86 | struct kasan_free_meta *get_free_info(struct kmem_cache *cache, | |
87 | const void *object); | |
88 | ||
0b24becc AR |
89 | static inline const void *kasan_shadow_to_mem(const void *shadow_addr) |
90 | { | |
91 | return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET) | |
92 | << KASAN_SHADOW_SCALE_SHIFT); | |
93 | } | |
94 | ||
0ba8663c | 95 | static inline bool kasan_report_enabled(void) |
0b24becc AR |
96 | { |
97 | return !current->kasan_depth; | |
98 | } | |
99 | ||
100 | void kasan_report(unsigned long addr, size_t size, | |
101 | bool is_write, unsigned long ip); | |
7e088978 AR |
102 | void kasan_report_double_free(struct kmem_cache *cache, void *object, |
103 | s8 shadow); | |
0b24becc | 104 | |
80a9201a | 105 | #if defined(CONFIG_SLAB) || defined(CONFIG_SLUB) |
55834c59 AP |
106 | void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache); |
107 | void quarantine_reduce(void); | |
108 | void quarantine_remove_cache(struct kmem_cache *cache); | |
109 | #else | |
110 | static inline void quarantine_put(struct kasan_free_meta *info, | |
111 | struct kmem_cache *cache) { } | |
112 | static inline void quarantine_reduce(void) { } | |
113 | static inline void quarantine_remove_cache(struct kmem_cache *cache) { } | |
114 | #endif | |
115 | ||
0b24becc | 116 | #endif |