Patchwork ext4: fix possible memory leak in ext4_xattr_set_acl()

login
register
mail settings
Submitter Eugene Shatokhin
Date Oct. 8, 2012, 11:11 a.m.
Message ID <1349694672-16992-1-git-send-email-eugene.shatokhin@rosalab.ru>
Download mbox | patch
Permalink /patch/189995/
State Accepted, archived
Headers show

Comments

Eugene Shatokhin - Oct. 8, 2012, 11:11 a.m.
In ext4_xattr_set_acl(), if ext4_journal_start() returns an error,
posix_acl_release() will not be called for 'acl' which may result
in a memory leak.

This patch fixes that.

Signed-off-by: Eugene Shatokhin <eugene.shatokhin@rosalab.ru>
---
 fs/ext4/acl.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Lukas Czerner - Oct. 8, 2012, 12:36 p.m.
On Mon, 8 Oct 2012, Eugene Shatokhin wrote:

> Date: Mon,  8 Oct 2012 15:11:12 +0400
> From: Eugene Shatokhin <eugene.shatokhin@rosalab.ru>
> To: linux-ext4@vger.kernel.org
> Cc: Eugene Shatokhin <eugene.shatokhin@rosalab.ru>
> Subject: [PATCH] ext4: fix possible memory leak in ext4_xattr_set_acl()
> 
> In ext4_xattr_set_acl(), if ext4_journal_start() returns an error,
> posix_acl_release() will not be called for 'acl' which may result
> in a memory leak.
> 
> This patch fixes that.
> 
> Signed-off-by: Eugene Shatokhin <eugene.shatokhin@rosalab.ru>
> ---
>  fs/ext4/acl.c |    6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c
> index a5c29bb..8535c45 100644
> --- a/fs/ext4/acl.c
> +++ b/fs/ext4/acl.c
> @@ -410,8 +410,10 @@ ext4_xattr_set_acl(struct dentry *dentry, const char *name, const void *value,
>  
>  retry:
>  	handle = ext4_journal_start(inode, EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
> -	if (IS_ERR(handle))
> -		return PTR_ERR(handle);
> +	if (IS_ERR(handle)) {
> +		error = PTR_ERR(handle);
> +		goto release_and_out;
> +	}
>  	error = ext4_set_acl(handle, inode, type, acl);
>  	ext4_journal_stop(handle);
>  	if (error == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
> 

Looks good.

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

Thanks for catching that.
-Lukas
--
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 - Nov. 8, 2012, 8:11 p.m.
On Mon, Oct 08, 2012 at 03:11:12PM +0400, Eugene Shatokhin wrote:
> In ext4_xattr_set_acl(), if ext4_journal_start() returns an error,
> posix_acl_release() will not be called for 'acl' which may result
> in a memory leak.
> 
> This patch fixes that.
> 
> Signed-off-by: Eugene Shatokhin <eugene.shatokhin@rosalab.ru>

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/acl.c b/fs/ext4/acl.c
index a5c29bb..8535c45 100644
--- a/fs/ext4/acl.c
+++ b/fs/ext4/acl.c
@@ -410,8 +410,10 @@  ext4_xattr_set_acl(struct dentry *dentry, const char *name, const void *value,
 
 retry:
 	handle = ext4_journal_start(inode, EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
-	if (IS_ERR(handle))
-		return PTR_ERR(handle);
+	if (IS_ERR(handle)) {
+		error = PTR_ERR(handle);
+		goto release_and_out;
+	}
 	error = ext4_set_acl(handle, inode, type, acl);
 	ext4_journal_stop(handle);
 	if (error == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))