net: dlink: handle copy_thresh allocation failure
Subsystems (2)
PATCH v4 1/1 net: dlink: handle copy_thresh allocation failure
The driver did not handle failure of netdev_alloc_skb_ip_align(). If the allocation failed, dereferencing skb->protocol could lead to a NULL pointer dereference.
This patch tries to allocate skb. If the allocation fails, it falls back to the normal path.
Tested-on: D-Link DGE-550T Rev-A3
--- drivers/net/ethernet/dlink/dl2k.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
---
Changelog:
v4:
- consolidated into a single patch
- removed goto statement, per Jakub's suggestion
- reorder changelog for clarity
v3: https://lore.kernel.org/netdev/[email protected]/
- change confusing label name
v2: https://lore.kernel.org/netdev/[email protected]/
- split into two patches: whitespace cleanup and functional fix
v1: https://lore.kernel.org/netdev/[email protected]/
---
drivers/net/ethernet/dlink/dl2k.c +5 -2
@@ -964,15 +964,18 @@ receive_packet (struct net_device *dev) }else {struct sk_buff *skb; + skb =NULL ;/* Small skbuffs for short packets */ -if (pkt_len > copy_thresh) { +if (pkt_len <= copy_thresh) + skb =netdev_alloc_skb_ip_align (dev, pkt_len); +if (!skb) {dma_unmap_single (&np->pdev->dev,desc_to_dma (desc), np->rx_buf_sz,DMA_FROM_DEVICE );skb_put (skb = np->rx_skbuff[entry], pkt_len); np->rx_skbuff[entry] =NULL ; - }else if ((skb =netdev_alloc_skb_ip_align (dev, pkt_len))) { + }else { dma_sync_single_for_cpu(&np->pdev->dev, desc_to_dma(desc), np->rx_buf_sz,
Signature · 1 line
2.51.0
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Mon, 29 Sep 2025 04:01:24 +0900 you wrote:
The driver did not handle failure of
netdev_alloc_skb_ip_align(). If the allocation failed, dereferencingskb->protocolcould lead to a NULL pointer dereference.This patch tries to allocate
skb. If the allocation fails, it falls back to the normal path.[...]
Here is the summary with links:
- [net,v4] net: dlink: handle copy_thresh allocation failure
https://git.kernel.org/netdev/net/c/8169a6011c5f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html