1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 20b24beccSAndrey Ryabinin #ifndef _LINUX_KASAN_H 30b24beccSAndrey Ryabinin #define _LINUX_KASAN_H 40b24beccSAndrey Ryabinin 534303244SAndrey Konovalov #include <linux/static_key.h> 60b24beccSAndrey Ryabinin #include <linux/types.h> 70b24beccSAndrey Ryabinin 80b24beccSAndrey Ryabinin struct kmem_cache; 90b24beccSAndrey Ryabinin struct page; 10a5af5aa8SAndrey Ryabinin struct vm_struct; 115be9b730SMasami Hiramatsu struct task_struct; 120b24beccSAndrey Ryabinin 130b24beccSAndrey Ryabinin #ifdef CONFIG_KASAN 140b24beccSAndrey Ryabinin 15d5750edfSAndrey Konovalov #include <linux/linkage.h> 1665fddcfcSMike Rapoport #include <asm/kasan.h> 170b24beccSAndrey Ryabinin 1883c4e7a0SPatricia Alfonso /* kasan_data struct is used in KUnit tests for KASAN expected failures */ 1983c4e7a0SPatricia Alfonso struct kunit_kasan_expectation { 2083c4e7a0SPatricia Alfonso bool report_expected; 2183c4e7a0SPatricia Alfonso bool report_found; 2283c4e7a0SPatricia Alfonso }; 2383c4e7a0SPatricia Alfonso 24d5750edfSAndrey Konovalov #endif 25d5750edfSAndrey Konovalov 26d5750edfSAndrey Konovalov #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) 27d5750edfSAndrey Konovalov 28d5750edfSAndrey Konovalov #include <linux/pgtable.h> 29d5750edfSAndrey Konovalov 30d5750edfSAndrey Konovalov /* Software KASAN implementations use shadow memory. */ 31d5750edfSAndrey Konovalov 32d5750edfSAndrey Konovalov #ifdef CONFIG_KASAN_SW_TAGS 33d5750edfSAndrey Konovalov #define KASAN_SHADOW_INIT 0xFF 34d5750edfSAndrey Konovalov #else 35d5750edfSAndrey Konovalov #define KASAN_SHADOW_INIT 0 36d5750edfSAndrey Konovalov #endif 37d5750edfSAndrey Konovalov 3829970dc2SHailong Liu #ifndef PTE_HWTABLE_PTRS 3929970dc2SHailong Liu #define PTE_HWTABLE_PTRS 0 4029970dc2SHailong Liu #endif 4129970dc2SHailong Liu 429577dd74SAndrey Konovalov extern unsigned char kasan_early_shadow_page[PAGE_SIZE]; 4329970dc2SHailong Liu extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE + PTE_HWTABLE_PTRS]; 449577dd74SAndrey Konovalov extern pmd_t kasan_early_shadow_pmd[PTRS_PER_PMD]; 459577dd74SAndrey Konovalov extern pud_t kasan_early_shadow_pud[PTRS_PER_PUD]; 469577dd74SAndrey Konovalov extern p4d_t kasan_early_shadow_p4d[MAX_PTRS_PER_P4D]; 4769786cdbSAndrey Ryabinin 489577dd74SAndrey Konovalov int kasan_populate_early_shadow(const void *shadow_start, 4969786cdbSAndrey Ryabinin const void *shadow_end); 5069786cdbSAndrey Ryabinin 510b24beccSAndrey Ryabinin static inline void *kasan_mem_to_shadow(const void *addr) 520b24beccSAndrey Ryabinin { 530b24beccSAndrey Ryabinin return (void *)((unsigned long)addr >> KASAN_SHADOW_SCALE_SHIFT) 540b24beccSAndrey Ryabinin + KASAN_SHADOW_OFFSET; 550b24beccSAndrey Ryabinin } 560b24beccSAndrey Ryabinin 57d5750edfSAndrey Konovalov int kasan_add_zero_shadow(void *start, unsigned long size); 58d5750edfSAndrey Konovalov void kasan_remove_zero_shadow(void *start, unsigned long size); 59d5750edfSAndrey Konovalov 60d73b4936SAndrey Konovalov /* Enable reporting bugs after kasan_disable_current() */ 61d73b4936SAndrey Konovalov extern void kasan_enable_current(void); 62d73b4936SAndrey Konovalov 63d73b4936SAndrey Konovalov /* Disable reporting bugs for current task */ 64d73b4936SAndrey Konovalov extern void kasan_disable_current(void); 65d73b4936SAndrey Konovalov 66d5750edfSAndrey Konovalov #else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ 67d5750edfSAndrey Konovalov 68d5750edfSAndrey Konovalov static inline int kasan_add_zero_shadow(void *start, unsigned long size) 69d5750edfSAndrey Konovalov { 70d5750edfSAndrey Konovalov return 0; 71d5750edfSAndrey Konovalov } 72d5750edfSAndrey Konovalov static inline void kasan_remove_zero_shadow(void *start, 73d5750edfSAndrey Konovalov unsigned long size) 74d5750edfSAndrey Konovalov {} 75d5750edfSAndrey Konovalov 76d73b4936SAndrey Konovalov static inline void kasan_enable_current(void) {} 77d73b4936SAndrey Konovalov static inline void kasan_disable_current(void) {} 78d73b4936SAndrey Konovalov 79d5750edfSAndrey Konovalov #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ 80d5750edfSAndrey Konovalov 81d5750edfSAndrey Konovalov #ifdef CONFIG_KASAN 82d5750edfSAndrey Konovalov 837ed2f9e6SAlexander Potapenko struct kasan_cache { 847ed2f9e6SAlexander Potapenko int alloc_meta_offset; 857ed2f9e6SAlexander Potapenko int free_meta_offset; 867ed2f9e6SAlexander Potapenko }; 877ed2f9e6SAlexander Potapenko 8834303244SAndrey Konovalov #ifdef CONFIG_KASAN_HW_TAGS 89e86f8b09SAndrey Konovalov 9034303244SAndrey Konovalov DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); 91e86f8b09SAndrey Konovalov 9234303244SAndrey Konovalov static __always_inline bool kasan_enabled(void) 9334303244SAndrey Konovalov { 9434303244SAndrey Konovalov return static_branch_likely(&kasan_flag_enabled); 9534303244SAndrey Konovalov } 96e86f8b09SAndrey Konovalov 97e86f8b09SAndrey Konovalov #else /* CONFIG_KASAN_HW_TAGS */ 98e86f8b09SAndrey Konovalov 9934303244SAndrey Konovalov static inline bool kasan_enabled(void) 10034303244SAndrey Konovalov { 10134303244SAndrey Konovalov return true; 10234303244SAndrey Konovalov } 103e86f8b09SAndrey Konovalov 104e86f8b09SAndrey Konovalov #endif /* CONFIG_KASAN_HW_TAGS */ 105e86f8b09SAndrey Konovalov 106e86f8b09SAndrey Konovalov slab_flags_t __kasan_never_merge(void); 107e86f8b09SAndrey Konovalov static __always_inline slab_flags_t kasan_never_merge(void) 108e86f8b09SAndrey Konovalov { 109e86f8b09SAndrey Konovalov if (kasan_enabled()) 110e86f8b09SAndrey Konovalov return __kasan_never_merge(); 111e86f8b09SAndrey Konovalov return 0; 112e86f8b09SAndrey Konovalov } 11334303244SAndrey Konovalov 11434303244SAndrey Konovalov void __kasan_unpoison_range(const void *addr, size_t size); 11534303244SAndrey Konovalov static __always_inline void kasan_unpoison_range(const void *addr, size_t size) 11634303244SAndrey Konovalov { 11734303244SAndrey Konovalov if (kasan_enabled()) 11834303244SAndrey Konovalov __kasan_unpoison_range(addr, size); 11934303244SAndrey Konovalov } 12034303244SAndrey Konovalov 12134303244SAndrey Konovalov void __kasan_alloc_pages(struct page *page, unsigned int order); 12234303244SAndrey Konovalov static __always_inline void kasan_alloc_pages(struct page *page, 12334303244SAndrey Konovalov unsigned int order) 12434303244SAndrey Konovalov { 12534303244SAndrey Konovalov if (kasan_enabled()) 12634303244SAndrey Konovalov __kasan_alloc_pages(page, order); 12734303244SAndrey Konovalov } 12834303244SAndrey Konovalov 12934303244SAndrey Konovalov void __kasan_free_pages(struct page *page, unsigned int order); 13034303244SAndrey Konovalov static __always_inline void kasan_free_pages(struct page *page, 13134303244SAndrey Konovalov unsigned int order) 13234303244SAndrey Konovalov { 13334303244SAndrey Konovalov if (kasan_enabled()) 13434303244SAndrey Konovalov __kasan_free_pages(page, order); 13534303244SAndrey Konovalov } 13634303244SAndrey Konovalov 13734303244SAndrey Konovalov void __kasan_cache_create(struct kmem_cache *cache, unsigned int *size, 13834303244SAndrey Konovalov slab_flags_t *flags); 13934303244SAndrey Konovalov static __always_inline void kasan_cache_create(struct kmem_cache *cache, 14034303244SAndrey Konovalov unsigned int *size, slab_flags_t *flags) 14134303244SAndrey Konovalov { 14234303244SAndrey Konovalov if (kasan_enabled()) 14334303244SAndrey Konovalov __kasan_cache_create(cache, size, flags); 14434303244SAndrey Konovalov } 14534303244SAndrey Konovalov 14634303244SAndrey Konovalov size_t __kasan_metadata_size(struct kmem_cache *cache); 14734303244SAndrey Konovalov static __always_inline size_t kasan_metadata_size(struct kmem_cache *cache) 14834303244SAndrey Konovalov { 14934303244SAndrey Konovalov if (kasan_enabled()) 15034303244SAndrey Konovalov return __kasan_metadata_size(cache); 15134303244SAndrey Konovalov return 0; 15234303244SAndrey Konovalov } 15334303244SAndrey Konovalov 15434303244SAndrey Konovalov void __kasan_poison_slab(struct page *page); 15534303244SAndrey Konovalov static __always_inline void kasan_poison_slab(struct page *page) 15634303244SAndrey Konovalov { 15734303244SAndrey Konovalov if (kasan_enabled()) 15834303244SAndrey Konovalov __kasan_poison_slab(page); 15934303244SAndrey Konovalov } 16034303244SAndrey Konovalov 16134303244SAndrey Konovalov void __kasan_unpoison_object_data(struct kmem_cache *cache, void *object); 16234303244SAndrey Konovalov static __always_inline void kasan_unpoison_object_data(struct kmem_cache *cache, 16334303244SAndrey Konovalov void *object) 16434303244SAndrey Konovalov { 16534303244SAndrey Konovalov if (kasan_enabled()) 16634303244SAndrey Konovalov __kasan_unpoison_object_data(cache, object); 16734303244SAndrey Konovalov } 16834303244SAndrey Konovalov 16934303244SAndrey Konovalov void __kasan_poison_object_data(struct kmem_cache *cache, void *object); 17034303244SAndrey Konovalov static __always_inline void kasan_poison_object_data(struct kmem_cache *cache, 17134303244SAndrey Konovalov void *object) 17234303244SAndrey Konovalov { 17334303244SAndrey Konovalov if (kasan_enabled()) 17434303244SAndrey Konovalov __kasan_poison_object_data(cache, object); 17534303244SAndrey Konovalov } 17634303244SAndrey Konovalov 17734303244SAndrey Konovalov void * __must_check __kasan_init_slab_obj(struct kmem_cache *cache, 17834303244SAndrey Konovalov const void *object); 17934303244SAndrey Konovalov static __always_inline void * __must_check kasan_init_slab_obj( 18034303244SAndrey Konovalov struct kmem_cache *cache, const void *object) 18134303244SAndrey Konovalov { 18234303244SAndrey Konovalov if (kasan_enabled()) 18334303244SAndrey Konovalov return __kasan_init_slab_obj(cache, object); 18434303244SAndrey Konovalov return (void *)object; 18534303244SAndrey Konovalov } 18634303244SAndrey Konovalov 18734303244SAndrey Konovalov bool __kasan_slab_free(struct kmem_cache *s, void *object, unsigned long ip); 188027b37b5SAndrey Konovalov static __always_inline bool kasan_slab_free(struct kmem_cache *s, void *object) 18934303244SAndrey Konovalov { 19034303244SAndrey Konovalov if (kasan_enabled()) 191027b37b5SAndrey Konovalov return __kasan_slab_free(s, object, _RET_IP_); 19234303244SAndrey Konovalov return false; 19334303244SAndrey Konovalov } 19434303244SAndrey Konovalov 195eeb3160cSAndrey Konovalov void __kasan_slab_free_mempool(void *ptr, unsigned long ip); 196027b37b5SAndrey Konovalov static __always_inline void kasan_slab_free_mempool(void *ptr) 197eeb3160cSAndrey Konovalov { 198eeb3160cSAndrey Konovalov if (kasan_enabled()) 199027b37b5SAndrey Konovalov __kasan_slab_free_mempool(ptr, _RET_IP_); 200eeb3160cSAndrey Konovalov } 201eeb3160cSAndrey Konovalov 20234303244SAndrey Konovalov void * __must_check __kasan_slab_alloc(struct kmem_cache *s, 20334303244SAndrey Konovalov void *object, gfp_t flags); 20434303244SAndrey Konovalov static __always_inline void * __must_check kasan_slab_alloc( 20534303244SAndrey Konovalov struct kmem_cache *s, void *object, gfp_t flags) 20634303244SAndrey Konovalov { 20734303244SAndrey Konovalov if (kasan_enabled()) 20834303244SAndrey Konovalov return __kasan_slab_alloc(s, object, flags); 20934303244SAndrey Konovalov return object; 21034303244SAndrey Konovalov } 21134303244SAndrey Konovalov 21234303244SAndrey Konovalov void * __must_check __kasan_kmalloc(struct kmem_cache *s, const void *object, 21334303244SAndrey Konovalov size_t size, gfp_t flags); 21434303244SAndrey Konovalov static __always_inline void * __must_check kasan_kmalloc(struct kmem_cache *s, 21534303244SAndrey Konovalov const void *object, size_t size, gfp_t flags) 21634303244SAndrey Konovalov { 21734303244SAndrey Konovalov if (kasan_enabled()) 21834303244SAndrey Konovalov return __kasan_kmalloc(s, object, size, flags); 21934303244SAndrey Konovalov return (void *)object; 22034303244SAndrey Konovalov } 22134303244SAndrey Konovalov 22234303244SAndrey Konovalov void * __must_check __kasan_kmalloc_large(const void *ptr, 22334303244SAndrey Konovalov size_t size, gfp_t flags); 22434303244SAndrey Konovalov static __always_inline void * __must_check kasan_kmalloc_large(const void *ptr, 22534303244SAndrey Konovalov size_t size, gfp_t flags) 22634303244SAndrey Konovalov { 22734303244SAndrey Konovalov if (kasan_enabled()) 22834303244SAndrey Konovalov return __kasan_kmalloc_large(ptr, size, flags); 22934303244SAndrey Konovalov return (void *)ptr; 23034303244SAndrey Konovalov } 23134303244SAndrey Konovalov 23234303244SAndrey Konovalov void * __must_check __kasan_krealloc(const void *object, 23334303244SAndrey Konovalov size_t new_size, gfp_t flags); 23434303244SAndrey Konovalov static __always_inline void * __must_check kasan_krealloc(const void *object, 23534303244SAndrey Konovalov size_t new_size, gfp_t flags) 23634303244SAndrey Konovalov { 23734303244SAndrey Konovalov if (kasan_enabled()) 23834303244SAndrey Konovalov return __kasan_krealloc(object, new_size, flags); 23934303244SAndrey Konovalov return (void *)object; 24034303244SAndrey Konovalov } 24134303244SAndrey Konovalov 24234303244SAndrey Konovalov void __kasan_kfree_large(void *ptr, unsigned long ip); 243027b37b5SAndrey Konovalov static __always_inline void kasan_kfree_large(void *ptr) 24434303244SAndrey Konovalov { 24534303244SAndrey Konovalov if (kasan_enabled()) 246027b37b5SAndrey Konovalov __kasan_kfree_large(ptr, _RET_IP_); 24734303244SAndrey Konovalov } 2489b75a867SAndrey Ryabinin 249*611806b4SAndrey Konovalov /* 250*611806b4SAndrey Konovalov * Unlike kasan_check_read/write(), kasan_check_byte() is performed even for 251*611806b4SAndrey Konovalov * the hardware tag-based mode that doesn't rely on compiler instrumentation. 252*611806b4SAndrey Konovalov */ 253*611806b4SAndrey Konovalov bool __kasan_check_byte(const void *addr, unsigned long ip); 254*611806b4SAndrey Konovalov static __always_inline bool kasan_check_byte(const void *addr) 255*611806b4SAndrey Konovalov { 256*611806b4SAndrey Konovalov if (kasan_enabled()) 257*611806b4SAndrey Konovalov return __kasan_check_byte(addr, _RET_IP_); 258*611806b4SAndrey Konovalov return true; 259*611806b4SAndrey Konovalov } 260*611806b4SAndrey Konovalov 261*611806b4SAndrey Konovalov 262b0845ce5SMark Rutland bool kasan_save_enable_multi_shot(void); 263b0845ce5SMark Rutland void kasan_restore_multi_shot(bool enabled); 264b0845ce5SMark Rutland 2650b24beccSAndrey Ryabinin #else /* CONFIG_KASAN */ 2660b24beccSAndrey Ryabinin 26734303244SAndrey Konovalov static inline bool kasan_enabled(void) 26834303244SAndrey Konovalov { 26934303244SAndrey Konovalov return false; 27034303244SAndrey Konovalov } 271e86f8b09SAndrey Konovalov static inline slab_flags_t kasan_never_merge(void) 272e86f8b09SAndrey Konovalov { 273e86f8b09SAndrey Konovalov return 0; 274e86f8b09SAndrey Konovalov } 275cebd0eb2SAndrey Konovalov static inline void kasan_unpoison_range(const void *address, size_t size) {} 276b8c73fc2SAndrey Ryabinin static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} 277b8c73fc2SAndrey Ryabinin static inline void kasan_free_pages(struct page *page, unsigned int order) {} 2787ed2f9e6SAlexander Potapenko static inline void kasan_cache_create(struct kmem_cache *cache, 279be4a7988SAlexey Dobriyan unsigned int *size, 280d50112edSAlexey Dobriyan slab_flags_t *flags) {} 28134303244SAndrey Konovalov static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } 2820316bec2SAndrey Ryabinin static inline void kasan_poison_slab(struct page *page) {} 2830316bec2SAndrey Ryabinin static inline void kasan_unpoison_object_data(struct kmem_cache *cache, 2840316bec2SAndrey Ryabinin void *object) {} 2850316bec2SAndrey Ryabinin static inline void kasan_poison_object_data(struct kmem_cache *cache, 2860316bec2SAndrey Ryabinin void *object) {} 2870116523cSAndrey Konovalov static inline void *kasan_init_slab_obj(struct kmem_cache *cache, 2880116523cSAndrey Konovalov const void *object) 2890116523cSAndrey Konovalov { 2900116523cSAndrey Konovalov return (void *)object; 2910116523cSAndrey Konovalov } 292027b37b5SAndrey Konovalov static inline bool kasan_slab_free(struct kmem_cache *s, void *object) 2930116523cSAndrey Konovalov { 29434303244SAndrey Konovalov return false; 2950116523cSAndrey Konovalov } 296027b37b5SAndrey Konovalov static inline void kasan_slab_free_mempool(void *ptr) {} 29734303244SAndrey Konovalov static inline void *kasan_slab_alloc(struct kmem_cache *s, void *object, 29834303244SAndrey Konovalov gfp_t flags) 29934303244SAndrey Konovalov { 30034303244SAndrey Konovalov return object; 30134303244SAndrey Konovalov } 3020116523cSAndrey Konovalov static inline void *kasan_kmalloc(struct kmem_cache *s, const void *object, 3030116523cSAndrey Konovalov size_t size, gfp_t flags) 3040116523cSAndrey Konovalov { 3050116523cSAndrey Konovalov return (void *)object; 3060116523cSAndrey Konovalov } 30734303244SAndrey Konovalov static inline void *kasan_kmalloc_large(const void *ptr, size_t size, gfp_t flags) 30834303244SAndrey Konovalov { 30934303244SAndrey Konovalov return (void *)ptr; 31034303244SAndrey Konovalov } 3110116523cSAndrey Konovalov static inline void *kasan_krealloc(const void *object, size_t new_size, 3120116523cSAndrey Konovalov gfp_t flags) 3130116523cSAndrey Konovalov { 3140116523cSAndrey Konovalov return (void *)object; 3150116523cSAndrey Konovalov } 316027b37b5SAndrey Konovalov static inline void kasan_kfree_large(void *ptr) {} 317*611806b4SAndrey Konovalov static inline bool kasan_check_byte(const void *address) 318*611806b4SAndrey Konovalov { 319*611806b4SAndrey Konovalov return true; 320*611806b4SAndrey Konovalov } 3219b75a867SAndrey Ryabinin 3220b24beccSAndrey Ryabinin #endif /* CONFIG_KASAN */ 3230b24beccSAndrey Ryabinin 324d56a9ef8SAndrey Konovalov #if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK 325d56a9ef8SAndrey Konovalov void kasan_unpoison_task_stack(struct task_struct *task); 326d56a9ef8SAndrey Konovalov #else 327d56a9ef8SAndrey Konovalov static inline void kasan_unpoison_task_stack(struct task_struct *task) {} 328d56a9ef8SAndrey Konovalov #endif 329d56a9ef8SAndrey Konovalov 3302bd926b4SAndrey Konovalov #ifdef CONFIG_KASAN_GENERIC 3312bd926b4SAndrey Konovalov 3322bd926b4SAndrey Konovalov void kasan_cache_shrink(struct kmem_cache *cache); 3332bd926b4SAndrey Konovalov void kasan_cache_shutdown(struct kmem_cache *cache); 33426e760c9SWalter Wu void kasan_record_aux_stack(void *ptr); 3352bd926b4SAndrey Konovalov 3362bd926b4SAndrey Konovalov #else /* CONFIG_KASAN_GENERIC */ 3372bd926b4SAndrey Konovalov 3382bd926b4SAndrey Konovalov static inline void kasan_cache_shrink(struct kmem_cache *cache) {} 3392bd926b4SAndrey Konovalov static inline void kasan_cache_shutdown(struct kmem_cache *cache) {} 34026e760c9SWalter Wu static inline void kasan_record_aux_stack(void *ptr) {} 3412bd926b4SAndrey Konovalov 3422bd926b4SAndrey Konovalov #endif /* CONFIG_KASAN_GENERIC */ 3432bd926b4SAndrey Konovalov 3442e903b91SAndrey Konovalov #if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) 3453c9e3aa1SAndrey Konovalov 346c0054c56SAndrey Konovalov static inline void *kasan_reset_tag(const void *addr) 347c0054c56SAndrey Konovalov { 348c0054c56SAndrey Konovalov return (void *)arch_kasan_reset_tag(addr); 349c0054c56SAndrey Konovalov } 3503c9e3aa1SAndrey Konovalov 35149c6631dSVincenzo Frascino /** 35249c6631dSVincenzo Frascino * kasan_report - print a report about a bad memory access detected by KASAN 35349c6631dSVincenzo Frascino * @addr: address of the bad access 35449c6631dSVincenzo Frascino * @size: size of the bad access 35549c6631dSVincenzo Frascino * @is_write: whether the bad access is a write or a read 35649c6631dSVincenzo Frascino * @ip: instruction pointer for the accessibility check or the bad access itself 35749c6631dSVincenzo Frascino */ 3588cceeff4SWalter Wu bool kasan_report(unsigned long addr, size_t size, 35941eea9cdSAndrey Konovalov bool is_write, unsigned long ip); 36041eea9cdSAndrey Konovalov 3612e903b91SAndrey Konovalov #else /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ 3623c9e3aa1SAndrey Konovalov 3633c9e3aa1SAndrey Konovalov static inline void *kasan_reset_tag(const void *addr) 3643c9e3aa1SAndrey Konovalov { 3653c9e3aa1SAndrey Konovalov return (void *)addr; 3663c9e3aa1SAndrey Konovalov } 3673c9e3aa1SAndrey Konovalov 3682e903b91SAndrey Konovalov #endif /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS*/ 3692e903b91SAndrey Konovalov 3702e903b91SAndrey Konovalov #ifdef CONFIG_KASAN_SW_TAGS 3712e903b91SAndrey Konovalov void __init kasan_init_sw_tags(void); 3722e903b91SAndrey Konovalov #else 3732e903b91SAndrey Konovalov static inline void kasan_init_sw_tags(void) { } 3742e903b91SAndrey Konovalov #endif 3752e903b91SAndrey Konovalov 3762e903b91SAndrey Konovalov #ifdef CONFIG_KASAN_HW_TAGS 3772e903b91SAndrey Konovalov void kasan_init_hw_tags_cpu(void); 3782e903b91SAndrey Konovalov void __init kasan_init_hw_tags(void); 3792e903b91SAndrey Konovalov #else 3802e903b91SAndrey Konovalov static inline void kasan_init_hw_tags_cpu(void) { } 3812e903b91SAndrey Konovalov static inline void kasan_init_hw_tags(void) { } 3822e903b91SAndrey Konovalov #endif 383080eb83fSAndrey Konovalov 3843c5c3cfbSDaniel Axtens #ifdef CONFIG_KASAN_VMALLOC 3853b1a4a86SAndrey Konovalov 386d98c9e83SAndrey Ryabinin int kasan_populate_vmalloc(unsigned long addr, unsigned long size); 387d98c9e83SAndrey Ryabinin void kasan_poison_vmalloc(const void *start, unsigned long size); 388d98c9e83SAndrey Ryabinin void kasan_unpoison_vmalloc(const void *start, unsigned long size); 3893c5c3cfbSDaniel Axtens void kasan_release_vmalloc(unsigned long start, unsigned long end, 3903c5c3cfbSDaniel Axtens unsigned long free_region_start, 3913c5c3cfbSDaniel Axtens unsigned long free_region_end); 3923b1a4a86SAndrey Konovalov 3933b1a4a86SAndrey Konovalov #else /* CONFIG_KASAN_VMALLOC */ 3943b1a4a86SAndrey Konovalov 395d98c9e83SAndrey Ryabinin static inline int kasan_populate_vmalloc(unsigned long start, 396d98c9e83SAndrey Ryabinin unsigned long size) 3973c5c3cfbSDaniel Axtens { 3983c5c3cfbSDaniel Axtens return 0; 3993c5c3cfbSDaniel Axtens } 4003c5c3cfbSDaniel Axtens 401d98c9e83SAndrey Ryabinin static inline void kasan_poison_vmalloc(const void *start, unsigned long size) 402d98c9e83SAndrey Ryabinin { } 403d98c9e83SAndrey Ryabinin static inline void kasan_unpoison_vmalloc(const void *start, unsigned long size) 404d98c9e83SAndrey Ryabinin { } 4053c5c3cfbSDaniel Axtens static inline void kasan_release_vmalloc(unsigned long start, 4063c5c3cfbSDaniel Axtens unsigned long end, 4073c5c3cfbSDaniel Axtens unsigned long free_region_start, 4083c5c3cfbSDaniel Axtens unsigned long free_region_end) {} 4093b1a4a86SAndrey Konovalov 4103b1a4a86SAndrey Konovalov #endif /* CONFIG_KASAN_VMALLOC */ 4113b1a4a86SAndrey Konovalov 4120fea6e9aSAndrey Konovalov #if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ 4130fea6e9aSAndrey Konovalov !defined(CONFIG_KASAN_VMALLOC) 4143b1a4a86SAndrey Konovalov 4153b1a4a86SAndrey Konovalov /* 4163b1a4a86SAndrey Konovalov * These functions provide a special case to support backing module 4173b1a4a86SAndrey Konovalov * allocations with real shadow memory. With KASAN vmalloc, the special 4183b1a4a86SAndrey Konovalov * case is unnecessary, as the work is handled in the generic case. 4193b1a4a86SAndrey Konovalov */ 4203b1a4a86SAndrey Konovalov int kasan_module_alloc(void *addr, size_t size); 4213b1a4a86SAndrey Konovalov void kasan_free_shadow(const struct vm_struct *vm); 4223b1a4a86SAndrey Konovalov 4230fea6e9aSAndrey Konovalov #else /* (CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) && !CONFIG_KASAN_VMALLOC */ 4243b1a4a86SAndrey Konovalov 4253b1a4a86SAndrey Konovalov static inline int kasan_module_alloc(void *addr, size_t size) { return 0; } 4263b1a4a86SAndrey Konovalov static inline void kasan_free_shadow(const struct vm_struct *vm) {} 4273b1a4a86SAndrey Konovalov 4280fea6e9aSAndrey Konovalov #endif /* (CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) && !CONFIG_KASAN_VMALLOC */ 4293c5c3cfbSDaniel Axtens 4302f004eeaSJann Horn #ifdef CONFIG_KASAN_INLINE 4312f004eeaSJann Horn void kasan_non_canonical_hook(unsigned long addr); 4322f004eeaSJann Horn #else /* CONFIG_KASAN_INLINE */ 4332f004eeaSJann Horn static inline void kasan_non_canonical_hook(unsigned long addr) { } 4342f004eeaSJann Horn #endif /* CONFIG_KASAN_INLINE */ 4352f004eeaSJann Horn 4360b24beccSAndrey Ryabinin #endif /* LINUX_KASAN_H */ 437