anolis-cloud-kernel/kernel/trace
Steven Rostedt (Google) ba47f07fbc tracing: Make sure trace_printk() can output as soon as it can be used
ANBZ: #19809

commit 3bb06eb6e9 upstream.

Currently trace_printk() can be used as soon as early_trace_init() is
called from start_kernel(). But if a crash happens, and
"ftrace_dump_on_oops" is set on the kernel command line, all you get will
be:

  [    0.456075]   <idle>-0         0dN.2. 347519us : Unknown type 6
  [    0.456075]   <idle>-0         0dN.2. 353141us : Unknown type 6
  [    0.456075]   <idle>-0         0dN.2. 358684us : Unknown type 6

This is because the trace_printk() event (type 6) hasn't been registered
yet. That gets done via an early_initcall(), which may be early, but not
early enough.

Instead of registering the trace_printk() event (and other ftrace events,
which are not trace events) via an early_initcall(), have them registered at
the same time that trace_printk() can be used. This way, if there is a
crash before early_initcall(), then the trace_printk()s will actually be
useful.

Link: https://lkml.kernel.org/r/20230104161412.019f6c55@gandalf.local.home

Cc: stable@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Fixes: e725c731e3 ("tracing: Split tracing initialization into two for early initialization")
Reported-by: "Joel Fernandes (Google)" <joel@joelfernandes.org>
Tested-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

