From: sashiko-bot@kernel.org
To: "Yichong Chen" <chenyichong@uniontech.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH] ext4: fix the logical block counter overflow in indirect migration
Date: Mon, 14 Sep 2026 07:18:53 +0000 [thread overview]
Message-ID: <20260914071853.ED58F1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260914065544.3438431-1-chenyichong@uniontech.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] The bounds check for `curr_block` incorrectly allows migrating a logical block at `EXT_MAX_BLOCKS` (`0xffffffff`), which is a reserved sentinel in extent trees.
Pre-existing issues:
- [Critical] Unbounded extent length accumulation in `update_extent_range()` leads to `ee_len` overflow and data corruption.
- [Critical] If journal credit extension fails after successfully swapping inode data, `tmp_inode` is evicted with its extent tree intact, erroneously freeing the migrated blocks.
--
commit 09fb778181d3ee108e977c6ec47d3771e863f54a
Author: Yichong Chen <chenyichong@uniontech.com>
ext4: fix the logical block counter overflow in indirect migration
update_tind_extent_range() advances lb->curr_block by max_entries *
max_entries for every empty triple-indirect slot. This fixes the block
counter overflow by keeping the counter in 64-bit and refusing migration
with -EOPNOTSUPP when a data block is found after the last logical block.
> diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c
> index c5e3fc998211a..dbf13d47aae4c 100644
> --- a/fs/ext4/migrate.c
> +++ b/fs/ext4/migrate.c
[ ... ]
> @@ -66,6 +66,10 @@ static int update_extent_range(handle_t *handle, struct inode *inode,
> ext4_fsblk_t pblock, struct migrate_struct *lb)
> {
> int retval;
> +
> + if (lb->curr_block > (ext4_lblk_t)-1)
> + return -EOPNOTSUPP;
> +
[Severity: High]
Does this bounds check correctly handle the EXT_MAX_BLOCKS sentinel?
Since EXT_MAX_BLOCKS is 0xffffffff, when lb->curr_block is exactly
0xffffffff, the condition 0xffffffff > 0xffffffff evaluates to false.
This successfully allows the logical block to be migrated and inserted into
the extent tree with ee_block = 0xffffffff, which subsequent block mapping
operations will reject with -EFSCORRUPTED.
Should this use >= to properly reject the EXT_MAX_BLOCKS sentinel?
> /*
> * See if we can add on to the existing range (if it exists)
> */
> if (lb->first_pblock &&
> (lb->last_pblock+1 == pblock) &&
> (lb->last_block+1 == lb->curr_block)) {
> lb->last_pblock = pblock;
> lb->last_block = lb->curr_block;
> lb->curr_block++;
> return 0;
> }
[Severity: Critical]
This is a pre-existing issue, but does this loop lack bounds checking against
the maximum extent length (EXT_INIT_MAX_LEN)?
Because contiguous blocks are accumulated here indefinitely, if the run of
blocks becomes > 32768, could this overflow the 16-bit ee_len field when
written in finish_range()?
fs/ext4/migrate.c:finish_range() {
...
newext.ee_len = cpu_to_le16(lb->last_block - lb->first_block + 1);
...
}
An overflow could set the MSB (0x8000), marking the extent as unwritten, or
wrap past 65535, truncating the length. This silently corrupts the migrated
file by replacing valid user data with zeros or unmapping it entirely.
[ ... ]
[Severity: Critical]
This is also a pre-existing issue, but what happens if journal credit
extension fails after successfully swapping inode data in ext4_ext_migrate()?
fs/ext4/migrate.c:ext4_ext_migrate() {
...
else {
retval = ext4_ext_swap_inode_data(handle, inode, tmp_inode);
if (retval)
free_ext_block(handle, tmp_inode);
}
retval = ext4_journal_ensure_credits(handle, 1, 0);
if (retval < 0)
goto out_stop;
...
}
If ext4_journal_ensure_credits() fails, the error path jumps to out_stop
without clearing tmp_inode's i_data array. Does this leave tmp_inode to
be evicted with its extent tree intact?
Since the extent tree now points to the original file's data blocks,
will this erroneously free the migrated blocks during tmp_inode eviction,
leading to a use-after-free and cross-file data corruption?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260914065544.3438431-1-chenyichong@uniontech.com?part=1
next prev parent reply other threads:[~2026-09-14 7:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 6:55 [PATCH] ext4: fix the logical block counter overflow in indirect migration Yichong Chen
2026-09-14 7:18 ` sashiko-bot [this message]
2026-09-14 7:38 ` Yichong Chen
2026-09-14 9:57 ` 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=20260914071853.ED58F1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=chenyichong@uniontech.com \
--cc=linux-ext4@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tytso@mit.edu \
/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