Skip to content

Commit 883bbbf

Browse files
author
Peter Zijlstra
committed
ftrace,kcfi: Separate ftrace_stub() and ftrace_stub_graph()
Different function signatures means they needs to be different functions; otherwise CFI gets upset. As triggered by the ftrace boot tests: [] CFI failure at ftrace_return_to_handler+0xac/0x16c (target: ftrace_stub+0x0/0x14; expected type: 0x0a5d5347) Fixes: 3c516f8 ("x86: Add support for CONFIG_CFI_CLANG") Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Tested-by: Mark Rutland <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b5f1fc3 commit 883bbbf

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

arch/arm64/kernel/entry-ftrace.S

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <linux/linkage.h>
10+
#include <linux/cfi_types.h>
1011
#include <asm/asm-offsets.h>
1112
#include <asm/assembler.h>
1213
#include <asm/ftrace.h>
@@ -294,10 +295,14 @@ SYM_FUNC_END(ftrace_graph_caller)
294295
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
295296
#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */
296297

297-
SYM_FUNC_START(ftrace_stub)
298+
SYM_TYPED_FUNC_START(ftrace_stub)
298299
ret
299300
SYM_FUNC_END(ftrace_stub)
300301

302+
SYM_TYPED_FUNC_START(ftrace_stub_graph)
303+
ret
304+
SYM_FUNC_END(ftrace_stub_graph)
305+
301306
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
302307
/*
303308
* void return_to_handler(void)

arch/x86/kernel/ftrace_64.S

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include <linux/linkage.h>
7+
#include <linux/cfi_types.h>
78
#include <asm/ptrace.h>
89
#include <asm/ftrace.h>
910
#include <asm/export.h>
@@ -129,6 +130,14 @@
129130

130131
.endm
131132

133+
SYM_TYPED_FUNC_START(ftrace_stub)
134+
RET
135+
SYM_FUNC_END(ftrace_stub)
136+
137+
SYM_TYPED_FUNC_START(ftrace_stub_graph)
138+
RET
139+
SYM_FUNC_END(ftrace_stub_graph)
140+
132141
#ifdef CONFIG_DYNAMIC_FTRACE
133142

134143
SYM_FUNC_START(__fentry__)
@@ -176,11 +185,6 @@ SYM_INNER_LABEL(ftrace_caller_end, SYM_L_GLOBAL)
176185
SYM_FUNC_END(ftrace_caller);
177186
STACK_FRAME_NON_STANDARD_FP(ftrace_caller)
178187

179-
SYM_FUNC_START(ftrace_stub)
180-
UNWIND_HINT_FUNC
181-
RET
182-
SYM_FUNC_END(ftrace_stub)
183-
184188
SYM_FUNC_START(ftrace_regs_caller)
185189
/* Save the current flags before any operations that can change them */
186190
pushfq
@@ -282,9 +286,6 @@ STACK_FRAME_NON_STANDARD_FP(ftrace_regs_caller)
282286
SYM_FUNC_START(__fentry__)
283287
cmpq $ftrace_stub, ftrace_trace_function
284288
jnz trace
285-
286-
SYM_INNER_LABEL(ftrace_stub, SYM_L_GLOBAL)
287-
ENDBR
288289
RET
289290

290291
trace:

include/asm-generic/vmlinux.lds.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,23 @@
162162
#define PATCHABLE_DISCARDS *(__patchable_function_entries)
163163
#endif
164164

165+
#ifndef CONFIG_ARCH_SUPPORTS_CFI_CLANG
166+
/*
167+
* Simply points to ftrace_stub, but with the proper protocol.
168+
* Defined by the linker script in linux/vmlinux.lds.h
169+
*/
170+
#define FTRACE_STUB_HACK ftrace_stub_graph = ftrace_stub;
171+
#else
172+
#define FTRACE_STUB_HACK
173+
#endif
174+
165175
#ifdef CONFIG_FTRACE_MCOUNT_RECORD
166176
/*
167177
* The ftrace call sites are logged to a section whose name depends on the
168178
* compiler option used. A given kernel image will only use one, AKA
169179
* FTRACE_CALLSITE_SECTION. We capture all of them here to avoid header
170180
* dependencies for FTRACE_CALLSITE_SECTION's definition.
171181
*
172-
* Need to also make ftrace_stub_graph point to ftrace_stub
173-
* so that the same stub location may have different protocols
174-
* and not mess up with C verifiers.
175-
*
176182
* ftrace_ops_list_func will be defined as arch_ftrace_ops_list_func
177183
* as some archs will have a different prototype for that function
178184
* but ftrace_ops_list_func() will have a single prototype.
@@ -182,11 +188,11 @@
182188
KEEP(*(__mcount_loc)) \
183189
KEEP_PATCHABLE \
184190
__stop_mcount_loc = .; \
185-
ftrace_stub_graph = ftrace_stub; \
191+
FTRACE_STUB_HACK \
186192
ftrace_ops_list_func = arch_ftrace_ops_list_func;
187193
#else
188194
# ifdef CONFIG_FUNCTION_TRACER
189-
# define MCOUNT_REC() ftrace_stub_graph = ftrace_stub; \
195+
# define MCOUNT_REC() FTRACE_STUB_HACK \
190196
ftrace_ops_list_func = arch_ftrace_ops_list_func;
191197
# else
192198
# define MCOUNT_REC()

0 commit comments

Comments
 (0)