Skip to contentSkip to conversation

net: ena: avoid double-counting TX DMA mappings on failure

PATCH RESEND Applied Avi Weiss 3 participants 3 messages Nov 15 – Nov 18

Subsystems (3)
lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

PATCH RESEND v2 1/1 net: ena: avoid double-counting TX DMA mappings on failure

ena_tx_map_skb() increments tx_info->num_of_bufs after each successful DMA mapping. If a later fragment mapping fails, the error path adds the fragment index to this count before calling ena_unmap_tx_buff(). This can cause DMA unmapping of buffers that were never mapped and out-of-bounds access to the buffer array.

Remove the extra increment so that cleanup uses only the number of successfully mapped buffers.

Discovered by comparing the in-tree ENA driver with Amazon's standalone ENA driver.

Compiled with W=1 under x86_64 defconfig and allmodconfig configurations.

Fixes 38005ca816a7 ("net: ena: add functions for handling Low Latency Queues in ena_netdev")
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/ethernet/amazon/ena/ena_netdev.c +0 -1
index 7eb6456ed0d5..e0df628e1df6 100644
@@ -2608,7 +2608,6 @@ static int ena_tx_map_skb(struct ena_ring *tx_ring,
 
 	tx_info->skb = NULL;
 
-	tx_info->num_of_bufs += i;
 	ena_unmap_tx_buff(tx_ring, tx_info);
 
 	return -EINVAL;
Signature · 1 line
2.43.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines

ena_tx_map_skb() increments tx_info->num_of_bufs after each successful DMA mapping. If a later fragment mapping fails, the error path adds the fragment index to this count before calling ena_unmap_tx_buff(). This can cause DMA unmapping of buffers that were never mapped and out-of-bounds access to the buffer array.

Remove the extra increment so that cleanup uses only the number of successfully mapped buffers.

Quoted 7 lines

Discovered by comparing the in-tree ENA driver with Amazon's standalone ENA driver.

Compiled with W=1 under x86_64 defconfig and allmodconfig configurations.

Fixes 38005ca816a7 ("net: ena: add functions for handling Low Latency Queues in ena_netdev")

Seems like v2 was resend to add the "changes" section only ..

anyway, this version does what was asked for on v1 and the fix looks good to me.

#2 lore raw
In reply to Avi Weiss
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 Sun, 15 Nov 2026 13:42:34 +0200 you wrote:

ena_tx_map_skb() increments tx_info->num_of_bufs after each successful DMA mapping. If a later fragment mapping fails, the error path adds the fragment index to this count before calling ena_unmap_tx_buff(). This can cause DMA unmapping of buffers that were never mapped and out-of-bounds access to the buffer array.

Remove the extra increment so that cleanup uses only the number of successfully mapped buffers.

[...]

Here is the summary with links:
- [net,v2,RESEND] net: ena: avoid double-counting TX DMA mappings on failure

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

You are awesome, thank you!

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