twx-linux/kernel/trace
Jeongjun Park 056ebbddb8 tracing: Fix oob write in trace_seq_to_buffer()
commit f5178c41bb43444a6008150fe6094497135d07cb upstream.

syzbot reported this bug:
==================================================================
BUG: KASAN: slab-out-of-bounds in trace_seq_to_buffer kernel/trace/trace.c:1830 [inline]
BUG: KASAN: slab-out-of-bounds in tracing_splice_read_pipe+0x6be/0xdd0 kernel/trace/trace.c:6822
Write of size 4507 at addr ffff888032b6b000 by task syz.2.320/7260

CPU: 1 UID: 0 PID: 7260 Comm: syz.2.320 Not tainted 6.15.0-rc1-syzkaller-00301-g3bde70a2c827 #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 02/12/2025
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:120
 print_address_description mm/kasan/report.c:408 [inline]
 print_report+0xc3/0x670 mm/kasan/report.c:521
 kasan_report+0xe0/0x110 mm/kasan/report.c:634
 check_region_inline mm/kasan/generic.c:183 [inline]
 kasan_check_range+0xef/0x1a0 mm/kasan/generic.c:189
 __asan_memcpy+0x3c/0x60 mm/kasan/shadow.c:106
 trace_seq_to_buffer kernel/trace/trace.c:1830 [inline]
 tracing_splice_read_pipe+0x6be/0xdd0 kernel/trace/trace.c:6822
 ....
==================================================================

It has been reported that trace_seq_to_buffer() tries to copy more data
than PAGE_SIZE to buf. Therefore, to prevent this, we should use the
smaller of trace_seq_used(&iter->seq) and PAGE_SIZE as an argument.

Link: https://lore.kernel.org/20250422113026.13308-1-aha310510@gmail.com
Reported-by: syzbot+c8cd2d2c412b868263fb@syzkaller.appspotmail.com
Fixes: 3c56819b14b0 ("tracing: splice support for tracing_pipe")
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-05-09 09:43:53 +02:00
..
rv rv: Update rv_en(dis)able_monitor doc to match kernel-doc 2024-06-12 11:12:49 +02:00
blktrace.c
bpf_trace.c bpf: Fix deadlock between rcu_tasks_trace and event_mutex. 2025-05-02 07:50:52 +02:00
bpf_trace.h
error_report-traces.c
fgraph.c
fprobe.c
ftrace_internal.h
ftrace.c ftrace: fix incorrect hash size in register_ftrace_direct() 2025-04-25 10:45:47 +02:00
Kconfig tracing: Build event generation tests only as modules 2024-06-27 13:49:05 +02:00
kprobe_event_gen_test.c
Makefile
pid_list.c trace/pid_list: Change gfp flags in pid_list_fill_irq() 2024-08-03 08:54:17 +02:00
pid_list.h
power-traces.c
preemptirq_delay_test.c tracing: Add MODULE_DESCRIPTION() to preemptirq_delay_test 2024-06-27 13:49:14 +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 tracing/probes: Fix to search structure fields correctly 2024-02-23 09:25:05 +01:00
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
trace_dynevent.h
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: Correct the refcount if the hist/hist_debug file fails to open 2025-04-10 14:37:41 +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: Have format file honor EVENT_FILE_FL_FREED 2024-09-04 13:28:22 +02:00
trace_events_user.c tracing/user_events: Fix non-spaced field matching 2024-06-12 11:12:11 +02:00
trace_events.c tracing: Verify event formats that have "%*p.." 2025-05-02 07:50:37 +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: Correct preemption accounting for function tracing. 2025-02-27 04:10:53 -08: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/kprobe: Make trace_kprobe's module callback called after jump_label update 2025-01-02 10:32:03 +01:00
trace_mmiotrace.c
trace_nop.c
trace_osnoise.c tracing/osnoise: Fix possible recursive locking for cpus_read_lock() 2025-04-10 14:37:43 +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: probe-events: Add comments about entry data storing code 2025-04-25 10:45:20 +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 bpf: Fix theoretical prog_array UAF in __uprobe_perf_func() 2024-12-19 18:11:25 +01:00
trace.c tracing: Fix oob write in trace_seq_to_buffer() 2025-05-09 09:43:53 +02:00
trace.h tracing: Allow creating instances with specified system events 2025-04-10 14:37:41 +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