Skip to content

Commit 9ea1e8d

Browse files
committed
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/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 57fbad1 commit 9ea1e8d

File tree

5 files changed

+32
-32
lines changed

5 files changed

+32
-32
lines changed

include/linux/kstack_erase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static inline void stackleak_task_init(struct task_struct *t)
8080
asmlinkage void noinstr stackleak_erase(void);
8181
asmlinkage void noinstr stackleak_erase_on_task_stack(void);
8282
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);
8484

8585
#else /* !CONFIG_KSTACK_ERASE */
8686
static inline void stackleak_task_init(struct task_struct *t) { }

kernel/kstack_erase.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ asmlinkage void noinstr stackleak_erase_off_task_stack(void)
156156
__stackleak_erase(false);
157157
}
158158

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)
160160
{
161161
unsigned long sp = current_stack_pointer;
162162

@@ -174,4 +174,4 @@ void __used __no_caller_saved_registers noinstr stackleak_track_stack(void)
174174
current->lowest_stack = sp;
175175
}
176176
}
177-
EXPORT_SYMBOL(stackleak_track_stack);
177+
EXPORT_SYMBOL(__sanitizer_cov_stack_depth);

scripts/gcc-plugins/stackleak_plugin.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* any of the gcc libraries
1010
*
1111
* 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:
1313
* - after alloca();
1414
* - for the functions with a stack frame size greater than or equal
1515
* to the "track-min-size" plugin parameter.
@@ -33,7 +33,7 @@ __visible int plugin_is_GPL_compatible;
3333

3434
static int track_frame_size = -1;
3535
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";
3737
static bool disable = false;
3838
static bool verbose = false;
3939

@@ -58,7 +58,7 @@ static void add_stack_tracking_gcall(gimple_stmt_iterator *gsi, bool after)
5858
cgraph_node_ptr node;
5959
basic_block bb;
6060

61-
/* Insert calling stackleak_track_stack() */
61+
/* Insert calling __sanitizer_cov_stack_depth() */
6262
stmt = gimple_build_call(track_function_decl, 0);
6363
gimple_call = as_a_gcall(stmt);
6464
if (after)
@@ -120,12 +120,12 @@ static void add_stack_tracking_gasm(gimple_stmt_iterator *gsi, bool after)
120120
gcc_assert(build_for_x86);
121121

122122
/*
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"
125125
* :: "r" (current_stack_pointer))
126126
* Use ASM_CALL_CONSTRAINT trick from arch/x86/include/asm/asm.h.
127127
* 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()
129129
* call is inserted after the prologue of the containing function,
130130
* when the stack frame is prepared.
131131
*/
@@ -137,7 +137,7 @@ static void add_stack_tracking_gasm(gimple_stmt_iterator *gsi, bool after)
137137
input = build_tree_list(NULL_TREE, build_const_char_string(2, "r"));
138138
input = chainon(NULL_TREE, build_tree_list(input, sp_decl));
139139
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",
141141
inputs, NULL, NULL, NULL);
142142
gimple_asm_set_volatile(asm_call, true);
143143
if (after)
@@ -151,11 +151,11 @@ static void add_stack_tracking(gimple_stmt_iterator *gsi, bool after)
151151
{
152152
/*
153153
* 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.
156156
* That improves performance: we avoid useless operations with the
157157
* 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.
159159
*/
160160
if (lookup_attribute_spec(get_identifier("no_caller_saved_registers")))
161161
add_stack_tracking_gasm(gsi, after);
@@ -165,7 +165,7 @@ static void add_stack_tracking(gimple_stmt_iterator *gsi, bool after)
165165

166166
/*
167167
* 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
169169
* of the function if it is not instrumented.
170170
*/
171171
static unsigned int stackleak_instrument_execute(void)
@@ -205,7 +205,7 @@ static unsigned int stackleak_instrument_execute(void)
205205
DECL_NAME_POINTER(current_function_decl));
206206
}
207207

208-
/* Insert stackleak_track_stack() call after alloca() */
208+
/* Insert __sanitizer_cov_stack_depth() call after alloca() */
209209
add_stack_tracking(&gsi, true);
210210
if (bb == entry_bb)
211211
prologue_instrumented = true;
@@ -241,7 +241,7 @@ static unsigned int stackleak_instrument_execute(void)
241241
return 0;
242242
}
243243

