This is a note to let you know that I've just added the patch titled ext4: improve error recovery code paths in __ext4_remount() to the 6.3-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: ext4-improve-error-recovery-code-paths-in-__ext4_remount.patch and it can be found in the queue-6.3 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 4c0b4818b1f636bc96359f7817a2d8bab6370162 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o <tytso@xxxxxxx> Date: Fri, 5 May 2023 22:20:29 -0400 Subject: ext4: improve error recovery code paths in __ext4_remount() From: Theodore Ts'o <tytso@xxxxxxx> commit 4c0b4818b1f636bc96359f7817a2d8bab6370162 upstream. If there are failures while changing the mount options in __ext4_remount(), we need to restore the old mount options. This commit fixes two problem. The first is there is a chance that we will free the old quota file names before a potential failure leading to a use-after-free. The second problem addressed in this commit is if there is a failed read/write to read-only transition, if the quota has already been suspended, we need to renable quota handling. Cc: stable@xxxxxxxxxx Link: https://lore.kernel.org/r/20230506142419.984260-2-tytso@xxxxxxx Signed-off-by: Theodore Ts'o <tytso@xxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/ext4/super.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -6579,9 +6579,6 @@ static int __ext4_remount(struct fs_cont } #ifdef CONFIG_QUOTA - /* Release old quota file names */ - for (i = 0; i < EXT4_MAXQUOTAS; i++) - kfree(old_opts.s_qf_names[i]); if (enable_quota) { if (sb_any_quota_suspended(sb)) dquot_resume(sb, -1); @@ -6591,6 +6588,9 @@ static int __ext4_remount(struct fs_cont goto restore_opts; } } + /* Release old quota file names */ + for (i = 0; i < EXT4_MAXQUOTAS; i++) + kfree(old_opts.s_qf_names[i]); #endif if (!test_opt(sb, BLOCK_VALIDITY) && sbi->s_system_blks) ext4_release_system_zone(sb); @@ -6601,6 +6601,13 @@ static int __ext4_remount(struct fs_cont return 0; restore_opts: + /* + * If there was a failing r/w to ro transition, we may need to + * re-enable quota + */ + if ((sb->s_flags & SB_RDONLY) && !(old_sb_flags & SB_RDONLY) && + sb_any_quota_suspended(sb)) + dquot_resume(sb, -1); sb->s_flags = old_sb_flags; sbi->s_mount_opt = old_opts.s_mount_opt; sbi->s_mount_opt2 = old_opts.s_mount_opt2; Patches currently in stable-queue which might be from tytso@xxxxxxx are queue-6.3/ext4-improve-error-recovery-code-paths-in-__ext4_remount.patch queue-6.3/ext4-fix-warning-in-mb_find_extent.patch queue-6.3/ext4-avoid-deadlock-in-fs-reclaim-with-page-writeback.patch queue-6.3/ext4-fix-deadlock-when-converting-an-inline-directory-in-nojournal-mode.patch queue-6.3/ext4-bail-out-of-ext4_xattr_ibody_get-fails-for-any-reason.patch queue-6.3/ext4-improve-error-handling-from-ext4_dirhash.patch queue-6.3/ext4-add-bounds-checking-in-get_max_inline_xattr_value_size.patch queue-6.3/ext4-avoid-a-potential-slab-out-of-bounds-in-ext4_group_desc_csum.patch queue-6.3/ext4-check-iomap-type-only-if-ext4_iomap_begin-does-not-fail.patch queue-6.3/ext4-fix-lockdep-warning-when-enabling-mmp.patch queue-6.3/ext4-fix-invalid-free-tracking-in-ext4_xattr_move_to_block.patch queue-6.3/ext4-remove-a-bug_on-in-ext4_mb_release_group_pa.patch queue-6.3/ext4-fix-data-races-when-using-cached-status-extents.patch