]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: xilinx: axienet: Add error handling for RX metadata pointer retrieval
authorAbin Joseph <abin.joseph@amd.com>
Wed, 3 Sep 2025 02:52:13 +0000 (08:22 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 9 Sep 2025 16:58:14 +0000 (18:58 +0200)
[ Upstream commit 8bbceba7dc5090c00105e006ce28d1292cfda8dd ]

Add proper error checking for dmaengine_desc_get_metadata_ptr() which
can return an error pointer and lead to potential crashes or undefined
behaviour if the pointer retrieval fails.

Properly handle the error by unmapping DMA buffer, freeing the skb and
returning early to prevent further processing with invalid data.

Fixes: 6a91b846af85 ("net: axienet: Introduce dmaengine support")
Signed-off-by: Abin Joseph <abin.joseph@amd.com>
Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
Link: https://patch.msgid.link/20250903025213.3120181-1-abin.joseph@amd.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/xilinx/xilinx_axienet_main.c

index 1775e060d39d38df99849ea0f0e0e806d6840763..3339c5e1a57a9ae3ac610e069a089aa616b5f696 100644 (file)
@@ -1127,6 +1127,15 @@ static void axienet_dma_rx_cb(void *data, const struct dmaengine_result *result)
                                                       &meta_max_len);
        dma_unmap_single(lp->dev, skbuf_dma->dma_address, lp->max_frm_size,
                         DMA_FROM_DEVICE);
+
+       if (IS_ERR(app_metadata)) {
+               if (net_ratelimit())
+                       netdev_err(lp->ndev, "Failed to get RX metadata pointer\n");
+               dev_kfree_skb_any(skb);
+               lp->ndev->stats.rx_dropped++;
+               goto rx_submit;
+       }
+
        /* TODO: Derive app word index programmatically */
        rx_len = (app_metadata[LEN_APP] & 0xFFFF);
        skb_put(skb, rx_len);
@@ -1139,6 +1148,7 @@ static void axienet_dma_rx_cb(void *data, const struct dmaengine_result *result)
        u64_stats_add(&lp->rx_bytes, rx_len);
        u64_stats_update_end(&lp->rx_stat_sync);
 
+rx_submit:
        for (i = 0; i < CIRC_SPACE(lp->rx_ring_head, lp->rx_ring_tail,
                                   RX_BUF_NUM_DEFAULT); i++)
                axienet_rx_submit_desc(lp->ndev);