public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs: fix memory leak in xfs_dir2_node_removename
@ 2013-09-27 13:01 Mark Tinguely
  2013-09-27 13:08 ` Carlos Maiolino
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Mark Tinguely @ 2013-09-27 13:01 UTC (permalink / raw)
  To: xfs

[-- Attachment #1: xfs-fix-leak-in-xfs_dir2_node_removename.patch --]
[-- Type: text/plain, Size: 1328 bytes --]

Free the memory pointed to by state before returning on error from 
xfs_dir2_node_removename.c

Signed-off-by: Mark Tinguely <tinguely@sgi.com>
---
Found by Coverity (134681) in userspace, same patch applies there
also.

 fs/xfs/xfs_dir2_node.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Index: b/fs/xfs/xfs_dir2_node.c
===================================================================
--- a/fs/xfs/xfs_dir2_node.c
+++ b/fs/xfs/xfs_dir2_node.c
@@ -2131,10 +2131,9 @@ xfs_dir2_node_removename(
 	/*
 	 * Didn't find it, upper layer screwed up.
 	 */
-	if (rval != EEXIST) {
-		xfs_da_state_free(state);
-		return rval;
-	}
+	if (rval != EEXIST)
+		goto done;
+
 	blk = &state->path.blk[state->path.active - 1];
 	ASSERT(blk->magic == XFS_DIR2_LEAFN_MAGIC);
 	ASSERT(state->extravalid);
@@ -2145,7 +2144,7 @@ xfs_dir2_node_removename(
 	error = xfs_dir2_leafn_remove(args, blk->bp, blk->index,
 		&state->extrablk, &rval);
 	if (error)
-		return error;
+		goto done;
 	/*
 	 * Fix the hash values up the btree.
 	 */
@@ -2160,6 +2159,7 @@ xfs_dir2_node_removename(
 	 */
 	if (!error)
 		error = xfs_dir2_node_to_leaf(state);
+done:
 	xfs_da_state_free(state);
 	return error;
 }


_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH] xfs: fix memory leak in xfs_dir2_node_removename
  2013-09-27 13:01 [PATCH] xfs: fix memory leak in xfs_dir2_node_removename Mark Tinguely
@ 2013-09-27 13:08 ` Carlos Maiolino
  2013-09-27 16:44 ` Eric Sandeen
  2013-09-27 19:36 ` Roger Willcocks
  2 siblings, 0 replies; 8+ messages in thread
From: Carlos Maiolino @ 2013-09-27 13:08 UTC (permalink / raw)
  To: xfs

Looks good,

Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>

