From: sashiko-bot@kernel.org
To: "Theodore Ts'o" <tytso@mit.edu>,
"Ext4 Developers List" <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH 11/27] ext4: add KUnit tests for fs/ext4/ialloc.c
Date: Thu, 12 Nov 2026 04:25:58 +0000 [thread overview]
Message-ID: <sashiko-outbox-210333@kernel.org> (raw)
In-Reply-To: <20261112040638.1576836-12-tytso@mit.edu>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ext4: UAF on super_block in ialloc_test_cleanup() from
undrained fserror work
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] ext4: missing error handling for blkdev_issue_flush() in
ext4_fc_commit() [1]
--
commit 52f553b981802c3fefc912614c6427cda362ae6f
Author: Theodore Ts'o <tytso@mit.edu>
ext4: add KUnit tests for fs/ext4/ialloc.c
This commit adds a KUnit test suite for fs/ext4/ialloc.c along with static
stub hooks and helper exports to test inode allocation, freeing, bitmap
validation, and lazy inode table initialization.
> diff --git a/fs/ext4/ialloc-test.c b/fs/ext4/ialloc-test.c
> new file mode 100644
> index 0000000000000..a3066b788ce6a
> --- /dev/null
> +++ b/fs/ext4/ialloc-test.c
[ ... ]
> +static void ialloc_test_cleanup(void *data)
> +{
> + struct ialloc_test_ctx *ctx = data;
> + handle_t *handle;
> + unsigned int i;
> +
> + ctx->evict_skip_free = true;
> + ctx->sbi.s_journal = NULL;
> +
> + while ((handle = ext4_journal_current_handle()) != NULL)
> + ext4_journal_stop(handle);
> +
> + for (i = 0; i < ctx->nr_tracked_inodes; i++) {
> + struct inode *ti = ctx->tracked_inodes[i];
> +
> + if (ti) {
> + if (inode_state_read_once(ti) & I_NEW)
> + unlock_new_inode(ti);
> + spin_lock(&ti->i_lock);
> + inode_state_clear(ti, I_DIRTY_TIME);
> + spin_unlock(&ti->i_lock);
> + set_nlink(ti, 1);
> + iput(ti);
> + ctx->tracked_inodes[i] = NULL;
> + }
> + }
> + ctx->nr_tracked_inodes = 0;
> +
> + ctx->sb->s_root = NULL;
> + if (ctx->root_inode) {
> + set_nlink(ctx->root_inode, 2);
> + iput(ctx->root_inode);
> + ctx->root_inode = NULL;
> + }
> +
> + deactivate_super(ctx->sb);
[Severity: Medium]
Can clearing ctx->sb->s_root before deactivate_super(ctx->sb) cause a
use-after-free on ctx->sb in fserror_worker()?
ialloc_test_init() sets SB_ACTIVE on ctx->sb, so tests that trigger
ext4_error() or ext4_std_error() queue fserror_worker() items referencing
ctx->sb via fserror_report_metadata(). In generic_shutdown_super(),
fserror_unmount(sb) is only called inside the if (sb->s_root) block, so
nulling s_root beforehand skips draining those pending work items before
ctx->sb is freed:
CPU0 kworker
ialloc_test_validate_ibitmap_csum()
ext4_error()
fserror_report_metadata()
queue_work(..., &event->work)
ialloc_test_cleanup()
ctx->sb->s_root = NULL
deactivate_super(ctx->sb)
generic_shutdown_super()
/* skips fserror_unmount() */
put_super()
...
kfree(sb)
fserror_worker()
sb = event->sb
if (sb->s_flags & SB_ACTIVE)
<-- use-after-free
Omitting SB_ACTIVE in ialloc_test_init() would avoid queueing fserror
events in the first place.
> diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
> index 02546b828836c..66215b6359320 100644
> --- a/fs/ext4/ialloc.c
> +++ b/fs/ext4/ialloc.c
[ ... ]
> @@ -1521,6 +1527,23 @@ unsigned long ext4_count_dirs(struct super_block * sb)
> }
> return count;
> }
> +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_count_dirs);
> +
> +int ext4_itable_zeroout(struct super_block *sb, ext4_fsblk_t blk, int num,
> + int barrier)
> +{
> + int ret;
> +
> + KUNIT_STATIC_STUB_REDIRECT(ext4_itable_zeroout, sb, blk, num, barrier);
> +
> + ret = sb_issue_zeroout(sb, blk, num, GFP_NOFS);
> + if (ret < 0)
> + return ret;
> + if (barrier)
> + blkdev_issue_flush(sb->s_bdev);
> + return ret;
> +}
> +EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_itable_zeroout);
[Severity: Critical]
This problem wasn't introduced by this patch, but should
ext4_itable_zeroout() check and return the error from
blkdev_issue_flush() [1]?
When barrier is set and blkdev_issue_flush() fails, ext4_itable_zeroout()
still returns 0, so ext4_init_inode_table() proceeds to set
EXT4_BG_INODE_ZEROED in the group descriptor even though the zeroed inode
table blocks may not have been flushed to stable storage before a crash.
(The same unchecked blkdev_issue_flush() pattern also exists in
ext4_fc_perform_commit() and ext4_fc_replay_inode() in
fs/ext4/fast_commit.c.)
[1] https://sashiko.dev/#/bug/linux-d85ff7fd-2937-4bb0-8016-be8fb0499fbd
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261112040638.1576836-1-tytso@mit.edu?part=11
next prev parent reply other threads:[~2026-11-12 4:25 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 [this message]
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-210333@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.