syzbot
KCSAN: data-race in rb_commit / ring_buffer_unlock_commit
Status:
moderation: reported on 2026/11/18 00:00
Subsystems:
trace
Labels:
race:benign
prio:low
[Documentation on labels]
Reported-by: syzbot+546b1edd7d20ea738510@syzkaller.appspotmail.com
First crash: 20h39m, last: 12h01m
✨ AI-generated root cause summary:
In kernel/trace/ring_buffer.c, ring_buffer_unlock_commit() runs with preemption disabled but interrupts enabled. After rb_commit() finishes and decrements cpu_buffer->committing to 0, rb_wakeups() performs an unmarked plain read of cpu_buffer->commit_page (line 4396). If a timer interrupt/softirq preempts the task on the same CPU and logs a trace event, trace_recursive_lock() permits re-entrancy for the higher context level; when the interrupt commits, its rb_commit() sees committing == 1 and invokes rb_set_commit_to_write(), updating cpu_buffer->commit_page via rb_inc_page() with an unmarked write. This causes a formal KCSAN data race between the outer task's read in rb_wakeups() and the interrupt's write in rb_set_commit_to_write() due to missing READ_ONCE()/WRITE_ONCE() annotations.
▶
▼
✨ Full AI root cause analysis
Technical Root Cause Analysis
1. Functions, Structs, and Fields Involved
- File:
kernel/trace/ring_buffer.c
- Data Structures and Fields:
struct ring_buffer_per_cpu:
commit_page: Pointer to the current committed struct buffer_page.
reader_page: Pointer to the reader's struct buffer_page.
committing: A local_t nesting counter tracking active commits on this CPU buffer.
commits: A local_t sequence counter tracking the total number of commits started.
- Key Functions:
ring_buffer_unlock_commit() (lines 4573–4590)
rb_commit() / rb_end_commit() (lines 4310–4359)
rb_wakeups() (lines 4378–4411)
rb_set_commit_to_write() (lines 4250–4308)
rb_inc_page() (lines 1467–1472)
trace_recursive_lock() / trace_recursive_unlock() (lines 4482–4514)
2. Detailed Mechanism and Trigger Sequence
-
Locking and Re-entrancy Model:
In kernel/trace/ring_buffer.c, event reservation and commit (ring_buffer_lock_reserve() and ring_buffer_unlock_commit()) operate with preemption disabled (preempt_disable_notrace()), but interrupts are deliberately kept enabled for low-overhead, lockless execution.
Recursion control is managed per-CPU by trace_recursive_lock(cpu_buffer): it assigns bit masks based on context (RB_CTX_NORMAL, RB_CTX_SOFTIRQ, RB_CTX_IRQ, RB_CTX_NMI). When an interrupt preempts process context on the same CPU, trace_recursive_lock() intentionally permits the higher interrupt context to record trace events re-entrantly.
-
Commit Flow in the Interrupted Task Context:
A task running on CPU 1 (in this report, inside skb_copy_datagram_iter() triggering trace_skb_copy_datagram_iovec) calls ring_buffer_unlock_commit():
-
Preemption by Interrupt and Intra-CPU Race:
While the task is executing rb_wakeups() (where KCSAN placed a read watchpoint on cpu_buffer->commit_page), an APIC timer interrupt occurs on CPU 1 (sysvec_apic_timer_interrupt), which invokes softirq processing (run_timer_softirq).
-
Invariant and Concurrency Violation:
cpu_buffer->commit_page is modified locklessly and re-entrantly across interrupt contexts (and observed locklessly across CPUs, as seen in ring_buffer_iter_empty()). However, unlike ring_buffer_iter_empty() which explicitly uses READ_ONCE(cpu_buffer->commit_page), rb_wakeups() uses an unmarked C read, and rb_inc_page() uses an unmarked write. Under the Linux Kernel Memory Model (LKMM), concurrent unmarked access between an interrupt handler and the interrupted context on the same CPU constitutes a data race.
Sample crash report:
* Struck through repros no longer work on HEAD.