android_kernel_sony_sdm845/kernel/trace
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Haoran Luo 7db12bae1a tracing: Fix bug in rb_per_cpu_empty() that might cause deadloop.
commit 67f0d6d9883c13174669f88adac4f0ee656cc16a upstream.

The "rb_per_cpu_empty()" misinterpret the condition (as not-empty) when
"head_page" and "commit_page" of "struct ring_buffer_per_cpu" points to
the same buffer page, whose "buffer_data_page" is empty and "read" field
is non-zero.

An error scenario could be constructed as followed (kernel perspective):

1. All pages in the buffer has been accessed by reader(s) so that all of
them will have non-zero "read" field.

2. Read and clear all buffer pages so that "rb_num_of_entries()" will
return 0 rendering there's no more data to read. It is also required
that the "read_page", "commit_page" and "tail_page" points to the same
page, while "head_page" is the next page of them.

3. Invoke "ring_buffer_lock_reserve()" with large enough "length"
so that it shot pass the end of current tail buffer page. Now the
"head_page", "commit_page" and "tail_page" points to the same page.

4. Discard current event with "ring_buffer_discard_commit()", so that
"head_page", "commit_page" and "tail_page" points to a page whose buffer
data page is now empty.

When the error scenario has been constructed, "tracing_read_pipe" will
be trapped inside a deadloop: "trace_empty()" returns 0 since
"rb_per_cpu_empty()" returns 0 when it hits the CPU containing such
constructed ring buffer. Then "trace_find_next_entry_inc()" always
return NULL since "rb_num_of_entries()" reports there's no more entry
to read. Finally "trace_seq_to_user()" returns "-EBUSY" spanking
"tracing_read_pipe" back to the start of the "waitagain" loop.

I've also written a proof-of-concept script to construct the scenario
and trigger the bug automatically, you can use it to trace and validate
my reasoning above:

  https://github.com/aegistudio/RingBufferDetonator.git

Tests has been carried out on linux kernel 5.14-rc2
(2734d6c1b1a089fb593ef6a23d4b70903526fe0c), my fixed version
of kernel (for testing whether my update fixes the bug) and
some older kernels (for range of affected kernels). Test result is
also attached to the proof-of-concept repository.

Link: https://lore.kernel.org/linux-trace-devel/YPaNxsIlb2yjSi5Y@aegistudio/
Link: https://lore.kernel.org/linux-trace-devel/YPgrN85WL9VyrZ55@aegistudio

Cc: stable@vger.kernel.org
Fixes: bf41a158ca ("ring-buffer: make reentrant")
Suggested-by: Linus Torvalds <torvalds@linuxfoundation.org>
Signed-off-by: Haoran Luo <www@aegistudio.net>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-07-28 09:14:28 +02:00
..
blktrace.c blktrace: break out of blktrace setup on concurrent calls 2020-06-30 15:38:43 -04:00
bpf_trace.c bpf: fix check of allowed specifiers in bpf_trace_printk 2018-12-17 09:38:33 +01:00
ftrace.c ftrace: Do not blindly read the ip address in ftrace_bug() 2021-06-16 11:36:36 +02:00
Kconfig Stop the ad-hoc games with -Wno-maybe-initialized 2020-05-20 08:15:37 +02:00
Makefile Disable the __builtin_return_address() warning globally after all 2016-10-12 10:23:41 -07:00
power-traces.c
ring_buffer.c tracing: Fix bug in rb_per_cpu_empty() that might cause deadloop. 2021-07-28 09:14:28 +02:00
ring_buffer_benchmark.c
rpm-traces.c
trace.c tracing: Do not stop recording comms if the trace file is being read 2021-06-30 08:49:18 -04:00
trace.h tracing: Fix userstacktrace option for instances 2020-12-11 13:38:01 +01:00
trace_benchmark.c
trace_benchmark.h
trace_branch.c
trace_clock.c tracing: Do no increment trace_clock_global() by one 2021-06-30 08:49:17 -04:00
trace_entries.h tracing: Set kernel_stack's caller size properly 2020-10-01 20:40:05 +02:00
trace_event_perf.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2016-05-17 16:26:30 -07:00
trace_events.c tracing: Do not count ftrace events in top level enable output 2021-02-23 13:59:15 +01:00
trace_events_filter.c tracing: Fix regex_match_front() to not over compare the test string 2018-05-16 10:08:43 +02:00
trace_events_filter_test.h
trace_events_hist.c tracing: Do not reference char * as a string in histograms 2021-07-20 16:21:11 +02:00
trace_events_trigger.c tracing: Fix event trigger to accept redundant spaces 2020-06-30 15:38:45 -04:00
trace_export.c
trace_functions.c ftrace: Have set_ftrace_pid use the bitmap like events do 2016-06-20 09:54:19 -04:00
trace_functions_graph.c tracing: Fix missing return symbol in function_graph output 2018-07-11 16:26:43 +02:00
trace_hwlat.c tracing/hwlat: Honor the tracing_cpumask 2020-08-26 10:29:03 +02:00
trace_irqsoff.c
trace_kdb.c tracing: Silence GCC 9 array bounds warning 2019-07-10 09:55:28 +02:00
trace_kprobe.c tracing: Quiet gcc warning about maybe unused link variable 2018-08-03 07:55:12 +02:00
trace_mmiotrace.c tracing: Expose CPU physical addresses (resource values) for PCI devices 2016-06-20 09:54:22 -04:00
trace_nop.c
trace_output.c tracing: Add NMI tracing in hwlat detector 2016-09-02 12:47:55 -04:00
trace_output.h
trace_printk.c tracing: Handle NULL formats in hold_module_trace_bprintk_format() 2016-06-20 09:46:12 -04:00
trace_probe.c tracing: probeevent: Fix to support minus offset from symbol 2018-03-28 18:39:23 +02:00
trace_probe.h tracing: probeevent: Fix to support minus offset from symbol 2018-03-28 18:39:23 +02:00
trace_sched_switch.c
trace_sched_wakeup.c kernel/trace: Fix do not unregister tracepoints when register sched_migrate_task fail 2020-01-14 20:04:26 +01:00
trace_selftest.c ftrace: Handle tracing when switching between context 2020-11-10 10:24:02 +01:00
trace_selftest_dynamic.c
trace_seq.c
trace_stack.c tracing: Have stack tracer compile when MCOUNT_INSN_SIZE is not defined 2020-01-14 20:04:26 +01:00
trace_stat.c tracing: Fix very unlikely race of registering two stat tracers 2020-02-28 15:42:21 +01:00
trace_stat.h
trace_syscalls.c tracing/syscalls: fix multiline in error message text 2016-09-29 10:25:23 +02:00
trace_uprobe.c tracing/uprobes: Fix output for multiple string arguments 2019-02-20 10:18:32 +01:00
tracing_map.c tracing: Have the histogram compare functions convert to u64 first 2020-01-12 11:24:14 +01:00
tracing_map.h