mirror_ubuntu-kernels/kernel/trace
Krister Johansen c45e13621f tracing/perf: Fix double put of trace event when init fails
BugLink: https://bugs.launchpad.net/bugs/1987232

commit 7249921d94 upstream.

If in perf_trace_event_init(), the perf_trace_event_open() fails, then it
will call perf_trace_event_unreg() which will not only unregister the perf
trace event, but will also call the put() function of the tp_event.

The problem here is that the trace_event_try_get_ref() is called by the
caller of perf_trace_event_init() and if perf_trace_event_init() returns a
failure, it will then call trace_event_put(). But since the
perf_trace_event_unreg() already called the trace_event_put() function, it
triggers a WARN_ON().

 WARNING: CPU: 1 PID: 30309 at kernel/trace/trace_dynevent.c:46 trace_event_dyn_put_ref+0x15/0x20

If perf_trace_event_reg() does not call the trace_event_try_get_ref() then
the perf_trace_event_unreg() should not be calling trace_event_put(). This
breaks symmetry and causes bugs like these.

Pull out the trace_event_put() from perf_trace_event_unreg() and call it
in the locations that perf_trace_event_unreg() is called. This not only
fixes this bug, but also brings back the proper symmetry of the reg/unreg
vs get/put logic.

Link: https://lore.kernel.org/all/cover.1660347763.git.kjlx@templeofstupid.com/
Link: https://lkml.kernel.org/r/20220816192817.43d5e17f@gandalf.local.home

Cc: stable@vger.kernel.org
Fixes: 1d18538e6a ("tracing: Have dynamic events have a ref counter")
Reported-by: Krister Johansen <kjlx@templeofstupid.com>
Reviewed-by: Krister Johansen <kjlx@templeofstupid.com>
Tested-by: Krister Johansen <kjlx@templeofstupid.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

(cherry picked from commit 0d7970e8702b7d15293a844cb59ddd352c298f26 linux-5.15.y)
Signed-off-by: Krister Johansen <kjlx@templeofstupid.com>
Acked-by: Stefan Bader <stefan.bader@canonical.com>
Acked-by: Tim Gardner <tim.gardner@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2022-09-16 10:53:55 +02:00
..
blktrace.c blktrace: fix use after free for struct blk_trace 2022-03-09 15:17:52 +01:00
bpf_trace.c bpf: Add MEM_RDONLY for helper args that are pointers to rdonly mem. 2022-06-22 14:22:29 +02:00
bpf_trace.h
error_report-traces.c
fgraph.c
ftrace_internal.h
ftrace.c tracing: Place trace_pid_list logic into abstract functions 2022-09-16 10:53:32 +02:00
Kconfig
kprobe_event_gen_test.c
Makefile tracing: Place trace_pid_list logic into abstract functions 2022-09-16 10:53:32 +02:00
pid_list.c tracing: Place trace_pid_list logic into abstract functions 2022-09-16 10:53:32 +02:00
pid_list.h tracing: Place trace_pid_list logic into abstract functions 2022-09-16 10:53:32 +02:00
power-traces.c
preemptirq_delay_test.c
ring_buffer_benchmark.c
ring_buffer.c
rpm-traces.c
synth_event_gen_test.c
trace_benchmark.c
trace_benchmark.h
trace_boot.c tracing: Initialize integer variable to prevent garbage return value 2022-08-10 09:25:11 +02:00
trace_branch.c
trace_clock.c
trace_dynevent.c
trace_dynevent.h
trace_entries.h
trace_eprobe.c
trace_event_perf.c tracing/perf: Fix double put of trace event when init fails 2022-09-16 10:53:55 +02:00
trace_events_filter_test.h
trace_events_filter.c tracing: Add ustring operation to filtering string pointers 2022-03-09 15:17:45 +01:00
trace_events_hist.c tracing/histograms: Fix memory leak problem 2022-09-16 10:52:34 +02:00
trace_events_inject.c tracing: Merge irqflags + preempt counter. 2021-02-02 17:02:06 -05:00
trace_events_synth.c tracing: Do not let synth_events block other dyn_event systems during create 2022-03-09 15:17:46 +01:00
trace_events_trigger.c tracing: Have traceon and traceoff trigger honor the instance 2022-03-07 11:46:01 +01:00
trace_events.c tracing: Place trace_pid_list logic into abstract functions 2022-09-16 10:53:32 +02:00
trace_export.c
trace_functions_graph.c
trace_functions.c
trace_hwlat.c
trace_irqsoff.c
trace_kdb.c
trace_kprobe_selftest.c
trace_kprobe_selftest.h
trace_kprobe.c tracing/kprobes: Check whether get_kretprobe() returns NULL in kretprobe_dispatcher() 2022-08-26 10:53:44 +02:00
trace_mmiotrace.c
trace_nop.c
trace_osnoise.c tracing/osnoise: Force quiescent states while tracing 2022-03-23 11:49:04 +01:00
trace_output.c
trace_output.h
trace_preemptirq.c
trace_printk.c
trace_probe_tmpl.h
trace_probe.c tracing/probes: check the return value of kstrndup() for pbuf 2022-03-09 15:17:48 +01:00
trace_probe.h
trace_recursion_record.c
trace_sched_switch.c
trace_sched_wakeup.c
trace_selftest_dynamic.c
trace_selftest.c
trace_seq.c
trace_stack.c
trace_stat.c
trace_stat.h
trace_synth.h
trace_syscalls.c tracing: Make tp_printk work on syscall tracepoints 2022-08-26 10:52:52 +02:00
trace_uprobe.c tracing/uprobes: Check the return value of kstrdup() for tu->filename 2022-03-09 15:17:48 +01:00
trace.c tracing: Fix return value of trace_pid_write() 2022-09-16 10:53:32 +02:00
trace.h tracing: Place trace_pid_list logic into abstract functions 2022-09-16 10:53:32 +02:00
tracing_map.c
tracing_map.h