* [PATCH] exfat: reject cluster counts above the exFAT maximum
@ 2026-11-29 13:53 Andrew Stellman
0 siblings, 0 replies; only message in thread
From: Andrew Stellman @ 2026-11-29 13:53 UTC (permalink / raw)
To: Namjae Jeon, Sungjong Seo; +Cc: Yuezhang Mo, exfat, linux-fsdevel, linux-kernel
From: Andrew Stellman <astellman@stellman-greene.com>
exfat_read_boot_sector() adds the two reserved clusters to the on-disk
ClusterCount without a range check, so a ClusterCount of 0xffffffff
wraps num_clusters to 1, and the FAT length check that follows uses the
wrapped value. With a crafted 64 MiB image, a read-only mount got as
far as the allocation bitmap size check, which reported a required size
of 536870912 bytes, before failing.
Reject a ClusterCount above EXFAT_MAX_NUM_CLUSTER before adding the
reserved clusters. This changes behavior for images with a
ClusterCount above that limit: the mount is now rejected at boot-sector
validation.
Tested in an arm64 QEMU guest with KASAN: the crafted image now fails
with "bogus cluster count", and an ordinary image mounts with and
without the patch.
The issue was found by Claude running Quality Playbook, an LLM-driven
code review tool:
https://github.com/andrewstellman/quality-playbook
The fix was drafted with OpenAI GPT-6 (Codex) and this changelog with
Claude Opus 5.5, and both were reviewed by me.
Fixes: 719c1e182916 ("exfat: add super block operations")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
A reproducer is available on request.
fs/exfat/super.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/fs/exfat/super.c b/fs/exfat/super.c
index 4943cef977418..762ebd14cb43a 100644
--- a/fs/exfat/super.c
+++ b/fs/exfat/super.c
@@ -444,6 +444,7 @@ static int exfat_read_boot_sector(struct super_block *sb)
{
struct boot_sector *p_boot;
struct exfat_sb_info *sbi = EXFAT_SB(sb);
+ u32 clu_count;
/* set block size to read super block */
if (!sb_min_blocksize(sb, 512)) {
@@ -514,9 +515,13 @@ static int exfat_read_boot_sector(struct super_block *sb)
sbi->data_start_sector = le32_to_cpu(p_boot->clu_offset);
sbi->data_start_bytes = sbi->data_start_sector << p_boot->sect_size_bits;
sbi->num_sectors = le64_to_cpu(p_boot->vol_length);
+ clu_count = le32_to_cpu(p_boot->clu_count);
+ if (clu_count > EXFAT_MAX_NUM_CLUSTER) {
+ exfat_err(sb, "bogus cluster count : %u", clu_count);
+ return -EINVAL;
+ }
/* because the cluster index starts with 2 */
- sbi->num_clusters = le32_to_cpu(p_boot->clu_count) +
- EXFAT_RESERVED_CLUSTERS;
+ sbi->num_clusters = clu_count + EXFAT_RESERVED_CLUSTERS;
sbi->root_dir = le32_to_cpu(p_boot->root_cluster);
sbi->dentries_per_clu_bits = sbi->cluster_size_bits - DENTRY_SIZE_BITS;
base-commit: bb13fcd7f4385fdf64340e5561a26bd951bc3d78
--
2.53.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-29 13:53 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 13:53 [PATCH] exfat: reject cluster counts above the exFAT maximum Andrew Stellman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®