kasan.h (942baad211336efefb93a8369478888ab845c450) | kasan.h (7a3b835371883558eb63e069d891bd87f562380d) |
---|---|
1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef _LINUX_KASAN_H 3#define _LINUX_KASAN_H 4 | 1/* SPDX-License-Identifier: GPL-2.0 */ 2#ifndef _LINUX_KASAN_H 3#define _LINUX_KASAN_H 4 |
5#include <linux/bug.h> |
|
5#include <linux/static_key.h> 6#include <linux/types.h> 7 8struct kmem_cache; 9struct page; 10struct vm_struct; 11struct task_struct; 12 --- 61 unchanged lines hidden (view full) --- 74 unsigned long size) 75{} 76 77static inline void kasan_enable_current(void) {} 78static inline void kasan_disable_current(void) {} 79 80#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ 81 | 6#include <linux/static_key.h> 7#include <linux/types.h> 8 9struct kmem_cache; 10struct page; 11struct vm_struct; 12struct task_struct; 13 --- 61 unchanged lines hidden (view full) --- 75 unsigned long size) 76{} 77 78static inline void kasan_enable_current(void) {} 79static inline void kasan_disable_current(void) {} 80 81#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ 82 |
82#ifdef CONFIG_KASAN 83 84struct kasan_cache { 85 int alloc_meta_offset; 86 int free_meta_offset; 87 bool is_kmalloc; 88}; 89 | |
90#ifdef CONFIG_KASAN_HW_TAGS 91 92DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); 93 94static __always_inline bool kasan_enabled(void) 95{ 96 return static_branch_likely(&kasan_flag_enabled); 97} 98 99static inline bool kasan_has_integrated_init(void) 100{ 101 return kasan_enabled(); 102} 103 | 83#ifdef CONFIG_KASAN_HW_TAGS 84 85DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); 86 87static __always_inline bool kasan_enabled(void) 88{ 89 return static_branch_likely(&kasan_flag_enabled); 90} 91 92static inline bool kasan_has_integrated_init(void) 93{ 94 return kasan_enabled(); 95} 96 |
97void kasan_alloc_pages(struct page *page, unsigned int order, gfp_t flags); 98void kasan_free_pages(struct page *page, unsigned int order); 99 |
|
104#else /* CONFIG_KASAN_HW_TAGS */ 105 106static inline bool kasan_enabled(void) 107{ | 100#else /* CONFIG_KASAN_HW_TAGS */ 101 102static inline bool kasan_enabled(void) 103{ |
108 return true; | 104 return IS_ENABLED(CONFIG_KASAN); |
109} 110 111static inline bool kasan_has_integrated_init(void) 112{ 113 return false; 114} 115 | 105} 106 107static inline bool kasan_has_integrated_init(void) 108{ 109 return false; 110} 111 |
112static __always_inline void kasan_alloc_pages(struct page *page, 113 unsigned int order, gfp_t flags) 114{ 115 /* Only available for integrated init. */ 116 BUILD_BUG(); 117} 118 119static __always_inline void kasan_free_pages(struct page *page, 120 unsigned int order) 121{ 122 /* Only available for integrated init. */ 123 BUILD_BUG(); 124} 125 |
|
116#endif /* CONFIG_KASAN_HW_TAGS */ 117 | 126#endif /* CONFIG_KASAN_HW_TAGS */ 127 |
128#ifdef CONFIG_KASAN 129 130struct kasan_cache { 131 int alloc_meta_offset; 132 int free_meta_offset; 133 bool is_kmalloc; 134}; 135 |
|
118slab_flags_t __kasan_never_merge(void); 119static __always_inline slab_flags_t kasan_never_merge(void) 120{ 121 if (kasan_enabled()) 122 return __kasan_never_merge(); 123 return 0; 124} 125 126void __kasan_unpoison_range(const void *addr, size_t size); 127static __always_inline void kasan_unpoison_range(const void *addr, size_t size) 128{ 129 if (kasan_enabled()) 130 __kasan_unpoison_range(addr, size); 131} 132 | 136slab_flags_t __kasan_never_merge(void); 137static __always_inline slab_flags_t kasan_never_merge(void) 138{ 139 if (kasan_enabled()) 140 return __kasan_never_merge(); 141 return 0; 142} 143 144void __kasan_unpoison_range(const void *addr, size_t size); 145static __always_inline void kasan_unpoison_range(const void *addr, size_t size) 146{ 147 if (kasan_enabled()) 148 __kasan_unpoison_range(addr, size); 149} 150 |
133void __kasan_alloc_pages(struct page *page, unsigned int order, bool init); 134static __always_inline void kasan_alloc_pages(struct page *page, | 151void __kasan_poison_pages(struct page *page, unsigned int order, bool init); 152static __always_inline void kasan_poison_pages(struct page *page, |
135 unsigned int order, bool init) 136{ 137 if (kasan_enabled()) | 153 unsigned int order, bool init) 154{ 155 if (kasan_enabled()) |
138 __kasan_alloc_pages(page, order, init); | 156 __kasan_poison_pages(page, order, init); |
139} 140 | 157} 158 |
141void __kasan_free_pages(struct page *page, unsigned int order, bool init); 142static __always_inline void kasan_free_pages(struct page *page, 143 unsigned int order, bool init) | 159void __kasan_unpoison_pages(struct page *page, unsigned int order, bool init); 160static __always_inline void kasan_unpoison_pages(struct page *page, 161 unsigned int order, bool init) |
144{ 145 if (kasan_enabled()) | 162{ 163 if (kasan_enabled()) |
146 __kasan_free_pages(page, order, init); | 164 __kasan_unpoison_pages(page, order, init); |
147} 148 149void __kasan_cache_create(struct kmem_cache *cache, unsigned int *size, 150 slab_flags_t *flags); 151static __always_inline void kasan_cache_create(struct kmem_cache *cache, 152 unsigned int *size, slab_flags_t *flags) 153{ 154 if (kasan_enabled()) --- 125 unchanged lines hidden (view full) --- 280} 281 282 283bool kasan_save_enable_multi_shot(void); 284void kasan_restore_multi_shot(bool enabled); 285 286#else /* CONFIG_KASAN */ 287 | 165} 166 167void __kasan_cache_create(struct kmem_cache *cache, unsigned int *size, 168 slab_flags_t *flags); 169static __always_inline void kasan_cache_create(struct kmem_cache *cache, 170 unsigned int *size, slab_flags_t *flags) 171{ 172 if (kasan_enabled()) --- 125 unchanged lines hidden (view full) --- 298} 299 300 301bool kasan_save_enable_multi_shot(void); 302void kasan_restore_multi_shot(bool enabled); 303 304#else /* CONFIG_KASAN */ 305 |
288static inline bool kasan_enabled(void) 289{ 290 return false; 291} 292static inline bool kasan_has_integrated_init(void) 293{ 294 return false; 295} | |
296static inline slab_flags_t kasan_never_merge(void) 297{ 298 return 0; 299} 300static inline void kasan_unpoison_range(const void *address, size_t size) {} | 306static inline slab_flags_t kasan_never_merge(void) 307{ 308 return 0; 309} 310static inline void kasan_unpoison_range(const void *address, size_t size) {} |
301static inline void kasan_alloc_pages(struct page *page, unsigned int order, bool init) {} 302static inline void kasan_free_pages(struct page *page, unsigned int order, bool init) {} | 311static inline void kasan_poison_pages(struct page *page, unsigned int order, 312 bool init) {} 313static inline void kasan_unpoison_pages(struct page *page, unsigned int order, 314 bool init) {} |
303static inline void kasan_cache_create(struct kmem_cache *cache, 304 unsigned int *size, 305 slab_flags_t *flags) {} 306static inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) {} 307static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } 308static inline void kasan_poison_slab(struct page *page) {} 309static inline void kasan_unpoison_object_data(struct kmem_cache *cache, 310 void *object) {} --- 158 unchanged lines hidden --- | 315static inline void kasan_cache_create(struct kmem_cache *cache, 316 unsigned int *size, 317 slab_flags_t *flags) {} 318static inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) {} 319static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } 320static inline void kasan_poison_slab(struct page *page) {} 321static inline void kasan_unpoison_object_data(struct kmem_cache *cache, 322 void *object) {} --- 158 unchanged lines hidden --- |