KCSAN: data-race in __io_commit_cqring_flush / io_submit_sqes (2)

Status: moderation: reported on 2026/11/20 00:05
Subsystems: io-uring
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+1348744d623585ce0fc4@syzkaller.appspotmail.com
First crash: 2d21h, last: 3h04m
✨ AI-generated root cause summary:

A data race occurs on the 32-bit non-atomic ctx->int_flags field between io_init_req() and __io_commit_cqring_flush(). When an SQE with IOSQE_CQE_SKIP_SUCCESS is submitted (e.g. by an SQPOLL thread holding ctx->uring_lock), io_init_req() performs a non-atomic read-modify-write ctx->int_flags |= IO_RING_F_DRAIN_DISABLED;. Meanwhile, an async completion running concurrently on an io-wq worker calls io_commit_cqring_flush(), which evaluates data_race(ctx->int_flags) & SHOULD_FLUSH_MASK and invokes __io_commit_cqring_flush(), where unannotated plain C loads inspect ctx->int_flags without holding uring_lock. Because mutable submission flags and cross-thread completion flush flags share the same unannotated non-atomic integer word, KCSAN detects the concurrent read and write.

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

Technical Breakdown: KCSAN Data Race on ctx->int_flags

1. Racing Field and Affected Data Structures

2. Writer Context and Execution Path

  • Call Trace:
    __io_sq_thread()                     [io_uring/sqpoll.c:252]
      io_submit_sqes()                   [io_uring/io_uring.c:2212]
        io_submit_sqe()                  [io_uring/io_uring.c:2044]
          io_init_req()                  [io_uring/io_uring.c:1939]
    
  • Mechanism: During SQE processing in io_init_req(), if the request contains IOSQE_CQE_SKIP_SUCCESS, the kernel sets the internal flag:
    if (sqe_flags & IOSQE_CQE_SKIP_SUCCESS)
        ctx->int_flags |= IO_RING_F_DRAIN_DISABLED;
    
    This is executed under ctx->uring_lock (held by the SQPOLL thread or the task calling io_uring_enter()). This operation is a plain C non-atomic read-modify-write on ctx->int_flags.

3. Reader Context and Execution Path

  • Call Trace:
    io_wq_worker()                       [io_uring/io-wq.c:768]
      io_worker_handle_work()            [io_uring/io-wq.c:677]
        io_wq_submit_work()              [io_uring/io_uring.c:1677]
          io_issue_sqe()                 [io_uring/io_uring.c:1546]
            io_req_complete_post()       [io_uring/io_uring.c:1030]
              io_cq_unlock_post()        [io_uring/io_uring.c:572]
                io_commit_cqring_flush() [io_uring/io_uring.h:518]
                  __io_commit_cqring_flush() [io_uring/io_uring.c:535]
    
  • Mechanism: When an asynchronous work item completes on an io-wq worker thread, io_req_complete_post() calls io_cq_unlock_post(). After unlocking ctx->completion_lock, io_commit_cqring_flush() checks whether any deferred flush actions are required:
    #define SHOULD_FLUSH_MASK (IO_RING_F_OFF_TIMEOUT_USED | \
                               IO_RING_F_HAS_EVFD | IO_RING_F_POLL_ACTIVATED)
    
    static inline void io_commit_cqring_flush(struct io_ring_ctx *ctx)
    {
        if (unlikely(data_race(ctx->int_flags) & SHOULD_FLUSH_MASK))
            __io_commit_cqring_flush(ctx);
    }
    
    On rings without IO_RING_F_TASK_COMPLETE (such as IORING_SETUP_SQPOLL without IOPOLL), io_uring_create() initializes IO_RING_F_POLL_ACTIVATED into ctx->int_flags (io_uring/io_uring.c:3266-3267). Therefore, SHOULD_FLUSH_MASK matches, and __io_commit_cqring_flush(ctx) is called. Inside __io_commit_cqring_flush():
    void __io_commit_cqring_flush(struct io_ring_ctx *ctx)
    {
        if (ctx->int_flags & IO_RING_F_POLL_ACTIVATED)
            io_poll_wq_wake(ctx);
        if (ctx->int_flags & IO_RING_F_OFF_TIMEOUT_USED)
            io_flush_timeouts(ctx);
        if (ctx->int_flags & IO_RING_F_HAS_EVFD)
            io_eventfd_signal(ctx, true, false);
    }
    
    Unlike the caller io_commit_cqring_flush(), which wrapped its access in data_race(), __io_commit_cqring_flush() performs three unannotated, plain C reads from ctx->int_flags without holding ctx->uring_lock.

