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
6199 6199
6200 for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) {6200 for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) {
6201 if (ops_references_rec(ops, rec)) {6201 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;
6202 cnt++;6206 cnt++;
6203 if (ops->flags & FTRACE_OPS_FL_SAVE_REGS)6207 if (ops->flags & FTRACE_OPS_FL_SAVE_REGS)
6204 rec->flags |= FTRACE_FL_REGS;6208 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;
6205 }6213 }
6206 }6214 }
6207 6215