Skip to content

Commit b83b43f

Browse files
committed
fgraph: Fix function type mismatches of ftrace_graph_return using ftrace_stub
The C compiler is allowing more checks to make sure that function pointers are assigned to the correct prototype function. Unfortunately, the function graph tracer uses a special name with its assigned ftrace_graph_return function pointer that maps to a stub function used by the function tracer (ftrace_stub). The ftrace_graph_return variable is compared to the ftrace_stub in some archs to know if the function graph tracer is enabled or not. This means we can not just simply create a new function stub that compares it without modifying all the archs. Instead, have the linker script create a function_graph_stub that maps to ftrace_stub, and this way we can define the prototype for it to match the prototype of ftrace_graph_return, and make the compiler checks all happy! Link: http://lkml.kernel.org/r/20191015090055.789a0aed@gandalf.local.home Cc: linux-sh@vger.kernel.org Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Cc: Rich Felker <dalias@libc.org> Reported-by: Sami Tolvanen <samitolvanen@google.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 953ae45 commit b83b43f

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

‎arch/sh/boot/compressed/misc.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ void __stack_chk_fail(void)
111111
error("stack-protector: Kernel stack is corrupted\n");
112112
}
113113

114+
/* Needed because vmlinux.lds.h references this */
115+
void ftrace_stub(void)
116+
{
117+
}
118+
114119
#ifdef CONFIG_SUPERH64
115120
#define stackalign 8
116121
#else

‎include/asm-generic/vmlinux.lds.h‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,29 @@
111111

112112
#ifdef CONFIG_FTRACE_MCOUNT_RECORD
113113
#ifdef CC_USING_PATCHABLE_FUNCTION_ENTRY
114+
/*
115+
* Need to also make ftrace_graph_stub point to ftrace_stub
116+
* so that the same stub location may have different protocols
117+
* and not mess up with C verifiers.
118+
*/
114119
#define MCOUNT_REC() . = ALIGN(8); \
115120
__start_mcount_loc = .; \
116121
KEEP(*(__patchable_function_entries)) \
117-
__stop_mcount_loc = .;
122+
__stop_mcount_loc = .; \
123+
ftrace_graph_stub = ftrace_stub;
118124
#else
119125
#define MCOUNT_REC() . = ALIGN(8); \
120126
__start_mcount_loc = .; \
121127
KEEP(*(__mcount_loc)) \
122-
__stop_mcount_loc = .;
128+
__stop_mcount_loc = .; \
129+
ftrace_graph_stub = ftrace_stub;
123130
#endif
124131
#else
125-
#define MCOUNT_REC()
132+
# ifdef CONFIG_FUNCTION_TRACER
133+
# define MCOUNT_REC() ftrace_graph_stub = ftrace_stub;
134+
# else
135+
# define MCOUNT_REC()
136+
# endif
126137
#endif
127138

128139
#ifdef CONFIG_TRACE_BRANCH_PROFILING

‎kernel/trace/fgraph.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,14 @@ int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
332332
return 0;
333333
}
334334

335+
/*
336+
* Simply points to ftrace_stub, but with the proper protocol.
337+
* Defined by the linker script in linux/vmlinux.lds.h
338+
*/
339+
extern void ftrace_graph_stub(struct ftrace_graph_ret *);
340+
335341
/* The callbacks that hook a function */
336-
trace_func_graph_ret_t ftrace_graph_return =
337-
(trace_func_graph_ret_t)ftrace_stub;
342+
trace_func_graph_ret_t ftrace_graph_return = ftrace_graph_stub;
338343
trace_func_graph_ent_t ftrace_graph_entry = ftrace_graph_entry_stub;
339344
static trace_func_graph_ent_t __ftrace_graph_entry = ftrace_graph_entry_stub;
340345

@@ -614,7 +619,7 @@ void unregister_ftrace_graph(struct fgraph_ops *gops)
614619
goto out;
615620

616621
ftrace_graph_active--;
617-
ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub;
622+
ftrace_graph_return = ftrace_graph_stub;
618623
ftrace_graph_entry = ftrace_graph_entry_stub;
619624
__ftrace_graph_entry = ftrace_graph_entry_stub;
620625
ftrace_shutdown(&graph_ops, FTRACE_STOP_FUNC_RET);

0 commit comments

Comments
 (0)