|
| 1 | +From: Andrey Konovalov < [email protected]> |
| 2 | +Subject: kasan: clean up comments in internal kasan.h |
| 3 | + |
| 4 | +Clean up comments in mm/kasan/kasan.h: clarify, unify styles, fix |
| 5 | +punctuation, etc. |
| 6 | + |
| 7 | +Link: https://lkml.kernel.org/r/a0680ff30035b56cb7bdd5f59fd400e71712ceb5.1652111464.git.andreyknvl@google.com |
| 8 | +Signed-off-by: Andrey Konovalov < [email protected]> |
| 9 | +Reviewed-by: Alexander Potapenko < [email protected]> |
| 10 | +Cc: Marco Elver < [email protected]> |
| 11 | +Cc: Alexander Potapenko < [email protected]> |
| 12 | +Cc: Dmitry Vyukov < [email protected]> |
| 13 | +Cc: Andrey Ryabinin < [email protected]> |
| 14 | +Signed-off-by: Andrew Morton < [email protected]> |
| 15 | +--- |
| 16 | + |
| 17 | + mm/kasan/kasan.h | 74 ++++++++++++++++++++------------------------- |
| 18 | + 1 file changed, 33 insertions(+), 41 deletions(-) |
| 19 | + |
| 20 | +--- a/mm/kasan/kasan.h~kasan-clean-up-comments-in-internal-kasanh |
| 21 | ++++ a/mm/kasan/kasan.h |
| 22 | +@@ -42,6 +42,7 @@ static inline bool kasan_sync_fault_poss |
| 23 | + { |
| 24 | + return kasan_mode == KASAN_MODE_SYNC || kasan_mode == KASAN_MODE_ASYMM; |
| 25 | + } |
| 26 | ++ |
| 27 | + #else |
| 28 | + |
| 29 | + static inline bool kasan_stack_collection_enabled(void) |
| 30 | +@@ -73,47 +74,41 @@ static inline bool kasan_sync_fault_poss |
| 31 | + #define KASAN_MEMORY_PER_SHADOW_PAGE (KASAN_GRANULE_SIZE << PAGE_SHIFT) |
| 32 | + |
| 33 | + #ifdef CONFIG_KASAN_GENERIC |
| 34 | +-#define KASAN_FREE_PAGE 0xFF /* page was freed */ |
| 35 | +-#define KASAN_PAGE_REDZONE 0xFE /* redzone for kmalloc_large allocations */ |
| 36 | +-#define KASAN_KMALLOC_REDZONE 0xFC /* redzone inside slub object */ |
| 37 | +-#define KASAN_KMALLOC_FREE 0xFB /* object was freed (kmem_cache_free/kfree) */ |
| 38 | +-#define KASAN_VMALLOC_INVALID 0xF8 /* unallocated space in vmapped page */ |
| 39 | ++#define KASAN_FREE_PAGE 0xFF /* freed page */ |
| 40 | ++#define KASAN_PAGE_REDZONE 0xFE /* redzone for kmalloc_large allocation */ |
| 41 | ++#define KASAN_KMALLOC_REDZONE 0xFC /* redzone for slab object */ |
| 42 | ++#define KASAN_KMALLOC_FREE 0xFB /* freed slab object */ |
| 43 | ++#define KASAN_VMALLOC_INVALID 0xF8 /* inaccessible space in vmap area */ |
| 44 | + #else |
| 45 | + #define KASAN_FREE_PAGE KASAN_TAG_INVALID |
| 46 | + #define KASAN_PAGE_REDZONE KASAN_TAG_INVALID |
| 47 | + #define KASAN_KMALLOC_REDZONE KASAN_TAG_INVALID |
| 48 | + #define KASAN_KMALLOC_FREE KASAN_TAG_INVALID |
| 49 | +-#define KASAN_VMALLOC_INVALID KASAN_TAG_INVALID /* only for SW_TAGS */ |
| 50 | ++#define KASAN_VMALLOC_INVALID KASAN_TAG_INVALID /* only used for SW_TAGS */ |
| 51 | + #endif |
| 52 | + |
| 53 | + #ifdef CONFIG_KASAN_GENERIC |
| 54 | + |
| 55 | +-#define KASAN_KMALLOC_FREETRACK 0xFA /* object was freed and has free track set */ |
| 56 | ++#define KASAN_KMALLOC_FREETRACK 0xFA /* freed slab object with free track */ |
| 57 | + #define KASAN_GLOBAL_REDZONE 0xF9 /* redzone for global variable */ |
| 58 | + |
| 59 | +-/* |
| 60 | +- * Stack redzone shadow values |
| 61 | +- * (Those are compiler's ABI, don't change them) |
| 62 | +- */ |
| 63 | ++/* Stack redzone shadow values. Compiler ABI, do not change. */ |
| 64 | + #define KASAN_STACK_LEFT 0xF1 |
| 65 | + #define KASAN_STACK_MID 0xF2 |
| 66 | + #define KASAN_STACK_RIGHT 0xF3 |
| 67 | + #define KASAN_STACK_PARTIAL 0xF4 |
| 68 | + |
| 69 | +-/* |
| 70 | +- * alloca redzone shadow values |
| 71 | +- */ |
| 72 | ++/* alloca redzone shadow values. */ |
| 73 | + #define KASAN_ALLOCA_LEFT 0xCA |
| 74 | + #define KASAN_ALLOCA_RIGHT 0xCB |
| 75 | + |
| 76 | ++/* alloca redzone size. Compiler ABI, do not change. */ |
| 77 | + #define KASAN_ALLOCA_REDZONE_SIZE 32 |
| 78 | + |
| 79 | +-/* |
| 80 | +- * Stack frame marker (compiler ABI). |
| 81 | +- */ |
| 82 | ++/* Stack frame marker. Compiler ABI, do not change. */ |
| 83 | + #define KASAN_CURRENT_STACK_FRAME_MAGIC 0x41B58AB3 |
| 84 | + |
| 85 | +-/* Don't break randconfig/all*config builds */ |
| 86 | ++/* Dummy value to avoid breaking randconfig/all*config builds. */ |
| 87 | + #ifndef KASAN_ABI_VERSION |
| 88 | + #define KASAN_ABI_VERSION 1 |
| 89 | + #endif |
| 90 | +@@ -141,21 +136,21 @@ struct kasan_report_info { |
| 91 | + unsigned long ip; |
| 92 | + }; |
| 93 | + |
| 94 | +-/* The layout of struct dictated by compiler */ |
| 95 | ++/* Do not change the struct layout: compiler ABI. */ |
| 96 | + struct kasan_source_location { |
| 97 | + const char *filename; |
| 98 | + int line_no; |
| 99 | + int column_no; |
| 100 | + }; |
| 101 | + |
| 102 | +-/* The layout of struct dictated by compiler */ |
| 103 | ++/* Do not change the struct layout: compiler ABI. */ |
| 104 | + struct kasan_global { |
| 105 | + const void *beg; /* Address of the beginning of the global variable. */ |
| 106 | + size_t size; /* Size of the global variable. */ |
| 107 | +- size_t size_with_redzone; /* Size of the variable + size of the red zone. 32 bytes aligned */ |
| 108 | ++ size_t size_with_redzone; /* Size of the variable + size of the redzone. 32 bytes aligned. */ |
| 109 | + const void *name; |
| 110 | + const void *module_name; /* Name of the module where the global variable is declared. */ |
| 111 | +- unsigned long has_dynamic_init; /* This needed for C++ */ |
| 112 | ++ unsigned long has_dynamic_init; /* This is needed for C++. */ |
| 113 | + #if KASAN_ABI_VERSION >= 4 |
| 114 | + struct kasan_source_location *location; |
| 115 | + #endif |
| 116 | +@@ -164,9 +159,7 @@ struct kasan_global { |
| 117 | + #endif |
| 118 | + }; |
| 119 | + |
| 120 | +-/** |
| 121 | +- * Structures to keep alloc and free tracks * |
| 122 | +- */ |
| 123 | ++/* Structures for keeping alloc and free tracks. */ |
| 124 | + |
| 125 | + #define KASAN_STACK_DEPTH 64 |
| 126 | + |
| 127 | +@@ -183,11 +176,8 @@ struct kasan_track { |
| 128 | + |
| 129 | + struct kasan_alloc_meta { |
| 130 | + struct kasan_track alloc_track; |
| 131 | ++ /* Generic mode stores free track in kasan_free_meta. */ |
| 132 | + #ifdef CONFIG_KASAN_GENERIC |
| 133 | +- /* |
| 134 | +- * The auxiliary stack is stored into struct kasan_alloc_meta. |
| 135 | +- * The free stack is stored into struct kasan_free_meta. |
| 136 | +- */ |
| 137 | + depot_stack_handle_t aux_stack[2]; |
| 138 | + #else |
| 139 | + struct kasan_track free_track[KASAN_NR_FREE_STACKS]; |
| 140 | +@@ -203,18 +193,18 @@ struct qlist_node { |
| 141 | + }; |
| 142 | + |
| 143 | + /* |
| 144 | +- * Generic mode either stores free meta in the object itself or in the redzone |
| 145 | +- * after the object. In the former case free meta offset is 0, in the latter |
| 146 | +- * case it has some sane value smaller than INT_MAX. Use INT_MAX as free meta |
| 147 | +- * offset when free meta isn't present. |
| 148 | ++ * Free meta is stored either in the object itself or in the redzone after the |
| 149 | ++ * object. In the former case, free meta offset is 0. In the latter case, the |
| 150 | ++ * offset is between 0 and INT_MAX. INT_MAX marks that free meta is not present. |
| 151 | + */ |
| 152 | + #define KASAN_NO_FREE_META INT_MAX |
| 153 | + |
| 154 | ++/* |
| 155 | ++ * Free meta is only used by Generic mode while the object is in quarantine. |
| 156 | ++ * After that, slab allocator stores the freelist pointer in the object. |
| 157 | ++ */ |
| 158 | + struct kasan_free_meta { |
| 159 | + #ifdef CONFIG_KASAN_GENERIC |
| 160 | +- /* This field is used while the object is in the quarantine. |
| 161 | +- * Otherwise it might be used for the allocator freelist. |
| 162 | +- */ |
| 163 | + struct qlist_node quarantine_link; |
| 164 | + struct kasan_track free_track; |
| 165 | + #endif |
| 166 | +@@ -417,9 +407,10 @@ static inline void kasan_unpoison(const |
| 167 | + return; |
| 168 | + /* |
| 169 | + * Explicitly initialize the memory with the precise object size to |
| 170 | +- * avoid overwriting the SLAB redzone. This disables initialization in |
| 171 | +- * the arch code and may thus lead to performance penalty. The penalty |
| 172 | +- * is accepted since SLAB redzones aren't enabled in production builds. |
| 173 | ++ * avoid overwriting the slab redzone. This disables initialization in |
| 174 | ++ * the arch code and may thus lead to performance penalty. This penalty |
| 175 | ++ * does not affect production builds, as slab redzones are not enabled |
| 176 | ++ * there. |
| 177 | + */ |
| 178 | + if (__slub_debug_enabled() && |
| 179 | + init && ((unsigned long)size & KASAN_GRANULE_MASK)) { |
| 180 | +@@ -503,8 +494,9 @@ void kasan_restore_multi_shot(bool enabl |
| 181 | + |
| 182 | + /* |
| 183 | + * Exported functions for interfaces called from assembly or from generated |
| 184 | +- * code. Declarations here to avoid warning about missing declarations. |
| 185 | ++ * code. Declared here to avoid warnings about missing declarations. |
| 186 | + */ |
| 187 | ++ |
| 188 | + asmlinkage void kasan_unpoison_task_stack_below(const void *watermark); |
| 189 | + void __asan_register_globals(struct kasan_global *globals, size_t size); |
| 190 | + void __asan_unregister_globals(struct kasan_global *globals, size_t size); |
| 191 | +@@ -573,4 +565,4 @@ void __hwasan_storeN_noabort(unsigned lo |
| 192 | + |
| 193 | + void __hwasan_tag_memory(unsigned long addr, u8 tag, unsigned long size); |
| 194 | + |
| 195 | +-#endif |
| 196 | ++#endif /* __MM_KASAN_KASAN_H */ |
| 197 | +_ |
0 commit comments