Skip to content

Commit 6aa3221

Browse files
esbendavem330
authored andcommitted
net: ll_temac: Make sure to free skb when it is completely used
With the skb pointer piggy-backed on the TX BD, we have a simple and efficient way to free the skb buffer when the frame has been transmitted. But in order to avoid freeing the skb while there are still fragments from the skb in use, we need to piggy-back on the TX BD of the skb, not the first. Without this, we are doing use-after-free on the DMA side, when the first BD of a multi TX BD packet is seen as completed in xmit_done, and the remaining BDs are still being processed. Cc: [email protected] # v5.4+ Signed-off-by: Esben Haabendal <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 35036d6 commit 6aa3221

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/net/ethernet/xilinx/ll_temac_main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,6 @@ temac_start_xmit(struct sk_buff *skb, struct net_device *ndev)
876876
return NETDEV_TX_OK;
877877
}
878878
cur_p->phys = cpu_to_be32(skb_dma_addr);
879-
ptr_to_txbd((void *)skb, cur_p);
880879

881880
for (ii = 0; ii < num_frag; ii++) {
882881
if (++lp->tx_bd_tail >= lp->tx_bd_num)
@@ -915,6 +914,11 @@ temac_start_xmit(struct sk_buff *skb, struct net_device *ndev)
915914
}
916915
cur_p->app0 |= cpu_to_be32(STS_CTRL_APP0_EOP);
917916

917+
/* Mark last fragment with skb address, so it can be consumed
918+
* in temac_start_xmit_done()
919+
*/
920+
ptr_to_txbd((void *)skb, cur_p);
921+
918922
tail_p = lp->tx_bd_p + sizeof(*lp->tx_bd_v) * lp->tx_bd_tail;
919923
lp->tx_bd_tail++;
920924
if (lp->tx_bd_tail >= lp->tx_bd_num)

0 commit comments

Comments
 (0)