From: sashiko-bot@kernel.org
To: "Theodore Ts'o" <tytso@mit.edu>,
"Ext4 Developers List" <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH 22/27] ext4: add KUnit tests for fs/ext4/indirect.c
Date: Thu, 12 Nov 2026 04:46:00 +0000 [thread overview]
Message-ID: <sashiko-outbox-210391@kernel.org> (raw)
In-Reply-To: <20261112040638.1576836-23-tytso@mit.edu>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ext4: indirect-test: UAF in ind_test_free_inode() after RCU
grace period
- [Low] ext4: uncleaned percpu_counter and uninited work/timer in
ind_test_init()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] ext4: incomplete error check in ext4_ind_map_blocks() [1]
--
commit ebeb5ffec6cf1b1539b939ab7329a1923d9ae24c
Author: Theodore Ts'o <tytso@mit.edu>
ext4: add KUnit tests for fs/ext4/indirect.c
This commit adds the ext4_indirect_test KUnit test suite for indirect block
mapping, truncation, and hole punching, and routes indirect block buffer
lookups through ext4_sb_getblk().
> diff --git a/fs/ext4/indirect-test.c b/fs/ext4/indirect-test.c
> new file mode 100644
> index 0000000000000..add5662adc3ba
> --- /dev/null
> +++ b/fs/ext4/indirect-test.c
[ ... ]
> +static void ind_test_free_inode(struct inode *inode)
> +{
> + ext4_es_remove_extent(inode, 0, EXT_MAX_BLOCKS);
> + kfree(EXT4_I(inode));
> +}
> +
> +static void ind_test_evict_inode(struct inode *inode)
> +{
> + truncate_inode_pages_final(&inode->i_data);
> + clear_inode(inode);
> +}
[Severity: Medium]
Can ind_test_free_inode() trigger a use-after-free on ctx->sbi after the
test finishes?
At the end of each test, iput() runs ind_test_evict_inode() synchronously
and queues i_callback() -> ind_test_free_inode() via call_rcu(). KUnit
then runs ind_test_cleanup() without an rcu_barrier() and frees ctx, so
when the RCU callback later runs ext4_es_remove_extent(), it dereferences
EXT4_SB(inode->i_sb) inside the freed ctx.
Moving ext4_es_remove_extent() into ind_test_evict_inode() and calling
rcu_barrier() in ind_test_cleanup() before deactivating sb would avoid
this.
[ ... ]
> +static void ind_test_cleanup(struct ind_test_ctx *ctx)
> +{
> + struct super_block *sb = ctx->sb;
> + struct ext4_sb_info *sbi = &ctx->sbi;
> + struct ind_mock_blk *blk, *tmp;
> +
> + if (sb) {
> + cancel_work_sync(&sbi->s_sb_upd_work);
> + timer_delete_sync(&sbi->s_err_report);
> + }
> +
> + if (ctx->es_shrinker_inited) {
> + ext4_es_unregister_shrinker(sbi);
> + ctx->es_shrinker_inited = false;
> + }
> +
> + if (ctx->counters_inited) {
> + percpu_counter_destroy(&sbi->s_freeclusters_counter);
> + percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
> + percpu_counter_destroy(&sbi->s_freeinodes_counter);
> + ctx->counters_inited = false;
> + }
[ ... ]
> + ctx->sb = sb;
> + up_write(&sb->s_umount);
> +
> + ret = kunit_add_action_or_reset(test, ind_test_cleanup_action, ctx);
> + KUNIT_ASSERT_EQ(test, ret, 0);
[ ... ]
> + INIT_WORK(&sbi->s_sb_upd_work, ind_test_sb_upd_work);
> + timer_setup(&sbi->s_err_report, ind_test_err_timer, 0);
[ ... ]
> + ret = percpu_counter_init(&sbi->s_freeclusters_counter, 4096,
> + GFP_KERNEL);
> + KUNIT_ASSERT_EQ(test, ret, 0);
> + ret = percpu_counter_init(&sbi->s_dirtyclusters_counter, 0, GFP_KERNEL);
> + KUNIT_ASSERT_EQ(test, ret, 0);
> + ret = percpu_counter_init(&sbi->s_freeinodes_counter, 200, GFP_KERNEL);
> + KUNIT_ASSERT_EQ(test, ret, 0);
> + ctx->counters_inited = true;
[Severity: Low]
If the second or third percpu_counter_init() fails, does KUNIT_ASSERT_EQ()
abort while ctx->counters_inited is still false? ind_test_cleanup() then
skips percpu_counter_destroy(), leaking the earlier counter and leaving it
linked in the global percpu_counters list when ctx is freed.
Also, ctx->sb is set before kunit_add_action_or_reset(), whereas
s_sb_upd_work and s_err_report are initialized later, so if
kunit_add_action_or_reset() fails, ind_test_cleanup() calls
cancel_work_sync() and timer_delete_sync() on uninitialized structures.
[ ... ]
> diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
> index 5aec759eed705..5b2b2be73a90a 100644
> --- a/fs/ext4/indirect.c
> +++ b/fs/ext4/indirect.c
> @@ -163,7 +163,7 @@ static Indirect *ext4_get_branch(struct inode *inode, int depth,
> ret = -EFSCORRUPTED;
> goto failure;
> }
> - bh = sb_getblk(sb, key);
> + bh = ext4_sb_getblk(sb, key);
> if (unlikely(!bh)) {
> ret = -ENOMEM;
> goto failure;
[Severity: Critical]
This problem wasn't introduced by this patch, but when ext4_get_branch()
fails with -EFSCORRUPTED or -ENOMEM [1], doesn't
ext4_ind_map_blocks() miss the error when EXT4_GET_BLOCKS_CREATE is set?
fs/ext4/indirect.c:ext4_ind_map_blocks() {
...
/* Failed read of indirect block */
if (err == -EIO)
goto cleanup;
...
}
Because ext4_ind_map_blocks() only checks for err == -EIO, it treats the
partial chain returned on -ENOMEM or -EFSCORRUPTED as a hole, allocates new
blocks, and splices them over the existing indirect block pointer,
orphaning the original subtree and corrupting the file.
[1] https://sashiko.dev/#/bug/linux-2bfbc9ba-6121-45d3-a664-11e7452ad5d6
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261112040638.1576836-1-tytso@mit.edu?part=22
next prev parent reply other threads:[~2026-11-12 4:46 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 4:06 [PATCH 00/27] ext4: add lots of KUnit tests! Theodore Ts'o
2026-11-12 4:06 ` [PATCH 01/27] ext4: add KUinit tests for fs/ext4/extents_status.c Theodore Ts'o
2026-11-12 4:18 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 02/27] ext4: add KUnit tests for fs/ext4/extents.c Theodore Ts'o
2026-11-12 4:28 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 03/27] ext4: add KUnit tests for ext4_ext_split() leaf and index splitting Theodore Ts'o
2026-11-12 4:15 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 04/27] ext4: add KUnit tests for fs/ext4/xattr.c Theodore Ts'o
2026-11-12 4:26 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 05/27] ext4: add KUnit tests for fs/ext4/namei.c Theodore Ts'o
2026-11-12 4:21 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 06/27] ext4: expand KUnit tests for fs/ext4/mballoc.c Theodore Ts'o
2026-11-12 4:26 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 07/27] ext4: add KUnit tests for fs/ext4/inline.c Theodore Ts'o
2026-11-12 4:29 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 08/27] ext4: zero s_fc_replay_state in ext4_fc_replay_cleanup() Theodore Ts'o
2026-11-12 4:16 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 09/27] ext4: add KUnit tests for fs/ext4/fast_commit.c Theodore Ts'o
2026-11-12 4:28 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 10/27] ext4: expand KUnit tests for fs/ext4/inode.c Theodore Ts'o
2026-11-12 4:36 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 11/27] ext4: add KUnit tests for fs/ext4/ialloc.c Theodore Ts'o
2026-11-12 4:25 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 12/27] ext4: add KUnit tests for fs/ext4/balloc.c Theodore Ts'o
2026-11-12 4:16 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 13/27] ext4: add KUnit tests for fs/ext4/orphan.c Theodore Ts'o
2026-11-12 4:18 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 14/27] ext4: add KUnit tests for fs/ext4/block_validity.c Theodore Ts'o
2026-11-12 4:21 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 15/27] ext4: check multi-block overlap on left traversal in add_system_zone() Theodore Ts'o
2026-11-12 4:10 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 16/27] ext4: enable full feature coverage in fs/ext4/.kunitconfig Theodore Ts'o
2026-11-12 4:24 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 17/27] ext4: add KUnit tests for fs/ext4/super.c Theodore Ts'o
2026-11-12 4:27 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 18/27] ext4: add KUnit tests for fs/ext4/sysfs.c Theodore Ts'o
2026-11-12 4:32 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 19/27] ext4: add KUnit tests for fs/ext4/ioctl.c Theodore Ts'o
2026-11-12 4:35 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 20/27] ext4: add KUnit tests for fs/ext4/resize.c Theodore Ts'o
2026-11-12 4:34 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 21/27] ext4: add KUnit tests for fs/ext4/migrate.c Theodore Ts'o
2026-11-12 4:37 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 22/27] ext4: add KUnit tests for fs/ext4/indirect.c Theodore Ts'o
2026-11-12 4:46 ` sashiko-bot [this message]
2026-11-12 4:06 ` [PATCH 23/27] ext4: expand KUnit tests in fs/ext4/extents-test.c for file range operations Theodore Ts'o
2026-11-12 4:34 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 24/27] ext4: add KUnit tests for fs/ext4/fsmap.c Theodore Ts'o
2026-11-12 4:30 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 25/27] ext4: add KUnit tests for fs/ext4/move_extent.c Theodore Ts'o
2026-11-12 4:36 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 26/27] ext4: add KUnit tests for fs/ext4/mmp.c Theodore Ts'o
2026-11-12 4:29 ` sashiko-bot
2026-11-12 4:06 ` [PATCH 27/27] ext4: add KUnit tests for fs/ext4/dir.c Theodore Ts'o
2026-11-12 4:41 ` sashiko-bot
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-210391@kernel.org \
--to=sashiko-bot@kernel.org \
--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