Patchwork ext4: fix possible memory leak in ext4_remount()

login
register
mail settings
Submitter Wei Yongjun
Date Feb. 27, 2013, 5:18 a.m.
Message ID <CAPgLHd-J=j=aVCpjutq2B1+NMqxz=v50xNcEQA_57Ni_7v9HKA@mail.gmail.com>
Download mbox | patch
Permalink /patch/223501/
State Accepted
Headers show

Comments

Wei Yongjun - Feb. 27, 2013, 5:18 a.m.
From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

'orig_data' is malloced in ext4_remount() and should be freed
before leaving from the error handling cases, otherwise it will
cause memory leak.

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 fs/ext4/super.c | 1 +
 1 file changed, 1 insertion(+)



--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Lukas Czerner - Feb. 27, 2013, 12:45 p.m.
On Wed, 27 Feb 2013, Wei Yongjun wrote:

> Date: Wed, 27 Feb 2013 13:18:53 +0800
> From: Wei Yongjun <weiyj.lk@gmail.com>
> To: tytso@mit.edu, adilger.kernel@dilger.ca
> Cc: yongjun_wei@trendmicro.com.cn, linux-ext4@vger.kernel.org
> Subject: [PATCH] ext4: fix possible memory leak in ext4_remount()
> 
> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> 
> 'orig_data' is malloced in ext4_remount() and should be freed
> before leaving from the error handling cases, otherwise it will
> cause memory leak.

Good catch, thanks!

Reviewed-by: Lukas Czerner <lczerner@redhat.com>

> 
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> ---
>  fs/ext4/super.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 373d46c..8ae09e3 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -4538,6 +4538,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
>  			if (!old_opts.s_qf_names[i]) {
>  				for (j = 0; j < i; j++)
>  					kfree(old_opts.s_qf_names[j]);
> +				kfree(orig_data);
>  				return -ENOMEM;
>  			}
>  		} else
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Theodore Ts'o - March 2, 2013, 10:13 p.m.
On Wed, Feb 27, 2013 at 01:18:53PM +0800, Wei Yongjun wrote:
> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> 
> 'orig_data' is malloced in ext4_remount() and should be freed
> before leaving from the error handling cases, otherwise it will
> cause memory leak.
> 
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

Thanks, applied.

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 373d46c..8ae09e3 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4538,6 +4538,7 @@  static int ext4_remount(struct super_block *sb, int *flags, char *data)
 			if (!old_opts.s_qf_names[i]) {
 				for (j = 0; j < i; j++)
 					kfree(old_opts.s_qf_names[j]);
+				kfree(orig_data);
 				return -ENOMEM;
 			}
 		} else