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: 19h58m, last: 11h20m
✨ AI cause bisection: candidate commits (most relevant first) (AI job):
  1e0d6714aceb ring-buffer: Do not wake up a splice waiter when page is not full
  03329f993978 tracing: Add tracefs file buffer_percentage
  
✨ 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
Based on kernel commit 666539eecdf4:

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

  1. 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.

  2. 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():

    • Line 4580: rb_commit(cpu_buffer) invokes rb_end_commit(cpu_buffer).
    • In rb_end_commit(), the task checks local_read(&cpu_buffer->committing) == 1, completes its commit to write, and executes local_dec(&cpu_buffer->committing).
    • At this point, cpu_buffer->committing reaches 0.
    • Line 4582: The task proceeds to call rb_wakeups(buffer, cpu_buffer).
    • Line 4396: Inside rb_wakeups(), the code evaluates:
      if (cpu_buffer->reader_page == cpu_buffer->commit_page)
          return;
      
      This check performs an unmarked plain load of cpu_buffer->commit_page.
  3. 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).

    • The softirq triggers an event with tracing enabled (addrconf_rs_timer -> ... -> kfree -> trace_kfree).
    • trace_recursive_lock() allows this softirq event to proceed.
    • During ring_buffer_unlock_commit(), the interrupt context calls rb_commit(cpu_buffer) -> rb_end_commit(cpu_buffer).
    • Because cpu_buffer->committing was 0 when the interrupt arrived, rb_start_commit() incremented it to 1. In rb_end_commit(), local_read(&cpu_buffer->committing) == 1 is true for this new outer context.
    • The interrupt executes rb_set_commit_to_write(cpu_buffer).
    • Line 4278: In rb_set_commit_to_write(), moving the commit pointer over a page boundary calls rb_inc_page(&cpu_buffer->commit_page):
      *bpage = list_entry(p, struct buffer_page, list);
      
      This performs an unmarked plain write to cpu_buffer->commit_page.
  4. 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.

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
fe0e8afd bisect-cause ❓ KCSAN: data-race in rb_commit / ring_buffer_unlock_commit 2026/11/17 23:07 2026/11/17 23:07 2026/11/17 23:51 ca622473
58b60fb7 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in rb_commit / ring_buffer_unlock_commit 2026/11/17 23:06 2026/11/17 23:06 2026/11/17 23:13 ca622473
39b0edc5 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in rb_commit / ring_buffer_unlock_commit 2026/11/17 23:04 2026/11/17 23:04 2026/11/17 23:15 ca622473

Sample crash report:
==================================================================
BUG: KCSAN: data-race in rb_commit / ring_buffer_unlock_commit