Fixes: CVE-2023-53007
Signed-off-by: Xiao Long <xiaolong@openanolis.org>
Signed-off-by: Tianchen Ding <dtcccc@linux.alibaba.com>
Link: https://gitee.com/anolis/cloud-kernel/pulls/5002
2025-03-31 15:12:44 +08:00
..
Kconfig tracing: Build event generation tests only as modules 2024-12-20 06:33:40 +00:00
Makefile ftrace: Add recording of functions that caused recursion 2024-02-01 13:23:07 +00:00
blktrace.c blktrace: Trace remapped requests correctly 2024-08-05 02:06:43 +00:00
bpf_trace.c bpf: Send signals asynchronously if !preemptible 2025-02-28 14:00:04 +08:00
bpf_trace.h
fgraph.c ftrace/fgraph: fix increased missing-prototypes warnings 2024-02-20 06:07:35 +00:00
ftrace.c ftrace: Fix regression with module command in stack_trace_filter 2025-02-05 08:56:51 +00:00
ftrace_internal.h
kprobe_event_gen_test.c
power-traces.c
preemptirq_delay_test.c
ring_buffer.c ring-buffer: Fix a race between readers and resize checks 2025-02-05 08:55:42 +00:00
ring_buffer_benchmark.c
rpm-traces.c
synth_event_gen_test.c tracing / synthetic: Disable events after testing in synth_event_gen_test_init() 2024-08-12 06:28:58 +00:00
trace.c tracing: Make sure trace_printk() can output as soon as it can be used 2025-03-31 15:12:44 +08:00
trace.h tracing: Make sure trace_printk() can output as soon as it can be used 2025-03-31 15:12:44 +08:00
trace_benchmark.c
trace_benchmark.h
trace_boot.c tracing/boot: Fix a hist trigger dependency for boot time tracing 2021-09-22 12:28:03 +02:00
trace_branch.c tracing: Merge irqflags + preempt counter. 2022-08-02 16:36:37 +08:00
trace_clock.c tracing: Do no increment trace_clock_global() by one 2021-06-23 14:42:50 +02:00
trace_dynevent.c tracing: Free buffers when a used dynamic event is removed 2024-08-05 11:38:45 +00:00
trace_dynevent.h
trace_entries.h fgraph: Make overruns 4 bytes in graph stack structure 2024-02-01 13:23:07 +00:00
trace_event_perf.c ftrace: Have the callbacks receive a struct ftrace_regs instead of pt_regs 2024-02-01 13:23:07 +00:00
trace_events.c tracing: Have trace_event_file have ref counters 2024-08-12 06:28:58 +00:00
trace_events_filter.c tracing: Have trace_event_file have ref counters 2024-08-12 06:28:58 +00:00
trace_events_filter_test.h
trace_events_hist.c tracing/histograms: Return an error if we fail to add histogram to hist_vars list 2024-08-06 12:34:21 +00:00
trace_events_inject.c tracing: Have event inject files inc the trace array ref count 2024-08-07 09:30:34 +00:00
trace_events_synth.c tracing: Disable "other" permission bits in the tracefs files 2022-08-02 16:36:47 +08:00
trace_events_trigger.c Revert "tracing/trigger: Fix to return error if failed to alloc snapshot" 2024-08-15 02:59:27 +00:00
trace_export.c treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
trace_functions.c ftrace: Have the callbacks receive a struct ftrace_regs instead of pt_regs 2024-02-01 13:23:07 +00:00
trace_functions_graph.c fgraph: Make overruns 4 bytes in graph stack structure 2024-02-01 13:23:07 +00:00
trace_hwlat.c tracing: Quiet smp_processor_id() use in preemptable warning in hwlat 2022-08-02 16:36:50 +08:00
trace_irqsoff.c tracing: Fix memleak due to race between current_tracer and trace 2024-08-07 09:30:34 +00:00
trace_kdb.c
trace_kprobe.c tracing/kprobes: Fix the description of variable length arguments 2024-08-07 09:30:34 +00:00
trace_kprobe_selftest.c
trace_kprobe_selftest.h
trace_mmiotrace.c tracing: Merge irqflags + preempt counter. 2022-08-02 16:36:37 +08:00
trace_nop.c
trace_osnoise.c anolis: tracing/timerlat: Do not start timerlat kthread when it already started 2023-11-13 10:09:14 +08:00
trace_output.c tracing: Make sure trace_printk() can output as soon as it can be used 2025-03-31 15:12:44 +08:00
trace_output.h ftrace: Add recording of functions that caused recursion 2024-02-01 13:23:07 +00:00
trace_preemptirq.c
trace_printk.c tracing: Disable "other" permission bits in the tracefs files 2022-08-02 16:36:47 +08:00
trace_probe.c tracing: Consider the NULL character when validating the event length 2025-02-05 08:50:33 +00:00
trace_probe.h tracing/probe: trace_probe_primary_from_call(): checked list_first_entry 2024-08-06 12:34:21 +00:00
trace_probe_tmpl.h tracing/probes: Fix to update dynamic data counter if fetcharg uses it 2024-08-07 09:30:34 +00:00
trace_recursion_record.c tracing: Disable "other" permission bits in the tracefs files 2022-08-02 16:36:47 +08:00
trace_sched_switch.c
trace_sched_wakeup.c tracing: Fix memleak due to race between current_tracer and trace 2024-08-07 09:30:34 +00:00
trace_selftest.c ftrace: selftest: remove broken trace_direct_tramp 2024-03-07 07:26:03 +00:00
trace_selftest_dynamic.c
trace_seq.c
trace_stack.c ftrace: Have the callbacks receive a struct ftrace_regs instead of pt_regs 2024-02-01 13:23:07 +00:00
trace_stat.c tracing: Disable "other" permission bits in the tracefs files 2022-08-02 16:36:47 +08:00
trace_stat.h
trace_synth.h tracing: Synthetic event field_pos is an index not a boolean 2021-07-28 14:35:45 +02:00
trace_syscalls.c tracing: Merge irqflags + preempt counter. 2022-08-02 16:36:37 +08:00
trace_uprobe.c anolis: uprobe: avoid out-of-bounds memory access of fetching args. 2024-10-17 06:17:52 +00:00
tracing_map.c tracing: Fix overflow in get_free_elt() 2024-12-20 01:56:34 +00:00
tracing_map.h