Root Cause Analysis
1. Mechanism and Involved Entities
The KCSAN report detects a data race between an in-kernel metadata write in fat_set_state() (fs/fat/inode.c) and a concurrent userspace read from the underlying block device via _copy_to_iter() (lib/iov_iter.c).
-
Mount Path (Writer - CPU 0 / Task 8878):
When mounting a FAT filesystem, vfat_fill_super() calls fat_fill_super() (fs/fat/inode.c), which invokes fat_set_state(sb, 1, 0) at line 1880 to mark the filesystem as dirty on disk. fat_set_state() reads sector 0 using sb_bread(sb, 0). The resulting struct buffer_head *bh has its memory backed directly by the block device's page cache (sb->s_bdev->bd_mapping).
fat_set_state() then casts bh->b_data to struct fat_boot_sector *b and modifies b->fat32.state (or b->fat16.state):
if (is_fat32(sbi)) {
if (set)
b->fat32.state |= FAT_STATE_DIRTY;
...
In FAT32, b->fat32.state is a 1-byte (__u8) field located at offset 0x41 (65) within the 512-byte boot sector. This write directly touches the page cache folio memory at 0xffff88811c180041.
-
Userspace Read Path (Reader - CPU 1 / Task 3285 udevd):
Concurrently, udevd probes the newly attached or mounted block device by opening it read-only and issuing a read() for the first 512 bytes (sector 0).
The read path proceeds through:
ksys_read() -> vfs_read() -> blkdev_read_iter() (block/fops.c) -> filemap_read() (mm/filemap.c) -> copy_folio_to_iter() -> _copy_to_iter().
Because the folio containing sector 0 was already brought into the page cache and marked uptodate by sb_bread(), filemap_read() does not execute any I/O or take folio locks; it simply copies 512 bytes from the folio starting at 0xffff88811c180000 to user space using copy_to_user_iter().
-
Race Condition:
blkdev_read_iter() holds bd_inode->i_rwsem in shared mode, but filesystem operations updating buffer_head metadata through sb_bread() do not take bd_inode->i_rwsem, nor does fat_set_state() hold any buffer lock. Thus, fat_set_state() modifies byte 0x41 in place while _copy_to_iter() simultaneously reads the 512-byte buffer, triggering the KCSAN report.
Runtime Impact in Production
- Memory Corruption (
MemoryCorruption = false):
Neither thread performs out-of-bounds access, invalid frees, or pointer corruption. The write is a single-byte store to valid page cache memory, and the read is an in-bounds copy of valid page cache memory to userspace.
- Information Leak (
InfoLeak = "none"):
No uninitialized kernel memory or kernel pointers are exposed. The read merely copies on-disk filesystem boot sector data that userspace is already authorized to read.
- Denial of Service (
RawDenialOfService = false):
Single-byte reads and writes are atomic on x86 and modern architectures. The reader (udevd) will observe either the clean state (0x00) or the dirty state (0x01) in the undocumented mount state flag byte of the FAT boot sector. This has no adverse effect on system stability, causes no deadlock, panic, or resource leak, and is completely benign.