From: sashiko-bot@kernel.org
To: "Theodore Ts'o" <tytso@mit.edu>,
"Ext4 Developers List" <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH 09/27] ext4: add KUnit tests for fs/ext4/fast_commit.c
Date: Thu, 12 Nov 2026 04:28:32 +0000 [thread overview]
Message-ID: <sashiko-outbox-210338@kernel.org> (raw)
In-Reply-To: <20261112040638.1576836-10-tytso@mit.edu>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] ext4: uninitialized j_trans_commit_map in
fast_commit_test_init()
- [Medium] ext4: excessive stack frame size in fast_commit-test.c test
cases
- [Low] ext4: resource leak and UAF on abort in fast_commit_test_init()
and cleanup
--
commit 0a44fff123afc676ec0d455ddc174806f24be58f
Author: Theodore Ts'o <tytso@mit.edu>
ext4: add KUnit tests for fs/ext4/fast_commit.c
This commit adds the ext4_fast_commit_test KUnit test suite in
fs/ext4/fast_commit-test.c and exports fast commit helpers and static stub
hooks in fs/ext4/fast_commit.c and related files.
> diff --git a/fs/ext4/fast_commit-test.c b/fs/ext4/fast_commit-test.c
> new file mode 100644
> index 0000000000000..57745e51bea67
> --- /dev/null
> +++ b/fs/ext4/fast_commit-test.c
[ ... ]
> +/* --- Suite Setup & Teardown --- */
> +
> +static void fc_cleanup_all(void *priv)
> +{
> + struct fc_test_ctx *ctx = priv;
> + int i;
> +
> + ctx->sbi->s_mount_state &= ~EXT4_FC_REPLAY;
> + ext4_fc_cleanup_test(&ctx->journal, 1, 999999);
> + ext4_fc_replay_cleanup(ctx->sb);
> +
> + for (i = 0; i < TEST_MAX_INODES; i++) {
> + if (!ctx->inodes[i].allocated)
> + continue;
> + down_write(&ctx->inodes[i].ei.i_data_sem);
> + ext4_es_remove_extent(&ctx->inodes[i].ei.vfs_inode, 0,
> + EXT_MAX_BLOCKS);
> + up_write(&ctx->inodes[i].ei.i_data_sem);
> + ext4_fc_free_inode_snap_test(&ctx->inodes[i].ei.vfs_inode);
> + }
> +
> + ext4_es_unregister_shrinker(ctx->sbi);
> + deactivate_super(ctx->sb);
> +}
> +
> +static int fast_commit_test_init(struct kunit *test)
> +{
> + struct fc_test_ctx *ctx;
> + struct ext4_sb_info *sbi;
> + struct super_block *sb;
> + struct fs_context *fc;
> + int i, err;
> +
> + ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx);
> +
> + sbi = kunit_kzalloc(test, sizeof(*sbi), GFP_KERNEL);
> + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, sbi);
> +
> + fc = fs_context_for_mount(&fc_fs_type, 0);
> + KUNIT_ASSERT_FALSE(test, IS_ERR(fc));
> + sb = sget_fc(fc, NULL, fc_set_anon);
> + put_fs_context(fc);
> + KUNIT_ASSERT_FALSE(test, IS_ERR(sb));
[ ... ]
> + up_write(&sb->s_umount);
> +
> + err = ext4_es_register_shrinker(sbi);
> + KUNIT_ASSERT_EQ(test, err, 0);
> + ctx->shrinker_count = sbi->s_es_shrinker->count_objects;
> + ctx->shrinker_scan = sbi->s_es_shrinker->scan_objects;
> + WRITE_ONCE(sbi->s_es_shrinker->count_objects, fc_dummy_shrinker_count);
> + WRITE_ONCE(sbi->s_es_shrinker->scan_objects, fc_dummy_shrinker_scan);
> +
> + /* Mock journal, running transaction, and handle setup */
> + rwlock_init(&ctx->journal.j_state_lock);
> + spin_lock_init(&ctx->journal.j_list_lock);
> + mutex_init(&ctx->journal.j_barrier);
[Severity: Medium]
Does fast_commit_test_init() leave ctx->journal.j_trans_commit_map
uninitialized?
ctx is heap-allocated with kunit_kzalloc(). When test_fc_commit_paths()
calls ext4_fc_commit() -> ext4_fc_perform_commit() ->
jbd2_journal_lock_updates(), jbd2_might_wait_for_commit() passes
&ctx->journal.j_trans_commit_map to rwsem_acquire() and rwsem_release().
With CONFIG_LOCKDEP enabled, its NULL key in non-static memory triggers
"INFO: trying to register non-static key" and turns off lockdep via
debug_locks_off().
[ ... ]
> + kunit_activate_static_stub(test, ext4_fc_submit_bh,
> + stub_fc_submit_bh);
> + kunit_activate_static_stub(test, ext4_fc_issue_flush,
> + stub_fc_issue_flush);
> +
> + init_mock_inode_slot(ctx, &ctx->inodes[0], TEST_ROOT_INO,
> + S_IFDIR | 0755);
> + init_mock_inode_slot(ctx, &ctx->inodes[1], TEST_DIR_INO,
> + S_IFDIR | 0755);
> + init_mock_inode_slot(ctx, &ctx->inodes[2], TEST_FILE1_INO,
> + S_IFREG | 0644);
> + init_mock_inode_slot(ctx, &ctx->inodes[3], TEST_FILE2_INO,
> + S_IFREG | 0644);
> + init_mock_inode_slot(ctx, &ctx->inodes[4], TEST_SUBDIR_INO,
> + S_IFDIR | 0755);
> +
> + err = kunit_add_action_or_reset(test, fc_cleanup_all, ctx);
> + KUNIT_ASSERT_EQ(test, err, 0);
> +
> + return 0;
> +}
[Severity: Low]
Can an assertion failure in fast_commit_test_init() leak sb and leave
sbi->s_es_shrinker and sbi->s_es_stats percpu_counters registered after
KUnit frees sbi?
fc_cleanup_all() is only registered after ext4_es_register_shrinker() and
all the kunit_activate_static_stub() calls, which themselves assert on
allocation failure. Aborting in that window skips deactivate_super(sb) and
ext4_es_unregister_shrinker(sbi), causing a use-after-free once the
kunit_kzalloc()-allocated sbi is freed.
Also, in fc_cleanup_all(), calling ext4_fc_cleanup_test() only once drains
FC_Q_MAIN before splicing FC_Q_STAGING into FC_Q_MAIN, so any
ext4_fc_dentry_update entries on s_fc_dentry_q[FC_Q_STAGING] when a test
aborts are leaked.
> +
> +/* =========================================================================
> + * 1. Initialization, Eligibility, and Snapshot Stat Helpers
> + * =========================================================================
> + */
> +
> +static void test_fc_init_and_eligibility(struct kunit *test)
> +{
> + struct fc_test_ctx *ctx = test->priv;
> + struct super_block *sb = ctx->sb;
> + struct inode *inode = get_mock_inode(ctx, TEST_FILE1_INO);
> + struct ext4_inode_info *ei = EXT4_I(inode);
> + journal_t tmp_journal = {};
[Severity: Medium]
Does allocating tmp_journal on the stack here (and five struct dentry
objects on the stack in test_fc_replay_inode_and_dentries()) exceed
CONFIG_FRAME_WARN?
journal_t is over 1.3 KB (and over 2.2 KB with CONFIG_LOCKDEP enabled), and
the five dentries in test_fc_replay_inode_and_dentries() take ~1.6 KB with
CONFIG_LOCKDEP, triggering -Wframe-larger-than warnings or build failures
under CONFIG_WERROR. Could tmp_journal and the mock dentries be allocated
with kunit_kzalloc() or moved into struct fc_test_ctx?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261112040638.1576836-1-tytso@mit.edu?part=9
next prev parent reply other threads:[~2026-11-12 4:28 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 [this message]
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
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-210338@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 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.