netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] e1000: free skb when returning on -ENOMEM error
@ 2015-10-22 15:27 Jason A. Donenfeld
  2015-10-22 15:59 ` [Intel-wired-lan] " Alexander Duyck
  0 siblings, 1 reply; 3+ messages in thread
From: Jason A. Donenfeld @ 2015-10-22 15:27 UTC (permalink / raw)
  To: jeffrey.t.kirsher, jesse.brandeburg, shannon.nelson,
	carolyn.wyborny, donald.c.skidmore, matthew.vick, john.ronciak,
	mitch.a.williams, intel-wired-lan, netdev, linux-kernel
  Cc: Jason A. Donenfeld

eth_skb_pad returns 0 if it was successful, or -ENOMEM if it was not. In
that case, this function exits early. Some early exits return with
NETDEV_TX_BUSY, which queues the skb up to be tried again, and so the
skb should not be freed. Other early exits return with NETDEV_TX_OK,
like this one, in which case it's imperative that the skb is freed,
since it is not queued back up. In this case, upon receiving -ENOMEM
from eth_skb_pad, the function exits early with NETDEV_TX_OK, but
forgets to free the skb. This patch fixes that.

In a low memory situation, in which the GFP_ATOMIC allocation from
eth_skb_pad fails, if a network device is transmitting repeatedly, this
bug could lead to rapidly leaking memory that could only be recovered by
a reboot or crash.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/net/ethernet/intel/e1000/e1000_main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c
index 74dc150..0d6b4c8 100644
--- a/drivers/net/ethernet/intel/e1000/e1000_main.c
+++ b/drivers/net/ethernet/intel/e1000/e1000_main.c
@@ -3130,8 +3130,10 @@ static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
 	 * packets may get corrupted during padding by HW.
 	 * To WA this issue, pad all small packets manually.
 	 */
-	if (eth_skb_pad(skb))
+	if (eth_skb_pad(skb)) {
+		dev_kfree_skb_any(skb);
 		return NETDEV_TX_OK;
+	}
 
 	mss = skb_shinfo(skb)->gso_size;
 	/* The controller does a simple calculation to
-- 
2.6.2

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

* Re: [Intel-wired-lan] [PATCH] e1000: free skb when returning on -ENOMEM error
  2015-10-22 15:27 [PATCH] e1000: free skb when returning on -ENOMEM error Jason A. Donenfeld
@ 2015-10-22 15:59 ` Alexander Duyck
  2015-10-22 16:15   ` Jason A. Donenfeld
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Duyck @ 2015-10-22 15:59 UTC (permalink / raw)
  To: Jason A. Donenfeld, jeffrey.t.kirsher, jesse.brandeburg,
	shannon.nelson, carolyn.wyborny, donald.c.skidmore, matthew.vick,
	john.ronciak, mitch.a.williams, intel-wired-lan, netdev,
	linux-kernel

On 10/22/2015 08:27 AM, Jason A. Donenfeld wrote:
> eth_skb_pad returns 0 if it was successful, or -ENOMEM if it was not. In
> that case, this function exits early. Some early exits return with
> NETDEV_TX_BUSY, which queues the skb up to be tried again, and so the
> skb should not be freed. Other early exits return with NETDEV_TX_OK,
> like this one, in which case it's imperative that the skb is freed,
> since it is not queued back up. In this case, upon receiving -ENOMEM
> from eth_skb_pad, the function exits early with NETDEV_TX_OK, but
> forgets to free the skb. This patch fixes that.
>
> In a low memory situation, in which the GFP_ATOMIC allocation from
> eth_skb_pad fails, if a network device is transmitting repeatedly, this
> bug could lead to rapidly leaking memory that could only be recovered by
> a reboot or crash.
>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
>   drivers/net/ethernet/intel/e1000/e1000_main.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c
> index 74dc150..0d6b4c8 100644
> --- a/drivers/net/ethernet/intel/e1000/e1000_main.c
> +++ b/drivers/net/ethernet/intel/e1000/e1000_main.c
> @@ -3130,8 +3130,10 @@ static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
>   	 * packets may get corrupted during padding by HW.
>   	 * To WA this issue, pad all small packets manually.
>   	 */
> -	if (eth_skb_pad(skb))
> +	if (eth_skb_pad(skb)) {
> +		dev_kfree_skb_any(skb);
>   		return NETDEV_TX_OK;
> +	}
>
>   	mss = skb_shinfo(skb)->gso_size;
>   	/* The controller does a simple calculation to
>

This patch makes no sense.  The function eth_skb_pad will have freed the 
skb if it is returning an error value.  As such there is nothing to 
free.  The code was correct before.

- Alex

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

* Re: [Intel-wired-lan] [PATCH] e1000: free skb when returning on -ENOMEM error
  2015-10-22 15:59 ` [Intel-wired-lan] " Alexander Duyck
@ 2015-10-22 16:15   ` Jason A. Donenfeld
  0 siblings, 0 replies; 3+ messages in thread
From: Jason A. Donenfeld @ 2015-10-22 16:15 UTC (permalink / raw)
  To: Alexander Duyck
  Cc: Kirsher, Jeffrey T, jesse.brandeburg, shannon.nelson,
	carolyn.wyborny, donald.c.skidmore, matthew.vick, john.ronciak,
	mitch.a.williams, intel-wired-lan, Netdev, linux-kernel

You're right. Sorry for the noise Please ignore.

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

end of thread, other threads:[~2015-10-22 16:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-22 15:27 [PATCH] e1000: free skb when returning on -ENOMEM error Jason A. Donenfeld
2015-10-22 15:59 ` [Intel-wired-lan] " Alexander Duyck
2015-10-22 16:15   ` Jason A. Donenfeld

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).