Skip to content

Commit db81c14

Browse files
Stefan Wahrenpelwell
authored andcommitted
net: lan78xx: Fix race in tx skb size calculation (raspberrypi#2614)
The skb size calculation in lan78xx_tx_bh is in race with the start_xmit, which could lead to kernel oopses. So protect the whole skb walk with a spin lock. As a benefit we can unlink the skb directly. See: raspberrypi#2608 Signed-off-by: Floris Bos <bos@je-eigen-domein.nl> Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com> Fixes: 55d7de9 ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet")
1 parent 9499603 commit db81c14

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎drivers/net/usb/lan78xx.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3292,6 +3292,7 @@ static void lan78xx_tx_bh(struct lan78xx_net *dev)
32923292
pkt_cnt = 0;
32933293
count = 0;
32943294
length = 0;
3295+
spin_lock_irqsave(&tqp->lock, flags);
32953296
for (skb = tqp->next; pkt_cnt < tqp->qlen; skb = skb->next) {
32963297
if (skb_is_gso(skb)) {
32973298
if (pkt_cnt) {
@@ -3300,7 +3301,8 @@ static void lan78xx_tx_bh(struct lan78xx_net *dev)
33003301
}
33013302
count = 1;
33023303
length = skb->len - TX_OVERHEAD;
3303-
skb2 = skb_dequeue(tqp);
3304+
__skb_unlink(skb, tqp);
3305+
spin_unlock_irqrestore(&tqp->lock, flags);
33043306
goto gso_skb;
33053307
}
33063308

@@ -3309,6 +3311,7 @@ static void lan78xx_tx_bh(struct lan78xx_net *dev)
33093311
skb_totallen = skb->len + roundup(skb_totallen, sizeof(u32));
33103312
pkt_cnt++;
33113313
}
3314+
spin_unlock_irqrestore(&tqp->lock, flags);
33123315

33133316
/* copy to a single skb */
33143317
skb = alloc_skb(skb_totallen, GFP_ATOMIC);

0 commit comments

Comments
 (0)