* [PATCH] net: lan78xx: Fix race in tx pending skb size calculation
@ 2018-07-15 19:53 ` Stefan Wahren
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Wahren @ 2018-07-15 19:53 UTC (permalink / raw)
To: Woojung Huh, UNGLinuxDriver, David S. Miller
Cc: Greg Kroah-Hartman, Dave Stevenson, netdev, linux-usb,
Stefan Wahren, stable, Floris Bos
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: 55d7de9de6c3 ("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>
---
drivers/net/usb/lan78xx.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index 2e41307..ed10d49 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -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) {
@@ -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;
}
@@ -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);
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* net: lan78xx: Fix race in tx pending skb size calculation
@ 2018-07-15 19:53 ` Stefan Wahren
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Wahren @ 2018-07-15 19:53 UTC (permalink / raw)
To: Woojung Huh, UNGLinuxDriver, David S. Miller
Cc: Greg Kroah-Hartman, Dave Stevenson, netdev, linux-usb,
Stefan Wahren, stable, Floris Bos
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: 55d7de9de6c3 ("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>
---
drivers/net/usb/lan78xx.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index 2e41307..ed10d49 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -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) {
@@ -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;
}
@@ -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);
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] net: lan78xx: Fix race in tx pending skb size calculation
@ 2018-07-16 21:13 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-07-16 21:13 UTC (permalink / raw)
To: stefan.wahren
Cc: woojung.huh, UNGLinuxDriver, gregkh, dave.stevenson, netdev,
linux-usb, stable, bos
From: Stefan Wahren <stefan.wahren@i2se.com>
Date: Sun, 15 Jul 2018 21:53:20 +0200
> 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: 55d7de9de6c3 ("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>
Applied and queued up for -stable, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* net: lan78xx: Fix race in tx pending skb size calculation
@ 2018-07-16 21:13 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-07-16 21:13 UTC (permalink / raw)
To: stefan.wahren
Cc: woojung.huh, UNGLinuxDriver, gregkh, dave.stevenson, netdev,
linux-usb, stable, bos
From: Stefan Wahren <stefan.wahren@i2se.com>
Date: Sun, 15 Jul 2018 21:53:20 +0200
> 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: 55d7de9de6c3 ("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>
Applied and queued up for -stable, thanks.
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-07-16 21:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-15 19:53 [PATCH] net: lan78xx: Fix race in tx pending skb size calculation Stefan Wahren
2018-07-15 19:53 ` Stefan Wahren
2018-07-16 21:13 ` [PATCH] " David Miller
2018-07-16 21:13 ` David Miller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.