Skip to contentSkip to conversation

net: korina: remove busy skb free

PATCH In review Vincent Stehlé 4 participants 9 messages Dec 13, 2020 – Dec 16, 2020

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

PATCH 1/1 net: korina: remove busy skb free

The ndo_start_xmit() method must not attempt to free the skb to transmit when returning NETDEV_TX_BUSY. Fix the korina_send_packet() function accordingly.

Fixes ef11291bcd5f ("Add support the Korina (IDT RC32434) Ethernet MAC")
Cc David S. Miller <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Florian Fainelli <[email protected]>
---
 drivers/net/ethernet/korina.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/ethernet/korina.c +0 -1
index bf48f0ded9c7d..9d84191de6824 100644
@@ -216,7 +216,6 @@ static int korina_send_packet(struct sk_buff *skb, struct net_device *dev)
 			netif_stop_queue(dev);
 		else {
 			dev->stats.tx_dropped++;
-			dev_kfree_skb_any(skb);
 			spin_unlock_irqrestore(&lp->lock, flags);
 
 			return NETDEV_TX_BUSY;
Signature · 1 line
2.29.2
#1 lore raw
Quoted 19 lines · Vincent Stehlé

The ndo_start_xmit() method must not attempt to free the skb to transmit when returning NETDEV_TX_BUSY. Fix the korina_send_packet() function accordingly.

Fixes ef11291bcd5f ("Add support the Korina (IDT RC32434) Ethernet MAC")
Cc David S. Miller <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Florian Fainelli <[email protected]>
---
 drivers/net/ethernet/korina.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/ethernet/korina.c +0 -0
index bf48f0ded9c7d..9d84191de6824 100644

drivers/net/ethernet/korina.c static int korina_send_packet(struct sk_buff *skb, struct net_device *dev) · line 221

Quoted 7 lines
drivers/net/ethernet/korina.c +0 -1
@@ -216,7 +216,6 @@ static int korina_send_packet(struct sk_buff *skb, struct net_device *dev)
 			netif_stop_queue(dev);
 		else {
 			dev->stats.tx_dropped++;
-			dev_kfree_skb_any(skb);
 			spin_unlock_irqrestore(&lp->lock, flags);
 
 			return NETDEV_TX_BUSY;

As this skb is returned to the stack (and not dropped), the tx_dropped statistics increment looks bogus too.

maintainer
#2 lore raw
Quoted 11 lines · On Mon, 14 Dec 2020 11:03:12 +0100 Julian Wiedmann wrote:
Quoted 11 lines
drivers/net/ethernet/korina.c +0 -1
index bf48f0ded9c7d..9d84191de6824 100644
@@ -216,7 +216,6 @@ static int korina_send_packet(struct sk_buff *skb, struct net_device *dev)
 			netif_stop_queue(dev);
 		else {
 			dev->stats.tx_dropped++;
-			dev_kfree_skb_any(skb);
 			spin_unlock_irqrestore(&lp->lock, flags);
 
Quoted 5 lines

drivers/net/ethernet/korina.c static int korina_send_packet(struct sk_buff *skb, struct net_device *dev) · line 221

Quoted 2 lines
drivers/net/ethernet/korina.c +0 -0
 			return NETDEV_TX_BUSY;

As this skb is returned to the stack (and not dropped), the tx_dropped statistics increment looks bogus too.

Since this is clearly an ugly use after free, and nobody complained we can assume that the driver correctly stops its TX queue ahead of time. So perhaps we can change the return value to NETDEV_TX_OK instead.

#3 lore raw
Quoted 18 lines · Jakub Kicinski
Quoted 11 lines · On Mon, 14 Dec 2020 11:03:12 +0100 Julian Wiedmann wrote:
Quoted 11 lines
drivers/net/ethernet/korina.c +0 -1
index bf48f0ded9c7d..9d84191de6824 100644
@@ -216,7 +216,6 @@ static int korina_send_packet(struct sk_buff *skb, struct net_device *dev)
 			netif_stop_queue(dev);
 		else {
 			dev->stats.tx_dropped++;
-			dev_kfree_skb_any(skb);
 			spin_unlock_irqrestore(&lp->lock, flags);
 
Quoted 5 lines

drivers/net/ethernet/korina.c static int korina_send_packet(struct sk_buff *skb, struct net_device *dev) · line 221

Quoted 2 lines
drivers/net/ethernet/korina.c +0 -0
 			return NETDEV_TX_BUSY;

As this skb is returned to the stack (and not dropped), the tx_dropped statistics increment looks bogus too.

Quoted 3 lines

Since this is clearly an ugly use after free, and nobody complained we can assume that the driver correctly stops its TX queue ahead of time. So perhaps we can change the return value to NETDEV_TX_OK instead.

Hi Jakub,

Thanks for the review.

Ok, if this is the preferred fix I will respin the patch this way.

Best regards,
Vincent.

#4 lore raw

PATCH v2 1/1 net: korina: fix return value

In reply to Jakub Kicinski

The ndo_start_xmit() method must not attempt to free the skb to transmit when returning NETDEV_TX_BUSY. Therefore, make sure the korina_send_packet() function returns NETDEV_TX_OK when it frees a packet.

Fixes ef11291bcd5f ("Add support the Korina (IDT RC32434) Ethernet MAC")
Cc David S. Miller <[email protected]>
Cc Florian Fainelli <[email protected]>

---

Changes since v1:
- Keep freeing the packet but return NETDEV_TX_OK, as suggested by Jakub

 drivers/net/ethernet/korina.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/korina.c +1 -1
index bf48f0ded9c7d..925161959b9ba 100644
@@ -219,7 +219,7 @@ static int korina_send_packet(struct sk_buff *skb, struct net_device *dev)
 			dev_kfree_skb_any(skb);
 			spin_unlock_irqrestore(&lp->lock, flags);
 
-			return NETDEV_TX_BUSY;
+			return NETDEV_TX_OK;
 		}
 	}
 
Signature · 1 line
2.29.2
maintainer
#5 lore raw

Re: [PATCH v2] net: korina: fix return value

Quoted 9 lines · On Mon, 14 Dec 2020 23:09:52 +0100 Vincent Stehlé wrote:

The ndo_start_xmit() method must not attempt to free the skb to transmit when returning NETDEV_TX_BUSY. Therefore, make sure the korina_send_packet() function returns NETDEV_TX_OK when it frees a packet.

Fixes ef11291bcd5f ("Add support the Korina (IDT RC32434) Ethernet MAC")
Cc David S. Miller <[email protected]>
Cc Florian Fainelli <[email protected]>

Let me CC Florian's more recent email just in case he wants to review.

Quoted 20 lines

Changes since v1:
- Keep freeing the packet but return NETDEV_TX_OK, as suggested by Jakub

 drivers/net/ethernet/korina.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/korina.c +1 -1
index bf48f0ded9c7d..925161959b9ba 100644
@@ -219,7 +219,7 @@ static int korina_send_packet(struct sk_buff *skb, struct net_device *dev)
 			dev_kfree_skb_any(skb);
 			spin_unlock_irqrestore(&lp->lock, flags);
 
-			return NETDEV_TX_BUSY;
+			return NETDEV_TX_OK;
 		}
 	}
 
