linux-yocto/kernel/trace
Tomas Glozar 823d798900 tracing/osnoise: Fix crash in timerlat_dump_stack()
commit 85a3bce695 upstream.

We have observed kernel panics when using timerlat with stack saving,
with the following dmesg output:

memcpy: detected buffer overflow: 88 byte write of buffer size 0
WARNING: CPU: 2 PID: 8153 at lib/string_helpers.c:1032 __fortify_report+0x55/0xa0
CPU: 2 UID: 0 PID: 8153 Comm: timerlatu/2 Kdump: loaded Not tainted 6.15.3-200.fc42.x86_64 #1 PREEMPT(lazy)
Call Trace:
 <TASK>
 ? trace_buffer_lock_reserve+0x2a/0x60
 __fortify_panic+0xd/0xf
 __timerlat_dump_stack.cold+0xd/0xd
 timerlat_dump_stack.part.0+0x47/0x80
 timerlat_fd_read+0x36d/0x390
 vfs_read+0xe2/0x390
 ? syscall_exit_to_user_mode+0x1d5/0x210
 ksys_read+0x73/0xe0
 do_syscall_64+0x7b/0x160
 ? exc_page_fault+0x7e/0x1a0
 entry_SYSCALL_64_after_hwframe+0x76/0x7e

__timerlat_dump_stack() constructs the ftrace stack entry like this:

struct stack_entry *entry;
...
memcpy(&entry->caller, fstack->calls, size);
entry->size = fstack->nr_entries;

Since commit e7186af7fb ("tracing: Add back FORTIFY_SOURCE logic to
kernel_stack event structure"), struct stack_entry marks its caller
field with __counted_by(size). At the time of the memcpy, entry->size
contains garbage from the ringbuffer, which under some circumstances is
zero, triggering a kernel panic by buffer overflow.

Populate the size field before the memcpy so that the out-of-bounds
check knows the correct size. This is analogous to
__ftrace_trace_stack().

Cc: stable@vger.kernel.org
Cc: John Kacur <jkacur@redhat.com>
Cc: Luis Goncalves <lgoncalv@redhat.com>
Cc: Attila Fazekas <afazekas@redhat.com>
Link: https://lore.kernel.org/20250716143601.7313-1-tglozar@redhat.com
Fixes: e7186af7fb ("tracing: Add back FORTIFY_SOURCE logic to kernel_stack event structure")
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-07-24 08:53:12 +02:00
..
rv
blktrace.c
bpf_trace.c bpf: Fix WARN() in get_bpf_raw_tp_regs 2025-06-19 15:28:15 +02:00
bpf_trace.h
error_report-traces.c
fgraph.c
fprobe.c
ftrace_internal.h
ftrace.c ftrace: Fix UAF when lookup kallsym after ftrace disabled 2025-06-27 11:08:49 +01:00
Kconfig
kprobe_event_gen_test.c
Makefile
pid_list.c
pid_list.h
power-traces.c
preemptirq_delay_test.c
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: probes: Fix a possible race in trace_probe_log APIs 2025-05-22 14:12:12 +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: Rename event_trigger_alloc() to trigger_data_alloc() 2025-06-19 15:28:14 +02:00
trace_events_inject.c tracing: Have format file honor EVENT_FILE_FL_FREED 2024-09-04 13:28:22 +02:00
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: tprobe-events: Fix a memory leak when tprobe with $retval 2025-03-13 12:58:23 +01: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: probes: Fix a possible race in trace_probe_log APIs 2025-05-22 14:12:12 +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: probe-events: Remove unused MAX_ARG_BUF_LEN macro 2025-03-13 12:58:29 +01: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: probes: Fix a possible race in trace_probe_log APIs 2025-05-22 14:12:12 +02:00
trace.c tracing: Fix compilation warning on arm32 2025-06-19 15:27:59 +02:00
trace.h tracing: Rename event_trigger_alloc() to trigger_data_alloc() 2025-06-19 15:28:14 +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