linux-yocto/kernel/trace
Song Liu 7ea2ea68df ftrace: Fix BPF fexit with livepatch
[ Upstream commit 56b3c85e15 ]

When livepatch is attached to the same function as bpf trampoline with
a fexit program, bpf trampoline code calls register_ftrace_direct()
twice. The first time will fail with -EAGAIN, and the second time it
will succeed. This requires register_ftrace_direct() to unregister
the address on the first attempt. Otherwise, the bpf trampoline cannot
attach. Here is an easy way to reproduce this issue:

  insmod samples/livepatch/livepatch-sample.ko
  bpftrace -e 'fexit:cmdline_proc_show {}'
  ERROR: Unable to attach probe: fexit:vmlinux:cmdline_proc_show...

Fix this by cleaning up the hash when register_ftrace_function_nolock hits
errors.

Also, move the code that resets ops->func and ops->trampoline to the error
path of register_ftrace_direct(); and add a helper function reset_direct()
in register_ftrace_direct() and unregister_ftrace_direct().

Fixes: d05cb47066 ("ftrace: Fix modification of direct_function hash while in use")
Cc: stable@vger.kernel.org # v6.6+
Reported-by: Andrey Grodzovsky <andrey.grodzovsky@crowdstrike.com>
Closes: https://lore.kernel.org/live-patching/c5058315a39d4615b333e485893345be@crowdstrike.com/
Cc: Steven Rostedt (Google) <rostedt@goodmis.org>
Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Acked-and-tested-by: Andrey Grodzovsky <andrey.grodzovsky@crowdstrike.com>
Signed-off-by: Song Liu <song@kernel.org>
Reviewed-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20251027175023.1521602-2-song@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
[ moved cleanup to reset_direct() ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-12-01 11:41:53 +01:00
..
rv
blktrace.c
bpf_trace.c bpf: Remove migrate_disable in kprobe_multi_link_prog_run 2025-10-15 11:57:49 +02:00
bpf_trace.h
error_report-traces.c
fgraph.c
fprobe.c
ftrace_internal.h
ftrace.c ftrace: Fix BPF fexit with livepatch 2025-12-01 11:41:53 +01:00
Kconfig
kprobe_event_gen_test.c
Makefile
pid_list.c
pid_list.h
power-traces.c
preemptirq_delay_test.c minmax: make generic MIN() and MAX() macros available everywhere 2025-10-02 13:42:55 +02:00
rethook.c
ring_buffer_benchmark.c
ring_buffer.c ring-buffer: Fix bytes_dropped calculation issue 2025-04-10 14:37:35 +02:00
rpm-traces.c
synth_event_gen_test.c
trace_benchmark.c
trace_benchmark.h
trace_boot.c tracing: Allow creating instances with specified system events 2025-04-10 14:37:41 +02:00
trace_branch.c
trace_btf.c
trace_btf.h
trace_clock.c tracing: Use atomic64_inc_return() in trace_clock_counter() 2024-12-14 20:00:10 +01:00
trace_dynevent.c tracing: dynevent: Add a missing lockdown check on dynevent 2025-10-02 13:42:53 +02:00
trace_dynevent.h tracing: probes: Fix a possible race in trace_probe_log APIs 2025-05-22 14:12:12 +02:00
trace_entries.h
trace_eprobe.c tracing/eprobe: Fix to release eprobe when failed to add dyn_event 2024-12-14 20:00:20 +01:00
trace_event_perf.c trace/trace_event_perf: remove duplicate samples on the first tracepoint event 2024-12-09 10:32:12 +01:00
trace_events_filter_test.h
trace_events_filter.c tracing: Fix filter string testing 2025-04-25 10:45:50 +02:00
trace_events_hist.c tracing: Fix memory leaks in create_field_var() 2025-11-24 10:29:54 +01:00
trace_events_inject.c
trace_events_synth.c tracing: Do not add length to print format in synthetic events 2025-04-25 10:45:32 +02:00
trace_events_trigger.c tracing: Fix error handling in event_trigger_parse() 2025-06-19 15:28:14 +02:00
trace_events_user.c
trace_events.c tracing: Add down_write(trace_event_sem) when adding trace event 2025-07-24 08:53:12 +02:00
trace_export.c
trace_fprobe.c tracing: Fix race condition in kprobe initialization causing NULL pointer dereference 2025-10-19 16:30:58 +02:00
trace_functions_graph.c tracing: Fix use-after-free in print_graph_function_flags during tracer switching 2025-04-10 14:37:43 +02:00
trace_functions.c ftrace: Fix preemption accounting for stacktrace filter command 2025-05-22 14:12:21 +02:00
trace_hwlat.c tracing/hwlat: Fix a race during cpuhp processing 2024-10-10 11:57:59 +02:00
trace_irqsoff.c tracing: Fix use-after-free in print_graph_function_flags during tracer switching 2025-04-10 14:37:43 +02:00
trace_kdb.c
trace_kprobe_selftest.c
trace_kprobe_selftest.h
trace_kprobe.c tracing: Fix race condition in kprobe initialization causing NULL pointer dereference 2025-10-19 16:30:58 +02:00
trace_mmiotrace.c
trace_nop.c
trace_osnoise.c tracing/osnoise: Fix crash in timerlat_dump_stack() 2025-07-24 08:53:12 +02:00
trace_output.c tracing: Do not take trace_event_sem in print_event_fields() 2025-05-09 09:43:52 +02:00
trace_output.h
trace_preemptirq.c
trace_printk.c
trace_probe_kernel.h
trace_probe_tmpl.h tracing/probes: Support $argN in return probe (kprobe and fprobe) 2024-11-01 01:58:26 +01:00
trace_probe.c tracing/probes: Avoid using params uninitialized in parse_btf_arg() 2025-07-24 08:53:12 +02:00
trace_probe.h tracing: Fix race condition in kprobe initialization causing NULL pointer dereference 2025-10-19 16:30:58 +02:00
trace_recursion_record.c
trace_sched_switch.c
trace_sched_wakeup.c tracing: Fix use-after-free in print_graph_function_flags during tracer switching 2025-04-10 14:37:43 +02:00
trace_selftest_dynamic.c
trace_selftest.c
trace_seq.c tracing: Move readpos from seq_buf to trace_seq 2025-01-09 13:31:55 +01:00
trace_stack.c
trace_stat.c
trace_stat.h
trace_synth.h
trace_syscalls.c tracing/ftrace: disable preemption in syscall probe 2024-12-14 20:00:10 +01:00
trace_uprobe.c tracing: Fix race condition in kprobe initialization causing NULL pointer dereference 2025-10-19 16:30:58 +02:00
trace.c tracing: Silence warning when chunk allocation fails in trace_pid_write 2025-09-19 16:32:02 +02:00
trace.h tracing: Limit access to parser->buffer when trace_get_user failed 2025-08-28 16:28:46 +02:00
tracing_map.c tracing: Fix cmp_entries_dup() to respect sort() comparison rules 2024-12-14 19:59:52 +01:00
tracing_map.h