Skip to content

Commit c069db7

Browse files
ebiggerstytso
authored andcommitted
ext4: fix memory leak in parse_apply_sb_mount_options()
If processing the on-disk mount options fails after any memory was allocated in the ext4_fs_context, e.g. s_qf_names, then this memory is leaked. Fix this by calling ext4_fc_free() instead of kfree() directly. Reproducer: mkfs.ext4 -F /dev/vdc tune2fs /dev/vdc -E mount_opts=usrjquota=file echo clear > /sys/kernel/debug/kmemleak mount /dev/vdc /vdc echo scan > /sys/kernel/debug/kmemleak sleep 5 echo scan > /sys/kernel/debug/kmemleak cat /sys/kernel/debug/kmemleak Fixes: 7edfd85 ("ext4: Completely separate options parsing and sb setup") Cc: [email protected] Signed-off-by: Eric Biggers <[email protected]> Tested-by: Ritesh Harjani <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent cb8435d commit c069db7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/ext4/super.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,8 +2628,10 @@ static int parse_apply_sb_mount_options(struct super_block *sb,
26282628
ret = ext4_apply_options(fc, sb);
26292629

26302630
out_free:
2631-
kfree(s_ctx);
2632-
kfree(fc);
2631+
if (fc) {
2632+
ext4_fc_free(fc);
2633+
kfree(fc);
2634+
}
26332635
kfree(s_mount_opts);
26342636
return ret;
26352637
}

0 commit comments

Comments
 (0)