Skip to contentSkip to conversation

net: xilinx: axienet: Add error handling for RX metadata pointer retrieval

PATCH Superseded Abin Joseph 3 participants 3 messages Sep 2, 2025

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: xilinx: axienet: Add error handling for RX metadata pointer retrieval

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")

---

Changes in v2:
Update the alias to net

---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +11 -0
index 0d8a05fe541a..83469f7f08d1 100644
@@ -1166,8 +1166,18 @@ static void axienet_dma_rx_cb(void *data, const struct dmaengine_result *result)
 	skb = skbuf_dma->skb;
 	app_metadata = dmaengine_desc_get_metadata_ptr(skbuf_dma->desc, &meta_len,
 						       &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);
@@ -1180,6 +1190,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);
Signature · 1 line
2.34.1
#1 lore raw
FYI: kernel test robot notices the stable kernel rule is not satisfied.

Hi,

Thanks for your patch.

FYI: kernel test robot notices the stable kernel rule is not satisfied.

The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-1

Rule: add the tag "Cc: [email protected]" in the sign-off area to have the patch automatically included in the stable tree.
Subject: [PATCH net v2] net: xilinx: axienet: Add error handling for RX metadata pointer retrieval

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Abin Joseph

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 16 lines

-----Original Message-----
From: Abin Joseph <[email protected]>
Sent: Tuesday, September 2, 2025 7:02 AM
To: Pandey, Radhey Shyam <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>
Cc: git (AMD-Xilinx) <[email protected]>; Joseph, Abin <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: [PATCH net v2] net: xilinx: axienet: Add error handling for RX metadata pointer retrieval

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.

Quoted 5 lines

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")

With one minor comment below-

Quoted 15 lines

---

Changes in v2:
Update the alias to net

---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -0
index 0d8a05fe541a..83469f7f08d1 100644

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static void axienet_dma_rx_cb(void *data, const struct · line 1171

Quoted 6 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1 -0
@@ -1166,8 +1166,18 @@ static void axienet_dma_rx_cb(void *data, const struct
 dmaengine_result *result)
      skb = skbuf_dma->skb;
      app_metadata = dmaengine_desc_get_metadata_ptr(skbuf_dma->desc,
 &meta_len,
                                                     &meta_max_len);
+

This is unrelated change.

Quoted 25 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +9 -0
      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);
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1 -0
@@ -1180,6 +1190,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);

--
2.34.1