mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chi Zhiling <chizhiling@163.com>
To: Youling Tang <youling.tang@linux.dev>,
	Namjae Jeon <linkinjeon@kernel.org>,
	Sungjong Seo <sj1557.seo@samsung.com>
Cc: Yuezhang Mo <yuezhang.mo@sony.com>,
	exfat@lists.linux.dev, linux-kernel@vger.kernel.org,
	Youling Tang <tangyouling@kylinos.cn>,
	stable@vger.kernel.org
Subject: Re: [PATCH 1/2] exfat: fix iomap mapping when writeback races with truncate
Date: Fri, 13 Nov 2026 16:45:25 +0800	[thread overview]
Message-ID: <6e7fd20e-918a-49cd-9634-78fc01249825@163.com> (raw)
In-Reply-To: <20261113080658.2440516-2-youling.tang@linux.dev>

On 11/13/26 4:06 PM, Youling Tang wrote:
> 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>

Looks good to me:

Reviewed-by: Chi Zhiling <chizhiling@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,


  reply	other threads:[~2026-11-13  8:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13  8:06 [PATCH 0/2] exfat: fix iomap mapping vs truncate race Youling Tang
2026-11-13  8:06 ` [PATCH 1/2] exfat: fix iomap mapping when writeback races with truncate Youling Tang
2026-11-13  8:45   ` Chi Zhiling [this message]
2026-11-13  8:06 ` [PATCH 2/2] exfat: don't map EXFAT_EOF_CLUSTER as a physical cluster 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=6e7fd20e-918a-49cd-9634-78fc01249825@163.com \
    --to=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=youling.tang@linux.dev \
    --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®