From: Keisuke Tsukuda <tkdkei@outlook.jp>
To: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"wei.fang@nxp.com" <wei.fang@nxp.com>
Cc: "frank.li@nxp.com" <frank.li@nxp.com>,
"shenwei.wang@nxp.com" <shenwei.wang@nxp.com>,
"andrew+netdev@lunn.ch" <andrew+netdev@lunn.ch>,
"davem@davemloft.net" <davem@davemloft.net>,
"edumazet@kernel.org" <edumazet@kernel.org>,
"kuba@kernel.org" <kuba@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"imx@lists.linux.dev" <imx@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Keisuke Tsukuda <tkdkei@outlook.jp>
Subject: [PATCH net] net: fec: fix TSO DMA mapping failure handling
Date: Fri, 27 Nov 2026 03:39:11 +0000 [thread overview]
Message-ID: <20261127033906.9561-1-tkdkei@outlook.jp> (raw)
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>
---
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..a2c760218 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. */
+ 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
reply other threads:[~2026-11-27 3:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127033906.9561-1-tkdkei@outlook.jp \
--to=tkdkei@outlook.jp \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=frank.li@nxp.com \
--cc=imx@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shenwei.wang@nxp.com \
--cc=wei.fang@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox