Skip to content

Commit 4c0b481

Browse files
committed
ext4: improve error recovery code paths in __ext4_remount()
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: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 4b3cb1d commit 4c0b481

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

fs/ext4/super.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6617,9 +6617,6 @@ static int __ext4_remount(struct fs_context *fc, struct super_block *sb)
66176617
}
66186618

66196619
#ifdef CONFIG_QUOTA
6620-
/* Release old quota file names */
6621-
for (i = 0; i < EXT4_MAXQUOTAS; i++)
6622-
kfree(old_opts.s_qf_names[i]);
66236620
if (enable_quota) {
66246621
if (sb_any_quota_suspended(sb))
66256622
dquot_resume(sb, -1);
@@ -6629,6 +6626,9 @@ static int __ext4_remount(struct fs_context *fc, struct super_block *sb)
66296626
goto restore_opts;
66306627
}
66316628
}
6629+
/* Release old quota file names */
6630+
for (i = 0; i < EXT4_MAXQUOTAS; i++)
6631+
kfree(old_opts.s_qf_names[i]);
66326632
#endif
66336633
if (!test_opt(sb, BLOCK_VALIDITY) && sbi->s_system_blks)
66346634
ext4_release_system_zone(sb);
@@ -6642,6 +6642,13 @@ static int __ext4_remount(struct fs_context *fc, struct super_block *sb)
66426642
return 0;
66436643

66446644
restore_opts:
6645+
/*
6646+
* If there was a failing r/w to ro transition, we may need to
6647+
* re-enable quota
6648+
*/
6649+
if ((sb->s_flags & SB_RDONLY) && !(old_sb_flags & SB_RDONLY) &&
6650+
sb_any_quota_suspended(sb))
6651+
dquot_resume(sb, -1);
66456652
sb->s_flags = old_sb_flags;
66466653
sbi->s_mount_opt = old_opts.s_mount_opt;
66476654
sbi->s_mount_opt2 = old_opts.s_mount_opt2;

0 commit comments

Comments
 (0)