read-write to 0xffff888100079060 of 8 bytes by interrupt on cpu 1:
 rb_inc_page kernel/trace/ring_buffer.c:1471 [inline]
 rb_set_commit_to_write kernel/trace/ring_buffer.c:4278 [inline]
 rb_end_commit kernel/trace/ring_buffer.c:4323 [inline]
 rb_commit+0x1d6/0x520 kernel/trace/ring_buffer.c:4358
 ring_buffer_unlock_commit+0x42/0x3b0 kernel/trace/ring_buffer.c:4580
 __buffer_unlock_commit kernel/trace/trace.h:1695 [inline]
 trace_buffer_unlock_commit_regs+0x43/0x310 kernel/trace/trace.c:2060
 trace_event_buffer_commit+0x149/0x5b0 kernel/trace/trace.c:2035
 do_trace_event_raw_event_kfree include/trace/events/kmem.h:97 [inline]
 trace_event_raw_event_kfree+0x94/0xf0 include/trace/events/kmem.h:97
 __do_trace_kfree include/trace/events/kmem.h:97 [inline]
 trace_kfree include/trace/events/kmem.h:97 [inline]
 kfree+0x351/0x3b0 mm/slub.c:6909
 skb_kfree_head net/core/skbuff.c:1085 [inline]
 skb_free_head net/core/skbuff.c:1097 [inline]
 skb_release_data+0x49c/0x560 net/core/skbuff.c:1125
 skb_release_all net/core/skbuff.c:1189 [inline]
 __kfree_skb+0x44/0x180 net/core/skbuff.c:1203
 sk_skb_reason_drop+0xd6/0x270 net/core/skbuff.c:1242
 kfree_skb_reason include/linux/skbuff.h:1329 [inline]
 kfree_skb include/linux/skbuff.h:1338 [inline]
 ip_tunnel_xmit+0x12ec/0x13a0 net/ipv4/ip_tunnel.c:-1
 __gre_xmit+0xf1/0x110 net/ipv4/ip_gre.c:488
 erspan_xmit+0x6c8/0xbe0 net/ipv4/ip_gre.c:752
 __netdev_start_xmit include/linux/netdevice.h:5457 [inline]
 netdev_start_xmit include/linux/netdevice.h:5466 [inline]
 xmit_one net/core/dev.c:4068 [inline]
 dev_hard_start_xmit+0x107/0x3d0 net/core/dev.c:4084
 sch_direct_xmit+0x1c4/0x360 net/sched/sch_generic.c:411
 __dev_xmit_skb net/core/dev.c:4419 [inline]
 __dev_queue_xmit+0xe7d/0x2020 net/core/dev.c:5058
 dev_queue_xmit include/linux/netdevice.h:3485 [inline]
 neigh_resolve_output+0x3fb/0x470 net/core/neighbour.c:1634
 neigh_output include/net/neighbour.h:554 [inline]
 ip6_finish_output2+0x9a1/0xe80 net/ipv6/ip6_output.c:138
 __ip6_finish_output net/ipv6/ip6_output.c:-1 [inline]
 ip6_finish_output+0x1e1/0x410 net/ipv6/ip6_output.c:221
 NF_HOOK_COND include/linux/netfilter.h:314 [inline]
 ip6_output+0x10a/0x280 net/ipv6/ip6_output.c:248
 dst_output include/net/dst.h:472 [inline]
 NF_HOOK include/linux/netfilter.h:325 [inline]
 ndisc_send_skb+0x510/0x7e0 net/ipv6/ndisc.c:513
 ndisc_send_rs+0x339/0x380 net/ipv6/ndisc.c:724
 addrconf_rs_timer+0x1e5/0x320 net/ipv6/addrconf.c:4099
 call_timer_fn+0x36/0x280 kernel/time/timer.c:1749
 expire_timers kernel/time/timer.c:1800 [inline]
 __run_timers kernel/time/timer.c:2375 [inline]
 __run_timer_base+0x40c/0x610 kernel/time/timer.c:2387
 run_timer_base kernel/time/timer.c:2396 [inline]
 run_timer_softirq+0x31/0x70 kernel/time/timer.c:2406
 handle_softirqs+0x109/0x310 kernel/softirq.c:669
 __do_softirq kernel/softirq.c:703 [inline]
 invoke_softirq kernel/softirq.c:542 [inline]
 __irq_exit_rcu+0x40/0xf0 kernel/softirq.c:786
 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1062 [inline]
 sysvec_apic_timer_interrupt+0x74/0x80 arch/x86/kernel/apic/apic.c:1062
 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:674
 rdtsc_ordered arch/x86/include/asm/tsc.h:57 [inline]
 delay_tsc+0x5b/0xa0 arch/x86/lib/delay.c:70
 udelay include/asm-generic/delay.h:64 [inline]
 delay_access kernel/kcsan/core.c:332 [inline]
 kcsan_setup_watchpoint+0x255/0x3f0 kernel/kcsan/core.c:622
 rb_wakeups kernel/trace/ring_buffer.c:4396 [inline]
 ring_buffer_unlock_commit+0x191/0x3b0 kernel/trace/ring_buffer.c:4582
 __buffer_unlock_commit kernel/trace/trace.h:1695 [inline]
 trace_buffer_unlock_commit_regs+0x43/0x310 kernel/trace/trace.c:2060
 trace_event_buffer_commit+0x149/0x5b0 kernel/trace/trace.c:2035
 do_trace_event_raw_event_skb_copy_datagram_iovec include/trace/events/skb.h:76 [inline]
 trace_event_raw_event_skb_copy_datagram_iovec+0xb9/0x160 include/trace/events/skb.h:76
 __do_trace_skb_copy_datagram_iovec include/trace/events/skb.h:76 [inline]
 trace_skb_copy_datagram_iovec include/trace/events/skb.h:76 [inline]
 skb_copy_datagram_iter+0xe4/0x100 net/core/datagram.c:534
 skb_copy_datagram_msg include/linux/skbuff.h:4268 [inline]
 __unix_dgram_recvmsg+0x4a4/0x920 net/unix/af_unix.c:2637
 unix_dgram_recvmsg+0x7e/0x90 net/unix/af_unix.c:2694
 sock_recvmsg_nosec+0xc2/0xf0 net/socket.c:1154
 ____sys_recvmsg+0x23f/0x250 net/socket.c:2931
 ___sys_recvmsg+0x156/0x3a0 net/socket.c:2978
 do_recvmmsg+0x1e4/0x550 net/socket.c:3073
 __sys_recvmmsg net/socket.c:3147 [inline]
 __do_sys_recvmmsg net/socket.c:3170 [inline]
 __se_sys_recvmmsg net/socket.c:3163 [inline]
 __x64_sys_recvmmsg+0xe5/0x170 net/socket.c:3163
 x64_sys_call+0x77f/0x2550 arch/x86/include/generated/asm/syscalls_64.h:300
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

