Skip to content

Commit 13b215a

Browse files
Lukas Czernertytso
authored andcommitted
ext4: don't use kfree() on rcu protected pointer sbi->s_qf_names
During ext4 mount api rework the commit e6e268c ("ext4: move quota configuration out of handle_mount_opt()") introduced a bug where we would kfree(sbi->s_qf_names[i]) before assigning the new quota name in ext4_apply_quota_options(). This is wrong because we're using kfree() on rcu prointer that could be simultaneously accessed from ext4_show_quota_options() during remount. Fix it by using rcu_replace_pointer() to replace the old qname with the new one and then kfree_rcu() the old quota name. Also use get_qf_name() instead of sbi->s_qf_names in strcmp() to silence the sparse warning. Fixes: e6e268c ("ext4: move quota configuration out of handle_mount_opt()") Reported-by: kernel test robot <[email protected]> Signed-off-by: Lukas Czerner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 173b6e3 commit 13b215a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

fs/ext4/super.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,8 +2636,10 @@ static void ext4_apply_quota_options(struct fs_context *fc,
26362636

26372637
qname = ctx->s_qf_names[i]; /* May be NULL */
26382638
ctx->s_qf_names[i] = NULL;
2639-
kfree(sbi->s_qf_names[i]);
2640-
rcu_assign_pointer(sbi->s_qf_names[i], qname);
2639+
qname = rcu_replace_pointer(sbi->s_qf_names[i], qname,
2640+
lockdep_is_held(&sb->s_umount));
2641+
if (qname)
2642+
kfree_rcu(qname);
26412643
set_opt(sb, QUOTA);
26422644
}
26432645
}
@@ -2691,7 +2693,7 @@ static int ext4_check_quota_consistency(struct fs_context *fc,
26912693
goto err_jquota_change;
26922694

26932695
if (sbi->s_qf_names[i] && ctx->s_qf_names[i] &&
2694-
strcmp(sbi->s_qf_names[i],
2696+
strcmp(get_qf_name(sb, sbi, i),
26952697
ctx->s_qf_names[i]) != 0)
26962698
goto err_jquota_specified;
26972699
}

0 commit comments

Comments
 (0)