Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net: mvpp2: clear rxq->descs after dma_free_coherent() on init failure
@ 2026-12-06  3:05 Yuansheng Yang
  2026-12-06  3:08 ` netdev-bot+sinfo
  0 siblings, 1 reply; 2+ messages in thread
From: Yuansheng Yang @ 2026-12-06  3:05 UTC (permalink / raw)
  To: Marcin Wojtas, Russell King, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, stable

In mvpp2_rxq_init(), if xdp_rxq_info_reg() or
xdp_rxq_info_reg_mem_model() fails after dma_alloc_coherent() has
succeeded, the err_free_dma unwind path calls dma_free_coherent() for
rxq->descs without resetting rxq->descs to NULL or rxq->descs_dma to 0.

On error return from mvpp2_rxq_init(), mvpp2_setup_rxqs() jumps to
err_cleanup and calls mvpp2_cleanup_rxqs() -> mvpp2_rxq_deinit(). Because
rxq->descs is still non-NULL on the failing queue, mvpp2_rxq_deinit()
invokes dma_free_coherent() a second time on the already-freed DMA
allocation:

  DMA-API: platform mvpp2_repro: device driver tries to free DMA memory it has not allocated [size=512 bytes]
  Call Trace:
   check_unmap
   debug_dma_free_coherent
   dma_free_attrs
   mvpp2_cleanup_rxqs
   mvpp2_setup_rxqs

Clear rxq->descs and rxq->descs_dma after freeing them on the error path
of mvpp2_rxq_init() so subsequent cleanup in mvpp2_rxq_deinit() skips the
already-freed descriptor ring.

Fixes: b27db2274ba8 ("mvpp2: use page_pool allocator")
Cc: stable@vger.kernel.org
Signed-off-by: Yuansheng Yang <0xbeac@gmail.com>
---
Compiled drivers/net/ethernet/marvell/mvpp2/mvpp2_main.o with W=1 on
x86_64 (0 warnings, 0 errors) and verified on v7.4-rc5 in an x86_64
KASAN + DMA-API debug QEMU guest via mvpp2_setup_rxqs() failing XDP
memory model registration followed by mvpp2_cleanup_rxqs(): before this
fix, DMA-API reports freeing unallocated DMA memory in
mvpp2_cleanup_rxqs(); after this fix, 10/10 iterations unwind cleanly
with rxq->descs == NULL and 0 DMA-API, KASAN, BUG, or WARNING
diagnostics.

 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 35adcee9a..1dfefd355 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -3021,6 +3021,8 @@ static int mvpp2_rxq_init(struct mvpp2_port *port,
 	dma_free_coherent(port->dev->dev.parent,
 			  rxq->size * MVPP2_DESC_ALIGNED_SIZE,
 			  rxq->descs, rxq->descs_dma);
+	rxq->descs = NULL;
+	rxq->descs_dma = 0;
 	return err;
 }
 
-- 
2.53.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-06  3:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06  3:05 [PATCH net] net: mvpp2: clear rxq->descs after dma_free_coherent() on init failure Yuansheng Yang
2026-12-06  3:08 ` netdev-bot+sinfo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox