> 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: stab…@vger.kernel.org > Signed-off-by: Keisuke Tsukuda <tkdk…@outlook.jp>
Thanks for fixing this issue. Reviewed-by: Wei Fang <wei…@nxp.com>