Skip to contentSkip to conversation

net: bcmasp: fix potential memory leak in bcmasp_xmit()

PATCH Applied Wang Hai 4 participants 6 messages Oct 14, 2024 – Oct 16, 2024

Subsystems (3)

v1 of 2 Applied 1/1 Latest is v2 →

lore
Share & tools
lore

Wang Hai

author
#0 lore raw

PATCH 1/1 net: bcmasp: fix potential memory leak in bcmasp_xmit()

The bcmasp_xmit() returns NETDEV_TX_OK without freeing skb in case of mapping fails, add dev_kfree_skb() to fix it.

Fixes 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller")
---
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +1 -0
index 82768b0e9026..9ea16ef4139d 100644
@@ -322,6 +322,7 @@ static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev)
 			}
 			/* Rewind so we do not have a hole */
 			spb_index = intf->tx_spb_index;
+			dev_kfree_skb(skb);
 			return NETDEV_TX_OK;
 		}
 
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 14 lines · Wang Hai

The bcmasp_xmit() returns NETDEV_TX_OK without freeing skb in case of mapping fails, add dev_kfree_skb() to fix it.

Fixes 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller")
---
  drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 1 +
  1 file changed, 1 insertion(+)
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +0 -0
index 82768b0e9026..9ea16ef4139d 100644

drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev) · line 325

Quoted 4 lines
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +1 -0
@@ -322,6 +322,7 @@ static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev)
  			}
  			/* Rewind so we do not have a hole */
  			spb_index = intf->tx_spb_index;
+			dev_kfree_skb(skb);

Similar reasoning to the change proposed to bcmsysport.c, we already have a private counter tracking DMA mapping errors, therefore I would consider using dev_consume_skb_any() here.

Signature · 1 line
Florian
author
#2 lore raw
Quoted 10 lines · Florian Fainelli
Quoted 9 lines · Wang Hai

The bcmasp_xmit() returns NETDEV_TX_OK without freeing skb in case of mapping fails, add dev_kfree_skb() to fix it.

Fixes 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller")

---
  drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 1 +

  1 file changed, 1 insertion(+)
Quoted 12 lines

drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c static netdev_tx_t bcmasp_xmit(struct sk_buff · line 326

Quoted 10 lines
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +1 -0
index 82768b0e9026..9ea16ef4139d 100644
@@ -322,6 +322,7 @@ static netdev_tx_t bcmasp_xmit(struct sk_buff 
 *skb, struct net_device *dev)
               }
               /* Rewind so we do not have a hole */
               spb_index = intf->tx_spb_index;
+            dev_kfree_skb(skb);

Similar reasoning to the change proposed to bcmsysport.c, we already have a private counter tracking DMA mapping errors, therefore I would consider using dev_consume_skb_any() here.

Hi, Florian.

Thanks for the suggestion, I've resent v2.

[PATCH v2 net] net: bcmasp: fix potential memory leak in bcmasp_xmit()

maintainer
#3 lore raw
In reply to Florian Fainelli
Quoted 10 lines · On Mon, 14 Oct 2024 10:14:59 -0700 Florian Fainelli wrote:
Quoted 9 lines · Wang Hai

The bcmasp_xmit() returns NETDEV_TX_OK without freeing skb in case of mapping fails, add dev_kfree_skb() to fix it.

Fixes 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller")
---
  drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 13 lines

drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev) · line 325

Quoted 9 lines
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +1 -0
index 82768b0e9026..9ea16ef4139d 100644
@@ -322,6 +322,7 @@ static netdev_tx_t bcmasp_xmit(struct sk_buff *skb, struct net_device *dev)
  			}
  			/* Rewind so we do not have a hole */
  			spb_index = intf->tx_spb_index;
+			dev_kfree_skb(skb);  

Similar reasoning to the change proposed to bcmsysport.c, we already have a private counter tracking DMA mapping errors, therefore I would consider using dev_consume_skb_any() here.

.. but this one hasn't been pushed and I presume same treatment will apply?

#5 lore raw
In reply to Wang Hai
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Mon, 14 Oct 2024 22:59:01 +0800 you wrote:

The bcmasp_xmit() returns NETDEV_TX_OK without freeing skb in case of mapping fails, add dev_kfree_skb() to fix it.

Fixes 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller")
---
 drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 1 +
 1 file changed, 1 insertion(+)

Here is the summary with links:
- [net] net: bcmasp: fix potential memory leak in bcmasp_xmit()

    https://git.kernel.org/netdev/net/c/fed07d3eb8a8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html