All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bnx2x: Fix mem leak in bnx2x_tpa_stop() if build_skb() fails.
@ 2012-02-06 21:28 Jesper Juhl
  2012-02-06 22:53 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Jesper Juhl @ 2012-02-06 21:28 UTC (permalink / raw)
  To: netdev; +Cc: Eilon Greenstein, linux-kernel, David Miller, Eliezer Tamir

We allocate memory for 'new_data' with kmalloc(). If we get the memory
we then try to build_skb() and if that should fail (which it can) we
do not enter 'if (likely(skb)) {' and actually use 'new_data' but
instead fall through to the 'drop:' label and end up returning from
the function without ever assigning 'new'data' to anything or freeing
it. That leaks the memory allocated to 'new_data'.

This patch fixes the memory leak by doing a kfree(new_data) in the
case where build_skb() fails (or where allocation of 'new_data' itself
fails, but in taht case it's just a harmless kfree(NULL)).

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

 No hardware to test, so compile tested only.

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
index 03f3935..7aee469 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
@@ -523,7 +523,6 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
 		skb = build_skb(data);
 
 	if (likely(skb)) {
-
 #ifdef BNX2X_STOP_ON_ERROR
 		if (pad + len > fp->rx_buf_size) {
 			BNX2X_ERR("skb_put is about to fail...  "
@@ -557,7 +556,7 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
 
 		return;
 	}
-
+	kfree(new_data);
 drop:
 	/* drop the packet and keep the buffer in the bin */
 	DP(NETIF_MSG_RX_STATUS,
-- 
1.7.9


-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


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

* Re: [PATCH] bnx2x: Fix mem leak in bnx2x_tpa_stop() if build_skb() fails.
  2012-02-06 21:28 [PATCH] bnx2x: Fix mem leak in bnx2x_tpa_stop() if build_skb() fails Jesper Juhl
@ 2012-02-06 22:53 ` Eric Dumazet
  2012-02-07  6:55   ` Eilon Greenstein
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2012-02-06 22:53 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: netdev, Eilon Greenstein, linux-kernel, David Miller, Eliezer Tamir

Le lundi 06 février 2012 à 22:28 +0100, Jesper Juhl a écrit :
> We allocate memory for 'new_data' with kmalloc(). If we get the memory
> we then try to build_skb() and if that should fail (which it can) we
> do not enter 'if (likely(skb)) {' and actually use 'new_data' but
> instead fall through to the 'drop:' label and end up returning from
> the function without ever assigning 'new'data' to anything or freeing
> it. That leaks the memory allocated to 'new_data'.
> 
> This patch fixes the memory leak by doing a kfree(new_data) in the
> case where build_skb() fails (or where allocation of 'new_data' itself
> fails, but in taht case it's just a harmless kfree(NULL)).
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> ---
>  drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c |    3 +--
>  1 files changed, 1 insertions(+), 2 deletions(-)
> 
>  No hardware to test, so compile tested only.
> 
> diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> index 03f3935..7aee469 100644
> --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> @@ -523,7 +523,6 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
>  		skb = build_skb(data);
>  
>  	if (likely(skb)) {
> -
>  #ifdef BNX2X_STOP_ON_ERROR
>  		if (pad + len > fp->rx_buf_size) {
>  			BNX2X_ERR("skb_put is about to fail...  "
> @@ -557,7 +556,7 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
>  
>  		return;
>  	}
> -
> +	kfree(new_data);
>  drop:
>  	/* drop the packet and keep the buffer in the bin */
>  	DP(NETIF_MSG_RX_STATUS,
> -- 
> 1.7.9
> 
> 

Good catch, my bad.

Thanks

Acked-by: Eric Dumazet <eric.dumazet@gmail.com>




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

* Re: [PATCH] bnx2x: Fix mem leak in bnx2x_tpa_stop() if build_skb() fails.
  2012-02-06 22:53 ` Eric Dumazet
@ 2012-02-07  6:55   ` Eilon Greenstein
  2012-02-07 18:14     ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Eilon Greenstein @ 2012-02-07  6:55 UTC (permalink / raw)
  To: Jesper Juhl, Eric Dumazet
  Cc: netdev, linux-kernel, David Miller, Eliezer Tamir

On Mon, 2012-02-06 at 23:53 +0100, Eric Dumazet wrote:
> Le lundi 06 février 2012 à 22:28 +0100, Jesper Juhl a écrit :
> > We allocate memory for 'new_data' with kmalloc(). If we get the memory
> > we then try to build_skb() and if that should fail (which it can) we
> > do not enter 'if (likely(skb)) {' and actually use 'new_data' but
> > instead fall through to the 'drop:' label and end up returning from
> > the function without ever assigning 'new'data' to anything or freeing
> > it. That leaks the memory allocated to 'new_data'.
> > 
> > This patch fixes the memory leak by doing a kfree(new_data) in the
> > case where build_skb() fails (or where allocation of 'new_data' itself
> > fails, but in taht case it's just a harmless kfree(NULL)).
> > 
> > Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> > ---
> >  drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c |    3 +--
> >  1 files changed, 1 insertions(+), 2 deletions(-)
> > 
> >  No hardware to test, so compile tested only.
> > 
> > diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> > index 03f3935..7aee469 100644
> > --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> > +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
> > @@ -523,7 +523,6 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
> >  		skb = build_skb(data);
> >  
> >  	if (likely(skb)) {
> > -
> >  #ifdef BNX2X_STOP_ON_ERROR
> >  		if (pad + len > fp->rx_buf_size) {
> >  			BNX2X_ERR("skb_put is about to fail...  "
> > @@ -557,7 +556,7 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
> >  
> >  		return;
> >  	}
> > -
> > +	kfree(new_data);
> >  drop:
> >  	/* drop the packet and keep the buffer in the bin */
> >  	DP(NETIF_MSG_RX_STATUS,
> > -- 
> > 1.7.9
> > 
> > 
> 
> Good catch, my bad.
> 
> Thanks
> 
> Acked-by: Eric Dumazet <eric.dumazet@gmail.com>

Indeed - nice catch. Thanks Jesper.

Acked-by: Eilon Greenstein <eilong@broadcom.com>






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

* Re: [PATCH] bnx2x: Fix mem leak in bnx2x_tpa_stop() if build_skb() fails.
  2012-02-07  6:55   ` Eilon Greenstein
@ 2012-02-07 18:14     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2012-02-07 18:14 UTC (permalink / raw)
  To: eilong; +Cc: jj, eric.dumazet, netdev, linux-kernel, eliezert

From: "Eilon Greenstein" <eilong@broadcom.com>
Date: Tue, 7 Feb 2012 08:55:01 +0200

> On Mon, 2012-02-06 at 23:53 +0100, Eric Dumazet wrote:
>> Le lundi 06 février 2012 à 22:28 +0100, Jesper Juhl a écrit :
>> > We allocate memory for 'new_data' with kmalloc(). If we get the memory
>> > we then try to build_skb() and if that should fail (which it can) we
>> > do not enter 'if (likely(skb)) {' and actually use 'new_data' but
>> > instead fall through to the 'drop:' label and end up returning from
>> > the function without ever assigning 'new'data' to anything or freeing
>> > it. That leaks the memory allocated to 'new_data'.
>> > 
>> > This patch fixes the memory leak by doing a kfree(new_data) in the
>> > case where build_skb() fails (or where allocation of 'new_data' itself
>> > fails, but in taht case it's just a harmless kfree(NULL)).
>> > 
>> > Signed-off-by: Jesper Juhl <jj@chaosbits.net>
...
>> Good catch, my bad.
>> 
>> Thanks
>> 
>> Acked-by: Eric Dumazet <eric.dumazet@gmail.com>
> 
> Indeed - nice catch. Thanks Jesper.
> 
> Acked-by: Eilon Greenstein <eilong@broadcom.com>

Applied, thanks everyone.

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

end of thread, other threads:[~2012-02-07 18:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-06 21:28 [PATCH] bnx2x: Fix mem leak in bnx2x_tpa_stop() if build_skb() fails Jesper Juhl
2012-02-06 22:53 ` Eric Dumazet
2012-02-07  6:55   ` Eilon Greenstein
2012-02-07 18:14     ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.