KCSAN: data-race in evict_folios / swap_read_end

Status: moderation: reported on 2026/11/18 00:00
Subsystems: mm
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+46303c3077dff5293bdb@syzkaller.appspotmail.com
First crash: 9h58m, last: 6h23m
✨ AI cause bisection: candidate commits (most relevant first) (AI job):
  1d798ca3f164 mm: make compound_head() robust
  4d5d14a01e2c mm/mglru: rework workingset protection
  dda8fb68b590 mm/swap: also use struct swap_iocb for block I/O
  
✨ AI-generated root cause summary:

In struct page / struct folio, folio->lru.next aliases page->compound_info within the first union word following flags. When swap-in allocates a folio, it adds it to the LRU before read I/O completes. While the swap-in bio is in flight with the folio locked, memory reclaim (evict_folios()) isolates the folio, fails to acquire the folio lock in shrink_folio_list(), and moves it to a local list via list_move(), performing an unmarked store to folio->lru.next. Concurrently, swap read bio completion (swap_read_end()) calls bvec_folio() -> page_folio() -> _compound_head(), which executes a READ_ONCE(page->compound_info) on the same memory location to test bit 0 (PageTail()), triggering a KCSAN data-race report.

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

Bug Mechanism and Root Cause Analysis

1. Overlapping Fields in struct page / struct folio

In include/linux/mm_types.h, the memory layout of struct page and struct folio defines a union immediately following the flags field (at offset 8):

struct page {
    memdesc_flags_t flags;
    union {
        struct {
            union {
                struct list_head lru;
                ...
            };
            ...
        };
        ...
        struct {
            unsigned long compound_info; /* Bit zero is set */
        };
        ...
    };
    ...
};

For order-0 and compound head pages (the base page representing the folio), the member folio->lru.next and page->compound_info share the exact same 8-byte word (offset 8 from the start of the struct page, which corresponds to 0xffffea00042ddbc8 in the report).

2. Reclaim Path (Unmarked Write via evict_folios())

When a swap-in fault occurs (swap_cache_read_folio() or swapin_sync() in mm/swap_state.c), a folio is allocated, locked (folio_test_locked() is true), and immediately added to the LRU list via folio_add_lru(folio) before the swap read bio is dispatched.

While the swap read I/O is in flight:

  1. Memory reclaim (evict_folios() in mm/vmscan.c) scans and isolates the folio from the LRU onto a local list (&list), where it is no longer protected by lruvec->lru_lock.
  2. In shrink_folio_list(), folio_trylock(folio) fails because the folio is held locked by the ongoing swap read I/O. As a result, the folio is not reclaimed and branches to the keep: label, where it is placed into ret_folios and spliced back into &list.
  3. Back in evict_folios(), the loop checks:
    if (!skip_retry && !folio_test_active(folio) && !folio_mapped(folio) &&
        !folio_test_dirty(folio) && !folio_test_writeback(folio)) {
        list_move(&folio->lru, &clean);
        continue;
    }
    
  4. list_move(&folio->lru, &clean) calls __list_add() (include/linux/list.h:173), which writes new->next = next; using a plain, unmarked C store directly to folio->lru.next (0xffffea00042ddbc8).

3. Swap I/O Completion Path (Marked Read in swap_read_end())

Concurrently, on an interrupt/softirq CPU handling the completion of the swap read bio:

  1. swap_bio_read_end_io() calls swap_read_end(sio, failed) (mm/page_io.c:556).
  2. swap_read_end() processes each bio vector:
    struct folio *folio = bvec_folio(&sio->bvecs[p]);
    
  3. bvec_folio() calls page_folio(bv->bv_page), which invokes _compound_head(page) (include/linux/page-flags.h:221):
    unsigned long info = READ_ONCE(page->compound_info);
    
  4. This marked read accesses page->compound_info, which is the exact same location as folio->lru.next.

Because list_move() performs an unmarked write while _compound_head() performs a concurrent READ_ONCE() on the same 8-byte memory location without mutual synchronization (the folio lock protects the page contents and state flags, but folio->lru is manipulated independently while isolated by the LRU scanner), KCSAN detects and flags the data race.

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
66987f5b assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in evict_folios / swap_read_end 2026/11/17 23:46 2026/11/17 23:46 2026/11/18 00:14 ca622473
a7295e4d assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in evict_folios / swap_read_end 2026/11/17 23:39 2026/11/17 23:39 2026/11/17 23:46 ca622473
91cf1c41 bisect-cause ❓ KCSAN: data-race in evict_folios / swap_read_end 2026/11/17 23:39 2026/11/17 23:39 2026/11/18 00:39 ca622473

Sample crash report:
==================================================================
BUG: KCSAN: data-race in evict_folios / swap_read_end

