kernel.ftrace_enabled=0 silently disables BPF trampolines: the hook stops firing, attach reports no error, and re-enabling restores it without notice. Trampolines used to be protected by FTRACE_OPS_FL_PERMANENT on the shared direct_ops, the way livepatch is. The flag was lost when the ops were split per trampoline. Restore it on both direct_ops and the per-trampoline ops. Both are private to BPF trampolines, so no ftrace.c changes are needed. Fixes: 00963a2e75a8 ("bpf: Support bpf_trampoline on functions with IPMODIFY (e.g. livepatch)") Cc: stable@vger.kernel.org Signed-off-by: Andrey Grodzovsky Acked-by: Jiri Olsa Acked-by: Steven Rostedt --- kernel/bpf/trampoline.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index 21d460866dfe..82c91b1bf657 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -224,6 +224,8 @@ void bpf_image_ksym_del(struct bpf_ksym *ksym) */ struct ftrace_ops direct_ops = { .ops_func = bpf_tramp_ftrace_ops_func, + /* Same protection livepatch gives its own ftrace_ops. */ + .flags = FTRACE_OPS_FL_PERMANENT, }; static int direct_ops_alloc(struct bpf_trampoline *tr) @@ -303,6 +305,8 @@ static int direct_ops_alloc(struct bpf_trampoline *tr) return -ENOMEM; tr->fops->private = tr; tr->fops->ops_func = bpf_tramp_ftrace_ops_func; + /* See the direct_ops initializer above for why. */ + tr->fops->flags |= FTRACE_OPS_FL_PERMANENT; return 0; } -- 2.34.1