From: sashiko-bot@kernel.org
To: "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 02:42:46 +0000 [thread overview]
Message-ID: <sashiko-outbox-170745@kernel.org> (raw)
In-Reply-To: <20261014021714.2382353-1-yi.zhang@huaweicloud.com>
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?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261014021714.2382353-1-yi.zhang@huaweicloud.com?part=1
next prev parent reply other threads:[~2026-10-14 2:42 UTC|newest]
Thread overview: 3+ 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 [this message]
2026-10-14 7:14 ` Zhang Yi
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=sashiko-outbox-170745@kernel.org \
--to=sashiko-bot@kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.