diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 945e87b0084efee808ffe605497bb3a7ab1655af..16388295696c4fcd4241f59f01735ca5396f8291 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -2900,6 +2900,16 @@ int ftrace_startup(struct ftrace_ops *ops, int command) ftrace_startup_enable(command); + /* + * If ftrace is in an undefined state, we just remove ops from list + * to prevent the NULL pointer, instead of totally rolling it back and + * free trampoline, because those actions could cause further damage. + */ + if (unlikely(ftrace_disabled)) { + __unregister_ftrace_function(ops); + return -ENODEV; + } + ops->flags &= ~FTRACE_OPS_FL_ADDING; return 0;