From: Yang Wen <anmuxixixi@gmail.com>
To: linkinjeon@kernel.org, sj1557.seo@samsung.com
Cc: yuezhang.mo@sony.com, exfat@lists.linux.dev,
linux-kernel@vger.kernel.org, Yang Wen <anmuxixixi@gmail.com>
Subject: [PATCH] exfat: fix overflow in cluster-to-dentry conversion
Date: Tue, 28 Jul 2026 23:07:04 +0800 [thread overview]
Message-ID: <20260728150704.314251-1-anmuxixixi@gmail.com> (raw)
The cluster-to-dentry calculation is performed as u32 and may overflow
and wrap around on large volumes. This can result in an incorrect
max_dentries value, causing readdir to stop early and omit directory
entries.
Cast nr_clusters to u64 before shifting to avoid the overflow.
Signed-off-by: Yang Wen <anmuxixixi@gmail.com>
---
fs/exfat/dir.c | 2 +-
fs/exfat/exfat_fs.h | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
index 4fd4ec52b8c0..ce5251ba9589 100644
--- a/fs/exfat/dir.c
+++ b/fs/exfat/dir.c
@@ -87,7 +87,7 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
exfat_bytes_to_cluster(sbi, i_size_read(inode)), ei->flags);
dentries_per_clu = sbi->dentries_per_clu;
- max_dentries = min(MAX_EXFAT_DENTRIES,
+ max_dentries = (unsigned int)min_t(u64, MAX_EXFAT_DENTRIES,
exfat_cluster_to_dentries(sbi, sbi->num_clusters));
clu_offset = exfat_dentries_to_cluster(sbi, dentry);
diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
index 1f020b041a3d..fa30ab9d8564 100644
--- a/fs/exfat/exfat_fs.h
+++ b/fs/exfat/exfat_fs.h
@@ -487,10 +487,10 @@ static inline u32 exfat_dentries_to_bytes(u32 dentry)
/*
* helpers for cluster size to dentry size conversion.
*/
-static inline u32 exfat_cluster_to_dentries(struct exfat_sb_info *sbi,
+static inline u64 exfat_cluster_to_dentries(struct exfat_sb_info *sbi,
u32 nr_clusters)
{
- return nr_clusters << (sbi->cluster_size_bits - DENTRY_SIZE_BITS);
+ return (u64)nr_clusters << (sbi->cluster_size_bits - DENTRY_SIZE_BITS);
}
static inline u32 exfat_dentries_to_cluster(struct exfat_sb_info *sbi,
--
2.34.1
next reply other threads:[~2026-07-28 15:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 15:07 Yang Wen [this message]
2026-08-05 15:13 ` Yang Wen
2026-08-05 23:13 ` Namjae Jeon
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=20260728150704.314251-1-anmuxixixi@gmail.com \
--to=anmuxixixi@gmail.com \
--cc=exfat@lists.linux.dev \
--cc=linkinjeon@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®