Patch "net: ethernet: mtk_eth_soc: fix potential memory leak in mtk_rx_alloc()" has been added to the 6.0-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    net: ethernet: mtk_eth_soc: fix potential memory leak in mtk_rx_alloc()

to the 6.0-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     net-ethernet-mtk_eth_soc-fix-potential-memory-leak-i.patch
and it can be found in the queue-6.0 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 2f8480dd1390869d9da5d9aff1394927b1dc2cfc
Author: Ziyang Xuan <william.xuanziyang@xxxxxxxxxx>
Date:   Sun Nov 20 11:54:05 2022 +0800

    net: ethernet: mtk_eth_soc: fix potential memory leak in mtk_rx_alloc()
    
    [ Upstream commit 3213f808ae21be3891885de2f3a775afafcda987 ]
    
    When fail to dma_map_single() in mtk_rx_alloc(), it returns directly.
    But the memory allocated for local variable data is not freed, and
    local variabel data has not been attached to ring->data[i] yet, so the
    memory allocated for local variable data will not be freed outside
    mtk_rx_alloc() too. Thus memory leak would occur in this scenario.
    
    Add skb_free_frag(data) when dma_map_single() failed.
    
    Fixes: 23233e577ef9 ("net: ethernet: mtk_eth_soc: rely on page_pool for single page buffers")
    Signed-off-by: Ziyang Xuan <william.xuanziyang@xxxxxxxxxx>
    Acked-by: Lorenzo Bianconi <lorenzo.bianconi@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20221120035405.1464341-1-william.xuanziyang@xxxxxxxxxx
    Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index a75f5931f746..916b570bdbf4 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -2363,8 +2363,10 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
 				data + NET_SKB_PAD + eth->ip_align,
 				ring->buf_size, DMA_FROM_DEVICE);
 			if (unlikely(dma_mapping_error(eth->dma_dev,
-						       dma_addr)))
+						       dma_addr))) {
+				skb_free_frag(data);
 				return -ENOMEM;
+			}
 		}
 		rxd->rxd1 = (unsigned int)dma_addr;
 		ring->data[i] = data;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux