Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Keisuke Tsukuda
Sat, 28 Nov 2026 12:05
[PATCH net v2] net: fec: fix TSO DMA mapping failure handling
Author: Keisuke Tsukuda
Date: Sat, 28 Nov 2026 12:05
Date: Sat, 28 Nov 2026 12:05
126 lines
21830 bytes
21830 bytes
From: Keisuke Tsukuda <tkdkei@outlook.jp>
The TSO descriptor helpers free the skb and return NETDEV_TX_OK when
dma_map_single() fails. As this is zero, fec_enet_txq_submit_tso()
continues after the failure. A failed data mapping then reaches
tso_build_data() with the freed skb, causing a use-after-free.
Return -ENOMEM from the helpers without freeing the skb. The caller
can unmap staged descriptors, free the skb once, and return
NETDEV_TX_OK after consuming the failed packet.
That cleanup must retain BD_ENET_TX_WRAP at the end of the ring.
It must also avoid touching descriptors already owned by the MAC:
the helpers currently set READY as each descriptor is built, so a
prior transmission can advance into a partly mapped TSO packet before
a later mapping fails. Leave the first descriptor unready until all
mappings succeed, then publish it after dma_wmb().
The error cleanup in fec_enet_txq_submit_tso() came from commit
61dc1fd9205b ("net: fec: implement TSO descriptor cleanup").
Backports to older trees need that cleanup or an equivalent.
The mismatch was found by inspecting the TSO error path. On an i.MX6Q
board, test-only 7.4.0-rc2 RAM kernels injected a failure before
the first data DMA mapping using an unregistered netdev and fake TX
ring. The unfixed full caller produced a KASAN use-after-free in
tso_build_data(). With this change, a ring-end test kept the first
descriptor unready, retained WRAP, and freed the skb once without a
KASAN report. The probes performed no real DMA map or transmission.
The hardware race and header mapping failure were not reproduced.
Network selftests were not run.
The updated FEC object built under ARM allyesconfig and allmodconfig
with W=1 using GCC 13.3.
Fixes: 06a4df5863f7 ("net: fec: fix improper use of NETDEV_TX_BUSY")
Cc: stable@vger.kernel.org
Signed-off-by: Keisuke Tsukuda <tkdkei@outlook.jp>
---
v2:
- Use dma_wmb() after setting READY instead of wmb().
v1: https://lore.kernel.org/netdev/20261127033906.9561-1-tkdkei@outlook.jp/
drivers/net/ethernet/freescale/fec_main.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index f7636f23d..2d1478a2b 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -746,10 +746,9 @@ fec_enet_txq_put_data_tso(struct fec_enet_priv_tx_q *txq, struct sk_buff *skb,
addr = dma_map_single(&fep->pdev->dev, data, size, DMA_TO_DEVICE);
if (dma_mapping_error(&fep->pdev->dev, addr)) {
- dev_kfree_skb_any(skb);
if (net_ratelimit())
netdev_err(ndev, "Tx DMA memory map failed\n");
- return NETDEV_TX_OK;
+ return -ENOMEM;
}
bdp->cbd_datlen = cpu_to_fec16(size);
@@ -792,8 +791,11 @@ fec_enet_txq_put_hdr_tso(struct fec_enet_priv_tx_q *txq,
unsigned int estatus = 0;
status = fec16_to_cpu(bdp->cbd_sc);
- status &= ~BD_ENET_TX_STATS;
- status |= (BD_ENET_TX_TC | BD_ENET_TX_READY);
+ status &= ~(BD_ENET_TX_STATS | BD_ENET_TX_READY);
+ status |= BD_ENET_TX_TC;
+ /* Keep the first descriptor unavailable until all mappings succeed. */
+ if (bdp != txq->bd.cur)
+ status |= BD_ENET_TX_READY;
bufaddr = txq->tso_hdrs + index * TSO_HEADER_SIZE;
dmabuf = txq->tso_hdrs_dma + index * TSO_HEADER_SIZE;
@@ -808,10 +810,9 @@ fec_enet_txq_put_hdr_tso(struct fec_enet_priv_tx_q *txq,
dmabuf = dma_map_single(&fep->pdev->dev, bufaddr,
hdr_len, DMA_TO_DEVICE);
if (dma_mapping_error(&fep->pdev->dev, dmabuf)) {
- dev_kfree_skb_any(skb);
if (net_ratelimit())
netdev_err(ndev, "Tx DMA memory map failed\n");
- return NETDEV_TX_OK;
+ return -ENOMEM;
}
}
@@ -901,6 +902,10 @@ static int fec_enet_txq_submit_tso(struct fec_enet_priv_tx_q *txq,
txq->tx_buf[index].buf_p = skb;
skb_tx_timestamp(skb);
+ dma_wmb();
+ txq->bd.cur->cbd_sc |= cpu_to_fec16(BD_ENET_TX_READY);
+ /* Make the READY update visible before advancing the ring cursor. */
+ dma_wmb();
txq->bd.cur = bdp;
/* Trigger transmission start */
@@ -922,7 +927,7 @@ static int fec_enet_txq_submit_tso(struct fec_enet_priv_tx_q *txq,
DMA_TO_DEVICE);
/* Clear standard buffer descriptor fields */
- tmp_bdp->cbd_sc = 0;
+ tmp_bdp->cbd_sc &= cpu_to_fec16(BD_ENET_TX_WRAP);
tmp_bdp->cbd_datlen = 0;
tmp_bdp->cbd_bufaddr = 0;
@@ -937,7 +942,7 @@ static int fec_enet_txq_submit_tso(struct fec_enet_priv_tx_q *txq,
dev_kfree_skb_any(skb);
- return ret;
+ return NETDEV_TX_OK;
}
static netdev_tx_t
RE: [PATCH net v2] net: fec: fix TSO DMA mapping failure handling
Author: Wei Fang
Date: Mon, 30 Nov 2026 06:14
Date: Mon, 30 Nov 2026 06:14
40 lines
19026 bytes
19026 bytes
> The TSO descriptor helpers free the skb and return NETDEV_TX_OK when
> dma_map_single() fails. As this is zero, fec_enet_txq_submit_tso()
> continues after the failure. A failed data mapping then reaches
> tso_build_data() with the freed skb, causing a use-after-free.
>
> Return -ENOMEM from the helpers without freeing the skb. The caller
> can unmap staged descriptors, free the skb once, and return
> NETDEV_TX_OK after consuming the failed packet.
>
> That cleanup must retain BD_ENET_TX_WRAP at the end of the ring.
> It must also avoid touching descriptors already owned by the MAC:
> the helpers currently set READY as each descriptor is built, so a
> prior transmission can advance into a partly mapped TSO packet before
> a later mapping fails. Leave the first descriptor unready until all
> mappings succeed, then publish it after dma_wmb().
>
> The error cleanup in fec_enet_txq_submit_tso() came from commit
> 61dc1fd9205b ("net: fec: implement TSO descriptor cleanup").
> Backports to older trees need that cleanup or an equivalent.
>
> The mismatch was found by inspecting the TSO error path. On an i.MX6Q
> board, test-only 7.4.0-rc2 RAM kernels injected a failure before
> the first data DMA mapping using an unregistered netdev and fake TX
> ring. The unfixed full caller produced a KASAN use-after-free in
> tso_build_data(). With this change, a ring-end test kept the first
> descriptor unready, retained WRAP, and freed the skb once without a
> KASAN report. The probes performed no real DMA map or transmission.
> The hardware race and header mapping failure were not reproduced.
> Network selftests were not run.
> The updated FEC object built under ARM allyesconfig and allmodconfig
> with W=1 using GCC 13.3.
>
> Fixes: 06a4df5863f7 ("net: fec: fix improper use of NETDEV_TX_BUSY")
> Cc: stable@vger.kernel.org
> Signed-off-by: Keisuke Tsukuda <tkdkei@outlook.jp>
Thanks for fixing this issue.
Reviewed-by: Wei Fang <wei.fang@nxp.com>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads