Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dcc7dae3 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Theodore Ts'o
Browse files

ext4: Fix potential memory leak in ext4_fill_super



Under heavy memory pressure we may hit out of memory
situation and as result kstrdup'ed options will not be
freed. Fix it.

Signed-off-by: default avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent 0c095c7f
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -2550,7 +2550,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
	struct inode *root;
	char *cp;
	const char *descr;
	int ret = -EINVAL;
	int ret = -ENOMEM;
	int blocksize;
	unsigned int db_count;
	unsigned int i;
@@ -2561,13 +2561,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)

	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
	if (!sbi)
		return -ENOMEM;
		goto out_free_orig;

	sbi->s_blockgroup_lock =
		kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
	if (!sbi->s_blockgroup_lock) {
		kfree(sbi);
		return -ENOMEM;
		goto out_free_orig;
	}
	sb->s_fs_info = sbi;
	sbi->s_mount_opt = 0;
@@ -2584,6 +2584,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
	for (cp = sb->s_id; (cp = strchr(cp, '/'));)
		*cp = '!';

	ret = -EINVAL;
	blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
	if (!blocksize) {
		ext4_msg(sb, KERN_ERR, "unable to set blocksize");
@@ -3190,6 +3191,7 @@ out_fail:
	kfree(sbi->s_blockgroup_lock);
	kfree(sbi);
	lock_kernel();
out_free_orig:
	kfree(orig_data);
	return ret;
}