On Fri, Sep 27, 2013 at 08:01:31AM -0500, Mark Tinguely wrote:
> Free the memory pointed to by state before returning on error from 
> xfs_dir2_node_removename.c
> 
> Signed-off-by: Mark Tinguely <tinguely@sgi.com>
> ---
> Found by Coverity (134681) in userspace, same patch applies there
> also.
> 
>  fs/xfs/xfs_dir2_node.c |   10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> Index: b/fs/xfs/xfs_dir2_node.c
> ===================================================================
> --- a/fs/xfs/xfs_dir2_node.c
> +++ b/fs/xfs/xfs_dir2_node.c
> @@ -2131,10 +2131,9 @@ xfs_dir2_node_removename(
>  	/*
>  	 * Didn't find it, upper layer screwed up.
>  	 */
> -	if (rval != EEXIST) {
> -		xfs_da_state_free(state);
> -		return rval;
> -	}
> +	if (rval != EEXIST)
> +		goto done;
> +
>  	blk = &state->path.blk[state->path.active - 1];
>  	ASSERT(blk->magic == XFS_DIR2_LEAFN_MAGIC);
>  	ASSERT(state->extravalid);
> @@ -2145,7 +2144,7 @@ xfs_dir2_node_removename(
>  	error = xfs_dir2_leafn_remove(args, blk->bp, blk->index,
>  		&state->extrablk, &rval);
>  	if (error)
> -		return error;
> +		goto done;
>  	/*
>  	 * Fix the hash values up the btree.
>  	 */
> @@ -2160,6 +2159,7 @@ xfs_dir2_node_removename(
>  	 */
>  	if (!error)
>  		error = xfs_dir2_node_to_leaf(state);
> +done:
>  	xfs_da_state_free(state);
>  	return error;
>  }
> 
> 
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs

-- 
Carlos

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH] xfs: fix memory leak in xfs_dir2_node_removename
  2013-09-27 13:01 [PATCH] xfs: fix memory leak in xfs_dir2_node_removename Mark Tinguely
  2013-09-27 13:08 ` Carlos Maiolino
@ 2013-09-27 16:44 ` Eric Sandeen
  2013-09-27 17:48   ` Mark Tinguely
  2013-09-27 19:36 ` Roger Willcocks
  2 siblings, 1 reply; 8+ messages in thread
From: Eric Sandeen @ 2013-09-27 16:44 UTC (permalink / raw)
  To: Mark Tinguely; +Cc: xfs

On 9/27/13 8:01 AM, Mark Tinguely wrote:
> Free the memory pointed to by state before returning on error from 
> xfs_dir2_node_removename.c
> 
> Signed-off-by: Mark Tinguely <tinguely@sgi.com>
> ---
> Found by Coverity (134681) in userspace, same patch applies there
> also.

Heh, looks like that one has been around since the dawn of time, thanks.

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

how do we handle the matching userspace fixes, separate patch to
be explicit?  Wait for the next syncup?

Thanks,
-Eric

>  fs/xfs/xfs_dir2_node.c |   10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> Index: b/fs/xfs/xfs_dir2_node.c
> ===================================================================
> --- a/fs/xfs/xfs_dir2_node.c
> +++ b/fs/xfs/xfs_dir2_node.c
> @@ -2131,10 +2131,9 @@ xfs_dir2_node_removename(
>  	/*
>  	 * Didn't find it, upper layer screwed up.
>  	 */
> -	if (rval != EEXIST) {
> -		xfs_da_state_free(state);
> -		return rval;
> -	}
> +	if (rval != EEXIST)
> +		goto done;
> +
>  	blk = &state->path.blk[state->path.active - 1];
>  	ASSERT(blk->magic == XFS_DIR2_LEAFN_MAGIC);
>  	ASSERT(state->extravalid);
> @@ -2145,7 +2144,7 @@ xfs_dir2_node_removename(
>  	error = xfs_dir2_leafn_remove(args, blk->bp, blk->index,
>  		&state->extrablk, &rval);
>  	if (error)
> -		return error;
> +		goto done;
>  	/*
>  	 * Fix the hash values up the btree.
>  	 */
> @@ -2160,6 +2159,7 @@ xfs_dir2_node_removename(
>  	 */
>  	if (!error)
>  		error = xfs_dir2_node_to_leaf(state);
> +done:
>  	xfs_da_state_free(state);
>  	return error;
>  }
> 
> 
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
> 

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH] xfs: fix memory leak in xfs_dir2_node_removename
  2013-09-27 16:44 ` Eric Sandeen
@ 2013-09-27 17:48   ` Mark Tinguely
  2013-09-27 17:55     ` Eric Sandeen
  0 siblings, 1 reply; 8+ messages in thread
From: Mark Tinguely @ 2013-09-27 17:48 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: xfs

On 09/27/13 11:44, Eric Sandeen wrote:
> On 9/27/13 8:01 AM, Mark Tinguely wrote:
>> Free the memory pointed to by state before returning on error from
>> xfs_dir2_node_removename.c
>>
>> Signed-off-by: Mark Tinguely<tinguely@sgi.com>
>> ---
>> Found by Coverity (134681) in userspace, same patch applies there
>> also.
>
> Heh, looks like that one has been around since the dawn of time, thanks.
>
> Reviewed-by: Eric Sandeen<sandeen@redhat.com>
>
> how do we handle the matching userspace fixes, separate patch to
> be explicit?  Wait for the next syncup?
>
> Thanks,
> -Eric

<patch delete>

Good question.

The user space should be kept up to date with the kernel.

Since the patches will be identical except the directory name, I was 
hoping to submit one copy. But I am not trying to invent a policy, just 
being lazy.

--Mark.

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH] xfs: fix memory leak in xfs_dir2_node_removename
  2013-09-27 17:48   ` Mark Tinguely
@ 2013-09-27 17:55     ` Eric Sandeen
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Sandeen @ 2013-09-27 17:55 UTC (permalink / raw)
  To: Mark Tinguely; +Cc: xfs

On 9/27/13 12:48 PM, Mark Tinguely wrote:
> On 09/27/13 11:44, Eric Sandeen wrote:
>> On 9/27/13 8:01 AM, Mark Tinguely wrote:
>>> Free the memory pointed to by state before returning on error from
>>> xfs_dir2_node_removename.c
>>>
>>> Signed-off-by: Mark Tinguely<tinguely@sgi.com>
>>> ---
>>> Found by Coverity (134681) in userspace, same patch applies there
>>> also.
>>
>> Heh, looks like that one has been around since the dawn of time, thanks.
>>
>> Reviewed-by: Eric Sandeen<sandeen@redhat.com>
>>
>> how do we handle the matching userspace fixes, separate patch to
>> be explicit?  Wait for the next syncup?
>>
>> Thanks,
>> -Eric
> 
> <patch delete>
> 
> Good question.
> 
> The user space should be kept up to date with the kernel.
> 
> Since the patches will be identical except the directory name, I was hoping to submit one copy. But I am not trying to invent a policy, just being lazy.
> 
> --Mark.
> 

Was just an offhanded question; it'd just be good to know what we all expect.

I suppose that it could depend on the severity of the flaw; a minor leak before exit()
isn't a big deal and could wait for a global sync-up; a data corruption fix might
need to be quickly merged to both trees.

-Eric

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH] xfs: fix memory leak in xfs_dir2_node_removename
  2013-09-27 13:01 [PATCH] xfs: fix memory leak in xfs_dir2_node_removename Mark Tinguely
  2013-09-27 13:08 ` Carlos Maiolino
  2013-09-27 16:44 ` Eric Sandeen
@ 2013-09-27 19:36 ` Roger Willcocks
  2013-09-27 19:52   ` Mark Tinguely
  2013-09-27 20:04   ` Eric Sandeen
  2 siblings, 2 replies; 8+ messages in thread
From: Roger Willcocks @ 2013-09-27 19:36 UTC (permalink / raw)
  To: Mark Tinguely; +Cc: xfs


On Fri, 2013-09-27 at 08:01 -0500, Mark Tinguely wrote:
> plain text document attachment
> (xfs-fix-leak-in-xfs_dir2_node_removename.patch)
> Free the memory pointed to by state before returning on error from 
> xfs_dir2_node_removename.c
> 
> Signed-off-by: Mark Tinguely <tinguely@sgi.com>
> ---
> Found by Coverity (134681) in userspace, same patch applies there
> also.
> 

Is the first hunk right ?

xfs_da_node_lookup_int called as

        error = xfs_da_node_lookup_int(state, &rval);

and returns with

        *result = retval;
        return(0);

so, on return, error == 0 and rval == an error code. The next lines:

        if (error)
                rval = error;

won't change that. But previously if rval != EEXIST you returned rval.
With the change below, you return error, which is zero.

--
Roger


>  fs/xfs/xfs_dir2_node.c |   10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> Index: b/fs/xfs/xfs_dir2_node.c
> ===================================================================
> --- a/fs/xfs/xfs_dir2_node.c
> +++ b/fs/xfs/xfs_dir2_node.c
> @@ -2131,10 +2131,9 @@ xfs_dir2_node_removename(
>  	/*
>  	 * Didn't find it, upper layer screwed up.
>  	 */
> -	if (rval != EEXIST) {
> -		xfs_da_state_free(state);
> -		return rval;
> -	}
> +	if (rval != EEXIST)
> +		goto done;
> +
>  	blk = &state->path.blk[state->path.active - 1];
>  	ASSERT(blk->magic == XFS_DIR2_LEAFN_MAGIC);
>  	ASSERT(state->extravalid);
> @@ -2145,7 +2144,7 @@ xfs_dir2_node_removename(
>  	error = xfs_dir2_leafn_remove(args, blk->bp, blk->index,
>  		&state->extrablk, &rval);
>  	if (error)
> -		return error;
> +		goto done;
>  	/*
>  	 * Fix the hash values up the btree.
>  	 */
> @@ -2160,6 +2159,7 @@ xfs_dir2_node_removename(
>  	 */
>  	if (!error)
>  		error = xfs_dir2_node_to_leaf(state);
> +done:
>  	xfs_da_state_free(state);
>  	return error;
>  }
> 
> 
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
> 
-- 
Roger Willcocks <roger@filmlight.ltd.uk>

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH] xfs: fix memory leak in xfs_dir2_node_removename
  2013-09-27 19:36 ` Roger Willcocks
@ 2013-09-27 19:52   ` Mark Tinguely
  2013-09-27 20:04   ` Eric Sandeen
  1 sibling, 0 replies; 8+ messages in thread
From: Mark Tinguely @ 2013-09-27 19:52 UTC (permalink / raw)
  To: Roger Willcocks; +Cc: xfs

On 09/27/13 14:36, Roger Willcocks wrote:
>
> On Fri, 2013-09-27 at 08:01 -0500, Mark Tinguely wrote:
>> plain text document attachment
>> (xfs-fix-leak-in-xfs_dir2_node_removename.patch)
>> Free the memory pointed to by state before returning on error from
>> xfs_dir2_node_removename.c
>>
>> Signed-off-by: Mark Tinguely<tinguely@sgi.com>
>> ---
>> Found by Coverity (134681) in userspace, same patch applies there
>> also.
>>
>
> Is the first hunk right ?
>
> xfs_da_node_lookup_int called as
>
>          error = xfs_da_node_lookup_int(state,&rval);
>
> and returns with
>
>          *result = retval;
>          return(0);
>
> so, on return, error == 0 and rval == an error code. The next lines:
>
>          if (error)
>                  rval = error;
>
> won't change that. But previously if rval != EEXIST you returned rval.
> With the change below, you return error, which is zero.
>
> --
> Roger


Thanks, guilty as charged. need to add the error = EEXIST.

--Mark.

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH] xfs: fix memory leak in xfs_dir2_node_removename
  2013-09-27 19:36 ` Roger Willcocks
  2013-09-27 19:52   ` Mark Tinguely
@ 2013-09-27 20:04   ` Eric Sandeen
  1 sibling, 0 replies; 8+ messages in thread
From: Eric Sandeen @ 2013-09-27 20:04 UTC (permalink / raw)
  To: Roger Willcocks; +Cc: Mark Tinguely, xfs

On 9/27/13 2:36 PM, Roger Willcocks wrote:
> 
> On Fri, 2013-09-27 at 08:01 -0500, Mark Tinguely wrote:
>> plain text document attachment
>> (xfs-fix-leak-in-xfs_dir2_node_removename.patch)
>> Free the memory pointed to by state before returning on error from 
>> xfs_dir2_node_removename.c
>>
>> Signed-off-by: Mark Tinguely <tinguely@sgi.com>
>> ---
>> Found by Coverity (134681) in userspace, same patch applies there
>> also.
>>
> 
> Is the first hunk right ?
> 
> xfs_da_node_lookup_int called as
> 
>         error = xfs_da_node_lookup_int(state, &rval);
> 
> and returns with
> 
>         *result = retval;
>         return(0);
> 
> so, on return, error == 0 and rval == an error code. The next lines:
> 
>         if (error)
>                 rval = error;
> 
> won't change that. But previously if rval != EEXIST you returned rval.
> With the change below, you return error, which is zero.

Oh geez.  o_O . . . Thanks Roger.

3rd review's the charm? ;)

-Eric

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

end of thread, other threads:[~2013-09-27 20:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-27 13:01 [PATCH] xfs: fix memory leak in xfs_dir2_node_removename Mark Tinguely
2013-09-27 13:08 ` Carlos Maiolino
2013-09-27 16:44 ` Eric Sandeen
2013-09-27 17:48   ` Mark Tinguely
2013-09-27 17:55     ` Eric Sandeen
2013-09-27 19:36 ` Roger Willcocks
2013-09-27 19:52   ` Mark Tinguely
2013-09-27 20:04   ` Eric Sandeen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox