linux/kernel/trace
Tze-nan Wu 788ea62499 tracing: Fix overflow in get_free_elt()
commit bcf86c01ca upstream.

"tracing_map->next_elt" in get_free_elt() is at risk of overflowing.

Once it overflows, new elements can still be inserted into the tracing_map
even though the maximum number of elements (`max_elts`) has been reached.
Continuing to insert elements after the overflow could result in the
tracing_map containing "tracing_map->max_size" elements, leaving no empty
entries.
If any attempt is made to insert an element into a full tracing_map using
`__tracing_map_insert()`, it will cause an infinite loop with preemption
disabled, leading to a CPU hang problem.

Fix this by preventing any further increments to "tracing_map->next_elt"
once it reaches "tracing_map->max_elt".

Cc: stable@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Fixes: 08d43a5fa0 ("tracing: Add lock-free tracing_map")
Co-developed-by: Cheng-Jui Wang <cheng-jui.wang@mediatek.com>
Link: https://lore.kernel.org/20240805055922.6277-1-Tze-nan.Wu@mediatek.com
Signed-off-by: Cheng-Jui Wang <cheng-jui.wang@mediatek.com>
Signed-off-by: Tze-nan Wu <Tze-nan.Wu@mediatek.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-08-14 13:52:59 +02:00
..
rv rv: Update rv_en(dis)able_monitor doc to match kernel-doc 2024-06-12 11:03:52 +02:00
blktrace.c trace/blktrace: fix memory leak with using debugfs_lookup() 2023-03-10 09:33:46 +01:00
bpf_trace.c bpf: Remove trace_printk_lock 2024-02-23 09:12:51 +01:00
bpf_trace.h
error_report-traces.c
fgraph.c arm64 fixes for 5.19-rc1: 2022-06-03 14:05:34 -07:00
fprobe.c fprobe: Fix to ensure the number of active retprobes is not zero 2023-10-25 12:03:12 +02:00
ftrace_internal.h
ftrace.c ftrace: Fix possible use-after-free issue in ftrace_location() 2024-06-12 11:02:54 +02:00
Kconfig tracing: Build event generation tests only as modules 2024-06-27 13:46:18 +02:00
kprobe_event_gen_test.c tracing: Fix wrong return in kprobe_event_gen_test.c 2023-04-06 12:10:41 +02:00
Makefile rv: Add Runtime Verification (RV) interface 2022-07-30 14:01:28 -04:00
pid_list.c trace/pid_list: Change gfp flags in pid_list_fill_irq() 2024-08-03 08:49:34 +02:00
pid_list.h
power-traces.c
preemptirq_delay_test.c tracing: Add MODULE_DESCRIPTION() to preemptirq_delay_test 2024-06-27 13:46:23 +02:00
rethook.c rethook: Use __rcu pointer for rethook::handler 2023-12-13 18:39:17 +01:00
ring_buffer_benchmark.c
ring_buffer.c ring-buffer: Fix a race between readers and resize checks 2024-06-12 11:02:56 +02:00
rpm-traces.c
synth_event_gen_test.c tracing / synthetic: Disable events after testing in synth_event_gen_test_init() 2024-01-01 12:39:07 +00:00
trace_benchmark.c tracing: Add numeric delta time to the trace event benchmark 2022-09-26 13:01:09 -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: Initialize integer variable to prevent garbage return value 2022-05-26 21:13:00 -04:00
trace_branch.c
trace_clock.c
trace_dynevent.c tracing: Free buffers when a used dynamic event is removed 2022-11-23 19:07:12 -05:00
trace_dynevent.h
trace_entries.h
trace_eprobe.c kernel/trace: Fix cleanup logic of enable_trace_eprobe 2023-07-23 13:49:24 +02:00
trace_event_perf.c tracing/perf: Fix double put of trace event when init fails 2022-08-21 15:56:07 -04:00
trace_events_filter_test.h
trace_events_filter.c tracing: Have trace_event_file have ref counters 2023-11-28 17:07:23 +00:00
trace_events_hist.c tracing: Fix uaf issue when open the hist or hist_debug file 2024-01-20 11:50:07 +01:00
trace_events_inject.c tracing: Have event inject files inc the trace array ref count 2023-09-23 11:11:11 +02:00
trace_events_synth.c tracing: Have the user copy of synthetic event address use correct context 2023-11-28 17:07:13 +00:00
trace_events_trigger.c tracing/trigger: Fix to return error if failed to alloc snapshot 2024-02-23 09:12:32 +01:00
trace_events_user.c tracing/user_events: Fix struct arg size match check 2023-07-23 13:49:47 +02:00
trace_events.c tracing: hide unused ftrace_event_id_fops 2024-04-17 11:18:26 +02:00
trace_export.c tracing: Fix TASK_COMM_LEN in trace event format file 2023-02-14 19:11:54 +01:00
trace_functions_graph.c
trace_functions.c
trace_hwlat.c tracing: Remove extra space at the end of hwlat_detector/mode 2023-09-13 09:42:57 +02:00
trace_irqsoff.c tracing: Fix memleak due to race between current_tracer and trace 2023-08-30 16:11:00 +02:00
trace_kdb.c
trace_kprobe_selftest.c
trace_kprobe_selftest.h
trace_kprobe.c tracing/kprobes: Fix symbol counting logic by looking at modules as well 2024-01-05 15:18:40 +01:00
trace_mmiotrace.c
trace_nop.c
trace_osnoise.c tracing/timerlat: Always wakeup the timerlat thread 2023-06-09 10:34:24 +02:00
trace_output.c tracing: Add size check when printing trace_marker output 2024-01-20 11:50:07 +01:00
trace_output.h
trace_preemptirq.c tracing: hold caller_addr to hardirq_{enable,disable}_ip 2022-09-06 22:26:00 -04:00
trace_printk.c
trace_probe_kernel.h tracing/probes: Fix to record 0-length data_loc in fetch_store_string*() if fails 2023-08-03 10:23:55 +02:00
trace_probe_tmpl.h tracing/probes: Fix to record 0-length data_loc in fetch_store_string*() if fails 2023-08-03 10:23:55 +02:00
trace_probe.c Revert "tracing: Add "(fault)" name injection to kernel probes" 2023-08-03 10:23:55 +02:00
trace_probe.h tracing/kprobes: Return EADDRNOTAVAIL when func matches several symbols 2023-10-25 12:03:16 +02: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 sched/tracing: Append prev_state to tp args instead 2022-05-12 00:37:11 +02:00
trace_sched_wakeup.c tracing: Fix memleak due to race between current_tracer and trace 2023-08-30 16:11:00 +02:00
trace_selftest_dynamic.c
trace_selftest.c tracing: Reset the function filter after completing trampoline/graph selftest 2022-05-25 16:57:37 -04:00
trace_seq.c
trace_stack.c
trace_stat.c
trace_stat.h
trace_synth.h tracing: Allow synthetic events to pass around stacktraces 2023-08-03 10:23:55 +02:00
trace_syscalls.c tracing: Remove unused __bad_type_size() method 2022-11-17 20:21:06 -05:00
trace_uprobe.c bpf: Clear the probe_addr for uprobe 2023-09-13 09:42:30 +02:00
trace.c tracing: Use .flush() call to wake up readers 2024-04-03 15:19:40 +02:00
trace.h tracing: Fix uaf issue when open the hist or hist_debug file 2024-01-20 11:50:07 +01:00
tracing_map.c tracing: Fix overflow in get_free_elt() 2024-08-14 13:52:59 +02:00
tracing_map.h