FAILED: patch "[PATCH] net: macb: fix dma_alloc_coherent() leak on macb_alloc()" failed to apply to 6.18-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 23d42b9a3bcd55b17d3b371544fedc708c2397e9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026092901-evaluator-improvise-eb56@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 23d42b9a3bcd55b17d3b371544fedc708c2397e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9o=20Lebrun?= <[email protected]>
Date: Fri, 18 Sep 2026 21:53:52 +0200
Subject: [PATCH] net: macb: fix dma_alloc_coherent() leak on macb_alloc()
error paths
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Fix 3 leaks in macb_alloc() error paths:
- Tx buffer allocated but crossing a 4G boundary: Tx leaked.
- Rx buffer allocation fails: Tx leaked.
- Rx buffer allocated but crossing a 4G boundary: Tx & Rx leaked.
This is because our error handling calls macb_free(bp) which in turn frees the buffers stored in bp->queues[0], but nothing has been stored in there. Fix by storing allocated buffers into bp->queues[0] ASAP.
drivers/net/ethernet/cadence/macb_main.c +12 -2
@@ -2749,14 +2749,24 @@ static int macb_alloc(struct macb *bp) size = bp->num_queues *macb_tx_ring_size_per_queue (bp); tx =dma_alloc_coherent (dev, size, &tx_dma,GFP_KERNEL ); -if (!tx ||upper_32_bits (tx_dma) !=upper_32_bits (tx_dma + size -1 )) +if (!tx) + goto out_err; +/* Record the buffer so that the error path frees it. */ + bp->queues[0 ].tx_ring = tx; + bp->queues[0 ].tx_ring_dma = tx_dma; +if (upper_32_bits (tx_dma) !=upper_32_bits (tx_dma + size -1 )) goto out_err;netdev_dbg (bp->netdev,"Allocated %zu bytes for %u TX rings at %08lx (mapped %p)\n" , size, bp->num_queues, (unsigned long )tx_dma, tx); size = bp->num_queues *macb_rx_ring_size_per_queue (bp); rx =dma_alloc_coherent (dev, size, &rx_dma,GFP_KERNEL ); -if (!rx ||upper_32_bits (rx_dma) !=upper_32_bits (rx_dma + size -1 )) +if (!rx) + goto out_err; +/* Record the buffer so that the error path frees it. */ + bp->queues[0 ].rx_ring = rx; + bp->queues[0 ].rx_ring_dma = rx_dma; +if (upper_32_bits (rx_dma) !=upper_32_bits (rx_dma + size -1 )) goto out_err;netdev_dbg (bp->netdev,"Allocated %zu bytes for %u RX rings at %08lx (mapped %p)\n" , size, bp->num_queues, (unsigned long )rx_dma, rx);
Sasha Levin
maintainerPATCH 1/1 net: macb: fix dma_alloc_coherent() leak on macb_alloc() error paths
From: Théo Lebrun <[email protected]>
[ Upstream commit 23d42b9a3bcd55b17d3b371544fedc708c2397e9 ]
Fix 3 leaks in macb_alloc() error paths:
- Tx buffer allocated but crossing a 4G boundary: Tx leaked.
- Rx buffer allocation fails: Tx leaked.
- Rx buffer allocated but crossing a 4G boundary: Tx & Rx leaked.
This is because our error handling calls macb_free(bp) which in turn frees the buffers stored in bp->queues[0], but nothing has been stored in there. Fix by storing allocated buffers into bp->queues[0] ASAP.
--- drivers/net/ethernet/cadence/macb_main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +12 -2
@@ -2663,14 +2663,24 @@ static int macb_alloc_consistent(struct macb *bp) size = bp->num_queues *macb_tx_ring_size_per_queue (bp); tx =dma_alloc_coherent (dev, size, &tx_dma,GFP_KERNEL ); -if (!tx ||upper_32_bits (tx_dma) !=upper_32_bits (tx_dma + size -1 )) +if (!tx) + goto out_err; +/* Record the buffer so that the error path frees it. */ + bp->queues[0 ].tx_ring = tx; + bp->queues[0 ].tx_ring_dma = tx_dma; +if (upper_32_bits (tx_dma) !=upper_32_bits (tx_dma + size -1 )) goto out_err;netdev_dbg (bp->dev,"Allocated %zu bytes for %u TX rings at %08lx (mapped %p)\n" , size, bp->num_queues, (unsigned long )tx_dma, tx); size = bp->num_queues *macb_rx_ring_size_per_queue (bp); rx =dma_alloc_coherent (dev, size, &rx_dma,GFP_KERNEL ); -if (!rx ||upper_32_bits (rx_dma) !=upper_32_bits (rx_dma + size -1 )) +if (!rx) + goto out_err; +/* Record the buffer so that the error path frees it. */ + bp->queues[0 ].rx_ring = rx; + bp->queues[0 ].rx_ring_dma = rx_dma; +if (upper_32_bits (rx_dma) !=upper_32_bits (rx_dma + size -1 )) goto out_err;netdev_dbg (bp->dev,"Allocated %zu bytes for %u RX rings at %08lx (mapped %p)\n" , size, bp->num_queues, (unsigned long )rx_dma, rx);
Signature · 1 line
2.53.0