netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: dwc-xlgmac: set skb to NULL after freeing it
@ 2018-11-28  9:20 Pan Bian
  2018-11-28 10:02 ` Jose Abreu
  2018-11-28 18:59 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Pan Bian @ 2018-11-28  9:20 UTC (permalink / raw)
  To: Jose Abreu, David S. Miller; +Cc: netdev, linux-kernel, Pan Bian

The buffer skb is freed via dev_kfree_skb in a loop. After freeing skb,
the value of packet_count is updated via packet_count++. If packet_count
happens to equal the upper bound (i.e., budget), the loop will be broken
and skb may be assigned to desc_data->state.skb. Resulting that
desc_data->state.skb may point to a freed memory chunk. To fix this, the
patch sets skb to NULL after dev_kfree_skb(skb).

Signed-off-by: Pan Bian <bianpan2016@163.com>
---
 drivers/net/ethernet/synopsys/dwc-xlgmac-net.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/synopsys/dwc-xlgmac-net.c b/drivers/net/ethernet/synopsys/dwc-xlgmac-net.c
index 1f8e960..a0d28c4 100644
--- a/drivers/net/ethernet/synopsys/dwc-xlgmac-net.c
+++ b/drivers/net/ethernet/synopsys/dwc-xlgmac-net.c
@@ -1180,6 +1180,7 @@ static int xlgmac_rx_poll(struct xlgmac_channel *channel, int budget)
 				netif_err(pdata, rx_err, netdev,
 					  "error in received packet\n");
 			dev_kfree_skb(skb);
+			skb = NULL;
 			goto next_packet;
 		}
 
@@ -1227,6 +1228,7 @@ static int xlgmac_rx_poll(struct xlgmac_channel *channel, int budget)
 			netif_err(pdata, rx_err, netdev,
 				  "packet length exceeds configured MTU\n");
 			dev_kfree_skb(skb);
+			skb = NULL;
 			goto next_packet;
 		}
 
-- 
2.7.4

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

* Re: [PATCH] net: dwc-xlgmac: set skb to NULL after freeing it
  2018-11-28  9:20 [PATCH] net: dwc-xlgmac: set skb to NULL after freeing it Pan Bian
@ 2018-11-28 10:02 ` Jose Abreu
  2018-11-28 18:59 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Jose Abreu @ 2018-11-28 10:02 UTC (permalink / raw)
  To: Pan Bian; +Cc: David S. Miller, netdev, linux-kernel

On 28-11-2018 09:20, Pan Bian wrote:
> The buffer skb is freed via dev_kfree_skb in a loop. After freeing skb,
> the value of packet_count is updated via packet_count++. If packet_count
> happens to equal the upper bound (i.e., budget), the loop will be broken
> and skb may be assigned to desc_data->state.skb. Resulting that
> desc_data->state.skb may point to a freed memory chunk. To fix this, the
> patch sets skb to NULL after dev_kfree_skb(skb).
>
> Signed-off-by: Pan Bian <bianpan2016@163.com>

This is missing the Fixes tag and your patch prefix should be
[PATCH net].

Thanks and Best Regards,
Jose Miguel Abreu

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

* Re: [PATCH] net: dwc-xlgmac: set skb to NULL after freeing it
  2018-11-28  9:20 [PATCH] net: dwc-xlgmac: set skb to NULL after freeing it Pan Bian
  2018-11-28 10:02 ` Jose Abreu
@ 2018-11-28 18:59 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2018-11-28 18:59 UTC (permalink / raw)
  To: bianpan2016; +Cc: Jose.Abreu, netdev, linux-kernel

From: Pan Bian <bianpan2016@163.com>
Date: Wed, 28 Nov 2018 17:20:53 +0800

> @@ -1180,6 +1180,7 @@ static int xlgmac_rx_poll(struct xlgmac_channel *channel, int budget)
>  				netif_err(pdata, rx_err, netdev,
>  					  "error in received packet\n");
>  			dev_kfree_skb(skb);
> +			skb = NULL;
>  			goto next_packet;
>  		}
>  
> @@ -1227,6 +1228,7 @@ static int xlgmac_rx_poll(struct xlgmac_channel *channel, int budget)
>  			netif_err(pdata, rx_err, netdev,
>  				  "packet length exceeds configured MTU\n");
>  			dev_kfree_skb(skb);
> +			skb = NULL;
>  			goto next_packet;
>  		}

Same problem as your amd-xgbe patch, the condition you say can occurr is
actually impossible.

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

end of thread, other threads:[~2018-11-28 18:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-28  9:20 [PATCH] net: dwc-xlgmac: set skb to NULL after freeing it Pan Bian
2018-11-28 10:02 ` Jose Abreu
2018-11-28 18:59 ` David Miller

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