linux/kernel/trace
Josh Poimboeuf fd593225d1 ftrace: Fix off-by-one fentry site disable in ftrace_free_mem()
commit 8b8292d648 upstream.

When a module's init text is freed, do_init_module() calls
ftrace_free_mem() with a half-open [start, end) range.  However the
ftrace_cmp_recs() comparator treats the upper bound as inclusive, as all
its other users do, passing 'ip + size - 1'.  So ftrace_free_mem() can
delete a record sitting exactly at 'end', which is outside the freed
range.

For a kernel without CFI or IBT, the first record of a function is at
the function start, which for the first function in a module is also the
base of its text allocation.  As the module allocator packs its regions,
that address is often the 'end' passed by a neighboring module's
do_init_module(), causing the first function's ftrace location to get
disabled, preventing an attempt to livepatch it:

  livepatch: failed to find location for function 'pcspkr_probe'

Convert the exclusive end to the inclusive 'end - 1' the comparator
expects, and return early for an empty range to avoid the subtraction
from underflowing when the init text size is zero.

Cc: stable@vger.kernel.org
Fixes: 42c269c88d ("ftrace: Allow for function tracing to record init functions on boot up")
Link: https://patch.msgid.link/1b5ccfa8095bdb1277f84af1c2c2e2205aca03ae.1785992188.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-08-23 14:17:16 +02:00
..
blktrace.c trace/blktrace: fix memory leak with using debugfs_lookup() 2023-03-10 09:39:47 +01:00
bpf_trace.c bpf: Fix WARN() in get_bpf_raw_tp_regs 2025-06-27 11:05:13 +01:00
bpf_trace.h bpf: Use dedicated bpf_trace_printk event instead of trace_printk() 2020-07-13 16:55:49 -07:00
error_report-traces.c tracing: add error_report_end trace point 2021-02-26 09:41:02 -08:00
fgraph.c tracing: Fix various typos in comments 2021-03-23 14:08:18 -04:00
ftrace.c ftrace: Fix off-by-one fentry site disable in ftrace_free_mem() 2026-08-23 14:17:16 +02:00
ftrace_internal.h x86/ftrace: Have ftrace trampolines turn read-only at the end of system boot up 2020-05-12 18:24:34 -04:00
Kconfig tracing: Build event generation tests only as modules 2024-07-05 09:14:29 +02:00
kprobe_event_gen_test.c tracing: Fix wrong return in kprobe_event_gen_test.c 2023-04-05 11:24:54 +02:00
Makefile tracing: Place trace_pid_list logic into abstract functions 2022-07-29 17:25:29 +02:00
pid_list.c tracing: Place trace_pid_list logic into abstract functions 2022-07-29 17:25:29 +02:00
pid_list.h tracing: Place trace_pid_list logic into abstract functions 2022-07-29 17:25:29 +02:00
power-traces.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
preemptirq_delay_test.c minmax: make generic MIN() and MAX() macros available everywhere 2025-10-19 16:21:52 +02:00
ring_buffer.c ring-buffer: Fix event length with forced 8-byte alignment 2026-07-24 15:51:44 +02:00
ring_buffer_benchmark.c sched,tracing: Convert to sched_set_fifo() 2020-07-29 11:43:53 +02:00
rpm-traces.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
synth_event_gen_test.c tracing / synthetic: Disable events after testing in synth_event_gen_test_init() 2024-01-05 15:13:35 +01:00
trace.c ring-buffer: Remove ring_buffer_read_prepare_sync() 2026-07-04 13:39:39 +02:00
trace.h tracing: Fix ftrace event field alignments 2026-02-11 13:35:33 +01:00
trace_benchmark.c tracing: Fix some typos in comments 2020-11-10 20:39:40 -05:00
trace_benchmark.h tracing: Fix SPDX format headers to use C++ style comments 2018-08-16 19:08:06 -04:00
trace_boot.c tracing: Initialize integer variable to prevent garbage return value 2022-06-09 10:23:21 +02:00
trace_branch.c tracing: branch: Fix inverted check on stat tracer registration 2026-06-01 17:35:41 +02:00
trace_clock.c tracing: Use atomic64_inc_return() in trace_clock_counter() 2024-12-14 19:51:40 +01:00
trace_dynevent.c tracing: dynevent: Add a missing lockdown check on dynevent 2025-10-02 13:39:13 +02:00
trace_dynevent.h tracing: probes: Fix a possible race in trace_probe_log APIs 2025-05-22 14:08:21 +02:00
trace_entries.h tracing: Fix ftrace event field alignments 2026-02-11 13:35:33 +01:00
trace_eprobe.c tracing/eprobe: Fix exact system name matching in eprobe_dyn_event_match() 2026-08-19 17:14:02 +02:00
trace_event_perf.c trace/trace_event_perf: remove duplicate samples on the first tracepoint event 2024-12-14 19:51:00 +01:00
trace_events.c tracing: Fix race between update_event_fields and, event_define_fields 2026-08-19 17:14:16 +02:00
trace_events_filter.c tracing/filters: Fix false positive match in regex_match_full() 2026-08-19 17:14:10 +02:00
trace_events_filter_test.h tracing: Fix SPDX format headers to use C++ style comments 2018-08-16 19:08:06 -04:00
trace_events_hist.c tracing: Avoid NULL return from hist_field_name() on truncation 2026-06-01 17:35:51 +02:00
trace_events_inject.c tracing: Have event inject files inc the trace array ref count 2023-10-06 13:18:02 +02:00
trace_events_synth.c tracing: Do not add length to print format in synthetic events 2025-10-02 13:38:59 +02:00
trace_events_trigger.c ftrace: Fix preemption accounting for stacktrace trigger command 2025-05-22 14:08:25 +02:00
trace_export.c tracing: Fix ftrace event field alignments 2026-02-11 13:35:33 +01:00
trace_functions.c ftrace: Fix preemption accounting for stacktrace filter command 2025-05-22 14:08:25 +02:00
trace_functions_graph.c tracing: Fix use-after-free in print_graph_function_flags during tracer switching 2025-04-10 14:32:06 +02:00
trace_hwlat.c tracing: Fix false sharing in hwlat get_sample() 2026-03-04 07:20:14 -05:00
trace_irqsoff.c tracing: Fix use-after-free in print_graph_function_flags during tracer switching 2025-04-10 14:32:06 +02:00
trace_kdb.c ring-buffer: Remove ring_buffer_read_prepare_sync() 2026-07-04 13:39:39 +02:00
trace_kprobe.c tracing: Fix race condition in kprobe initialization causing NULL pointer dereference 2025-10-19 16:21:51 +02:00
trace_kprobe_selftest.c selftest/ftrace: Move kprobe selftest function to separate compile unit 2018-07-30 18:41:04 -04:00
trace_kprobe_selftest.h tracing: Fix SPDX format headers to use C++ style comments 2018-08-16 19:08:06 -04:00
trace_mmiotrace.c tracing/mmiotrace: Reset dropped_count in mmio_reset_data() 2026-08-19 17:14:08 +02:00
trace_nop.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace_osnoise.c tracing: Fix potential deadlock in cpu hotplug with osnoise 2026-04-18 10:33:38 +02:00
trace_output.c tracing: Remove precision vsnprintf() check from print event 2024-10-17 15:11:48 +02:00
trace_output.h ftrace: Add recording of functions that caused recursion 2020-11-06 08:42:26 -05:00
trace_preemptirq.c tracing: hold caller_addr to hardirq_{enable,disable}_ip 2022-09-20 12:39:43 +02:00
trace_printk.c tracing: Disable "other" permission bits in the tracefs files 2021-11-18 19:16:15 +01:00
trace_probe.c tracing/probes: Prevent out-of-bounds write in __trace_probe_log_err() 2026-08-19 17:14:03 +02:00
trace_probe.h tracing: probes: fix typo in a log message 2026-07-24 15:51:41 +02:00
trace_probe_kernel.h tracing/probes: Fix to record 0-length data_loc in fetch_store_string*() if fails 2023-08-03 10:22:31 +02:00
trace_probe_tmpl.h tracing/probes: Fix to record 0-length data_loc in fetch_store_string*() if fails 2023-08-03 10:22:31 +02:00
trace_recursion_record.c tracing: Disable "other" permission bits in the tracefs files 2021-11-18 19:16:15 +01:00
trace_sched_switch.c tracing: Fix sched switch start/stop refcount racy updates 2020-01-30 09:46:10 -05:00
trace_sched_wakeup.c tracing: Fix use-after-free in print_graph_function_flags during tracer switching 2025-04-10 14:32:06 +02:00
trace_selftest.c tracing: Fix various typos in comments 2021-03-23 14:08:18 -04:00
trace_selftest_dynamic.c ftrace: Mark function tracer test functions noinline/noclone 2018-01-23 15:57:29 -05:00
trace_seq.c tracing: Fix various typos in comments 2021-03-23 14:08:18 -04:00
trace_stack.c tracing: Disable "other" permission bits in the tracefs files 2021-11-18 19:16:15 +01:00
trace_stat.c tracing: Disable "other" permission bits in the tracefs files 2021-11-18 19:16:15 +01:00
trace_stat.h tracing: Use generic type for comparator function 2019-11-14 13:15:11 -05:00
trace_synth.h tracing: Allow synthetic events to pass around stacktraces 2023-08-03 10:22:30 +02:00
trace_syscalls.c tracing: Make tp_printk work on syscall tracepoints 2022-06-14 18:36:14 +02:00
trace_uprobe.c tracing: Fix race condition in kprobe initialization causing NULL pointer dereference 2025-10-19 16:21:51 +02:00
tracing_map.c tracing: Do not call map->ops->elt_free() if elt_alloc() fails 2026-06-01 17:35:47 +02:00
tracing_map.h tracing: Fix some typos in comments 2020-11-10 20:39:40 -05:00