244-
/* Insert stackleak_track_stack() call at the function beginning */
244+
/* Insert __sanitizer_cov_stack_depth() call at the function beginning */
245245
bb = entry_bb;
246246
if (!single_pred_p(bb)) {
247247
/* gcc_assert(bb_loop_depth(bb) ||
@@ -270,15 +270,15 @@ static void remove_stack_tracking_gcall(void)
270270
rtx_insn *insn, *next;
271271

272272
/*
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,
274274
* which is an RTL representation of the code for a function.
275275
*
276276
* 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))
282282
*/
283283
for (insn = get_insns(); insn; insn = next) {
284284
rtx body;
@@ -318,7 +318,7 @@ static void remove_stack_tracking_gcall(void)
318318
if (SYMBOL_REF_DECL(body) != track_function_decl)
319319
continue;
320320

321-
/* Delete the stackleak_track_stack() call */
321+
/* Delete the __sanitizer_cov_stack_depth() call */
322322
delete_insn_and_edges(insn);
323323
#if BUILDING_GCC_VERSION < 8000
324324
if (GET_CODE(next) == NOTE &&
@@ -340,12 +340,12 @@ static bool remove_stack_tracking_gasm(void)
340340
gcc_assert(build_for_x86);
341341

342342
/*
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
344344
* insns, which is an RTL representation of the code for a function.
345345
*
346346
* The example of a matching insn:
347347
* (insn 11 5 12 2 (parallel [ (asm_operands/v
348-
* ("call stackleak_track_stack") ("") 0
348+
* ("call __sanitizer_cov_stack_depth") ("") 0
349349
* [ (reg/v:DI 7 sp [ current_stack_pointer ]) ]
350350
* [ (asm_input:DI ("r")) ] [])
351351
* (clobber (reg:CC 17 flags)) ]) -1 (nil))
@@ -375,7 +375,7 @@ static bool remove_stack_tracking_gasm(void)
375375
continue;
376376

377377
if (strcmp(ASM_OPERANDS_TEMPLATE(body),
378-
"call stackleak_track_stack")) {
378+
"call __sanitizer_cov_stack_depth")) {
379379
continue;
380380
}
381381

@@ -389,7 +389,7 @@ static bool remove_stack_tracking_gasm(void)
389389

390390
/*
391391
* 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
393393
* which don't call alloca() and don't have a large enough stack frame size.
394394
*/
395395
static unsigned int stackleak_cleanup_execute(void)
@@ -474,13 +474,13 @@ static bool stackleak_gate(void)
474474
return track_frame_size >= 0;
475475
}
476476

477-
/* Build the function declaration for stackleak_track_stack() */
477+
/* Build the function declaration for __sanitizer_cov_stack_depth() */
478478
static void stackleak_start_unit(void *gcc_data __unused,
479479
void *user_data __unused)
480480
{
481481
tree fntype;
482482

483-
/* void stackleak_track_stack(void) */
483+
/* void __sanitizer_cov_stack_depth(void) */
484484
fntype = build_function_type_list(void_type_node, NULL_TREE);
485485
track_function_decl = build_fn_decl(track_function, fntype);
486486
DECL_ASSEMBLER_NAME(track_function_decl); /* for LTO */

security/Kconfig.hardening

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ config KSTACK_ERASE_TRACK_MIN_SIZE
129129
help
130130
The KSTACK_ERASE option instruments the kernel code for tracking
131131
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.
134134
If unsure, leave the default value 100.
135135

136136
config KSTACK_ERASE_METRICS

tools/objtool/check.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ static const char *uaccess_safe_builtin[] = {
11931193
"__ubsan_handle_shift_out_of_bounds",
11941194
"__ubsan_handle_load_invalid_value",
11951195
/* KSTACK_ERASE */
1196-
"stackleak_track_stack",
1196+
"__sanitizer_cov_stack_depth",
11971197
/* TRACE_BRANCH_PROFILING */
11981198
"ftrace_likely_update",
11991199
/* STACKPROTECTOR */

0 commit comments

Comments
 (0)