OLD | NEW |
1 #ifndef __MM_KASAN_KASAN_H | 1 #ifndef __MM_KASAN_KASAN_H |
2 #define __MM_KASAN_KASAN_H | 2 #define __MM_KASAN_KASAN_H |
3 | 3 |
4 #include <linux/kasan.h> | 4 #include <linux/kasan.h> |
5 #include <linux/stackdepot.h> | 5 #include <linux/stackdepot.h> |
6 | 6 |
7 #define KASAN_SHADOW_SCALE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) | 7 #define KASAN_SHADOW_SCALE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) |
8 #define KASAN_SHADOW_MASK (KASAN_SHADOW_SCALE_SIZE - 1) | 8 #define KASAN_SHADOW_MASK (KASAN_SHADOW_SCALE_SIZE - 1) |
9 | 9 |
10 #define KASAN_FREE_PAGE 0xFF /* page was freed */ | 10 #define KASAN_FREE_PAGE 0xFF /* page was freed */ |
11 #define KASAN_PAGE_REDZONE 0xFE /* redzone for kmalloc_large allocations *
/ | 11 #define KASAN_PAGE_REDZONE 0xFE /* redzone for kmalloc_large allocations *
/ |
12 #define KASAN_KMALLOC_REDZONE 0xFC /* redzone inside slub object */ | 12 #define KASAN_KMALLOC_REDZONE 0xFC /* redzone inside slub object */ |
13 #define KASAN_KMALLOC_FREE 0xFB /* object was freed (kmem_cache_free/kfree
) */ | 13 #define KASAN_KMALLOC_FREE 0xFB /* object was freed (kmem_cache_free/kfree
) */ |
14 #define KASAN_GLOBAL_REDZONE 0xFA /* redzone for global variable */ | 14 #define KASAN_GLOBAL_REDZONE 0xFA /* redzone for global variable */ |
15 | 15 |
| 16 #define KASAN_PER_PAGE_BYPASS 0xFF /* page should be checked by per-byte shad
ow */ |
| 17 #define KASAN_PER_PAGE_FREE 0xFE /* page was freed */ |
| 18 |
16 /* | 19 /* |
17 * Stack redzone shadow values | 20 * Stack redzone shadow values |
18 * (Those are compiler's ABI, don't change them) | 21 * (Those are compiler's ABI, don't change them) |
19 */ | 22 */ |
20 #define KASAN_STACK_LEFT 0xF1 | 23 #define KASAN_STACK_LEFT 0xF1 |
21 #define KASAN_STACK_MID 0xF2 | 24 #define KASAN_STACK_MID 0xF2 |
22 #define KASAN_STACK_RIGHT 0xF3 | 25 #define KASAN_STACK_RIGHT 0xF3 |
23 #define KASAN_STACK_PARTIAL 0xF4 | 26 #define KASAN_STACK_PARTIAL 0xF4 |
24 #define KASAN_USE_AFTER_SCOPE 0xF8 | 27 #define KASAN_USE_AFTER_SCOPE 0xF8 |
25 | 28 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 struct qlist_node { | 81 struct qlist_node { |
79 struct qlist_node *next; | 82 struct qlist_node *next; |
80 }; | 83 }; |
81 struct kasan_free_meta { | 84 struct kasan_free_meta { |
82 /* This field is used while the object is in the quarantine. | 85 /* This field is used while the object is in the quarantine. |
83 * Otherwise it might be used for the allocator freelist. | 86 * Otherwise it might be used for the allocator freelist. |
84 */ | 87 */ |
85 struct qlist_node quarantine_link; | 88 struct qlist_node quarantine_link; |
86 }; | 89 }; |
87 | 90 |
| 91 extern unsigned long kasan_black_page_pfn; |
| 92 |
88 struct kasan_alloc_meta *get_alloc_info(struct kmem_cache *cache, | 93 struct kasan_alloc_meta *get_alloc_info(struct kmem_cache *cache, |
89 const void *object); | 94 const void *object); |
90 struct kasan_free_meta *get_free_info(struct kmem_cache *cache, | 95 struct kasan_free_meta *get_free_info(struct kmem_cache *cache, |
91 const void *object); | 96 const void *object); |
92 | 97 |
93 static inline const void *kasan_shadow_to_mem(const void *shadow_addr) | 98 #ifdef HAVE_KASAN_PER_PAGE_SHADOW |
94 { | 99 void arch_kasan_map_shadow(unsigned long s, unsigned long e); |
95 » return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET) | 100 bool arch_kasan_recheck_prepare(unsigned long addr, size_t size); |
96 » » << KASAN_SHADOW_SCALE_SHIFT); | |
97 } | |
98 | 101 |
| 102 static inline bool kasan_pshadow_inited(void) { return true; } |
| 103 |
| 104 #else |
| 105 static inline void arch_kasan_map_shadow(unsigned long s, unsigned long e) { } |
| 106 static inline bool arch_kasan_recheck_prepare(unsigned long addr, |
| 107 size_t size) { return false; } |
| 108 static inline bool kasan_pshadow_inited(void) { return false; } |
| 109 #endif |
| 110 |
| 111 void __kasan_report(unsigned long addr, size_t size, |
| 112 bool is_write, unsigned long ip); |
99 void kasan_report(unsigned long addr, size_t size, | 113 void kasan_report(unsigned long addr, size_t size, |
100 bool is_write, unsigned long ip); | 114 bool is_write, unsigned long ip); |
101 void kasan_report_double_free(struct kmem_cache *cache, void *object, | 115 void kasan_report_double_free(struct kmem_cache *cache, void *object, |
102 void *ip); | 116 void *ip); |
103 | 117 |
104 #if defined(CONFIG_SLAB) || defined(CONFIG_SLUB) | 118 #if defined(CONFIG_SLAB) || defined(CONFIG_SLUB) |
105 void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache); | 119 void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache); |
106 void quarantine_reduce(void); | 120 void quarantine_reduce(void); |
107 void quarantine_remove_cache(struct kmem_cache *cache); | 121 void quarantine_remove_cache(struct kmem_cache *cache); |
108 #else | 122 #else |
109 static inline void quarantine_put(struct kasan_free_meta *info, | 123 static inline void quarantine_put(struct kasan_free_meta *info, |
110 struct kmem_cache *cache) { } | 124 struct kmem_cache *cache) { } |
111 static inline void quarantine_reduce(void) { } | 125 static inline void quarantine_reduce(void) { } |
112 static inline void quarantine_remove_cache(struct kmem_cache *cache) { } | 126 static inline void quarantine_remove_cache(struct kmem_cache *cache) { } |
113 #endif | 127 #endif |
114 | 128 |
115 #endif | 129 #endif |
OLD | NEW |