History

ftrace: Do not let direct or IPMODIFY ftrace_ops be added to module and set trampolines

When inserting a module, we find all ftrace_ops referencing it on the ftrace_ops_list. But FTRACE_OPS_FL_DIRECT and FTRACE_OPS_FL_IPMODIFY flags are special, and should not be set automatically. So warn and skip ftrace_ops that have these two flags set and adding new code. Also check if only one ftrace_ops references the module, in which case we can use a trampoline as an optimization. Link: https://lkml.kernel.org/r/20200728180554.65203-2-zhouchengming@bytedance.com

Chengming Zhou committed 6 years ago

Commit c5f51571 parent 8a224ff1 file · +8 −0Browse files

Unified · Split

kernel/trace/ftrace.c+8−0
@@ -6199,9 +6199,17 @@ static int referenced_filters(struct dyn_ftrace *rec) · 6198 unmodified lines
61996199
62006200 for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) {
62016201 if (ops_references_rec(ops, rec)) {
6202+ if (WARN_ON_ONCE(ops->flags & FTRACE_OPS_FL_DIRECT))
6203+ continue;
6204+ if (WARN_ON_ONCE(ops->flags & FTRACE_OPS_FL_IPMODIFY))
6205+ continue;
62026206 cnt++;
62036207 if (ops->flags & FTRACE_OPS_FL_SAVE_REGS)
62046208 rec->flags |= FTRACE_FL_REGS;
6209+ if (cnt == 1 && ops->trampoline)
6210+ rec->flags |= FTRACE_FL_TRAMP;
6211+ else
6212+ rec->flags &= ~FTRACE_FL_TRAMP;
62056213 }
62066214 }
62076215