Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #ifndef __MM_KASAN_KASAN_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #define __MM_KASAN_KASAN_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/kasan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/kasan-tags.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/kfence.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/stackdepot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #ifdef CONFIG_KASAN_HW_TAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/static_key.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "../slab.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) DECLARE_STATIC_KEY_FALSE(kasan_flag_stacktrace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) extern bool kasan_flag_async __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static inline bool kasan_stack_collection_enabled(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	return static_branch_unlikely(&kasan_flag_stacktrace);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static inline bool kasan_async_mode_enabled(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	return kasan_flag_async;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static inline bool kasan_stack_collection_enabled(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static inline bool kasan_async_mode_enabled(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) extern bool kasan_flag_panic __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) extern bool kasan_flag_async __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define KASAN_GRANULE_SIZE	(1UL << KASAN_SHADOW_SCALE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <asm/mte-kasan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define KASAN_GRANULE_SIZE	MTE_GRANULE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define KASAN_GRANULE_MASK	(KASAN_GRANULE_SIZE - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define KASAN_MEMORY_PER_SHADOW_PAGE	(KASAN_GRANULE_SIZE << PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #ifdef CONFIG_KASAN_GENERIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define KASAN_FREE_PAGE         0xFF  /* page was freed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define KASAN_PAGE_REDZONE      0xFE  /* redzone for kmalloc_large allocations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define KASAN_KMALLOC_REDZONE   0xFC  /* redzone inside slub object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define KASAN_KMALLOC_FREE      0xFB  /* object was freed (kmem_cache_free/kfree) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define KASAN_KMALLOC_FREETRACK 0xFA  /* object was freed and has free track set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define KASAN_FREE_PAGE         KASAN_TAG_INVALID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define KASAN_PAGE_REDZONE      KASAN_TAG_INVALID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define KASAN_KMALLOC_REDZONE   KASAN_TAG_INVALID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define KASAN_KMALLOC_FREE      KASAN_TAG_INVALID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define KASAN_KMALLOC_FREETRACK KASAN_TAG_INVALID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define KASAN_GLOBAL_REDZONE    0xF9  /* redzone for global variable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #define KASAN_VMALLOC_INVALID   0xF8  /* unallocated space in vmapped page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * Stack redzone shadow values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * (Those are compiler's ABI, don't change them)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #define KASAN_STACK_LEFT        0xF1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define KASAN_STACK_MID         0xF2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define KASAN_STACK_RIGHT       0xF3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #define KASAN_STACK_PARTIAL     0xF4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * alloca redzone shadow values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #define KASAN_ALLOCA_LEFT	0xCA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #define KASAN_ALLOCA_RIGHT	0xCB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) #define KASAN_ALLOCA_REDZONE_SIZE	32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  * Stack frame marker (compiler ABI).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) #define KASAN_CURRENT_STACK_FRAME_MAGIC 0x41B58AB3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) /* Don't break randconfig/all*config builds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #ifndef KASAN_ABI_VERSION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #define KASAN_ABI_VERSION 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) /* Metadata layout customization. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define META_BYTES_PER_BLOCK 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define META_BLOCKS_PER_ROW 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define META_BYTES_PER_ROW (META_BLOCKS_PER_ROW * META_BYTES_PER_BLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define META_MEM_BYTES_PER_ROW (META_BYTES_PER_ROW * KASAN_GRANULE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define META_ROWS_AROUND_ADDR 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct kasan_access_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	const void *access_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	const void *first_bad_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	size_t access_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	bool is_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	unsigned long ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* The layout of struct dictated by compiler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct kasan_source_location {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	const char *filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	int line_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	int column_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* The layout of struct dictated by compiler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct kasan_global {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	const void *beg;		/* Address of the beginning of the global variable. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	size_t size;			/* Size of the global variable. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	size_t size_with_redzone;	/* Size of the variable + size of the red zone. 32 bytes aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	const void *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	const void *module_name;	/* Name of the module where the global variable is declared. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	unsigned long has_dynamic_init;	/* This needed for C++ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #if KASAN_ABI_VERSION >= 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct kasan_source_location *location;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #if KASAN_ABI_VERSION >= 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	char *odr_indicator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * Structures to keep alloc and free tracks *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #define KASAN_STACK_DEPTH 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct kasan_track {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	u32 pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	depot_stack_handle_t stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #ifdef CONFIG_KASAN_SW_TAGS_IDENTIFY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #define KASAN_NR_FREE_STACKS 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #define KASAN_NR_FREE_STACKS 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct kasan_alloc_meta {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct kasan_track alloc_track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #ifdef CONFIG_KASAN_GENERIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	 * The auxiliary stack is stored into struct kasan_alloc_meta.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 * The free stack is stored into struct kasan_free_meta.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	depot_stack_handle_t aux_stack[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct kasan_track free_track[KASAN_NR_FREE_STACKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #ifdef CONFIG_KASAN_SW_TAGS_IDENTIFY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	u8 free_pointer_tag[KASAN_NR_FREE_STACKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	u8 free_track_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct qlist_node {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct qlist_node *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  * Generic mode either stores free meta in the object itself or in the redzone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * after the object. In the former case free meta offset is 0, in the latter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  * case it has some sane value smaller than INT_MAX. Use INT_MAX as free meta
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * offset when free meta isn't present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) #define KASAN_NO_FREE_META INT_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct kasan_free_meta {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #ifdef CONFIG_KASAN_GENERIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	/* This field is used while the object is in the quarantine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	 * Otherwise it might be used for the allocator freelist.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct qlist_node quarantine_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct kasan_track free_track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 						const void *object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #ifdef CONFIG_KASAN_GENERIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 						const void *object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static inline const void *kasan_shadow_to_mem(const void *shadow_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		<< KASAN_SHADOW_SCALE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static inline bool addr_has_metadata(const void *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	return (addr >= kasan_shadow_to_mem((void *)KASAN_SHADOW_START));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  * kasan_check_range - Check memory region, and report if invalid access.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  * @addr: the accessed address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * @size: the accessed size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  * @write: true if access is a write access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  * @ret_ip: return address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * @return: true if access was valid, false if invalid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) bool kasan_check_range(unsigned long addr, size_t size, bool write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 				unsigned long ret_ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) #else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static inline bool addr_has_metadata(const void *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	return (is_vmalloc_addr(addr) || virt_addr_valid(addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) void kasan_print_tags(u8 addr_tag, const void *addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static inline void kasan_print_tags(u8 addr_tag, const void *addr) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) void *kasan_find_first_bad_addr(void *addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) const char *kasan_get_bug_type(struct kasan_access_info *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) void kasan_metadata_fetch_row(char *buffer, void *row);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #if defined(CONFIG_KASAN_GENERIC) && defined(CONFIG_KASAN_STACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) void kasan_print_address_stack_frame(const void *addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static inline void kasan_print_address_stack_frame(const void *addr) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) bool kasan_report(unsigned long addr, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		bool is_write, unsigned long ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) void kasan_report_invalid_free(void *object, unsigned long ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct page *kasan_addr_to_page(const void *addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) depot_stack_handle_t kasan_save_stack(gfp_t flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) void kasan_set_track(struct kasan_track *track, gfp_t flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) void kasan_set_free_info(struct kmem_cache *cache, void *object, u8 tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct kasan_track *kasan_get_free_track(struct kmem_cache *cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 				void *object, u8 tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) #if defined(CONFIG_KASAN_GENERIC) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	(defined(CONFIG_SLAB) || defined(CONFIG_SLUB))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) bool kasan_quarantine_put(struct kmem_cache *cache, void *object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) void kasan_quarantine_reduce(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) void kasan_quarantine_remove_cache(struct kmem_cache *cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static inline bool kasan_quarantine_put(struct kmem_cache *cache, void *object) { return false; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static inline void kasan_quarantine_reduce(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static inline void kasan_quarantine_remove_cache(struct kmem_cache *cache) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #ifndef arch_kasan_set_tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	return addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) #ifndef arch_kasan_get_tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #define arch_kasan_get_tag(addr)	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) #define set_tag(addr, tag)	((void *)arch_kasan_set_tag((addr), (tag)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) #define get_tag(addr)		arch_kasan_get_tag(addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) #ifdef CONFIG_KASAN_HW_TAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #ifndef arch_enable_tagging_sync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) #define arch_enable_tagging_sync()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #ifndef arch_enable_tagging_async
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) #define arch_enable_tagging_async()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) #ifndef arch_set_tagging_report_once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) #define arch_set_tagging_report_once(state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) #ifndef arch_force_async_tag_fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) #define arch_force_async_tag_fault()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) #ifndef arch_get_random_tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) #define arch_get_random_tag()	(0xFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) #ifndef arch_get_mem_tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) #define arch_get_mem_tag(addr)	(0xFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #ifndef arch_set_mem_tag_range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) #define arch_set_mem_tag_range(addr, size, tag, init) ((void *)(addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) #define hw_enable_tagging_sync()		arch_enable_tagging_sync()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) #define hw_enable_tagging_async()		arch_enable_tagging_async()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) #define hw_set_tagging_report_once(state)	arch_set_tagging_report_once(state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) #define hw_force_async_tag_fault()		arch_force_async_tag_fault()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) #define hw_get_random_tag()			arch_get_random_tag()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) #define hw_get_mem_tag(addr)			arch_get_mem_tag(addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) #define hw_set_mem_tag_range(addr, size, tag, init) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			arch_set_mem_tag_range((addr), (size), (tag), (init))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) #else /* CONFIG_KASAN_HW_TAGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) #define hw_enable_tagging_sync()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) #define hw_enable_tagging_async()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) #define hw_set_tagging_report_once(state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) #endif /* CONFIG_KASAN_HW_TAGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) #if defined(CONFIG_KASAN_HW_TAGS) && IS_ENABLED(CONFIG_KASAN_KUNIT_TEST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) void kasan_set_tagging_report_once(bool state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) void kasan_enable_tagging_sync(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) void kasan_force_async_fault(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) #else /* CONFIG_KASAN_HW_TAGS || CONFIG_KASAN_KUNIT_TEST */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static inline void kasan_set_tagging_report_once(bool state) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) static inline void kasan_enable_tagging_sync(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static inline void kasan_force_async_fault(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) #endif /* CONFIG_KASAN_HW_TAGS || CONFIG_KASAN_KUNIT_TEST */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) #ifdef CONFIG_KASAN_SW_TAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) u8 kasan_random_tag(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) #elif defined(CONFIG_KASAN_HW_TAGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static inline u8 kasan_random_tag(void) { return hw_get_random_tag(); }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static inline u8 kasan_random_tag(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) #ifdef CONFIG_KASAN_HW_TAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static inline void kasan_poison(const void *addr, size_t size, u8 value, bool init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	addr = kasan_reset_tag(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	/* Skip KFENCE memory if called explicitly outside of sl*b. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	if (is_kfence_address(addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	if (WARN_ON(size & KASAN_GRANULE_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	hw_set_mem_tag_range((void *)addr, size, value, init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) static inline void kasan_unpoison(const void *addr, size_t size, bool init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	u8 tag = get_tag(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	addr = kasan_reset_tag(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	/* Skip KFENCE memory if called explicitly outside of sl*b. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	if (is_kfence_address(addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	if (WARN_ON((unsigned long)addr & KASAN_GRANULE_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	 * Explicitly initialize the memory with the precise object size to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	 * avoid overwriting the SLAB redzone. This disables initialization in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	 * the arch code and may thus lead to performance penalty. The penalty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	 * is accepted since SLAB redzones aren't enabled in production builds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	if (__slub_debug_enabled() &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	    init && ((unsigned long)size & KASAN_GRANULE_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		init = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		memzero_explicit((void *)addr, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	size = round_up(size, KASAN_GRANULE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	hw_set_mem_tag_range((void *)addr, size, tag, init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static inline bool kasan_byte_accessible(const void *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	u8 ptr_tag = get_tag(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	u8 mem_tag = hw_get_mem_tag((void *)addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	return ptr_tag == KASAN_TAG_KERNEL || ptr_tag == mem_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) #else /* CONFIG_KASAN_HW_TAGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  * kasan_poison - mark the memory range as unaccessible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)  * @addr - range start address, must be aligned to KASAN_GRANULE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)  * @size - range size, must be aligned to KASAN_GRANULE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)  * @value - value that's written to metadata for the range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)  * @init - whether to initialize the memory range (only for hardware tag-based)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)  * The size gets aligned to KASAN_GRANULE_SIZE before marking the range.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) void kasan_poison(const void *addr, size_t size, u8 value, bool init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)  * kasan_unpoison - mark the memory range as accessible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)  * @addr - range start address, must be aligned to KASAN_GRANULE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)  * @size - range size, can be unaligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)  * @init - whether to initialize the memory range (only for hardware tag-based)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)  * For the tag-based modes, the @size gets aligned to KASAN_GRANULE_SIZE before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)  * marking the range.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)  * For the generic mode, the last granule of the memory range gets partially
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)  * unpoisoned based on the @size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) void kasan_unpoison(const void *addr, size_t size, bool init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) bool kasan_byte_accessible(const void *addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) #endif /* CONFIG_KASAN_HW_TAGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) #ifdef CONFIG_KASAN_GENERIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)  * kasan_poison_last_granule - mark the last granule of the memory range as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)  * unaccessible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)  * @addr - range start address, must be aligned to KASAN_GRANULE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)  * @size - range size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)  * This function is only available for the generic mode, as it's the only mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  * that has partially poisoned memory granules.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) void kasan_poison_last_granule(const void *address, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) #else /* CONFIG_KASAN_GENERIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) static inline void kasan_poison_last_granule(const void *address, size_t size) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) #endif /* CONFIG_KASAN_GENERIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)  * Exported functions for interfaces called from assembly or from generated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)  * code. Declarations here to avoid warning about missing declarations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) asmlinkage void kasan_unpoison_task_stack_below(const void *watermark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) void __asan_register_globals(struct kasan_global *globals, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) void __asan_unregister_globals(struct kasan_global *globals, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) void __asan_handle_no_return(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) void __asan_alloca_poison(unsigned long addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) void __asan_allocas_unpoison(const void *stack_top, const void *stack_bottom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) void __asan_load1(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) void __asan_store1(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) void __asan_load2(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) void __asan_store2(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) void __asan_load4(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) void __asan_store4(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) void __asan_load8(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) void __asan_store8(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) void __asan_load16(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) void __asan_store16(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) void __asan_loadN(unsigned long addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) void __asan_storeN(unsigned long addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) void __asan_load1_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) void __asan_store1_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) void __asan_load2_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) void __asan_store2_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) void __asan_load4_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) void __asan_store4_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) void __asan_load8_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) void __asan_store8_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) void __asan_load16_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) void __asan_store16_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) void __asan_loadN_noabort(unsigned long addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) void __asan_storeN_noabort(unsigned long addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) void __asan_report_load1_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) void __asan_report_store1_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) void __asan_report_load2_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) void __asan_report_store2_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) void __asan_report_load4_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) void __asan_report_store4_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) void __asan_report_load8_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) void __asan_report_store8_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) void __asan_report_load16_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) void __asan_report_store16_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) void __asan_report_load_n_noabort(unsigned long addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) void __asan_report_store_n_noabort(unsigned long addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) void __asan_set_shadow_00(const void *addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) void __asan_set_shadow_f1(const void *addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) void __asan_set_shadow_f2(const void *addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) void __asan_set_shadow_f3(const void *addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) void __asan_set_shadow_f5(const void *addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) void __asan_set_shadow_f8(const void *addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) void __hwasan_load1_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) void __hwasan_store1_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) void __hwasan_load2_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) void __hwasan_store2_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) void __hwasan_load4_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) void __hwasan_store4_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) void __hwasan_load8_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) void __hwasan_store8_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) void __hwasan_load16_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) void __hwasan_store16_noabort(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) void __hwasan_loadN_noabort(unsigned long addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) void __hwasan_storeN_noabort(unsigned long addr, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) void __hwasan_tag_memory(unsigned long addr, u8 tag, unsigned long size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) #endif