]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: libwx: fix the using of Rx buffer DMA
authorJiawen Wu <jiawenwu@trustnetic.com>
Mon, 14 Jul 2025 02:47:54 +0000 (10:47 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 24 Jul 2025 06:58:29 +0000 (08:58 +0200)
commit 5fd77cc6bd9b368431a815a780e407b7781bcca0 upstream.

The wx_rx_buffer structure contained two DMA address fields: 'dma' and
'page_dma'. However, only 'page_dma' was actually initialized and used
to program the Rx descriptor. But 'dma' was uninitialized and used in
some paths.

This could lead to undefined behavior, including DMA errors or
use-after-free, if the uninitialized 'dma' was used. Althrough such
error has not yet occurred, it is worth fixing in the code.

Fixes: 3c47e8ae113a ("net: libwx: Support to receive packets in NAPI")
Cc: stable@vger.kernel.org
Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250714024755.17512-3-jiawenwu@trustnetic.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/ethernet/wangxun/libwx/wx_lib.c
drivers/net/ethernet/wangxun/libwx/wx_type.h

index ff86ec22bef04647b8403b8eb1b10227215104e2..87d03157c05d02dc9c234bf8c41e8f6908de74eb 100644 (file)
@@ -306,7 +306,7 @@ static bool wx_alloc_mapped_page(struct wx_ring *rx_ring,
                return false;
        dma = page_pool_get_dma_addr(page);
 
-       bi->page_dma = dma;
+       bi->dma = dma;
        bi->page = page;
        bi->page_offset = 0;
 
@@ -343,7 +343,7 @@ void wx_alloc_rx_buffers(struct wx_ring *rx_ring, u16 cleaned_count)
                                                 DMA_FROM_DEVICE);
 
                rx_desc->read.pkt_addr =
-                       cpu_to_le64(bi->page_dma + bi->page_offset);
+                       cpu_to_le64(bi->dma + bi->page_offset);
 
                rx_desc++;
                bi++;
index 4635e251b4303a16b797e64130f40cd93f49aab0..3554b870ed592aae429882af78f49c8cf80b0a7b 100644 (file)
@@ -947,7 +947,6 @@ struct wx_tx_buffer {
 struct wx_rx_buffer {
        struct sk_buff *skb;
        dma_addr_t dma;
-       dma_addr_t page_dma;
        struct page *page;
        unsigned int page_offset;
 };