Skip to content

Commit bb282aa

Browse files
tytsosfX-bot
authored andcommitted
ext4: improve error recovery code paths in __ext4_remount()
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: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d2c5488 commit bb282aa

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
@@ -6029,9 +6029,6 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
60296029
}
60306030

60316031
#ifdef CONFIG_QUOTA
6032-
/* Release old quota file names */
6033-
for (i = 0; i < EXT4_MAXQUOTAS; i++)
6034-
kfree(old_opts.s_qf_names[i]);
60356032
if (enable_quota) {
60366033
if (sb_any_quota_suspended(sb))
60376034
dquot_resume(sb, -1);
@@ -6041,6 +6038,9 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
60416038
goto restore_opts;
60426039
}
60436040
}
6041+
/* Release old quota file names */
6042+
for (i = 0; i < EXT4_MAXQUOTAS; i++)
6043+
kfree(old_opts.s_qf_names[i]);
60446044
#endif
60456045
if (!test_opt(sb, BLOCK_VALIDITY) && sbi->s_system_blks)
60466046
ext4_release_system_zone(sb);
@@ -6060,6 +6060,13 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
60606060
return 0;
60616061

60626062
restore_opts:
6063+
/*
6064+
* If there was a failing r/w to ro transition, we may need to
6065+
* re-enable quota
6066+
*/
6067+
if ((sb->s_flags & SB_RDONLY) && !(old_sb_flags & SB_RDONLY) &&
6068+
sb_any_quota_suspended(sb))
6069+
dquot_resume(sb, -1);
60636070
sb->s_flags = old_sb_flags;
60646071
sbi->s_mount_opt = old_opts.s_mount_opt;
60656072
sbi->s_mount_opt2 = old_opts.s_mount_opt2;

0 commit comments

Comments
 (0)