linux-stable/kernel/trace
Steven Rostedt 65a25d9f7a tracing: Add "%s" check in test_event_printk()
The test_event_printk() code makes sure that when a trace event is
registered, any dereferenced pointers in from the event's TP_printk() are
pointing to content in the ring buffer. But currently it does not handle
"%s", as there's cases where the string pointer saved in the ring buffer
points to a static string in the kernel that will never be freed. As that
is a valid case, the pointer needs to be checked at runtime.

Currently the runtime check is done via trace_check_vprintf(), but to not
have to replicate everything in vsnprintf() it does some logic with the
va_list that may not be reliable across architectures. In order to get rid
of that logic, more work in the test_event_printk() needs to be done. Some
of the strings can be validated at this time when it is obvious the string
is valid because the string will be saved in the ring buffer content.

Do all the validation of strings in the ring buffer at boot in
test_event_printk(), and make sure that the field of the strings that
point into the kernel are accessible. This will allow adding checks at
runtime that will validate the fields themselves and not rely on paring
the TP_printk() format at runtime.

Cc: stable@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/20241217024720.685917008@goodmis.org
Fixes: 5013f454a3 ("tracing: Add check of trace event print fmts for dereferencing pointers")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
2024-12-17 11:40:11 -05:00
..
rv rv: Fix a typo 2024-10-04 19:09:23 -04:00
blktrace.c blktrace: convert strncpy() to strscpy_pad() 2024-04-25 21:07:08 -07:00
bpf_trace.c bpf,perf: Fix invalid prog_array access in perf_event_detach_bpf_prog 2024-12-10 10:16:28 -08:00
bpf_trace.h tracing/treewide: Remove second parameter of __assign_str() 2024-05-22 20:14:47 -04:00
error_report-traces.c tracing: add error_report_end trace point 2021-02-26 09:41:02 -08:00
fgraph.c fgraph: Use guard(mutex)(&ftrace_lock) for unregister_ftrace_graph() 2024-10-29 07:43:02 -04:00
fprobe.c fprobe: Fix to allocate entry_data_size buffer with rethook instances 2024-03-01 09:18:24 +09:00
ftrace_internal.h function_graph: Make fgraph_update_pid_func() a stub for !DYNAMIC_FTRACE 2024-06-10 18:08:23 -04:00
ftrace.c tracing updates for v6.13: 2024-11-22 13:27:01 -08:00
Kconfig function_graph: Support recording and printing the function return address 2024-10-05 10:14:04 -04:00
kprobe_event_gen_test.c tracing: Fix wrong return in kprobe_event_gen_test.c 2023-03-19 12:20:48 -04:00
Makefile tracing/probes: Move finding func-proto API and getting func-param API to trace_btf 2023-08-23 09:39:45 +09:00
pid_list.c trace/pid_list: Change gfp flags in pid_list_fill_irq() 2024-07-15 15:07:14 -04:00
pid_list.h tracing: Create a sparse bitmask for pid filtering 2021-10-05 17:38:45 -04:00
power-traces.c
preemptirq_delay_test.c minmax: make generic MIN() and MAX() macros available everywhere 2024-07-28 15:49:18 -07:00
rethook.c rethook: honor CONFIG_FTRACE_VALIDATE_RCU_IS_WATCHING in rethook_try_get() 2024-05-01 23:18:48 +09:00
ring_buffer_benchmark.c ring-buffer: Use str_low_high() helper in ring_buffer_producer() 2024-10-19 11:12:25 -04:00
ring_buffer.c trace ring-buffer updates for v6.13 2024-11-22 13:11:17 -08:00
rpm-traces.c
synth_event_gen_test.c tracing / synthetic: Disable events after testing in synth_event_gen_test_init() 2023-12-21 10:04:45 -05:00
trace_benchmark.c tracing: Improve benchmark test performance by using do_div() 2024-05-13 20:00:57 -04:00
trace_benchmark.h tracing: Add numeric delta time to the trace event benchmark 2022-09-26 13:01:09 -04:00
trace_boot.c tracing: Allow creating instances with specified system events 2023-12-18 23:14:16 -05:00
trace_branch.c tracing: Remove TRACE_EVENT_FL_FILTERED logic 2024-10-08 15:24:49 -04:00
trace_btf.c tracing/probes: Fix to search structure fields correctly 2024-02-17 21:25:42 +09:00
trace_btf.h tracing/probes: Add a function to search a member of a struct/union 2023-08-23 09:40:16 +09:00
trace_clock.c tracing: Use atomic64_inc_return() in trace_clock_counter() 2024-10-09 19:59:49 -04:00
trace_dynevent.c tracing: Free buffers when a used dynamic event is removed 2022-11-23 19:07:12 -05:00
trace_dynevent.h tracing: Add DYNAMIC flag for dynamic events 2021-08-18 18:10:32 -04:00
trace_entries.h function_graph: Support recording and printing the function return address 2024-10-05 10:14:04 -04:00
trace_eprobe.c tracing/eprobe: Fix to release eprobe when failed to add dyn_event 2024-12-08 23:25:09 +09:00
trace_event_perf.c trace/trace_event_perf: remove duplicate samples on the first tracepoint event 2024-10-09 19:44:54 -04:00
trace_events_filter_test.h
trace_events_filter.c tracing: Replace multiple deprecated strncpy with memcpy 2024-10-30 19:41:08 -04:00
trace_events_hist.c tracing: Remove redundant check on field->field in histograms 2024-11-12 11:36:57 -05:00
trace_events_inject.c tracing: Have format file honor EVENT_FILE_FL_FREED 2024-08-07 18:12:46 -04:00
trace_events_synth.c tracing/synthetic: Fix trace_string() return value 2024-02-15 11:40:01 -05:00
trace_events_trigger.c tracing: Have format file honor EVENT_FILE_FL_FREED 2024-08-07 18:12:46 -04:00
trace_events_user.c tracepoints: Use new static branch API 2024-10-08 21:17:39 -04:00
trace_events.c tracing: Add "%s" check in test_event_printk() 2024-12-17 11:40:11 -05:00
trace_export.c tracing: Add back FORTIFY_SOURCE logic to kernel_stack event structure 2023-07-30 18:11:44 -04:00
trace_fprobe.c tracing/probes: Fix MAX_TRACE_ARGS limit handling 2024-10-23 17:24:44 +09:00
trace_functions_graph.c tracing updates for v6.13: 2024-11-22 13:27:01 -08:00
trace_functions.c ftrace: Get the true parent ip for function tracer 2024-11-18 12:02:43 -05:00
trace_hwlat.c tracing: Remove TRACE_EVENT_FL_FILTERED logic 2024-10-08 15:24:49 -04:00
trace_irqsoff.c fgraph: Simplify return address printing in function graph tracer 2024-10-10 14:06:26 -04:00
trace_kdb.c trace: kdb: Replace simple_strtoul with kstrtoul in kdb_ftdump 2024-11-02 08:33:13 +00:00
trace_kprobe_selftest.c tracing: arm64: Avoid missing-prototype warnings 2023-07-12 12:06:04 -04:00
trace_kprobe_selftest.h
trace_kprobe.c tracing/probes: Fix MAX_TRACE_ARGS limit handling 2024-10-23 17:24:44 +09:00
trace_mmiotrace.c tracing: Remove TRACE_EVENT_FL_FILTERED logic 2024-10-08 15:24:49 -04:00
trace_nop.c
trace_osnoise.c tracing: Remove TRACE_EVENT_FL_FILTERED logic 2024-10-08 15:24:49 -04:00
trace_output.c tracing: Record task flag NEED_RESCHED_LAZY. 2024-11-22 17:49:39 -05:00
trace_output.h tracing: Add "fields" option to show raw trace event fields 2023-03-29 06:52:08 -04:00
trace_preemptirq.c tracing: Fix archs that still call tracepoints without RCU watching 2024-12-05 09:28:58 -05:00
trace_printk.c tracing: Disable "other" permission bits in the tracefs files 2021-10-08 18:08:43 -04:00
trace_probe_kernel.h tracing/probes: Fix to record 0-length data_loc in fetch_store_string*() if fails 2023-07-14 17:04:58 +09:00
trace_probe_tmpl.h tracing/probes: Support $argN in return probe (kprobe and fprobe) 2024-03-07 00:27:34 +09:00
trace_probe.c tracing: Consider the NULL character when validating the event length 2024-10-23 17:24:47 +09:00
trace_probe.h tracing/probes: support '%pd' type for print struct dentry's name 2024-05-01 23:18:47 +09:00
trace_recursion_record.c tracing: Use trace_create_file() to simplify creation of tracefs entries 2022-05-26 21:12:52 -04:00
trace_sched_switch.c tracing: Replace strncpy() with strscpy() when copying comm 2024-11-01 14:37:31 -04:00
trace_sched_wakeup.c fgraph: Simplify return address printing in function graph tracer 2024-10-10 14:06:26 -04:00
trace_selftest_dynamic.c
trace_selftest.c ftrace updates for v6.13: 2024-11-20 11:34:10 -08:00
trace_seq.c trace_seq: Increase the buffer size to almost two pages 2023-12-18 23:14:16 -05:00
trace_stack.c sysctl: treewide: constify the ctl_table argument of proc_handlers 2024-07-24 20:59:29 +02:00
trace_stat.c tracing: Disable "other" permission bits in the tracefs files 2021-10-08 18:08:43 -04:00
trace_stat.h
trace_synth.h tracing: Allow synthetic events to pass around stacktraces 2023-01-25 10:31:24 -05:00
trace_syscalls.c tracing/perf: Add might_fault check to syscall probes 2024-10-09 17:09:46 -04:00
trace_uprobe.c bpf: Fix theoretical prog_array UAF in __uprobe_perf_func() 2024-12-10 13:06:51 -08:00
trace.c tracing: Record task flag NEED_RESCHED_LAZY. 2024-11-22 17:49:39 -05:00
trace.h tracing updates for v6.13: 2024-11-22 13:27:01 -08:00
tracing_map.c tracing: Fix cmp_entries_dup() to respect sort() comparison rules 2024-12-04 10:38:24 -05:00
tracing_map.h tracing: Remove unused extern declaration tracing_map_set_field_descr() 2023-07-23 11:08:14 -04:00