Skip to contentSkip to conversation

net: dwc-xlgmac: set skb to NULL after freeing it

PATCH In review Pan Bian 3 participants 3 messages Nov 28, 2018

Subsystems (3)
lore
Share & tools
lore

Pan Bian

author
#0 lore raw

PATCH 1/1 net: dwc-xlgmac: set skb to NULL after freeing it

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

---
 drivers/net/ethernet/synopsys/dwc-xlgmac-net.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/synopsys/dwc-xlgmac-net.c +2 -0
index 1f8e960..a0d28c4 100644
@@ -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;
 		}
 
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 8 lines · 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).

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

Thanks and Best Regards,
Jose Miguel Abreu

maintainer
#2 lore raw
In reply to Pan Bian

From: Pan Bian <[email protected]>
Date: Wed, 28 Nov 2018 17:20:53 +0800

Quoted 9 lines
drivers/net/ethernet/synopsys/dwc-xlgmac-net.c +1 -0
@@ -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;
 		}
 

drivers/net/ethernet/synopsys/dwc-xlgmac-net.c static int xlgmac_rx_poll(struct xlgmac_channel *channel, int budget) · line 1233

Quoted 6 lines
drivers/net/ethernet/synopsys/dwc-xlgmac-net.c +1 -0
@@ -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.