#6 lore raw

Re: [PATCH v2] net: korina: fix return value

Quoted 5 lines · Jakub Kicinski
Quoted 4 lines · On Mon, 14 Dec 2020 23:09:52 +0100 Vincent Stehlé wrote:

The ndo_start_xmit() method must not attempt to free the skb to transmit when returning NETDEV_TX_BUSY. Therefore, make sure the korina_send_packet() function returns NETDEV_TX_OK when it frees a packet.

Quoted 7 lines
Quoted 5 lines
Fixes ef11291bcd5f ("Add support the Korina (IDT RC32434) Ethernet MAC")
Cc David S. Miller <[email protected]>
Cc Florian Fainelli <[email protected]>

Let me CC Florian's more recent email just in case he wants to review.

Signature · 1 line
Florian
maintainer Applied
#7 lore raw

Re: [PATCH v2] net: korina: fix return value

Quoted 12 lines · On Wed, 16 Dec 2020 13:32:26 -0800 Florian Fainelli wrote:
Quoted 11 lines · Jakub Kicinski
Quoted 9 lines · On Mon, 14 Dec 2020 23:09:52 +0100 Vincent Stehlé wrote:

The ndo_start_xmit() method must not attempt to free the skb to transmit when returning NETDEV_TX_BUSY. Therefore, make sure the korina_send_packet() function returns NETDEV_TX_OK when it frees a packet.

Fixes ef11291bcd5f ("Add support the Korina (IDT RC32434) Ethernet MAC")
Cc David S. Miller <[email protected]>
Cc Florian Fainelli <[email protected]>
Quoted 3 lines
Quoted 1 line

Let me CC Florian's more recent email just in case he wants to review.

😬

Applied, thanks!

#8 lore raw
In reply to Julian Wiedmann
Quoted 1 line · Julian Wiedmann

On 13.12.20 18:20, Vincent Stehlé wrote:

...

Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/korina.c +0 -1
@@ -216,7 +216,6 @@ static int korina_send_packet(struct sk_buff *skb, struct net_device *dev)
 			netif_stop_queue(dev);
 		else {
 			dev->stats.tx_dropped++;
-			dev_kfree_skb_any(skb);
 			spin_unlock_irqrestore(&lp->lock, flags);
 
Quoted 5 lines

drivers/net/ethernet/korina.c static int korina_send_packet(struct sk_buff *skb, struct net_device *dev) · line 221

Quoted 2 lines
drivers/net/ethernet/korina.c +0 -0
 			return NETDEV_TX_BUSY;

As this skb is returned to the stack (and not dropped), the tx_dropped statistics increment looks bogus too.

Hi Julian,

Thanks for the review.
I will respin the patch to remove the statistics increment as well.

Best regards,
Vincent.