Skip to contentSkip to conversation

net: hns3: double free 'skb'

PATCH In review Wenjia Zhao 2 participants 2 messages Feb 3, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 4/4 net: hns3: double free 'skb'

net: hns3: double free 'skb'

The false branch of (tx_ret == NETDEV_TX_OK) free the skb. However, the kfree_skb(skb) in the out label will be execute when exits the function. So the skb has a double-free bugs.

Remove the kfree_skb(skb) at line 269

---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +0 -1
index 2622e04..1b926ff 100644
@@ -266,7 +266,6 @@ static int hns3_lp_run_test(struct net_device *ndev, enum hnae3_loop mode)
 		if (tx_ret == NETDEV_TX_OK) {
 			good_cnt++;
 		} else {
-			kfree_skb(skb);
 			netdev_err(ndev, "hns3_lb_run_test xmit failed: %d\n",
 				   tx_ret);
 		}
Signature · 1 line
2.7.4
#1 lore raw
Quoted 7 lines · Wenjia Zhao

net: hns3: double free 'skb'

The false branch of (tx_ret == NETDEV_TX_OK) free the skb. However, the kfree_skb(skb) in the out label will be execute when exits the function. So the skb has a double-free bugs.

Remove the kfree_skb(skb) at line 269

The freeing is added by the below patch:

commit: 8f9eed1a8791("net: hns3: fix for skb leak when doing selftest")

which is to fix a skb leak problem.

kfree_skb(skb) in the out label corresponds to alloc_skb(), and kfree_skb(skb) removed in this patch corresponds to skb_get(skb) before calling hns3_nic_net_xmit() when hns3_nic_net_xmit() non-NETDEV_TX_OK.

So I do not think there is double free 'skb' here, unless I miss something here?

Quoted 19 lines
---
 drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +0 -1
index 2622e04..1b926ff 100644
@@ -266,7 +266,6 @@ static int hns3_lp_run_test(struct net_device *ndev, enum hnae3_loop mode)
 		if (tx_ret == NETDEV_TX_OK) {
 			good_cnt++;
 		} else {
-			kfree_skb(skb);
 			netdev_err(ndev, "hns3_lb_run_test xmit failed: %d\n",
 				   tx_ret);
 		}