From: sashiko-bot@kernel.org
To: "Fan Wu" <fanwu01@zju.edu.cn>
Cc: tytso@mit.edu, linux-ext4@vger.kernel.org
Subject: Re: [PATCH] ext4: fix discard work use-after-free on failed mount
Date: Thu, 20 Aug 2026 05:44:30 +0000 [thread overview]
Message-ID: <20260820054431.2156B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260820052102.4616-1-fanwu01@zju.edu.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Incorrect teardown ordering causes Use-After-Free of s_group_info and unjournaled metadata modifications during mount failure.
--
--- Patch [1]: [PATCH] ext4: fix discard work use-after-free on failed mount ---
commit 7b05e08bede19859144c19d2964e5f55dbc626c5
Author: Fan Wu <fanwu01@zju.edu.cn>
ext4: fix discard work use-after-free on failed mount
This commit addresses a use-after-free during a failed mount by ensuring
the journal is destroyed before ext4_mb_release() drains the discard work.
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index bca0dc87d0b7c..5ec1d8f54e917 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -5776,6 +5776,12 @@ failed_mount8: __maybe_unused
> failed_mount7:
> ext4_unregister_li_request(sb);
> failed_mount6:
> + /*
> + * The last commit can re-arm s_discard_work, so destroy the
> + * journal before ext4_mb_release() flushes it.
> + */
> + if (sbi->s_journal)
> + ext4_journal_destroy(sbi, sbi->s_journal);
> ext4_mb_release(sb);
> ext4_flex_groups_free(sbi);
> failed_mount5:
[Severity: Critical]
This is a pre-existing issue, but does this error unwind sequence leave
sbi->s_group_info exposed to a use-after-free further down the failure path?
If a filesystem mount fails after journal replay (for example, if
ext4_enable_quotas() fails), the error unwind reaches failed_mount6 and
calls ext4_mb_release(), which frees sbi->s_group_info.
The unwind then continues down to failed_mount_wq:
failed_mount_wq:
flush_delayed_work(&sbi->s_ea_inode_work);
If journal replay had queued EA inodes for eviction, the flush worker
will process them:
ext4_evict_inode()
ext4_truncate()
ext4_free_blocks()
ext4_mb_clear_bb()
ext4_get_group_info()
Can this lead to ext4_mb_clear_bb() dereferencing the freed
sbi->s_group_info array?
Additionally, because this patch moves ext4_journal_destroy() to run before
the flush, sbi->s_journal is now NULL when ext4_evict_inode() runs. Will
this cause ext4_journal_start() to return a nojournal handle, resulting in
unjournaled metadata modifications?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260820052102.4616-1-fanwu01@zju.edu.cn?part=1
next prev parent reply other threads:[~2026-08-20 5:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 5:21 [PATCH] ext4: fix discard work use-after-free on failed mount Fan Wu
2026-08-20 5:44 ` sashiko-bot [this message]
2026-08-20 11:08 ` Jan Kara
2026-08-20 12:12 ` Fan Wu
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=20260820054431.2156B1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=fanwu01@zju.edu.cn \
--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.