KCSAN: data-race in evict_folios / mpage_end_io

Status: moderation: reported on 2026/11/19 00:05
Subsystems: ext4
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+31d0fd3e2418cf8d7d40@syzkaller.appspotmail.com
First crash: 1d22h, last: 4h48m
✨ AI-generated root cause summary:

A KCSAN data race occurs between proactive memory reclaim (evict_folios) and read I/O completion (mpage_end_io). In struct page / struct folio, folio->lru.next and page->compound_info share a union slot at byte offset 8. While an in-flight read bio completes in softirq context, mpage_end_io() traverses folios via bio_for_each_folio_all() -> page_folio() -> _compound_head(), which executes a marked READ_ONCE(page->compound_info) without holding locks. Concurrently, evict_folios() performs an unmarked plain store to folio->lru.next via list_move() -> __list_add(), triggering KCSAN due to an unmarked write racing with a marked read.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 20eef29b7c84:

Root Cause Analysis

1. Functions, Structs, and Fields Involved

  • struct page / struct folio (include/linux/mm_types.h):
    • In struct page (lines 89–131) and struct folio (lines 407–423), the 8-byte word at offset 8 (0xffffea000420f208) is an overlapping union member.
    • On head pages and base (order-0) pages, this word holds folio->lru.next (struct list_head lru).
    • On tail pages of compound pages, this word holds page->compound_info. By kernel convention (include/linux/mm_types.h:85-87), bit 0 encodes PageTail() (1 for tail pages, 0 for head/order-0 pages). All non-tail union users must guarantee bit 0 remains 0.
  • _compound_head() / page_folio() (include/linux/page-flags.h:219-248, 283-298):
    • page_folio() is explicitly documented to require neither references nor locks ("Context: No reference, nor lock is required on @page.").
    • It invokes _compound_head(), which executes READ_ONCE(page->compound_info) on the page to test whether bit 0 is set (info & 1).
  • evict_folios() / __list_add() (mm/vmscan.c:5115-5117, include/linux/list.h:165-176):
    • Proactive reclaim manipulates the folio's LRU linkage (folio->lru).
    • In __list_add(), new->next = next; (line 173) updates folio->lru.next via a plain C store without WRITE_ONCE().
  • mpage_end_io() / __read_end_io() (fs/ext4/readpage.c:61-70, 103-114):
    • The bio end-of-I/O handler iterates over folios in the completed read request using bio_for_each_folio_all(fi, bio) (include/linux/bio.h:281-319).
    • It resolves each bio_vec page to its enclosing folio via bvec_folio() -> page_folio() -> _compound_head().

2. Triggering Mechanism and Race Condition

  1. Readahead Folio Allocation and Submission:

    • During file readahead / fault handling (filemap_fault() -> filemap_add_folio()), a newly allocated page cache folio is locked (__folio_set_locked()) and immediately added to the LRU list via folio_add_lru().
    • The filesystem submits a read request (ext4_mpage_readpages()) creating a REQ_OP_READ bio with completion callback mpage_end_io(). The folio remains locked while I/O is in flight.
  2. Proactive Memory Reclaim on CPU 0:

    • Concurrently, proactive reclaim (evict_folios()) isolates folios from the LRU and passes them to shrink_folio_list().
    • In shrink_folio_list(), folio_trylock(folio) fails because the folio is held locked for read I/O, so the folio is returned on the local reclaim list.
    • Back in evict_folios() (lines 5115–5117), the loop tests !skip_retry && !folio_test_active(folio) && !folio_mapped(folio) && !folio_test_dirty(folio) && !folio_test_writeback(folio).
    • Because the folio is clean and inactive, list_move(&folio->lru, &clean) is called.
    • list_move() calls list_add(), which calls __list_add(), executing new->next = next; (include/linux/list.h:173). This writes to folio->lru.next at offset 8 as an unmarked plain store.
  3. Read Completion Softirq on CPU 1:

    • As the block device completes the read I/O, the interrupt triggers softirq execution (blk_done_softirq() -> bio_endio() -> mpage_end_io() -> __read_end_io()).
    • __read_end_io() calls bio_for_each_folio_all() -> bio_first_folio() -> bvec_folio() -> page_folio(bv->bv_page) -> _compound_head().
    • _compound_head() reads READ_ONCE(page->compound_info) from the exact same offset 8 on the head page.
  4. KCSAN Splat:

    • Under LKMM, an unmarked plain write (new->next = next) racing concurrently with a marked read (READ_ONCE(page->compound_info)) constitutes a data race, which KCSAN detects and flags.
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
479b4ecf assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in evict_folios / mpage_end_io 2026/11/18 22:59 2026/11/18 22:59 2026/11/18 23:25 2006bdcc
076b5125 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in evict_folios / mpage_end_io 2026/11/18 22:50 2026/11/18 22:50 2026/11/18 22:59 2006bdcc

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

read (marked) to 0xffffea000420f208 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]
 bio_first_folio include/linux/bio.h:291 [inline]
 bio_next_folio include/linux/bio.h:309 [inline]
 __read_end_io fs/ext4/readpage.c:65 [inline]
 mpage_end_io+0x262/0x4a0 fs/ext4/readpage.c:113
 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
 kcsan_setup_watchpoint+0x39c/0x3f0 kernel/kcsan/core.c:714
 memdesc_nid include/linux/mm.h:2599 [inline]
 folio_nid include/linux/mm.h:2617 [inline]
 folio_pgdat include/linux/mm.h:2842 [inline]
 folio_lruvec include/linux/memcontrol.h:772 [inline]
 lru_gen_refault mm/workingset.c:306 [inline]
 workingset_refault+0x264/0x9e0 mm/workingset.c:559
 filemap_add_folio+0x270/0x3c0 mm/filemap.c:985
 page_cache_ra_unbounded+0x1a4/0x3f0 mm/readahead.c:293
 do_page_cache_ra mm/readahead.c:348 [inline]
 page_cache_ra_order+0x149/0x220 mm/readahead.c:558
 do_sync_mmap_readahead+0x2c1/0x380 mm/filemap.c:3466
 filemap_fault+0x3e2/0xab0 mm/filemap.c:3620
 __do_fault mm/memory.c:5691 [inline]
 do_read_fault mm/memory.c:6136 [inline]
 do_fault mm/memory.c:6270 [inline]
 do_pte_missing mm/memory.c:4797 [inline]
 handle_pte_fault mm/memory.c:6689 [inline]
 __handle_mm_fault mm/memory.c:6841 [inline]
 handle_mm_fault+0x2183/0x3880 mm/memory.c:7008
 do_user_addr_fault+0x3ce/0xde0 arch/x86/mm/fault.c:1343
 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

write to 0xffffea000420f208 of 8 bytes by task 3647 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
 shrink_one+0x1b4/0x940 mm/vmscan.c:5318
 shrink_many mm/vmscan.c:5381 [inline]
 lru_gen_shrink_node mm/vmscan.c:5459 [inline]
 shrink_node+0x4034/0x4600 mm/vmscan.c:6465
 __node_reclaim+0xf0/0x3e0 mm/vmscan.c:8012
 user_proactive_reclaim+0x595/0x700 mm/vmscan.c:8202
 reclaim_store+0x4a/0x70 mm/vmscan.c:8268
 dev_attr_store+0x4a/0x70 drivers/base/core.c:2509
 sysfs_kf_write+0xfe/0x120 fs/sysfs/file.c:145
 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: 3647 Comm: syz.3.48 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================
syz.3.48 (3647) used greatest stack depth: 9016 bytes left

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