Skip to content

Commit c5f5157

Browse files
Chengming Zhourostedt
authored andcommitted
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/[email protected] Signed-off-by: Chengming Zhou <[email protected]> Signed-off-by: Muchun Song <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 8a224ff commit c5f5157

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

kernel/trace/ftrace.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6199,9 +6199,17 @@ static int referenced_filters(struct dyn_ftrace *rec)
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

0 commit comments

Comments
 (0)