From: Andrew Stellman <bugs@stellman-greene.com>
To: Namjae Jeon <linkinjeon@kernel.org>,
Sungjong Seo <sj1557.seo@samsung.com>
Cc: Yuezhang Mo <yuezhang.mo@sony.com>,
exfat@lists.linux.dev, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] exfat: reject cluster counts above the exFAT maximum
Date: Sun, 29 Nov 2026 08:53:09 -0500 [thread overview]
Message-ID: <20261129135309.80871-1-bugs@stellman-greene.com> (raw)
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
reply other threads:[~2026-11-29 13:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261129135309.80871-1-bugs@stellman-greene.com \
--to=bugs@stellman-greene.com \
--cc=exfat@lists.linux.dev \
--cc=linkinjeon@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sj1557.seo@samsung.com \
--cc=yuezhang.mo@sony.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®