[PATCH] ext4: Fix timer use-after-free on failed mount

Xiaxi Shen posted 1 patch 1 year, 5 months ago
fs/ext4/super.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] ext4: Fix timer use-after-free on failed mount
Posted by Xiaxi Shen 1 year, 5 months ago
Syzbot has found an ODEBUG bug in ext4_fill_super

The del_timer_sync function cancels the s_err_report timer,
which reminds about filesystem errors daily. We should
guarantee the timer is no longer active before kfree(sbi).

When filesystem mounting fails, the flow goes to failed_mount3,
where an error occurs when ext4_stop_mmpd is called, causing
a read I/O failure. This triggers the ext4_handle_error function
that ultimately re-arms the timer,
leaving the s_err_report timer active before kfree(sbi) is called.

Fix the issue by canceling the s_err_report timer after calling ext4_stop_mmpd.

Signed-off-by: Xiaxi Shen <shenxiaxi26@gmail.com>
Reported-and-tested-by: syzbot+59e0101c430934bc9a36@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=59e0101c430934bc9a36
---
 fs/ext4/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index c682fb927b64..1b4b0d3d8889 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -5626,8 +5626,8 @@ failed_mount8: __maybe_unused
 failed_mount3:
 	/* flush s_sb_upd_work before sbi destroy */
 	flush_work(&sbi->s_sb_upd_work);
-	del_timer_sync(&sbi->s_err_report);
 	ext4_stop_mmpd(sbi);
+	del_timer_sync(&sbi->s_err_report);
 	ext4_group_desc_free(sbi);
 failed_mount:
 	if (sbi->s_chksum_driver)
-- 
2.34.1
Re: [PATCH] ext4: Fix timer use-after-free on failed mount
Posted by Theodore Ts'o 1 year, 3 months ago
On Sun, 14 Jul 2024 21:33:36 -0700, Xiaxi Shen wrote:
> Syzbot has found an ODEBUG bug in ext4_fill_super
> 
> The del_timer_sync function cancels the s_err_report timer,
> which reminds about filesystem errors daily. We should
> guarantee the timer is no longer active before kfree(sbi).
> 
> When filesystem mounting fails, the flow goes to failed_mount3,
> where an error occurs when ext4_stop_mmpd is called, causing
> a read I/O failure. This triggers the ext4_handle_error function
> that ultimately re-arms the timer,
> leaving the s_err_report timer active before kfree(sbi) is called.
> 
> [...]

Applied, thanks!

[1/1] ext4: Fix timer use-after-free on failed mount
      commit: 0ce160c5bdb67081a62293028dc85758a8efb22a

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>