Skip to contentSkip to conversation

hinic: fix leak of ethtool RSS user configuration buffers

PATCH In review Chenguang Zhao 2 participants 2 messages Jul 20

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

PATCH 1/1 hinic: fix leak of ethtool RSS user configuration buffers

From: Chenguang Zhao <[email protected]>

rss_indir_user and rss_hkey_user are allocated in __set_rss_rxfh() when the user configures RSS via ethtool, but hinic_remove() never frees them. free_netdev() only releases the nic_dev structure itself, so the separately allocated buffers are leaked on driver unload.

Free both buffers in hinic_remove() after unregister_netdev().

Fixes 4fdc51bb4e92 ("hinic: add support for rss parameters with ethtool")
---
 drivers/net/ethernet/huawei/hinic/hinic_main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/huawei/hinic/hinic_main.c +3 -0
index 42f4792d255b..7d9c46004bcd 100644
@@ -1433,6 +1433,9 @@ static void hinic_remove(struct pci_dev *pdev)
 
 	hinic_free_intr_coalesce(nic_dev);
 
+	kfree(nic_dev->rss_indir_user);
+	kfree(nic_dev->rss_hkey_user);
+
 	hinic_port_del_mac(nic_dev, netdev->dev_addr, 0);
 
 	hinic_hwdev_cb_unregister(nic_dev->hwdev,
Signature · 1 line
2.25.1
#1 lore raw
Quoted 20 lines · Chenguang Zhao

From: Chenguang Zhao <[email protected]>

rss_indir_user and rss_hkey_user are allocated in __set_rss_rxfh() when the user configures RSS via ethtool, but hinic_remove() never frees them. free_netdev() only releases the nic_dev structure itself, so the separately allocated buffers are leaked on driver unload.

Free both buffers in hinic_remove() after unregister_netdev().

Fixes 4fdc51bb4e92 ("hinic: add support for rss parameters with ethtool")
---
 drivers/net/ethernet/huawei/hinic/hinic_main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/huawei/hinic/hinic_main.c +0 -0
index 42f4792d255b..7d9c46004bcd 100644

drivers/net/ethernet/huawei/hinic/hinic_main.c static void hinic_remove(struct pci_dev *pdev) · line 1438

Quoted 6 lines
drivers/net/ethernet/huawei/hinic/hinic_main.c +3 -0
@@ -1433,6 +1433,9 @@ static void hinic_remove(struct pci_dev *pdev)
 
 	hinic_free_intr_coalesce(nic_dev);
 
+	kfree(nic_dev->rss_indir_user);
+	kfree(nic_dev->rss_hkey_user);
+

I scanned the code and ... maybe I got this wrong ... but it looks like nothing actually uses these fields?

If you look at hinic_ethtool.c, the buffers are allocated, data is copied into them and then they are never used. hinic_get_rxfh seems to read the state directly from the device ?

I wonder if the correct fix is to drop the buffers and the memcpys entirely because they seem unnecessary and unused.