Skip to content

Commit c113d5e

Browse files
committed
Merge branch 'net-spacemit-a-few-error-handling-fixes'
Vivian Wang says: ==================== net: spacemit: A few error handling fixes Recently a user reported a supposed UAF/double-free in this driver. It turned out to be a false positive (ugh) from a bug with riscv's kfence_protect_page() [1], but it did also prompt me to review the driver code yet again. These are some fixes for error handling problems that I've found. [1]: https://lore.kernel.org/r/20260303-handle-kfence-protect-spurious-fault-v2-0-f80d8354d79d@iscas.ac.cn/ ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 4245a79 + 8629215 commit c113d5e

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

drivers/net/ethernet/spacemit/k1_emac.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,9 @@ static void emac_alloc_rx_desc_buffers(struct emac_priv *priv)
565565
DMA_FROM_DEVICE);
566566
if (dma_mapping_error(&priv->pdev->dev, rx_buf->dma_addr)) {
567567
dev_err_ratelimited(&ndev->dev, "Mapping skb failed\n");
568-
goto err_free_skb;
568+
dev_kfree_skb_any(skb);
569+
rx_buf->skb = NULL;
570+
break;
569571
}
570572

571573
rx_desc_addr = &((struct emac_desc *)rx_ring->desc_addr)[i];
@@ -590,10 +592,6 @@ static void emac_alloc_rx_desc_buffers(struct emac_priv *priv)
590592

591593
rx_ring->head = i;
592594
return;
593-
594-
err_free_skb:
595-
dev_kfree_skb_any(skb);
596-
rx_buf->skb = NULL;
597595
}
598596

599597
/* Returns number of packets received */
@@ -735,7 +733,7 @@ static void emac_tx_mem_map(struct emac_priv *priv, struct sk_buff *skb)
735733
struct emac_desc tx_desc, *tx_desc_addr;
736734
struct device *dev = &priv->pdev->dev;
737735
struct emac_tx_desc_buffer *tx_buf;
738-
u32 head, old_head, frag_num, f;
736+
u32 head, old_head, frag_num, f, i;
739737
bool buf_idx;
740738

741739
frag_num = skb_shinfo(skb)->nr_frags;
@@ -803,6 +801,15 @@ static void emac_tx_mem_map(struct emac_priv *priv, struct sk_buff *skb)
803801

804802
err_free_skb:
805803
dev_dstats_tx_dropped(priv->ndev);
804+
805+
i = old_head;
806+
while (i != head) {
807+
emac_free_tx_buf(priv, i);
808+
809+
if (++i == tx_ring->total_cnt)
810+
i = 0;
811+
}
812+
806813
dev_kfree_skb_any(skb);
807814
}
808815

0 commit comments

Comments
 (0)