]> git.ipfire.org Git - thirdparty/linux.git/commit
fat: reject BPB volumes whose data area starts beyond total sectors
authorSamuel Moelius <sam.moelius@trailofbits.com>
Fri, 5 Jun 2026 15:52:15 +0000 (15:52 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 17 Jun 2026 22:37:46 +0000 (15:37 -0700)
commit5108f4765637bd0ac5ea2897dc7d537486a09885
tree3e89137a491550641ed40cc68f6e972904093944
parentc7fdbc2c2f26b9c397eb3aad2fdc54dbd85f68e1
fat: reject BPB volumes whose data area starts beyond total sectors

fat_fill_super() subtracts sbi->data_start from the BPB total sector count
before computing the number of clusters.  A malformed image can declare a
total sector count smaller than data_start, causing the subtraction to
underflow and the mount code to derive a plausible cluster count from the
FAT length instead.

Reject such images before the subtraction.  In QEMU, a crafted FAT image
with total_sectors=2 and data_start=3 mounted successfully before the fix
and reading a file returned bytes stored past the BPB-declared end of the
volume.  With this change, the same image is rejected during mount.

Assisted-by: Codex:gpt-5.5-cyber-preview
Link: https://lore.kernel.org/20260605155216.2126545-1-sam.moelius@trailofbits.com
Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Christian Brauner <brauner@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/fat/inode.c