Skip to contentSkip to conversation

net: lantiq_xrx200: fix use after free bug

PATCH Applied Aleksander Jan Bajkowski 3 participants 3 messages Mar 5, 2022 – Mar 7, 2022

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

PATCH 1/1 net: lantiq_xrx200: fix use after free bug

The skb->len field is read after the packet is sent to the network stack. In the meantime, skb can be freed. This patch fixes this bug.

Fixes c3e6b2c35b34 ("net: lantiq_xrx200: add ingress SG DMA support")
---
 drivers/net/ethernet/lantiq_xrx200.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/lantiq_xrx200.c +1 -1
index 41d11137cde0..5712c3e94be8 100644
@@ -260,9 +260,9 @@ static int xrx200_hw_receive(struct xrx200_chan *ch)
 
 	if (ctl & LTQ_DMA_EOP) {
 		ch->skb_head->protocol = eth_type_trans(ch->skb_head, net_dev);
-		netif_receive_skb(ch->skb_head);
 		net_dev->stats.rx_packets++;
 		net_dev->stats.rx_bytes += ch->skb_head->len;
+		netif_receive_skb(ch->skb_head);
 		ch->skb_head = NULL;
 		ch->skb_tail = NULL;
 		ret = XRX200_DMA_PACKET_COMPLETE;
Signature · 1 line
2.30.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Aleksander Jan Bajkowski

The skb->len field is read after the packet is sent to the network stack. In the meantime, skb can be freed. This patch fixes this bug.

Fixes c3e6b2c35b34 ("net: lantiq_xrx200: add ingress SG DMA support")
Quoted 19 lines
---
  drivers/net/ethernet/lantiq_xrx200.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/lantiq_xrx200.c +1 -1
index 41d11137cde0..5712c3e94be8 100644
@@ -260,9 +260,9 @@ static int xrx200_hw_receive(struct xrx200_chan *ch)
 
  	if (ctl & LTQ_DMA_EOP) {
  		ch->skb_head->protocol = eth_type_trans(ch->skb_head, net_dev);
-		netif_receive_skb(ch->skb_head);
  		net_dev->stats.rx_packets++;
  		net_dev->stats.rx_bytes += ch->skb_head->len;
+		netif_receive_skb(ch->skb_head);
  		ch->skb_head = NULL;
  		ch->skb_tail = NULL;
  		ret = XRX200_DMA_PACKET_COMPLETE;
#2 lore raw
In reply to Aleksander Jan Bajkowski
This patch was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <[email protected]>:

Quoted 8 lines · On Sat, 5 Mar 2022 12:20:39 +0100 you wrote:

The skb->len field is read after the packet is sent to the network stack. In the meantime, skb can be freed. This patch fixes this bug.

Fixes c3e6b2c35b34 ("net: lantiq_xrx200: add ingress SG DMA support")

[...]

Here is the summary with links:
- [net] net: lantiq_xrx200: fix use after free bug

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

You are awesome, thank you!

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