From: Zhang Yi <yizhang089@gmail.com>
To: sashiko-reviews@lists.linux.dev,
Zhang Yi <yi.zhang@huaweicloud.com>,
linux-ext4@vger.kernel.org
Cc: tytso@mit.edu
Subject: Re: [PATCH] ext4: fix extent status cache clearing when truncating inline data
Date: Wed, 14 Oct 2026 15:14:45 +0800 [thread overview]
Message-ID: <53a4ffd5-3ea5-483d-ac11-74b95b5d37ed@gmail.com> (raw)
In-Reply-To: <sashiko-outbox-170745@kernel.org>
On 10/14/2026 10:42 AM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] ext4: integer truncation of i_size in ext4_inline_data_truncate()
> --
>
> commit dadd6832c867f600a26266f1d17a57f7cfd12f24
> Author: Zhang Yi <yi.zhang@huawei.com>
> Subject: ext4: fix extent status cache clearing when truncating inline data
>
> This commit restricts the extent status cache clear range during inline data
> truncation. Instead of dropping the whole extent status tree, it clears only
> the blocks that are actually truncated away to prevent inconsistencies with
> dirty, mapped, and delayed buffers.
>
> Link: https://lore.kernel.org/linux-ext4/20261009103033.2920530-9-yi.zhang@huaweicloud.com/
> Link: https://lore.kernel.org/linux-ext4/6ac92a4c.70ed5d86.2ac85.0072.GAE@google.com/
>
>> diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
>> index ceee69a66482b..b630e56815bb5 100644
>> --- a/fs/ext4/inline.c
>> +++ b/fs/ext4/inline.c
> [ ... ]
>> @@ -1905,8 +1905,12 @@ int ext4_inline_data_truncate(struct inode *inode, int *has_inline)
>> * the extent status cache must be cleared to avoid leaving
>> * behind stale delayed allocated extent entries
>> */
>> - if (!ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA))
>> - ext4_es_remove_extent(inode, 0, EXT_MAX_BLOCKS);
>> + if (!ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
>> + ext4_lblk_t lblk = EXT4_B_TO_LBLK(inode, i_size);
>> +
>> + ext4_es_remove_extent(inode, lblk,
>> + EXT_MAX_BLOCKS - lblk);
>> + }
>
> [Severity: High]
> Does this calculation inadvertently drop valid delayed allocation extents on
> 32-bit architectures for files larger than 4GB?
>
> Looking at ext4_inline_data_truncate(), the local variable i_size is
> declared as a size_t:
>
> fs/ext4/inline.c:ext4_inline_data_truncate() {
> size_t i_size;
> ...
> i_size = inode->i_size;
> EXT4_I(inode)->i_disksize = i_size;
> ...
> }
>
> On 32-bit architectures, size_t is 32-bit, while inode->i_size is a 64-bit
> loff_t.
>
> If a file with inline data is extended beyond 4GB via a delayed allocation
> write, inode->i_size successfully updates to >4GB. A subsequent failed write
> past EOF (e.g., from ENOSPC) triggers ext4_truncate_failed_write(), which
> calls ext4_inline_data_truncate().
>
> Because i_size is a 32-bit size_t, the 64-bit inode->i_size wraps around
> (e.g., 4GB + 10 truncates to 10). When this patch uses the truncated i_size
> to calculate lblk, lblk incorrectly evaluates to a block near 0. This
> results in dropping valid delayed allocation extents across the entire >4GB
> file.
>
> Additionally, the preexisting code assigns this truncated 32-bit i_size to
> the 64-bit EXT4_I(inode)->i_disksize, corrupting the on-disk size. Should
> i_size be changed to loff_t to prevent both the incorrect extent removal
> introduced here, and the disk size corruption?
>
This is not reachable today. ext4_inline_data_truncate() is only called
from ext4_truncate() when the inode still has inline data, and ext4
keeps the size of such an inode below the inline capacity. Every path
that can grow the size past it converts the inline data to extents first,
which destroys the inline data, so the inode cannot carry inline data
any more. So a file that still has inline data when
ext4_inline_data_truncate() runs has a size of at most a few bytes.
That said, in the future it would indeed be more appropriate to change
i_size to loff_t, but this patch doesn't need it.
Thanks,
Yi.
next prev parent reply other threads:[~2026-10-14 7:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 2:17 [PATCH] ext4: fix extent status cache clearing when truncating inline data Zhang Yi
2026-10-14 2:42 ` sashiko-bot
2026-10-14 7:14 ` Zhang Yi [this message]
2026-10-14 16:27 ` Jan Kara
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=53a4ffd5-3ea5-483d-ac11-74b95b5d37ed@gmail.com \
--to=yizhang089@gmail.com \
--cc=linux-ext4@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tytso@mit.edu \
--cc=yi.zhang@huaweicloud.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