KCSAN: data-race in lru_add / swap_read_end

Status: moderation: reported on 2026/11/17 04:38
Subsystems: mm
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+5ce1e9be6eba565c6df2@syzkaller.appspotmail.com
First crash: 2h47m, last: 2h47m
✨ AI cause bisection: candidate commits (most relevant first) (AI job):
  1d798ca3f164 mm: make compound_head() robust
  a4519e5b648a mm/swap_state: remove unnecessary lru_add_drain() from readahead
  dda8fb68b590 mm/swap: also use struct swap_iocb for block I/O
  48c935ad88f5 page-flags: define PG_locked behavior on compound pages
  
✨ AI-generated root cause summary:

In struct page and struct folio, the first union word at offset 8 is shared between page->compound_info and folio->lru.next. When asynchronous swapin allocates a folio in mm/swap_state.c, it adds the in-flight folio to the per-CPU lru_add batch via folio_add_lru() prior to I/O completion. If another task drains the LRU batch concurrently via lru_add_drain() -> lru_add(), __list_add() performs an unmarked plain store to folio->lru.next while softirq swap read completion in swap_read_end() (mm/page_io.c) concurrently invokes bvec_folio() -> page_folio() -> _compound_head(), performing a marked READ_ONCE(page->compound_info). This concurrent plain write and marked read to the aliased union field triggers a KCSAN data-race report.

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

Technical Root Cause Analysis

1. Memory Layout and Union Aliasing

In the Linux kernel's memory descriptor layout (include/linux/mm_types.h), struct page and struct folio use an overlapping union for page/folio metadata at offset 8 (the second 8-byte word on 64-bit systems):

  • In struct page:
    struct { /* Tail pages of compound page */
        unsigned long compound_info; /* Bit zero is set */
    };
    
  • In struct folio / base head pages:
    struct list_head lru;
    

This overlay is explicitly documented and matched via FOLIO_MATCH(compound_info, lru) at line 517 of include/linux/mm_types.h. As a consequence, folio->lru.next and page->compound_info share the exact same 8-byte memory location (e.g. 0xffffea0004218548).

For head pages and single (order-0) folios, bit 0 of this word must remain 0 to avoid false-positive detection of tail pages (PageTail()), as checked by _compound_head() (include/linux/page-flags.h):

static __always_inline unsigned long _compound_head(const struct page *page)
{
    unsigned long info = READ_ONCE(page->compound_info);
    ...
    if (!compound_info_has_mask()) {
        if (info & 1)
            return info - 1;
        return (unsigned long)page;
    }
    mask = (info & 1) - 1;
    mask |= info;
    return (unsigned long)page & mask;
}

2. Concurrency Window and Trigger Path

The data race occurs due to how folios are queued for swap-in read I/O versus LRU batch draining:

  1. Swap-in Allocation and LRU Batching (mm/swap_state.c): During asynchronous swap-in (e.g., swap_cache_read_folio() or swapin_sync()), a new locked folio is allocated and queued into the local CPU's per-CPU lru_add batch via folio_add_lru() before submitting the asynchronous block I/O via swap_read_folio(). At this point, the read I/O is still in-flight and the folio remains locked.

  2. LRU Batch Drain on CPU 0 (mm/folio.c, include/linux/mm_inline.h, include/linux/list.h): While the swap-read bio is in flight, CPU 0 triggers an LRU drain (e.g. via do_swap_page() -> do_wp_page() -> wp_can_reuse_anon_folio() -> lru_add_drain()). Draining the batch calls folio_batch_move_lru() -> lru_add(), which takes lruvec->lru_lock (without needing the folio lock) and inserts the folio into the LRU list:

    lruvec_add_folio(lruvec, folio);
        list_add(&folio->lru, &lruvec->lists[lru]);
            __list_add(new, head, head->next);
    

    In __list_add() (include/linux/list.h:173):

    next->prev = new;
    new->next = next;          // Plain, unmarked 8-byte store to &folio->lru.next
    new->prev = prev;
    WRITE_ONCE(prev->next, new);
    

    The write new->next = next is an unmarked store to folio->lru.next at offset 8.

  3. Softirq Swap Read Completion on CPU 1 (mm/page_io.c, include/linux/bvec.h): Concurrently on CPU 1, interrupt/softirq processing finishes the swap bio: blk_done_softirq() -> ... -> bio_endio() -> swap_bio_read_end_io() -> swap_read_end(). In swap_read_end():

    for (p = 0; p < sio->nr_bvecs; p++) {
        struct folio *folio = bvec_folio(&sio->bvecs[p]);
        ...
        folio_unlock(folio);
    }
    

    bvec_folio() calls page_folio(bv->bv_page) -> _compound_head(). _compound_head() reads page->compound_info using READ_ONCE(page->compound_info).

