Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2be27d44 authored by Stefan Wahren's avatar Stefan Wahren Committed by Greg Kroah-Hartman
Browse files

net: lan78xx: Fix race in tx pending skb size calculation

commit dea39aca1d7aef1e2b95b07edeacf04cc8863a2e 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: https://github.com/raspberrypi/linux/issues/2608


Fixes: 55d7de9d ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: default avatarFloris Bos <bos@je-eigen-domein.nl>
Signed-off-by: default avatarStefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 12c0949a
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -3197,6 +3197,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) {
@@ -3205,7 +3206,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;
		}

@@ -3214,6 +3216,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);