Skip to content

Commit 8169a60

Browse files
Cruzer-Skuba-moo
authored andcommitted
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. Fixes: 1da177e ("Linux-2.6.12-rc2") Suggested-by: Jakub Kicinski <[email protected]> Tested-on: D-Link DGE-550T Rev-A3 Signed-off-by: Yeounsu Moon <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f017156 commit 8169a60

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/net/ethernet/dlink/dl2k.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,15 +964,18 @@ receive_packet (struct net_device *dev)
964964
} else {
965965
struct sk_buff *skb;
966966

967+
skb = NULL;
967968
/* Small skbuffs for short packets */
968-
if (pkt_len > copy_thresh) {
969+
if (pkt_len <= copy_thresh)
970+
skb = netdev_alloc_skb_ip_align(dev, pkt_len);
971+
if (!skb) {
969972
dma_unmap_single(&np->pdev->dev,
970973
desc_to_dma(desc),
971974
np->rx_buf_sz,
972975
DMA_FROM_DEVICE);
973976
skb_put (skb = np->rx_skbuff[entry], pkt_len);
974977
np->rx_skbuff[entry] = NULL;
975-
} else if ((skb = netdev_alloc_skb_ip_align(dev, pkt_len))) {
978+
} else {
976979
dma_sync_single_for_cpu(&np->pdev->dev,
977980
desc_to_dma(desc),
978981
np->rx_buf_sz,

0 commit comments

Comments
 (0)