3. Why KCSAN Flags the Race

Under the Linux Kernel Memory Model (LKMM), a concurrent unmarked plain write (new->next = next) racing against a marked read (READ_ONCE(page->compound_info)) constitutes a data race. Because folio->lru.next and page->compound_info alias the exact same word, KCSAN detects and reports the concurrent read and write.

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
26b6897e bisect-cause ❓ KCSAN: data-race in lru_add / swap_read_end 2026/11/17 04:37 2026/11/17 04:37 2026/11/17 05:26 f5be7dee
02816152 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in lru_add / swap_read_end 2026/11/17 04:06 2026/11/17 04:06 2026/11/17 04:37 f5be7dee
269394ed assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in lru_add / swap_read_end 2026/11/17 03:56 2026/11/17 03:56 2026/11/17 04:59 f5be7dee

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

read (marked) to 0xffffea0004218548 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
 number+0x939/0xb80 lib/vsprintf.c:568
 vsnprintf+0x68f/0x8c0 lib/vsprintf.c:2912
 audit_log_vformat+0x1ff/0x490 kernel/audit.c:2032
 audit_log_format+0x8d/0xc0 kernel/audit.c:2066
 audit_log_task+0xeb/0x240 kernel/auditsc.c:2913
 audit_seccomp+0x6a/0x110 kernel/auditsc.c:2968
 seccomp_log kernel/seccomp.c:1052 [inline]
 __seccomp_filter+0x91d/0x1400 kernel/seccomp.c:1350
 __seccomp_permit_syscall+0x7d/0x150 kernel/seccomp.c:1410
 syscall_trace_enter include/linux/entry-common.h:98 [inline]
 syscall_enter_from_user_mode_work include/linux/entry-common.h:147 [inline]
 do_syscall_64+0xce/0x3a0 arch/x86/entry/syscall_64.c:86
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

write to 0xffffea0004218548 of 8 bytes by task 3286 on cpu 0:
 __list_add include/linux/list.h:173 [inline]
 list_add include/linux/list.h:192 [inline]
 lruvec_add_folio include/linux/mm_inline.h:448 [inline]
 lru_add+0x3ed/0x4f0 mm/folio.c:148
 folio_batch_move_lru+0x30d/0x420 mm/folio.c:194
 lru_add_drain_cpu+0x65/0x2c0 mm/folio.c:630
 lru_add_drain+0x26/0x70 mm/folio.c:721
 wp_can_reuse_anon_folio mm/memory.c:4415 [inline]
 do_wp_page+0xfcb/0x2100 mm/memory.c:4529
 do_swap_page+0x1aba/0x21b0 mm/memory.c:5368
 handle_pte_fault mm/memory.c:6668 [inline]
 __handle_mm_fault mm/memory.c:6817 [inline]
 handle_mm_fault+0xb84/0x3880 mm/memory.c:6984
 do_user_addr_fault+0xa71/0xde0 arch/x86/mm/fault.c:1394
 handle_page_fault arch/x86/mm/fault.c:1483 [inline]
 exc_page_fault+0x62/0xa0 arch/x86/mm/fault.c:1536
 asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:595

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

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