KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt (9)

Status: moderation: reported on 2026/11/17 18:56
Subsystems: virt
Labels: prio:high
[Documentation on labels]
Reported-by: syzbot+378ba14d9bff8b9e7210@syzkaller.appspotmail.com
First crash: 17h10m, last: 1h53m
✨ AI cause bisection: introduced by (AI job) :
commit 0a8a69dd77ddbd4513b21363021ecde7e1025502
Author: Rusty Russell <rusty@rustcorp.com.au>
Date: Mon Oct 22 01:03:40 2007 +0000

  Virtio helper routines for a descriptor ringbuffer implementation

  
✨ AI-generated root cause summary:

In virtio split-ring mode, an unmarked data race occurs on the 16-bit field vq->last_used_idx between virtqueue_get_buf_ctx_split() (which increments last_used_idx in softirq/NAPI context) and vring_interrupt() -> more_used_split() (which reads last_used_idx in hardirq context without locking). While the packed-ring implementation explicitly uses READ_ONCE() and WRITE_ONCE() to access last_used_idx across interrupt boundaries, the split-ring functions use plain, unannotated C accesses. As a result, KCSAN detects an unsynchronized read-write data race between the interrupt handler and buffer consumption.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 666539eecdf4:

Technical Root Cause Analysis

Involved Functions, Structs, and Fields

  • File: drivers/virtio/virtio_ring.c
  • Struct: struct vring_virtqueue
  • Field: u16 last_used_idx (offset 92 / 0x5c bytes into struct vring_virtqueue, size 2 bytes)
  • Functions:
    • virtqueue_get_buf_ctx_split() / virtqueue_get_buf_ctx_split_in_order()
    • more_used_split() / more_used_split_in_order() (invoked by vring_interrupt())

Mechanism and Triggering Flow

  1. Context & Operation:

    • In virtio drivers such as virtio_net, buffer reception and cleanup run in softirq context via NAPI (virtnet_poll() -> receive_buf() -> virtnet_rq_get_buf() -> virtqueue_get_buf_ctx() -> virtqueue_get_buf_ctx_split()).
    • When detaching a processed descriptor in virtqueue_get_buf_ctx_split(), the driver increments vq->last_used_idx (line 1008):
      detach_buf_split(vq, i, ctx);
      vq->last_used_idx++;
      
    • Because softirqs run with hard IRQs enabled, a virtqueue interrupt (MSI-X or shared vector) can arrive concurrently on the same CPU or another CPU, invoking the interrupt handler vring_interrupt().
    • In vring_interrupt() (line 3323), the handler checks whether work is available before invoking the queue callback:
      if (!more_used(vq)) {
          pr_debug("virtqueue interrupt with no work for %p\n", vq);
          return IRQ_NONE;
      }
      
    • For split virtqueues, more_used() delegates to more_used_split() (lines 955–958):
      static bool more_used_split(const struct vring_virtqueue *vq)
      {
          return virtqueue_poll_split(vq, vq->last_used_idx);
      }
      
      which reads vq->last_used_idx.
  2. The Invariant Violation:

    • Under the Linux Kernel Memory Model (LKMM), data shared across hardirq and softirq/process contexts without explicit locking must use marked memory accesses (READ_ONCE() / WRITE_ONCE()) to prevent compiler optimizations (such as invent-writes, re-reading, or tearing) and to document intentional data races to sanitizers.
    • In the packed-ring implementation (virtio_ring.c), this was previously addressed by explicitly using marked primitives:
      • more_used_packed() reads READ_ONCE(vq->last_used_idx)
      • update_last_used_idx_packed() writes WRITE_ONCE(vq->last_used_idx, ...)
    • In the split-ring path (virtqueue_get_buf_ctx_split() and more_used_split()), however, plain C loads and stores (vq->last_used_idx++ and vq->last_used_idx) are used without WRITE_ONCE() or READ_ONCE().
  3. Failure Manifestation:

    • When KCSAN monitors accesses to vq->last_used_idx, it instruments the write in virtqueue_get_buf_ctx_split() and inserts a delay window. A hard interrupt occurs during this window and executes more_used_split(), which performs an unannotated read on the exact same address 0xffff88810337f55c. KCSAN flags this as an unannotated read-write data race.
▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
0db65031 bisect-cause ❓ KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt (9) 2026/11/17 18:47 2026/11/17 18:47 2026/11/17 19:01 ca622473
aa5f7747 assessment-kcsan 🏃 KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt (9) 2026/11/17 18:46 2026/11/17 18:46 ca622473
5329e7e6 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ✅ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ✅ ❓ KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt (9) 2026/11/17 18:32 2026/11/17 18:32 2026/11/17 18:47 ca622473
▶ ▼ Similar bugs (8)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt (6) virt 6 1 1256d 1256d 0/29 auto-obsoleted due to no activity on 2023/07/15 08:54
upstream KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt (7) virt 6 1 462d 462d 0/29 auto-obsoleted due to no activity on 2025/10/07 07:38
upstream KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt virt 6 3 2570d 2580d 0/29 closed as invalid on 2019/11/19 13:44
upstream KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt (5) virt 6 1 1592d 1592d 0/29 auto-closed as invalid on 2022/08/13 10:50
upstream KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt (2) virt 6 4 2473d 2498d 0/29 auto-closed as invalid on 2020/04/19 05:34
upstream KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt (3) virt 6 1 1855d 1855d 0/29 auto-closed as invalid on 2021/11/23 01:54
upstream KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt (8) prio:low virt 6 1 195d 195d 0/29 auto-obsoleted due to no activity on 2026/07/01 06:55
upstream KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt (4) virt 6 1 1670d 1670d 0/29 auto-closed as invalid on 2022/05/27 01:16