4. Root Cause

ctx->int_flags combines submission-state flags (IO_RING_F_DRAIN_DISABLED, IO_RING_F_DRAIN_ACTIVE, IO_RING_F_DRAIN_NEXT), ring-creation flags (IO_RING_F_TASK_COMPLETE, IO_RING_F_LOCKLESS_CQ, etc.), and completion flush/wake flags (IO_RING_F_POLL_ACTIVATED, IO_RING_F_OFF_TIMEOUT_USED, IO_RING_F_HAS_EVFD) into a single non-atomic unsigned int variable.

While writers modifying submission flags hold ctx->uring_lock, asynchronous completions from io-wq run concurrently without ctx->uring_lock. io_commit_cqring_flush() recognized the lockless read and used data_race(), but __io_commit_cqring_flush() subsequently re-read ctx->int_flags with plain C loads, racing against ctx->int_flags |= IO_RING_F_DRAIN_DISABLED in io_init_req().

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
02e84309 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in __io_commit_cqring_flush / io_submit_sqes (2) 2026/11/19 05:38 2026/11/19 05:38 2026/11/19 05:46 2006bdcc
e2fa2d4c assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in __io_commit_cqring_flush / io_submit_sqes (2) 2026/11/19 05:36 2026/11/19 05:36 2026/11/19 05:51 2006bdcc
▶ ▼ Similar bugs (1)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in __io_commit_cqring_flush / io_submit_sqes io-uring 6 1 895d 895d 0/29 auto-obsoleted due to no activity on 2024/07/12 11:45

Sample crash report:
==================================================================
BUG: KCSAN: data-race in __io_commit_cqring_flush / io_submit_sqes

write to 0xffff888104547004 of 4 bytes by task 5128 on cpu 0:
 io_init_req io_uring/io_uring.c:1939 [inline]
 io_submit_sqe io_uring/io_uring.c:2044 [inline]
 io_submit_sqes+0xcf3/0x12b0 io_uring/io_uring.c:2212
 __io_sq_thread io_uring/sqpoll.c:252 [inline]
 io_sq_thread+0xaaa/0x16f0 io_uring/sqpoll.c:369
 ret_from_fork+0x146/0x330 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

read to 0xffff888104547004 of 4 bytes by task 5129 on cpu 1:
 __io_commit_cqring_flush+0x1e/0x100 io_uring/io_uring.c:533
 io_commit_cqring_flush io_uring/io_uring.h:519 [inline]
 io_cq_unlock_post io_uring/io_uring.c:572 [inline]
 io_req_complete_post io_uring/io_uring.c:1030 [inline]
 io_issue_sqe+0xc16/0xd20 io_uring/io_uring.c:1546
 io_wq_submit_work+0x64d/0x8f0 io_uring/io_uring.c:1677
 io_worker_handle_work+0x688/0xd30 io_uring/io-wq.c:677
 io_wq_worker+0x2be/0xcb0 io_uring/io-wq.c:768
 ret_from_fork+0x146/0x330 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245

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

Crashes (5):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/19 21:39 upstream 8dac6df92a2e 229865fb .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __io_commit_cqring_flush / io_submit_sqes
2026/11/17 19:01 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __io_commit_cqring_flush / io_submit_sqes
2026/11/17 03:43 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __io_commit_cqring_flush / io_submit_sqes
2026/11/17 03:43 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __io_commit_cqring_flush / io_submit_sqes
2026/11/17 03:43 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in __io_commit_cqring_flush / io_submit_sqes
* Struck through repros no longer work on HEAD.