Skip to content

Commit 59338f7

Browse files
committed
ftrace: Fix a slight race in modifying what function callback gets traced
There's a slight race when going from a list function to a non list function. That is, when only one callback is registered to the function tracer, it gets called directly by the mcount trampoline. But if this function has filters, it may be called by the wrong functions. As the list ops callback that handles multiple callbacks that are registered to ftrace, it also handles what functions they call. While the transaction is taking place, use the list function always, and after all the updates are finished (only the functions that should be traced are being traced), then we can update the trampoline to call the function directly. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent ccfe9e4 commit 59338f7

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

‎kernel/trace/ftrace.c‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1978,12 +1978,27 @@ int __weak ftrace_arch_code_modify_post_process(void)
19781978

19791979
void ftrace_modify_all_code(int command)
19801980
{
1981+
int update = command & FTRACE_UPDATE_TRACE_FUNC;
1982+
1983+
/*
1984+
* If the ftrace_caller calls a ftrace_ops func directly,
1985+
* we need to make sure that it only traces functions it
1986+
* expects to trace. When doing the switch of functions,
1987+
* we need to update to the ftrace_ops_list_func first
1988+
* before the transition between old and new calls are set,
1989+
* as the ftrace_ops_list_func will check the ops hashes
1990+
* to make sure the ops are having the right functions
1991+
* traced.
1992+
*/
1993+
if (update)
1994+
ftrace_update_ftrace_func(ftrace_ops_list_func);
1995+
19811996
if (command & FTRACE_UPDATE_CALLS)
19821997
ftrace_replace_code(1);
19831998
else if (command & FTRACE_DISABLE_CALLS)
19841999
ftrace_replace_code(0);
19852000

1986-
if (command & FTRACE_UPDATE_TRACE_FUNC)
2001+
if (update && ftrace_trace_function != ftrace_ops_list_func)
19872002
ftrace_update_ftrace_func(ftrace_trace_function);
19882003

19892004
if (command & FTRACE_START_FUNC_RET)

0 commit comments

Comments
 (0)