read to 0xffff888100079060 of 8 bytes by task 10132 on cpu 1:
 rb_wakeups kernel/trace/ring_buffer.c:4396 [inline]
 ring_buffer_unlock_commit+0x191/0x3b0 kernel/trace/ring_buffer.c:4582
 __buffer_unlock_commit kernel/trace/trace.h:1695 [inline]
 trace_buffer_unlock_commit_regs+0x43/0x310 kernel/trace/trace.c:2060
 trace_event_buffer_commit+0x149/0x5b0 kernel/trace/trace.c:2035
 do_trace_event_raw_event_skb_copy_datagram_iovec include/trace/events/skb.h:76 [inline]
 trace_event_raw_event_skb_copy_datagram_iovec+0xb9/0x160 include/trace/events/skb.h:76
 __do_trace_skb_copy_datagram_iovec include/trace/events/skb.h:76 [inline]
 trace_skb_copy_datagram_iovec include/trace/events/skb.h:76 [inline]
 skb_copy_datagram_iter+0xe4/0x100 net/core/datagram.c:534
 skb_copy_datagram_msg include/linux/skbuff.h:4268 [inline]
 __unix_dgram_recvmsg+0x4a4/0x920 net/unix/af_unix.c:2637
 unix_dgram_recvmsg+0x7e/0x90 net/unix/af_unix.c:2694
 sock_recvmsg_nosec+0xc2/0xf0 net/socket.c:1154
 ____sys_recvmsg+0x23f/0x250 net/socket.c:2931
 ___sys_recvmsg+0x156/0x3a0 net/socket.c:2978
 do_recvmmsg+0x1e4/0x550 net/socket.c:3073
 __sys_recvmmsg net/socket.c:3147 [inline]
 __do_sys_recvmmsg net/socket.c:3170 [inline]
 __se_sys_recvmmsg net/socket.c:3163 [inline]
 __x64_sys_recvmmsg+0xe5/0x170 net/socket.c:3163
 x64_sys_call+0x77f/0x2550 arch/x86/include/generated/asm/syscalls_64.h:300
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

value changed: 0xffff88811be59ec0 -> 0xffff88811be59e80

Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 10132 Comm: syz.3.1480 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 13:32 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in rb_commit / ring_buffer_unlock_commit
2026/11/17 04:54 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in rb_commit / ring_buffer_unlock_commit
* Struck through repros no longer work on HEAD.