read (marked) to 0xffffea00042ddbc8 of 8 bytes by interrupt on cpu 1:
 _compound_head include/linux/page-flags.h:221 [inline]
 bvec_folio include/linux/bvec.h:89 [inline]
 swap_read_end+0x6b/0x250 mm/page_io.c:556
 swap_bio_read_end_io+0x79/0x100 mm/page_io.c:593
 bio_endio+0x3ef/0x5e0 block/bio.c:1908
 blk_update_request+0x365/0x780 block/blk-mq.c:1036
 scsi_end_request+0x48/0x3a0 drivers/scsi/scsi_lib.c:671
 scsi_io_completion+0x7f/0x1d0 drivers/scsi/scsi_lib.c:1125
 scsi_finish_command+0x233/0x250 drivers/scsi/scsi.c:198
 scsi_complete+0x165/0x660 drivers/scsi/scsi_lib.c:1604
 blk_complete_reqs block/blk-mq.c:1242 [inline]
 blk_done_softirq+0x8d/0xc0 block/blk-mq.c:1247
 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
 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
 folio_batch_add include/linux/folio_batch.h:77 [inline]
 free_pages_and_swap_cache+0x176/0x270 mm/swap_state.c:653
 __tlb_batch_free_encoded_pages mm/mmu_gather.c:138 [inline]
 tlb_batch_pages_flush mm/mmu_gather.c:151 [inline]
 tlb_flush_mmu_free mm/mmu_gather.c:397 [inline]
 tlb_flush_mmu+0x56f/0x6d0 mm/mmu_gather.c:404
 zap_pte_range mm/memory.c:2068 [inline]
 zap_pmd_range mm/memory.c:2117 [inline]
 zap_pud_range mm/memory.c:2145 [inline]
 zap_p4d_range mm/memory.c:2166 [inline]
 __zap_vma_range+0x2765/0x2ed0 mm/memory.c:2206
 unmap_vmas+0x216/0x310 mm/memory.c:2275
 exit_mmap+0x1a2/0x650 mm/mmap.c:1315
 __mmput+0x28/0x1f0 kernel/fork.c:1192
 mmput+0x51/0x60 kernel/fork.c:1215
 exit_mm+0x12d/0x1d0 kernel/exit.c:586
 do_exit+0x44a/0x1530 kernel/exit.c:967
 do_group_exit+0xfe/0x140 kernel/exit.c:1123
 get_signal+0xc49/0xd30 kernel/signal.c:3113
 arch_do_signal_or_restart+0x96/0x480 arch/x86/kernel/signal.c:337
 __exit_to_user_mode_loop kernel/entry/common.c:66 [inline]
 exit_to_user_mode_loop+0x161/0x940 kernel/entry/common.c:101
 __exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
 syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:230 [inline]
 syscall_exit_to_user_mode include/linux/entry-common.h:343 [inline]
 do_syscall_64+0x23b/0x3a0 arch/x86/entry/syscall_64.c:107
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

write to 0xffffea00042ddbc8 of 8 bytes by task 6663 on cpu 0:
 __list_add include/linux/list.h:173 [inline]
 list_add include/linux/list.h:192 [inline]
 list_move include/linux/list.h:345 [inline]
 evict_folios+0x252e/0x2990 mm/vmscan.c:5117
 try_to_shrink_lruvec+0x9fb/0xd60 mm/vmscan.c:5271
 lru_gen_shrink_lruvec mm/vmscan.c:5422 [inline]
 shrink_lruvec mm/vmscan.c:6199 [inline]
 shrink_node_memcgs mm/vmscan.c:6438 [inline]
 shrink_node+0x97e/0x4600 mm/vmscan.c:6482
 shrink_zones mm/vmscan.c:6701 [inline]
 do_try_to_free_pages+0x310/0xb80 mm/vmscan.c:6763
 try_to_free_mem_cgroup_pages+0x201/0x450 mm/vmscan.c:7044
 mem_cgroup_force_empty mm/memcontrol-v1.c:1502 [inline]
 mem_cgroup_force_empty_write+0x6b/0x160 mm/memcontrol-v1.c:1518
 cgroup_file_write+0x197/0x350 kernel/cgroup/cgroup.c:4426
 kernfs_fop_write_iter+0x1d2/0x2e0 fs/kernfs/file.c:345
 new_sync_write fs/read_write.c:575 [inline]
 vfs_write+0x57a/0x9b0 fs/read_write.c:667
 ksys_write+0xdc/0x1a0 fs/read_write.c:719
 __do_sys_write fs/read_write.c:730 [inline]
 __se_sys_write fs/read_write.c:727 [inline]
 __x64_sys_write+0x40/0x50 fs/read_write.c:727
 x64_sys_call+0x154e/0x2550 arch/x86/include/generated/asm/syscalls_64.h:2
 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: 6663 Comm: syz.7.892 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 18:35 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in evict_folios / swap_read_end
2026/11/17 15:00 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in evict_folios / swap_read_end
* Struck through repros no longer work on HEAD.