Skip to content

Commit dea39ac

Browse files
lategoodbyedavem330
authored andcommitted
net: lan78xx: Fix race in tx pending skb size calculation
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]>
1 parent b5d2d75 commit dea39ac

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
@@ -3344,6 +3344,7 @@ static void lan78xx_tx_bh(struct lan78xx_net *dev)
33443344
pkt_cnt = 0;
33453345
count = 0;
33463346
length = 0;
3347+
spin_lock_irqsave(&tqp->lock, flags);
33473348
for (skb = tqp->next; pkt_cnt < tqp->qlen; skb = skb->next) {
33483349
if (skb_is_gso(skb)) {
33493350
if (pkt_cnt) {
@@ -3352,7 +3353,8 @@ static void lan78xx_tx_bh(struct lan78xx_net *dev)
33523353
}
33533354
count = 1;
33543355
length = skb->len - TX_OVERHEAD;
3355-
skb2 = skb_dequeue(tqp);
3356+
__skb_unlink(skb, tqp);
3357+
spin_unlock_irqrestore(&tqp->lock, flags);
33563358
goto gso_skb;
33573359
}
33583360

@@ -3361,6 +3363,7 @@ static void lan78xx_tx_bh(struct lan78xx_net *dev)
33613363
skb_totallen = skb->len + roundup(skb_totallen, sizeof(u32));
33623364
pkt_cnt++;
33633365
}
3366+
spin_unlock_irqrestore(&tqp->lock, flags);
33643367

33653368
/* copy to a single skb */
33663369
skb = alloc_skb(skb_totallen, GFP_ATOMIC);

0 commit comments

Comments
 (0)