Sample crash report:
==================================================================
BUG: KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt

read to 0xffff88810337f55c of 2 bytes by interrupt on cpu 1:
 more_used_split drivers/virtio/virtio_ring.c:957 [inline]
 more_used drivers/virtio/virtio_ring.c:3308 [inline]
 vring_interrupt+0x48/0x310 drivers/virtio/virtio_ring.c:3323
 __handle_irq_event_percpu+0x92/0x4a0 kernel/irq/handle.c:209
 handle_irq_event_percpu kernel/irq/handle.c:246 [inline]
 handle_irq_event+0x64/0xf0 kernel/irq/handle.c:263
 handle_edge_irq+0x155/0x440 kernel/irq/chip.c:859
 generic_handle_irq_desc include/linux/irqdesc.h:188 [inline]
 handle_irq arch/x86/kernel/irq.c:209 [inline]
 call_irq_handler arch/x86/kernel/irq.c:-1 [inline]
 __common_interrupt+0x60/0xb0 arch/x86/kernel/irq.c:280
 common_interrupt+0x3e/0x90 arch/x86/kernel/irq.c:273
 asm_common_interrupt+0x26/0x40 arch/x86/include/asm/idtentry.h:665
 native_pause arch/x86/include/asm/vdso/processor.h:13 [inline]
 delay_tsc+0x43/0xa0 arch/x86/lib/delay.c:76
 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
 virtqueue_get_buf_ctx_split drivers/virtio/virtio_ring.c:1008 [inline]
 virtqueue_get_buf_ctx+0x598/0xd10 drivers/virtio/virtio_ring.c:3168
 virtnet_rq_get_buf drivers/net/virtio_net.c:939 [inline]
 receive_mergeable drivers/net/virtio_net.c:2436 [inline]
 receive_buf+0x637/0xf30 drivers/net/virtio_net.c:2596
 virtnet_receive_packets drivers/net/virtio_net.c:2921 [inline]
 virtnet_receive drivers/net/virtio_net.c:2945 [inline]
 virtnet_poll+0x169f/0x1f60 drivers/net/virtio_net.c:3040
 __napi_poll+0x73/0x350 net/core/dev.c:7997
 napi_poll net/core/dev.c:8060 [inline]
 net_rx_action+0x33f/0x850 net/core/dev.c:8217
 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
 common_interrupt+0x83/0x90 arch/x86/kernel/irq.c:273
 asm_common_interrupt+0x26/0x40 arch/x86/include/asm/idtentry.h:665
 native_safe_halt arch/x86/include/asm/irqflags.h:48 [inline]
 pv_native_safe_halt+0xf/0x20 arch/x86/kernel/paravirt.c:63
 arch_safe_halt arch/x86/kernel/process.c:767 [inline]
 default_idle+0x9/0x20 arch/x86/kernel/process.c:768
 default_idle_call+0x3b/0x60 kernel/sched/idle.c:122
 cpuidle_idle_call kernel/sched/idle.c:199 [inline]
 do_idle+0x183/0x2d0 kernel/sched/idle.c:355
 cpu_startup_entry+0x24/0x30 kernel/sched/idle.c:458
 start_secondary+0x95/0xa0 arch/x86/kernel/smpboot.c:312
 common_startup_64+0x13e/0x157

read-write to 0xffff88810337f55c of 2 bytes by interrupt on cpu 1:
 virtqueue_get_buf_ctx_split drivers/virtio/virtio_ring.c:1008 [inline]
 virtqueue_get_buf_ctx+0x598/0xd10 drivers/virtio/virtio_ring.c:3168
 virtnet_rq_get_buf drivers/net/virtio_net.c:939 [inline]
 receive_mergeable drivers/net/virtio_net.c:2436 [inline]
 receive_buf+0x637/0xf30 drivers/net/virtio_net.c:2596
 virtnet_receive_packets drivers/net/virtio_net.c:2921 [inline]
 virtnet_receive drivers/net/virtio_net.c:2945 [inline]
 virtnet_poll+0x169f/0x1f60 drivers/net/virtio_net.c:3040
 __napi_poll+0x73/0x350 net/core/dev.c:7997
 napi_poll net/core/dev.c:8060 [inline]
 net_rx_action+0x33f/0x850 net/core/dev.c:8217
 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
 common_interrupt+0x83/0x90 arch/x86/kernel/irq.c:273
 asm_common_interrupt+0x26/0x40 arch/x86/include/asm/idtentry.h:665
 native_safe_halt arch/x86/include/asm/irqflags.h:48 [inline]
 pv_native_safe_halt+0xf/0x20 arch/x86/kernel/paravirt.c:63
 arch_safe_halt arch/x86/kernel/process.c:767 [inline]
 default_idle+0x9/0x20 arch/x86/kernel/process.c:768
 default_idle_call+0x3b/0x60 kernel/sched/idle.c:122
 cpuidle_idle_call kernel/sched/idle.c:199 [inline]
 do_idle+0x183/0x2d0 kernel/sched/idle.c:355
 cpu_startup_entry+0x24/0x30 kernel/sched/idle.c:458
 start_secondary+0x95/0xa0 arch/x86/kernel/smpboot.c:312
 common_startup_64+0x13e/0x157

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

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 17:16 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt
2026/11/17 10:19 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt
2026/11/17 02:00 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in virtqueue_get_buf_ctx / vring_interrupt
* Struck through repros no longer work on HEAD.