Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

stackleak: Rename stackleak_track_stack to __sanitizer_cov_stack_depth

The Clang stack depth tracking implementation has a fixed name for
the stack depth tracking callback, "__sanitizer_cov_stack_depth", so
rename the GCC plugin function to match since the plugin has no external
dependencies on naming.

Link: https://lore.kernel.org/r/20250717232519.2984886-2-kees@kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>

Kees Cook 9ea1e8d2 57fbad15

+32 -32
+1 -1
include/linux/kstack_erase.h
··· 80 80 asmlinkage void noinstr stackleak_erase(void); 81 81 asmlinkage void noinstr stackleak_erase_on_task_stack(void); 82 82 asmlinkage void noinstr stackleak_erase_off_task_stack(void); 83 - void __no_caller_saved_registers noinstr stackleak_track_stack(void); 83 + void __no_caller_saved_registers noinstr __sanitizer_cov_stack_depth(void); 84 84 85 85 #else /* !CONFIG_KSTACK_ERASE */ 86 86 static inline void stackleak_task_init(struct task_struct *t) { }
+2 -2
kernel/kstack_erase.c
··· 156 156 __stackleak_erase(false); 157 157 } 158 158 159 - void __used __no_caller_saved_registers noinstr stackleak_track_stack(void) 159 + void __used __no_caller_saved_registers noinstr __sanitizer_cov_stack_depth(void) 160 160 { 161 161 unsigned long sp = current_stack_pointer; 162 162 ··· 174 174 current->lowest_stack = sp; 175 175 } 176 176 } 177 - EXPORT_SYMBOL(stackleak_track_stack); 177 + EXPORT_SYMBOL(__sanitizer_cov_stack_depth);
+26 -26
scripts/gcc-plugins/stackleak_plugin.c
··· 9 9 * any of the gcc libraries 10 10 * 11 11 * This gcc plugin is needed for tracking the lowest border of the kernel stack. 12 - * It instruments the kernel code inserting stackleak_track_stack() calls: 12 + * It instruments the kernel code inserting __sanitizer_cov_stack_depth() calls: 13 13 * - after alloca(); 14 14 * - for the functions with a stack frame size greater than or equal 15 15 * to the "track-min-size" plugin parameter. ··· 33 33 34 34 static int track_frame_size = -1; 35 35 static bool build_for_x86 = false; 36 - static const char track_function[] = "stackleak_track_stack"; 36 + static const char track_function[] = "__sanitizer_cov_stack_depth"; 37 37 static bool disable = false; 38 38 static bool verbose = false; 39 39 ··· 58 58 cgraph_node_ptr node; 59 59 basic_block bb; 60 60 61 - /* Insert calling stackleak_track_stack() */ 61 + /* Insert calling __sanitizer_cov_stack_depth() */ 62 62 stmt = gimple_build_call(track_function_decl, 0); 63 63 gimple_call = as_a_gcall(stmt); 64 64 if (after) ··· 120 120 gcc_assert(build_for_x86); 121 121 122 122 /* 123 - * Insert calling stackleak_track_stack() in asm: 124 - * asm volatile("call stackleak_track_stack" 123 + * Insert calling __sanitizer_cov_stack_depth() in asm: 124 + * asm volatile("call __sanitizer_cov_stack_depth" 125 125 * :: "r" (current_stack_pointer)) 126 126 * Use ASM_CALL_CONSTRAINT trick from arch/x86/include/asm/asm.h. 127 127 * This constraint is taken into account during gcc shrink-wrapping 128 - * optimization. It is needed to be sure that stackleak_track_stack() 128 + * optimization. It is needed to be sure that __sanitizer_cov_stack_depth() 129 129 * call is inserted after the prologue of the containing function, 130 130 * when the stack frame is prepared. 131 131 */ ··· 137 137 input = build_tree_list(NULL_TREE, build_const_char_string(2, "r")); 138 138 input = chainon(NULL_TREE, build_tree_list(input, sp_decl)); 139 139 vec_safe_push(inputs, input); 140 - asm_call = gimple_build_asm_vec("call stackleak_track_stack", 140 + asm_call = gimple_build_asm_vec("call __sanitizer_cov_stack_depth", 141 141 inputs, NULL, NULL, NULL); 142 142 gimple_asm_set_volatile(asm_call, true); 143 143 if (after) ··· 151 151 { 152 152 /* 153 153 * The 'no_caller_saved_registers' attribute is used for 154 - * stackleak_track_stack(). If the compiler supports this attribute for 155 - * the target arch, we can add calling stackleak_track_stack() in asm. 154 + * __sanitizer_cov_stack_depth(). If the compiler supports this attribute for 155 + * the target arch, we can add calling __sanitizer_cov_stack_depth() in asm. 156 156 * That improves performance: we avoid useless operations with the 157 157 * caller-saved registers in the functions from which we will remove 158 - * stackleak_track_stack() call during the stackleak_cleanup pass. 158 + * __sanitizer_cov_stack_depth() call during the stackleak_cleanup pass. 159 159 */ 160 160 if (lookup_attribute_spec(get_identifier("no_caller_saved_registers"))) 161 161 add_stack_tracking_gasm(gsi, after); ··· 165 165 166 166 /* 167 167 * Work with the GIMPLE representation of the code. Insert the 168 - * stackleak_track_stack() call after alloca() and into the beginning 168 + * __sanitizer_cov_stack_depth() call after alloca() and into the beginning 169 169 * of the function if it is not instrumented. 170 170 */ 171 171 static unsigned int stackleak_instrument_execute(void) ··· 205 205 DECL_NAME_POINTER(current_function_decl)); 206 206 } 207 207 208 - /* Insert stackleak_track_stack() call after alloca() */ 208 + /* Insert __sanitizer_cov_stack_depth() call after alloca() */ 209 209 add_stack_tracking(&gsi, true); 210 210 if (bb == entry_bb) 211 211 prologue_instrumented = true; ··· 241 241 return 0; 242 242 } 243 243 244 - /* Insert stackleak_track_stack() call at the function beginning */ 244 + /* Insert __sanitizer_cov_stack_depth() call at the function beginning */ 245 245 bb = entry_bb; 246 246 if (!single_pred_p(bb)) { 247 247 /* gcc_assert(bb_loop_depth(bb) || ··· 270 270 rtx_insn *insn, *next; 271 271 272 272 /* 273 - * Find stackleak_track_stack() calls. Loop through the chain of insns, 273 + * Find __sanitizer_cov_stack_depth() calls. Loop through the chain of insns, 274 274 * which is an RTL representation of the code for a function. 275 275 * 276 276 * The example of a matching insn: 277 - * (call_insn 8 4 10 2 (call (mem (symbol_ref ("stackleak_track_stack") 278 - * [flags 0x41] <function_decl 0x7f7cd3302a80 stackleak_track_stack>) 279 - * [0 stackleak_track_stack S1 A8]) (0)) 675 {*call} (expr_list 280 - * (symbol_ref ("stackleak_track_stack") [flags 0x41] <function_decl 281 - * 0x7f7cd3302a80 stackleak_track_stack>) (expr_list (0) (nil))) (nil)) 277 + * (call_insn 8 4 10 2 (call (mem (symbol_ref ("__sanitizer_cov_stack_depth") 278 + * [flags 0x41] <function_decl 0x7f7cd3302a80 __sanitizer_cov_stack_depth>) 279 + * [0 __sanitizer_cov_stack_depth S1 A8]) (0)) 675 {*call} (expr_list 280 + * (symbol_ref ("__sanitizer_cov_stack_depth") [flags 0x41] <function_decl 281 + * 0x7f7cd3302a80 __sanitizer_cov_stack_depth>) (expr_list (0) (nil))) (nil)) 282 282 */ 283 283 for (insn = get_insns(); insn; insn = next) { 284 284 rtx body; ··· 318 318 if (SYMBOL_REF_DECL(body) != track_function_decl) 319 319 continue; 320 320 321 - /* Delete the stackleak_track_stack() call */ 321 + /* Delete the __sanitizer_cov_stack_depth() call */ 322 322 delete_insn_and_edges(insn); 323 323 #if BUILDING_GCC_VERSION < 8000 324 324 if (GET_CODE(next) == NOTE && ··· 340 340 gcc_assert(build_for_x86); 341 341 342 342 /* 343 - * Find stackleak_track_stack() asm calls. Loop through the chain of 343 + * Find __sanitizer_cov_stack_depth() asm calls. Loop through the chain of 344 344 * insns, which is an RTL representation of the code for a function. 345 345 * 346 346 * The example of a matching insn: 347 347 * (insn 11 5 12 2 (parallel [ (asm_operands/v 348 - * ("call stackleak_track_stack") ("") 0 348 + * ("call __sanitizer_cov_stack_depth") ("") 0 349 349 * [ (reg/v:DI 7 sp [ current_stack_pointer ]) ] 350 350 * [ (asm_input:DI ("r")) ] []) 351 351 * (clobber (reg:CC 17 flags)) ]) -1 (nil)) ··· 375 375 continue; 376 376 377 377 if (strcmp(ASM_OPERANDS_TEMPLATE(body), 378 - "call stackleak_track_stack")) { 378 + "call __sanitizer_cov_stack_depth")) { 379 379 continue; 380 380 } 381 381 ··· 389 389 390 390 /* 391 391 * Work with the RTL representation of the code. 392 - * Remove the unneeded stackleak_track_stack() calls from the functions 392 + * Remove the unneeded __sanitizer_cov_stack_depth() calls from the functions 393 393 * which don't call alloca() and don't have a large enough stack frame size. 394 394 */ 395 395 static unsigned int stackleak_cleanup_execute(void) ··· 474 474 return track_frame_size >= 0; 475 475 } 476 476 477 - /* Build the function declaration for stackleak_track_stack() */ 477 + /* Build the function declaration for __sanitizer_cov_stack_depth() */ 478 478 static void stackleak_start_unit(void *gcc_data __unused, 479 479 void *user_data __unused) 480 480 { 481 481 tree fntype; 482 482 483 - /* void stackleak_track_stack(void) */ 483 + /* void __sanitizer_cov_stack_depth(void) */ 484 484 fntype = build_function_type_list(void_type_node, NULL_TREE); 485 485 track_function_decl = build_fn_decl(track_function, fntype); 486 486 DECL_ASSEMBLER_NAME(track_function_decl); /* for LTO */
+2 -2
security/Kconfig.hardening
··· 129 129 help 130 130 The KSTACK_ERASE option instruments the kernel code for tracking 131 131 the lowest border of the kernel stack (and for some other purposes). 132 - It inserts the stackleak_track_stack() call for the functions with 133 - a stack frame size greater than or equal to this parameter. 132 + It inserts the __sanitizer_cov_stack_depth() call for the functions 133 + with a stack frame size greater than or equal to this parameter. 134 134 If unsure, leave the default value 100. 135 135 136 136 config KSTACK_ERASE_METRICS
+1 -1
tools/objtool/check.c
··· 1193 1193 "__ubsan_handle_shift_out_of_bounds", 1194 1194 "__ubsan_handle_load_invalid_value", 1195 1195 /* KSTACK_ERASE */ 1196 - "stackleak_track_stack", 1196 + "__sanitizer_cov_stack_depth", 1197 1197 /* TRACE_BRANCH_PROFILING */ 1198 1198 "ftrace_likely_update", 1199 1199 /* STACKPROTECTOR */