Skip to content

Commit bc394fa

Browse files
Chengming Zhougregkh
authored andcommitted
ftrace: Setup correct FTRACE_FL_REGS flags for module
commit 8a224ff upstream. When module loaded and enabled, we will use __ftrace_replace_code for module if any ftrace_ops referenced it found. But we will get wrong ftrace_addr for module rec in ftrace_get_addr_new, because rec->flags has not been setup correctly. It can cause the callback function of a ftrace_ops has FTRACE_OPS_FL_SAVE_REGS to be called with pt_regs set to NULL. So setup correct FTRACE_FL_REGS flags for rec when we call referenced_filters to find ftrace_ops references it. Link: https://lkml.kernel.org/r/20200728180554.65203-1-zhouchengming@bytedance.com Cc: stable@vger.kernel.org Fixes: 8c4f3c3 ("ftrace: Check module functions being traced on reload") Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com> Signed-off-by: Muchun Song <songmuchun@bytedance.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d6cf27c commit bc394fa

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎kernel/trace/ftrace.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6187,8 +6187,11 @@ static int referenced_filters(struct dyn_ftrace *rec)
61876187
int cnt = 0;
61886188

61896189
for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) {
6190-
if (ops_references_rec(ops, rec))
6191-
cnt++;
6190+
if (ops_references_rec(ops, rec)) {
6191+
cnt++;
6192+
if (ops->flags & FTRACE_OPS_FL_SAVE_REGS)
6193+
rec->flags |= FTRACE_FL_REGS;
6194+
}
61926195
}
61936196

61946197
return cnt;
@@ -6367,8 +6370,8 @@ void ftrace_module_enable(struct module *mod)
63676370
if (ftrace_start_up)
63686371
cnt += referenced_filters(rec);
63696372

6370-
/* This clears FTRACE_FL_DISABLED */
6371-
rec->flags = cnt;
6373+
rec->flags &= ~FTRACE_FL_DISABLED;
6374+
rec->flags += cnt;
63726375

63736376
if (ftrace_start_up && cnt) {
63746377
int failed = __ftrace_replace_code(rec, 1);

0 commit comments

Comments
 (0)