KCSAN: data-race in lo_ioctl / loop_queue_rq (7)

Status: moderation: reported on 2026/11/18 02:41
Subsystems: block
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+69b48067886244c43a44@syzkaller.appspotmail.com
First crash: 20h32m, last: 14h25m
✨ AI cause bisection: introduced by (AI job) :
commit afd69d5c4a1049230fa91c9b54fdd8132f755503
Author: Christoph Hellwig <hch@lst.de>
Date: Fri Jan 10 07:37:38 2025 +0000

  loop: remove the use_dio field in struct loop_device

  
✨ AI-generated root cause summary:

In the loop block driver (drivers/block/loop.c), loop_queue_rq() reads lo->lo_flags without locking (to check the LO_FLAGS_DIRECT_IO flag for setting cmd->use_aio) while processing block requests. Concurrently, an ioctl handler such as loop_clr_fd() (invoked via LOOP_CLR_FD) modifies lo->lo_flags by setting LO_FLAGS_AUTOCLEAR under lo->lo_mutex. Because loop_queue_rq() executes on the request submission fast path without acquiring lo->lo_mutex and without atomic bit operations or READ_ONCE()/data_race() annotations on lo->lo_flags, KCSAN detects an unsynchronized data race on the 4-byte lo_flags field.

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

Root Cause Analysis

1. Involved Components

  • Source File: drivers/block/loop.c
  • Data Structure: struct loop_device (field int lo_flags)
  • Functions:
    • Reader: loop_queue_rq() (line 1792)
    • Writer: loop_clr_fd() (line 1134, called via lo_ioctl() line 1467)

2. Technical Mechanism

In drivers/block/loop.c, struct loop_device tracks operational configuration flags in the 32-bit field lo_flags (such as LO_FLAGS_READ_ONLY, LO_FLAGS_AUTOCLEAR, LO_FLAGS_PARTSCAN, and LO_FLAGS_DIRECT_IO).

  • The Read Side: When a block I/O request is dispatched to the loop device, the blk-mq driver callback loop_queue_rq() is invoked on the request submission fast path. In loop_queue_rq():

    switch (req_op(rq)) {
    case REQ_OP_FLUSH:
    case REQ_OP_DISCARD:
    case REQ_OP_WRITE_ZEROES:
        cmd->use_aio = false;
        break;
    default:
        cmd->use_aio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
        break;
    }
    

    loop_queue_rq() does not acquire lo->lo_mutex (nor could it sleep or take device mutexes during request queueing). It directly reads lo->lo_flags using a plain memory access without READ_ONCE() or data_race() annotations.

  • The Write Side: Concurrently, user space issues the LOOP_CLR_FD ioctl on the loop device. This invokes lo_ioctl() -> loop_clr_fd(). Inside loop_clr_fd():

    err = loop_global_lock_killable(lo, true);
    if (err)
        return err;
    ...
    lo->lo_flags |= LO_FLAGS_AUTOCLEAR;
    ...
    loop_global_unlock(lo, true);
    

    loop_clr_fd() performs a non-atomic read-modify-write operation (|=) on lo->lo_flags under lo->lo_mutex and loop_ctl_mutex. However, because loop_queue_rq() does not hold these mutexes and the block queue is not frozen during loop_clr_fd(), the write runs concurrently with the read in loop_queue_rq().

3. Invariant Violation

