Skip to contentSkip to conversation

rtase: fix double free of multi-frag skb on DMA map failure

PATCH Applied Yun Lu 5 participants 5 messages Jul 21 – Jul 28

Subsystems (3)
lore
Share & tools
lore

Yun Lu

author
#0 lore raw

PATCH 1/1 rtase: fix double free of multi-frag skb on DMA map failure

From: Yun Lu <[email protected]>

In rtase_start_xmit(), when the head buffer DMA mapping fails after rtase_xmit_frags() has mapped all fragments, the error path clears the fragment descriptors with rtase_tx_clear_range(), which frees the skb through the last-frag slot and accounts tx_dropped. Control then falls through to the common error label, which frees the same skb a second time and counts it again.

Return right after clearing the fragments when the skb owns frags; the no-frag case still drops through and frees the head skb once.

Fixes d6e882b89fdf ("rtase: Implement .ndo_start_xmit function")
---
 drivers/net/ethernet/realtek/rtase/rtase_main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/realtek/rtase/rtase_main.c +3 -0
index 255667775f0e..67f7fdada119 100644
@@ -1426,6 +1426,9 @@ static netdev_tx_t rtase_start_xmit(struct sk_buff *skb,
 err_dma_1:
 	ring->skbuff[entry] = NULL;
 	rtase_tx_clear_range(ring, ring->cur_idx + 1, frags);
+	if (frags)
+		/* the frags were cleared above, along with the skb */
+		return NETDEV_TX_OK;
 
 err_dma_0:
 	tp->stats.tx_dropped++;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Yun Lu

From: Yun Lu <[email protected]>

In rtase_start_xmit(), when the head buffer DMA mapping fails after rtase_xmit_frags() has mapped all fragments, the error path clears the fragment descriptors with rtase_tx_clear_range(), which frees the skb through the last-frag slot and accounts tx_dropped. Control then falls through to the common error label, which frees the same skb a second time and counts it again.

Return right after clearing the fragments when the skb owns frags; the no-frag case still drops through and frees the head skb once.

Fixes d6e882b89fdf ("rtase: Implement .ndo_start_xmit function")
---
 drivers/net/ethernet/realtek/rtase/rtase_main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/realtek/rtase/rtase_main.c +0 -0
index 255667775f0e..67f7fdada119 100644

drivers/net/ethernet/realtek/rtase/rtase_main.c static netdev_tx_t rtase_start_xmit(struct sk_buff *skb, · line 1432

Quoted 7 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c +3 -0
@@ -1426,6 +1426,9 @@ static netdev_tx_t rtase_start_xmit(struct sk_buff *skb,
 err_dma_1:
 	ring->skbuff[entry] = NULL;
 	rtase_tx_clear_range(ring, ring->cur_idx + 1, frags);
+	if (frags)
+		/* the frags were cleared above, along with the skb */
+		return NETDEV_TX_OK;
 

This feels a bit strange, but it matches the code in rtase_tx_clear_range. I do find it a bit odd we're checking frags here even though they got freed.. but it does seem to check out with how the rtase_tx_clear_range() works.

Quoted 2 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c +0 -0
 err_dma_0:
 	tp->stats.tx_dropped++;
maintainer
#2 lore raw
In reply to Yun Lu
Quoted 9 lines · On Tue, 21 Jul 2026 10:38:36 +0800 Yun Lu wrote:

From: Yun Lu <[email protected]>

In rtase_start_xmit(), when the head buffer DMA mapping fails after rtase_xmit_frags() has mapped all fragments, the error path clears the fragment descriptors with rtase_tx_clear_range(), which frees the skb through the last-frag slot and accounts tx_dropped. Control then falls through to the common error label, which frees the same skb a second time and counts it again.

Quoted 5 lines

Return right after clearing the fragments when the skb owns frags; the no-frag case still drops through and frees the head skb once.

Fixes d6e882b89fdf ("rtase: Implement .ndo_start_xmit function")

Justin, please review.

Quoted 14 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c +3 -0
index 255667775f0e..67f7fdada119 100644
@@ -1426,6 +1426,9 @@ static netdev_tx_t rtase_start_xmit(struct sk_buff *skb,
 err_dma_1:
 	ring->skbuff[entry] = NULL;
 	rtase_tx_clear_range(ring, ring->cur_idx + 1, frags);
+	if (frags)
+		/* the frags were cleared above, along with the skb */
+		return NETDEV_TX_OK;
 
 err_dma_0:
 	tp->stats.tx_dropped++;
maintainer Reviewed-by
#3 lore raw
Quoted 33 lines · Jakub Kicinski
Quoted 9 lines · On Tue, 21 Jul 2026 10:38:36 +0800 Yun Lu wrote:

From: Yun Lu <[email protected]>

In rtase_start_xmit(), when the head buffer DMA mapping fails after rtase_xmit_frags() has mapped all fragments, the error path clears the fragment descriptors with rtase_tx_clear_range(), which frees the skb through the last-frag slot and accounts tx_dropped. Control then falls through to the common error label, which frees the same skb a second time and counts it again.

Quoted 5 lines

Return right after clearing the fragments when the skb owns frags; the no-frag case still drops through and frees the head skb once.

Fixes d6e882b89fdf ("rtase: Implement .ndo_start_xmit function")

Justin, please review.

Quoted 14 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c +3 -0
index 255667775f0e..67f7fdada119 100644
@@ -1426,6 +1426,9 @@ static netdev_tx_t rtase_start_xmit(struct
 sk_buff *skb,
 err_dma_1:
      ring->skbuff[entry] = NULL;
      rtase_tx_clear_range(ring, ring->cur_idx + 1, frags);
+     if (frags)
+             /* the frags were cleared above, along with the skb */
+             return NETDEV_TX_OK;
 
Quoted 2 lines
Quoted 2 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c +0 -0
 err_dma_0:
      tp->stats.tx_dropped++;
#4 lore raw
In reply to Yun Lu
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 10 lines · On Tue, 21 Jul 2026 10:38:36 +0800 you wrote:

From: Yun Lu <[email protected]>

In rtase_start_xmit(), when the head buffer DMA mapping fails after rtase_xmit_frags() has mapped all fragments, the error path clears the fragment descriptors with rtase_tx_clear_range(), which frees the skb through the last-frag slot and accounts tx_dropped. Control then falls through to the common error label, which frees the same skb a second time and counts it again.

[...]

Here is the summary with links:
- rtase: fix double free of multi-frag skb on DMA map failure

    https://git.kernel.org/netdev/net/c/6fb7b769d6ed

You are awesome, thank you!

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