Skip to content

Commit

Permalink
net: lan78xx: Fix race in tx pending skb size calculation
Browse files Browse the repository at this point in the history
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 <stable@vger.kernel.org>
Signed-off-by: Floris Bos <bos@je-eigen-domein.nl>
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
lategoodbye authored and davem330 committed Jul 16, 2018
1 parent b5d2d75 commit dea39ac
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/net/usb/lan78xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -3344,6 +3344,7 @@ static void lan78xx_tx_bh(struct lan78xx_net *dev)
pkt_cnt = 0;
count = 0;
length = 0;
spin_lock_irqsave(&tqp->lock, flags);
for (skb = tqp->next; pkt_cnt < tqp->qlen; skb = skb->next) {
if (skb_is_gso(skb)) {
if (pkt_cnt) {
Expand All @@ -3352,7 +3353,8 @@ static void lan78xx_tx_bh(struct lan78xx_net *dev)
}
count = 1;
length = skb->len - TX_OVERHEAD;
skb2 = skb_dequeue(tqp);
__skb_unlink(skb, tqp);
spin_unlock_irqrestore(&tqp->lock, flags);
goto gso_skb;
}

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

/* copy to a single skb */
skb = alloc_skb(skb_totallen, GFP_ATOMIC);
Expand Down

0 comments on commit dea39ac

Please sign in to comment.