KCSAN: data-race in filemap_fault / filemap_read_folio (2)

Status: moderation: reported on 2026/11/19 00:07
Subsystems: mm
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+b7808ed798bd9e9bd311@syzkaller.appspotmail.com
First crash: 1d16h, last: 1d06h
✨ AI-generated root cause summary:

A data race occurs on the 'ra_pages' field of struct file_ra_state (embedded in struct file as f_ra) between shrink_readahead_size_eio() and do_async_mmap_readahead(). When a folio read fails with an I/O error in filemap_read_folio(), shrink_readahead_size_eio() reduces the readahead size with an unsynchronized read-modify-write ('ra->ra_pages /= 4'). Concurrently, another thread faulting on the same shared file mapping in do_async_mmap_readahead() performs an unsynchronized read of 'ra->ra_pages'. Because struct file_ra_state accesses across concurrent page faults lack synchronization or atomic annotations (READ_ONCE/WRITE_ONCE), KCSAN flags the concurrent access as a data race.

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

Technical Analysis and Root Cause

1. Functions, Structs, and Files Involved

  • File: mm/filemap.c
  • Functions: shrink_readahead_size_eio(), filemap_read_folio(), do_async_mmap_readahead(), filemap_fault()
  • Data Structures and Fields: struct file (f_ra), struct file_ra_state (ra_pages)

2. Root Cause and Mechanism

struct file_ra_state is embedded inside each struct file (file->f_ra) to maintain readahead context and heuristics for that open file description. When multiple threads or processes map the same open file and take concurrent page faults, they share this file->f_ra instance without per-file synchronization.

  1. Write Path (shrink_readahead_size_eio): When an I/O error occurs while reading a folio from a backing device (as indicated by the loop device error in the report: Buffer I/O error on dev loop5... attempt to access beyond end of device), filemap_read_folio() determines that the folio could not be made up-to-date and calls:

    static void shrink_readahead_size_eio(struct file_ra_state *ra)
    {
        ra->ra_pages /= 4;
    }
    

    This performs an unsynchronized read-modify-write on ra->ra_pages to reduce the readahead window and avoid thrashing on media errors.

  2. Read Path (do_async_mmap_readahead): Concurrently, another thread executing filemap_fault() on a mapping of the same struct file enters do_async_mmap_readahead(), which inspects:

    /* If we don't want any read-ahead, don't bother */
    if (vmf->vma->vm_flags & VM_RAND_READ || !ra->ra_pages)
        return fpin;
    

    and subsequently passes ra->ra_pages to page_cache_async_ra().

  3. Concurrency Defect: Neither shrink_readahead_size_eio() nor do_async_mmap_readahead() takes a lock or uses atomic primitives/marked memory access operations (e.g., READ_ONCE() / WRITE_ONCE(), which are used for other fields in file_ra_state such as mmap_miss). Because one thread performs an unsynchronized write while another performs an unsynchronized read to the exact same 4-byte address ra->ra_pages, KCSAN detects and reports a data race.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
1f3e4f42 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in filemap_fault / filemap_read_folio (2) 2026/11/18 16:31 2026/11/18 16:31 2026/11/18 16:37 2006bdcc
25bcd2f8 assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in filemap_fault / filemap_read_folio (2) 2026/11/18 16:29 2026/11/18 16:29 2026/11/18 17:13 2006bdcc
▶ ▼ Similar bugs (1)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in filemap_fault / filemap_read_folio race:benign prio:low mm 6 1 181d 181d 0/29 auto-obsoleted due to no activity on 2026/07/16 07:42

Sample crash report:
loop5: rw=8388608, sector=57847, nr_sectors = 1 limit=8192
Buffer I/O error on dev loop5, logical block 57847, async page read
syz.5.265: attempt to access beyond end of device
loop5: rw=8388608, sector=57847, nr_sectors = 1 limit=8192
Buffer I/O error on dev loop5, logical block 57847, async page read
==================================================================
BUG: KCSAN: data-race in filemap_fault / filemap_read_folio

read to 0xffff88811c0e48d8 of 4 bytes by task 4492 on cpu 0:
 do_async_mmap_readahead mm/filemap.c:3479 [inline]
 filemap_fault+0x1bd/0xab0 mm/filemap.c:3600
 __do_fault mm/memory.c:5677 [inline]
 do_shared_fault mm/memory.c:6176 [inline]
 do_fault mm/memory.c:6250 [inline]
 do_pte_missing mm/memory.c:4778 [inline]
 handle_pte_fault mm/memory.c:6665 [inline]
 __handle_mm_fault mm/memory.c:6817 [inline]
 handle_mm_fault+0x24e5/0x3880 mm/memory.c:6984
 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

read-write to 0xffff88811c0e48d8 of 4 bytes by task 4493 on cpu 0:
 shrink_readahead_size_eio mm/filemap.c:2486 [inline]
 filemap_read_folio+0x120/0x150 mm/filemap.c:2561
 filemap_fault+0x66b/0xab0 mm/filemap.c:3706
 __do_fault mm/memory.c:5677 [inline]
 do_read_fault mm/memory.c:6112 [inline]
 do_fault mm/memory.c:6246 [inline]
 do_pte_missing mm/memory.c:4778 [inline]
 handle_pte_fault mm/memory.c:6665 [inline]
 __handle_mm_fault mm/memory.c:6817 [inline]
 handle_mm_fault+0x2183/0x3880 mm/memory.c:6984
 faultin_page mm/gup.c:1130 [inline]
 __get_user_pages+0xf69/0x19e0 mm/gup.c:1432
 populate_vma_page_range+0x16b/0x1b0 mm/gup.c:1868
 __mm_populate+0x1b0/0x2c0 mm/gup.c:1971
 mm_populate include/linux/mm.h:4451 [inline]
 vm_mmap_pgoff+0x272/0x320 mm/util.c:586
 ksys_mmap_pgoff+0x250/0x310 mm/mmap.c:619
 x64_sys_call+0x23b3/0x2550 arch/x86/include/generated/asm/syscalls_64.h:10
 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: 4493 Comm: syz.5.265 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:30 upstream 666539eecdf4 122f94d5 .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in filemap_fault / filemap_read_folio
2026/11/17 08:33 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in filemap_fault / filemap_read_folio
* Struck through repros no longer work on HEAD.