syzbot
KCSAN: data-race in copy_folio_from_iter_atomic / fat12_ent_put (6)
Status:
moderation: reported on 2026/11/22 03:07
Subsystems:
exfat
Labels:
race:harmful
prio:low
[Documentation on labels]
Reported-by: syzbot+83d50d1501e6be09f23a@syzkaller.appspotmail.com
First crash: 1h55m, last: 1h55m
✨ AI-generated root cause summary:
fat12_ent_put() in fs/fat/fatent.c modifies FAT table buffer_head data (fatent->bhs[0]->b_data and, for block-spanning entries, fatent->bhs[1]->b_data) without acquiring lock_buffer(). Because block device writeback (blkdev_writepages() -> block_write_full_folio() / write_dirty_buffer()) relies on lock_buffer() to synchronize buffer modifications against in-flight write bios, fat12_ent_put() can overwrite bh->b_data concurrently while the block driver (here loop1 via lo_rw_aio() -> shmem_file_write_iter() -> copy_folio_from_iter_atomic()) is reading the buffer for an ongoing writeback I/O.
▶
▼
✨ Full AI root cause analysis
Root Cause Analysis
The KCSAN data race is caused by fat12_ent_put() in fs/fat/fatent.c modifying a struct buffer_head's data (bh->b_data) in the block device's page cache without holding the buffer lock (lock_buffer(bh)), racing with ongoing block-device writeback of the same buffer.
Synchronization Invariant Violated
Filesystems that store metadata buffers in the underlying block device's address_space (bdev->bd_mapping) rely on the BH_Lock bit (lock_buffer() / unlock_buffer()) to serialize modifications to bh->b_data against writeback:
- In
block/fops.c, blkdev_writepages() calls block_write_full_folio() (__block_write_full_folio() in fs/buffer.c), specifically noting that the buffer lock provides the synchronization with writeback.
__block_write_full_folio() (as well as write_dirty_buffer() / __sync_dirty_buffer() in fs/buffer.c) acquires lock_buffer(bh), clears BH_Dirty, and submits the REQ_OP_WRITE bio (__bh_submit() / bh_submit()). BH_Lock remains held until I/O completion (bh_end_async_write() / bh_end_write()), ensuring bh->b_data stays stable while the block driver reads it.
How the Race Occurs
- Writeback read path (CPU 1, task 33):
A previously dirtied FAT12 metadata
buffer_head (at 0xffff8881074bf400, 1024 bytes) undergoes writeback. Writeback locks the buffer_head, clears BH_Dirty, and submits a write bio to loop1. The loop worker (loop_workfn -> loop_process_work -> loop_handle_cmd -> do_req_filebacked -> lo_rw_aio() in drivers/block/loop.c) builds an ITER_SOURCE bvec iov_iter over the bio's folio/buffer (bh->b_data) and passes it to shmem_file_write_iter() -> generic_perform_write() -> copy_folio_from_iter_atomic(), reading the 1024-byte block at 0xffff8881074bf400.
- Concurrent FAT12 write path (CPU 0, task 4984):
A
write() on a file in the FAT12 filesystem triggers fat_write_begin() -> cont_write_begin() -> block_write_begin() -> __block_write_begin_int() -> fat_get_block() -> __fat_get_block() -> fat_add_clusters() -> fat_alloc_chain() -> __fat_alloc_clusters() (fs/fat/fatent.c:506).
__fat_alloc_clusters() acquires lock_fat(sbi) (which only serializes FAT table callers, not block-device writeback) and obtains fatent->bhs[0] via fat_ent_read_block() -> fat12_ent_bread() -> sb_bread(). Since the buffer is already uptodate in bdev->bd_mapping, sb_bread() returns it unlocked without waiting on ongoing writeback.
- At
fs/fat/fatent.c:542, ops->ent_put(&fatent, FAT_ENT_EOF) invokes fat12_ent_put() (fs/fat/fatent.c:156).
fat12_ent_put() only takes the spinlock fat12_entry_lock and writes directly to *ent12_p[0] (0xffff8881074bf418, offset 0x18 within the same bh->b_data, line 168) and *ent12_p[1] before calling mmb_mark_buffer_dirty(). Because lock_buffer() is never called, fat12_ent_put() does not wait for the in-flight write bio holding BH_Lock, producing the concurrent write/read data race on bh->b_data.
Notes on Related Code
fat16_ent_put() (fs/fat/fatent.c:180) and fat32_ent_put() (fs/fat/fatent.c:190) exhibit the same pattern of modifying fatent->bhs[0]->b_data without lock_buffer().
- Note that
fat12_ent_put() currently holds spin_lock(&fat12_entry_lock) around the byte updates, so lock_buffer() (which can sleep) cannot simply be nested inside fat12_entry_lock; lock_buffer() would need to be acquired outside fat12_entry_lock (and note fatent->nr_bhs == 2 for block-spanning FAT12 entries, where bhs[0] and bhs[1] would need consistent lock ordering).
- By contrast,
fat_mirror_bhs() (fs/fat/fatent.c:398) already uses lock_buffer(c_bh) / unlock_buffer(c_bh) around memcpy(c_bh->b_data, ...).
Sample crash report:
==================================================================
BUG: KCSAN: data-race in copy_folio_from_iter_atomic / fat12_ent_put
write to 0xffff8881074bf418 of 1 bytes by task 4984 on cpu 0:
fat12_ent_put+0x74/0x180 fs/fat/fatent.c:168
__fat_alloc_clusters+0x571/0xdc0 fs/fat/fatent.c:542
fat_alloc_chain+0x25/0x30 fs/fat/fatent.c:610
fat_add_clusters fs/fat/inode.c:109 [inline]
__fat_get_block fs/fat/inode.c:156 [inline]
fat_get_block+0x276/0x650 fs/fat/inode.c:191
__block_write_begin_int+0x459/0x1070 fs/buffer.c:2043
block_write_begin fs/buffer.c:2157 [inline]
cont_write_begin+0x4af/0x6c0 fs/buffer.c:2519
fat_write_begin+0x52/0xf0 fs/fat/inode.c:233
generic_perform_write+0x198/0x510 mm/filemap.c:4407
__generic_file_write_iter+0x9e/0x120 mm/filemap.c:4524
generic_file_write_iter+0x77/0x1f0 mm/filemap.c:4550
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
read to 0xffff8881074bf400 of 1024 bytes by task 33 on cpu 1:
memcpy_from_iter lib/iov_iter.c:85 [inline]
iterate_bvec include/linux/iov_iter.h:123 [inline]
iterate_and_advance2 include/linux/iov_iter.h:306 [inline]
iterate_and_advance include/linux/iov_iter.h:332 [inline]
__copy_from_iter lib/iov_iter.c:261 [inline]
copy_folio_from_iter_atomic+0x73a/0x1050 lib/iov_iter.c:491
generic_perform_write+0x34b/0x510 mm/filemap.c:4425
shmem_file_write_iter+0xc5/0xf0 mm/shmem.c:3701
lo_rw_aio+0x6e9/0x7a0 drivers/block/loop.c:-1
do_req_filebacked drivers/block/loop.c:-1 [inline]
loop_handle_cmd drivers/block/loop.c:1847 [inline]
loop_process_work+0x569/0xb00 drivers/block/loop.c:1882
loop_workfn+0x31/0x40 drivers/block/loop.c:1906
process_one_work kernel/workqueue.c:3495 [inline]
process_scheduled_works+0x582/0xab0 kernel/workqueue.c:3578
worker_thread+0x56c/0x770 kernel/workqueue.c:3659
kthread+0x248/0x2a0 kernel/kthread.c:436
ret_from_fork+0x146/0x330 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 UID: 0 PID: 33 Comm: kworker/u8:1 Not tainted syzkaller #0 PREEMPT(lazy)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
Workqueue: loop1 loop_workfn
==================================================================
netdevsim netdevsim1 netdevsim3 (unregistering): unset [1, 0] type 2 family 0 port 6081 - 0
netdevsim netdevsim1 netdevsim2 (unregistering): unset [1, 0] type 2 family 0 port 6081 - 0
netdevsim netdevsim1 netdevsim1 (unregistering): unset [1, 0] type 2 family 0 port 6081 - 0
netdevsim netdevsim1 netdevsim0 (unregistering): unset [1, 0] type 2 family 0 port 6081 - 0
bond0 (unregistering): Released all slaves
hsr_slave_0: left promiscuous mode
hsr_slave_1: left promiscuous mode
veth1_macvtap: left promiscuous mode
veth0_macvtap: left promiscuous mode
veth1_vlan: left promiscuous mode
veth0_vlan: left promiscuous mode
netdevsim netdevsim4 netdevsim3 (unregistering): unset [1, 0] type 2 family 0 port 6081 - 0
netdevsim netdevsim4 netdevsim2 (unregistering): unset [1, 0] type 2 family 0 port 6081 - 0
netdevsim netdevsim4 netdevsim1 (unregistering): unset [1, 0] type 2 family 0 port 6081 - 0
netdevsim netdevsim4 netdevsim0 (unregistering): unset [1, 0] type 2 family 0 port 6081 - 0
bridge_slave_1: left allmulticast mode
bridge_slave_1: left promiscuous mode
bridge0: port 2(bridge_slave_1) entered disabled state
bridge_slave_0: left allmulticast mode
bridge_slave_0: left promiscuous mode
bridge0: port 1(bridge_slave_0) entered disabled state
bond0 (unregistering): (slave bond_slave_0): Releasing backup interface
bond_slave_0: left promiscuous mode
bond0 (unregistering): (slave bond_slave_1): Releasing backup interface
bond_slave_1: left promiscuous mode
bond0 (unregistering): Released all slaves
hsr_slave_0: left promiscuous mode
hsr_slave_1: left promiscuous mode
batman_adv: batadv0: Interface deactivated: batadv_slave_0
batman_adv: batadv0: Removing interface: batadv_slave_0
batman_adv: batadv0: Interface deactivated: batadv_slave_1
batman_adv: batadv0: Removing interface: batadv_slave_1
veth1_macvtap: left promiscuous mode
veth0_macvtap: left promiscuous mode
veth1_vlan: left promiscuous mode
veth0_vlan: left promiscuous mode
team0 (unregistering): Port device team_slave_1 removed
team0 (unregistering): Port device team_slave_0 removed
* Struck through repros no longer work on HEAD.