linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* ext4: fix memory leak in xattr code.
@ 2013-09-20 14:29 Dave Jones
  2013-09-20 15:29 ` Eric Sandeen
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Jones @ 2013-09-20 14:29 UTC (permalink / raw)
  To: tytso; +Cc: Andreas Dilger, linux-ext4, linux-kernel

If we take the 2nd retry path in ext4_expand_extra_isize_ea, we potentionally
return from the function without having freed these allocations.
If we don't do the return, we over-write the previous allocation pointers, 
so we leak either way.

Spotted with Coverity.

Signed-off-by: Dave Jones <davej@fedoraproject.org>

diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index c081e34..f3a6220 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -1350,6 +1350,8 @@ retry:
 				    s_min_extra_isize) {
 					tried_min_extra_isize++;
 					new_extra_isize = s_min_extra_isize;
+					kfree(is);
+					kfree(bs);
 					goto retry;
 				}
 				error = -1;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: ext4: fix memory leak in xattr code.
  2013-09-20 14:29 ext4: fix memory leak in xattr code Dave Jones
@ 2013-09-20 15:29 ` Eric Sandeen
  2013-09-22 19:33   ` Theodore Ts'o
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Sandeen @ 2013-09-20 15:29 UTC (permalink / raw)
  To: Dave Jones, tytso, Andreas Dilger, linux-ext4, linux-kernel

On 9/20/13 9:29 AM, Dave Jones wrote:
> If we take the 2nd retry path in ext4_expand_extra_isize_ea, we potentionally
> return from the function without having freed these allocations.
> If we don't do the return, we over-write the previous allocation pointers, 
> so we leak either way.
> 
> Spotted with Coverity.
> 
> Signed-off-by: Dave Jones <davej@fedoraproject.org>

Looks right to me.

Reviewed-by: Eric Sandeen <sandeen@redhat.com>

Thanks!

-Eric

> diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
> index c081e34..f3a6220 100644
> --- a/fs/ext4/xattr.c
> +++ b/fs/ext4/xattr.c
> @@ -1350,6 +1350,8 @@ retry:
>  				    s_min_extra_isize) {
>  					tried_min_extra_isize++;
>  					new_extra_isize = s_min_extra_isize;
> +					kfree(is);
> +					kfree(bs);
>  					goto retry;
>  				}
>  				error = -1;
> --
> 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
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ext4: fix memory leak in xattr code.
  2013-09-20 15:29 ` Eric Sandeen
@ 2013-09-22 19:33   ` Theodore Ts'o
  0 siblings, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2013-09-22 19:33 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: Dave Jones, Andreas Dilger, linux-ext4, linux-kernel

Thanks, applied with a minor bug fix...

						- Ted

commit 8484764f97a840df851f4586079f28715f13318e
Author: Dave Jones <davej@redhat.com>
Date:   Sun Sep 22 15:31:00 2013 -0400

    ext4: fix memory leak in xattr
    
    If we take the 2nd retry path in ext4_expand_extra_isize_ea, we
    potentionally return from the function without having freed these
    allocations.  If we don't do the return, we over-write the previous
    allocation pointers, so we leak either way.
    
    Spotted with Coverity.
    
    [ Fixed by tytso to set is and bs to NULL after freeing these
      pointers, in case in the retry loop we later end up triggering an
      error causing a jump to cleanup, at which point we could have a double
      free bug. -- Ted ]
    
    Signed-off-by: Dave Jones <davej@fedoraproject.org>
    Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
    Reviewed-by: Eric Sandeen <sandeen@redhat.com>

diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index c081e34..3c53192 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -1350,6 +1350,9 @@ retry:
 				    s_min_extra_isize) {
 					tried_min_extra_isize++;
 					new_extra_isize = s_min_extra_isize;
+					kfree(is);
+					kfree(bs);
+					is = bs = NULL;
 					goto retry;
 				}
 				error = -1;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-09-22 19:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-20 14:29 ext4: fix memory leak in xattr code Dave Jones
2013-09-20 15:29 ` Eric Sandeen
2013-09-22 19:33   ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).