Skip to content

Commit 2be27d4

Browse files
lategoodbyegregkh
authored andcommitted
net: lan78xx: Fix race in tx pending skb size calculation
commit dea39ac upstream. The skb size calculation in lan78xx_tx_bh is in race with the start_xmit, which could lead to rare kernel oopses. So protect the whole skb walk with a spin lock. As a benefit we can unlink the skb directly. This patch was tested on Raspberry Pi 3B+ Link: raspberrypi/linux#2608 Fixes: 55d7de9 ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet") Cc: stable <[email protected]> Signed-off-by: Floris Bos <[email protected]> Signed-off-by: Stefan Wahren <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 12c0949 commit 2be27d4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/net/usb/lan78xx.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3197,6 +3197,7 @@ static void lan78xx_tx_bh(struct lan78xx_net *dev)
31973197
pkt_cnt = 0;
31983198
count = 0;
31993199
length = 0;
3200+
spin_lock_irqsave(&tqp->lock, flags);
32003201
for (skb = tqp->next; pkt_cnt < tqp->qlen; skb = skb->next) {
32013202
if (skb_is_gso(skb)) {
32023203
if (pkt_cnt) {
@@ -3205,7 +3206,8 @@ static void lan78xx_tx_bh(struct lan78xx_net *dev)
32053206
}
32063207
count = 1;
32073208
length = skb->len - TX_OVERHEAD;
3208-
skb2 = skb_dequeue(tqp);
3209+
__skb_unlink(skb, tqp);
3210+
spin_unlock_irqrestore(&tqp->lock, flags);
32093211
goto gso_skb;
32103212
}
32113213

@@ -3214,6 +3216,7 @@ static void lan78xx_tx_bh(struct lan78xx_net *dev)
32143216
skb_totallen = skb->len + roundup(skb_totallen, sizeof(u32));
32153217
pkt_cnt++;
32163218
}
3219+
spin_unlock_irqrestore(&tqp->lock, flags);
32173220

32183221
/* copy to a single skb */
32193222
skb = alloc_skb(skb_totallen, GFP_ATOMIC);

0 commit comments

Comments
 (0)