rtase: fix double free of multi-frag skb on DMA map failure
Subsystems (3)
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.
--- drivers/net/ethernet/realtek/rtase/rtase_main.c | 3 +++ 1 file changed, 3 insertions(+)
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 ; err_dma_0: tp->stats.tx_dropped++;
Signature · 1 line
2.43.0
Quoted 23 lines · Yun Lu
From: Yun Lu <[email protected]>
In
rtase_start_xmit(), when the head buffer DMA mapping fails afterrtase_xmit_frags()has mapped all fragments, the error path clears the fragment descriptors withrtase_tx_clear_range(), which frees the skb through the last-frag slot and accountstx_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")Signed-off-by Yun Lu <[email protected]>--- drivers/net/ethernet/realtek/rtase/rtase_main.c | 3 +++ 1 file changed, 3 insertions(+)drivers/net/ethernet/realtek/rtase/rtase_main.c +0
-0
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
-0err_dma_0: tp->stats.tx_dropped++;
Jakub Kicinski
maintainerQuoted 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 afterrtase_xmit_frags()has mapped all fragments, the error path clears the fragment descriptors withrtase_tx_clear_range(), which frees the skb through the last-frag slot and accountstx_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")Signed-off-by Yun Lu <[email protected]>
Justin, please review.
Quoted 14 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 ; err_dma_0: tp->stats.tx_dropped++;
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 afterrtase_xmit_frags()has mapped all fragments, the error path clears the fragment descriptors withrtase_tx_clear_range(), which frees the skb through the last-frag slot and accountstx_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")Signed-off-by Yun Lu <[email protected]>Justin, please review.
Quoted 14 lines
drivers/net/ethernet/realtek/rtase/rtase_main.c +3
-0@@ -1426,6 +1426,9 @@ static netdev_tx_t rtase_start_xmit(structsk_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
-0err_dma_0:tp->stats.tx_dropped++;
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 afterrtase_xmit_frags()has mapped all fragments, the error path clears the fragment descriptors withrtase_tx_clear_range(), which frees the skb through the last-frag slot and accountstx_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