This fixes a long-standing issue: kernel.ftrace_enabled=0 silently disables BPF trampolines (fentry/fexit) and ftrace-based kprobes/kretprobes. The write succeeds, the hook stops firing with no error, and re-enabling silently restores it. Livepatch already solved this for itself via FTRACE_OPS_FL_PERMANENT, which refuses to disable ftrace while a permanent ops is registered and refuses to register one while ftrace is disabled[1].
For trampolines this restores a historical property: from 2019-2022 they shared one global direct_ops, marked permanent the same way[2].It was later lost as a side effect of the 2022 per-trampoline-ops split (patch 1's Fixes tag) and never restored.[3][4] Kprobes never carried this protection at all, so for them that is long-standing issue rather than a regression. Patch 1: trampolines. Patch 2: classic kprobes/kretprobes. Patch 3: a selftest covering both directions for all four hook types. P.S I initially implemented a per-record opt-in flag[5], but dropped it as over-engineering once I saw the original blanket restriction. P.P.S Open question: kprobe.multi/kretprobe.multi/kprobe.session (fprobe-backed) aren't covered -- return-capturing fprobes share the function-graph tracer's subops manager with unrelated tracers, so marking it permanent needs a different, per-record approach. Perhaps something along the lines of [5]. [1] - https://lore.kernel.org/all/[email protected]/T/#u [2] - https://lore.kernel.org/all/[email protected]/ [3] - https://lore.kernel.org/all/[email protected]/ [4] - https://lore.kernel.org/bpf/[email protected]/ [5] - https://github.com/kernel-patches/bpf/compare/bpf-next_base...andrey-grodzovsky:bpf:ftrace-permanent-per-record Andrey Grodzovsky (3): bpf: mark trampoline ftrace_ops permanent kprobes: mark ftrace-based kprobe ops permanent selftests/bpf: add ftrace_permanent test kernel/bpf/trampoline.c | 4 + kernel/kprobes.c | 5 +- .../bpf/prog_tests/ftrace_permanent.c | 144 ++++++++++++++++++ .../selftests/bpf/progs/ftrace_permanent.c | 43 ++++++ 4 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/ftrace_permanent.c create mode 100644 tools/testing/selftests/bpf/progs/ftrace_permanent.c -- 2.34.1
