From: Youling Tang <youling.tang@linux.dev>
To: Namjae Jeon <linkinjeon@kernel.org>,
Sungjong Seo <sj1557.seo@samsung.com>
Cc: Yuezhang Mo <yuezhang.mo@sony.com>,
Chi Zhiling <chizhiling@163.com>,
exfat@lists.linux.dev, linux-kernel@vger.kernel.org,
Youling Tang <tangyouling@kylinos.cn>,
stable@vger.kernel.org
Subject: [PATCH 1/2] exfat: fix iomap mapping when writeback races with truncate
Date: Fri, 13 Nov 2026 16:06:56 +0800 [thread overview]
Message-ID: <20261113080658.2440516-2-youling.tang@linux.dev> (raw)
In-Reply-To: <20261113080658.2440516-1-youling.tang@linux.dev>
From: Youling Tang <tangyouling@kylinos.cn>
__exfat_iomap_begin() reads i_size twice: once to detect a range that
starts beyond EOF, and once to clamp the mapping to EOF. A concurrent
truncate can shrink i_size between the two reads, so the clamp can
produce a negative length. The unsigned cluster index subtraction then
underflows, making exfat_map_cluster() believe it has to allocate a huge
number of clusters and report a hole.
Fix this by reading i_size once for both the EOF check and the
block-aligned clamp.
Fixes: 82a81a7352bc ("exfat: add iomap buffered I/O support")
Cc: stable@vger.kernel.org
Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
---
fs/exfat/iomap.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/fs/exfat/iomap.c b/fs/exfat/iomap.c
index 4e6f3ed9dcc8..11823591b3a8 100644
--- a/fs/exfat/iomap.c
+++ b/fs/exfat/iomap.c
@@ -51,8 +51,10 @@ static int __exfat_iomap_begin(struct inode *inode, loff_t offset, loff_t length
bool balloc = false;
if (!may_alloc) {
+ loff_t isize = i_size_read(inode);
+
/* Completely beyond EOF. Treat as hole */
- if (i_size_read(inode) <= offset) {
+ if (offset >= isize) {
iomap->type = IOMAP_HOLE;
iomap->addr = IOMAP_NULL_ADDR;
iomap->offset = offset;
@@ -61,9 +63,8 @@ static int __exfat_iomap_begin(struct inode *inode, loff_t offset, loff_t length
}
/* Clamp length if the requested range goes beyond i_size */
- if (offset + length > i_size_read(inode))
- length = round_up(i_size_read(inode),
- i_blocksize(inode)) - offset;
+ if (offset + length > isize)
+ length = round_up(isize, i_blocksize(inode)) - offset;
}
num_clusters = exfat_bytes_to_cluster_round_up(sbi,
--
2.43.0
next parent reply other threads:[~2026-11-13 8:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261113080658.2440516-1-youling.tang@linux.dev>
2026-11-13 8:06 ` Youling Tang [this message]
2026-11-13 8:06 ` [PATCH 2/2] exfat: don't map EXFAT_EOF_CLUSTER as a physical cluster Youling Tang
[not found] <20261113080013.2432300-1-youling.tang@linux.dev>
2026-11-13 8:00 ` [PATCH 1/2] exfat: fix iomap mapping when writeback races with truncate Youling Tang
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=20261113080658.2440516-2-youling.tang@linux.dev \
--to=youling.tang@linux.dev \
--cc=chizhiling@163.com \
--cc=exfat@lists.linux.dev \
--cc=linkinjeon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sj1557.seo@samsung.com \
--cc=stable@vger.kernel.org \
--cc=tangyouling@kylinos.cn \
--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