Linux concurrency rules require that any shared variable accessed concurrently by multiple threads where at least one thread writes must either use proper locking, atomic operations (e.g. atomic bitops such as set_bit() / test_bit()), or marked accesses (READ_ONCE(), WRITE_ONCE(), or data_race()). Here, lo->lo_flags is an ordinary int manipulated with plain C read and bitwise OR assignment without synchronization against the lockless queue dispatch path, triggering the KCSAN data-race report.

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
f85eb112 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in lo_ioctl / loop_queue_rq (7) 2026/11/18 02:49 2026/11/18 02:49 2026/11/18 03:07 ca622473
10b49346 bisect-cause ❓ KCSAN: data-race in lo_ioctl / loop_queue_rq (7) 2026/11/18 02:41 2026/11/18 02:41 2026/11/18 02:49 ca622473
4827ccf8 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in lo_ioctl / loop_queue_rq (7) 2026/11/18 02:35 2026/11/18 02:35 2026/11/18 02:40 ca622473
▶ ▼ Similar bugs (6)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in lo_ioctl / loop_queue_rq (4) block 6 2 1035d 1050d 0/29 auto-obsoleted due to no activity on 2024/02/21 17:00
upstream KCSAN: data-race in lo_ioctl / loop_queue_rq (6) block 6 2 379d 387d 0/29 auto-obsoleted due to no activity on 2025/12/29 09:54
upstream KCSAN: data-race in lo_ioctl / loop_queue_rq (3) block 6 1 1585d 1585d 0/29 auto-closed as invalid on 2022/08/20 11:36
upstream KCSAN: data-race in lo_ioctl / loop_queue_rq (2) block 6 1 2031d 2031d 0/29 auto-closed as invalid on 2021/05/31 09:44
upstream KCSAN: data-race in lo_ioctl / loop_queue_rq (5) block 6 1 585d 585d 0/29 auto-obsoleted due to no activity on 2025/06/06 09:54
upstream KCSAN: data-race in lo_ioctl / loop_queue_rq block 6 1 2533d 2533d 0/29 auto-closed as invalid on 2020/02/19 07:26

Sample crash report:
EXT4-fs (loop0): mounted filesystem 00000000-0000-0000-0000-000000000000 r/w without journal. Quota mode: writeback.
ext4 filesystem being mounted at /3/bus supports timestamps until 2038-01-19 (0x7fffffff)
==================================================================
BUG: KCSAN: data-race in lo_ioctl / loop_queue_rq

read to 0xffff8881016bea18 of 4 bytes by task 3283 on cpu 0:
 loop_queue_rq+0xe2/0x6a0 drivers/block/loop.c:1792
 __blk_mq_issue_directly block/blk-mq.c:2718 [inline]
 blk_mq_request_issue_directly+0x227/0x3b0 block/blk-mq.c:2805
 blk_mq_issue_direct+0x18a/0x510 block/blk-mq.c:2826
 blk_mq_dispatch_queue_requests+0x221/0x360 block/blk-mq.c:2901
 blk_mq_flush_plug_list+0x2ad/0x320 block/blk-mq.c:2984
 __blk_flush_plug+0x22f/0x2b0 block/blk-core.c:1274
 blk_finish_plug+0x47/0x70 block/blk-core.c:1301
 read_pages+0x540/0x5c0 mm/readahead.c:187
 page_cache_ra_unbounded+0x307/0x3f0 mm/readahead.c:315
 do_page_cache_ra mm/readahead.c:348 [inline]
 force_page_cache_ra+0x190/0x1d0 mm/readahead.c:378
 page_cache_sync_ra+0x133/0x580 mm/readahead.c:602
 filemap_get_pages+0x314/0x1020 mm/filemap.c:2743
 filemap_read+0x20d/0x8d0 mm/filemap.c:2853
 blkdev_read_iter+0x29c/0x390 block/fops.c:892
 new_sync_read fs/read_write.c:473 [inline]
 vfs_read+0x6ac/0x7d0 fs/read_write.c:554
 ksys_read+0xdc/0x1a0 fs/read_write.c:696
 __do_sys_read fs/read_write.c:705 [inline]
 __se_sys_read fs/read_write.c:703 [inline]
 __x64_sys_read+0x40/0x50 fs/read_write.c:703
 x64_sys_call+0x2135/0x2550 arch/x86/include/generated/asm/syscalls_64.h:1
 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-write to 0xffff8881016bea18 of 4 bytes by task 3598 on cpu 0:
 loop_clr_fd drivers/block/loop.c:1134 [inline]
 lo_ioctl+0x96e/0xd60 drivers/block/loop.c:1467
 blkdev_ioctl+0x387/0x460 block/ioctl.c:798
 vfs_ioctl fs/ioctl.c:52 [inline]
 __do_sys_ioctl fs/ioctl.c:598 [inline]
 __se_sys_ioctl+0xce/0x140 fs/ioctl.c:584
 __x64_sys_ioctl+0x43/0x50 fs/ioctl.c:584
 x64_sys_call+0x239d/0x2550 arch/x86/include/generated/asm/syscalls_64.h:17
 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

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 3598 Comm: syz.0.28 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:40 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in lo_ioctl / loop_queue_rq
2026/11/17 07:33 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in lo_ioctl / loop_queue_rq
* Struck through repros no longer work on HEAD.