Linux USB
 help / color / mirror / Atom feed
* [PATCH net v3] usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return()
@ 2026-10-07 22:01 Ömer Mete Kaya
  2026-10-07 22:09 ` netdev-bot+sinfo
  2026-10-08 22:03 ` sashiko-bot
  0 siblings, 2 replies; 8+ messages in thread
From: Ömer Mete Kaya @ 2026-10-07 22:01 UTC (permalink / raw)
  To: netdev
  Cc: oneukum, andrew+netdev, davem, edumazet, kuba, pabeni, linux-usb,
	linux-kernel, Ömer Mete Kaya

On SMP, usbnet_skb_return() can pass the test_bit(EVENT_RX_PAUSED) check
on CPU0 while usbnet_resume_rx() clears the flag and drains rxq_pause on
CPU1, leaving the skb stranded until the next MTU change or device stop.

Protect the flag check and enqueue with a double-check pattern under
rxq_pause.lock on the slow path, keeping the normal RX fast path
lock-free. Wrap clear_bit() in usbnet_resume_rx() under the same lock.

Fixes: 43daa96b166c ("usbnet: Stop RX Q on MTU change")
Signed-off-by: Ömer Mete Kaya <omermetekaya0@gmail.com>

---
v3: Use spin_lock() inside existing local_bh_disable() section in
    usbnet_resume_rx() instead of spin_lock_bh(); move local_bh_enable()
    before queue_work() to restore BH context correctly.

 drivers/net/usb/usbnet.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 84f97f448b2d..d138d353fd98 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -329,9 +329,14 @@ void usbnet_skb_return(struct usbnet *dev, struct sk_buff *skb)
 	unsigned long flags;
 	int	status;

-	if (test_bit(EVENT_RX_PAUSED, &dev->flags)) {
-		skb_queue_tail(&dev->rxq_pause, skb);
-		return;
+	if (unlikely(test_bit(EVENT_RX_PAUSED, &dev->flags))) {
+		spin_lock_bh(&dev->rxq_pause.lock);
+		if (test_bit(EVENT_RX_PAUSED, &dev->flags)) {
+			__skb_queue_tail(&dev->rxq_pause, skb);
+			spin_unlock_bh(&dev->rxq_pause.lock);
+			return;
+		}
+		spin_unlock_bh(&dev->rxq_pause.lock);
 	}

 	/* only update if unset to allow minidriver rx_fixup override */
@@ -702,15 +707,16 @@ void usbnet_resume_rx(struct usbnet *dev)
 	int num = 0;

 	local_bh_disable();
+	spin_lock(&dev->rxq_pause.lock);
 	clear_bit(EVENT_RX_PAUSED, &dev->flags);
-
+	spin_unlock(&dev->rxq_pause.lock);
 	while ((skb = skb_dequeue(&dev->rxq_pause)) != NULL) {
 		usbnet_skb_return(dev, skb);
 		num++;
 	}

-	queue_work(system_bh_wq, &dev->bh_work);
 	local_bh_enable();
+	queue_work(system_bh_wq, &dev->bh_work);

 	netif_dbg(dev, rx_status, dev->net,
 		  "paused rx queue disabled, %d skbs requeued\n", num);
--
2.56.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH net v3] usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return()
  2026-10-07 22:01 [PATCH net v3] usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return() Ömer Mete Kaya
@ 2026-10-07 22:09 ` netdev-bot+sinfo
  2026-10-08 15:40   ` Jakub Kicinski
  2026-10-08 15:42   ` Ömer Mete Kaya
  2026-10-08 22:03 ` sashiko-bot
  1 sibling, 2 replies; 8+ messages in thread
From: netdev-bot+sinfo @ 2026-10-07 22:09 UTC (permalink / raw)
  To: Ömer Mete Kaya
  Cc: netdev, oneukum, andrew+netdev, davem, edumazet, kuba, pabeni,
	linux-usb, linux-kernel

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by code inspection). If it was triggered please include
   the symptoms, like the stack trace or error messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account. If the series needs another revision for
other reasons, please include the information in the commit messages
then.

The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net v3] usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return()
  2026-10-07 22:09 ` netdev-bot+sinfo
@ 2026-10-08 15:40   ` Jakub Kicinski
  2026-10-08 15:47     ` Ömer Mete Kaya
  2026-10-08 15:42   ` Ömer Mete Kaya
  1 sibling, 1 reply; 8+ messages in thread
From: Jakub Kicinski @ 2026-10-08 15:40 UTC (permalink / raw)
  To: netdev-bot+sinfo
  Cc: Ömer Mete Kaya, netdev, oneukum, andrew+netdev, davem,
	edumazet, pabeni, linux-usb, linux-kernel

On Wed, 07 Oct 2026 22:09:08 +0000 netdev-bot+sinfo@kernel.org wrote:
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
> 
>  - How the issue was discovered, e.g. hit in production, hit during
>    development, syzbot report, manual code inspection, LLM or static
>    analysis tool scan.
> 
>  - Whether the issue was actually triggered, or is only theoretical
>    (e.g. found by code inspection). If it was triggered please include
>    the symptoms, like the stack trace or error messages.

Hi, please answer these questions, and try to include the answers in
the commit msg of future submissions.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net v3] usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return()
  2026-10-07 22:09 ` netdev-bot+sinfo
  2026-10-08 15:40   ` Jakub Kicinski
@ 2026-10-08 15:42   ` Ömer Mete Kaya
  1 sibling, 0 replies; 8+ messages in thread
From: Ömer Mete Kaya @ 2026-10-08 15:42 UTC (permalink / raw)
  To: netdev-bot+sinfo
  Cc: netdev, oneukum, andrew+netdev, davem, edumazet, kuba, pabeni,
	linux-usb, linux-kernel



On 10/8/26 01:09, netdev-bot+sinfo@kernel.org wrote:
> Hi!
> 
> This is an automated message. This series looks like a fix, but its
> commit messages seem to be missing some information:
> 
>  - How the issue was discovered, e.g. hit in production, hit during
>    development, syzbot report, manual code inspection, LLM or static
>    analysis tool scan.

Sashiko AI suggestion.

>  - Whether the issue was actually triggered, or is only theoretical
>    (e.g. found by code inspection). If it was triggered please include
>    the symptoms, like the stack trace or error messages.

Theoretical.

> Please do not repost the series just to address the above. Instead,
> reply to this email with the missing information, so that reviewers
> can take it into account. If the series needs another revision for
> other reasons, please include the information in the commit messages
> then.
> 
> The evaluation is done by an LLM so it may be wrong, if you think
> that is the case please reply and explain.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net v3] usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return()
  2026-10-08 15:40   ` Jakub Kicinski
@ 2026-10-08 15:47     ` Ömer Mete Kaya
  2026-10-08 18:03       ` Jakub Kicinski
  0 siblings, 1 reply; 8+ messages in thread
From: Ömer Mete Kaya @ 2026-10-08 15:47 UTC (permalink / raw)
  To: Jakub Kicinski, netdev-bot+sinfo
  Cc: netdev, oneukum, andrew+netdev, davem, edumazet, pabeni,
	linux-usb, linux-kernel



On 10/8/26 18:40, Jakub Kicinski wrote:
> Hi, please answer these questions, and try to include the answers in
> the commit msg of future submissions.

Hi, I couldnt add reported-by tag when it comes from sashiko,
should I include the answers under the "---" for future submissions?

Thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net v3] usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return()
  2026-10-08 15:47     ` Ömer Mete Kaya
@ 2026-10-08 18:03       ` Jakub Kicinski
  0 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2026-10-08 18:03 UTC (permalink / raw)
  To: Ömer Mete Kaya
  Cc: netdev-bot+sinfo, netdev, oneukum, andrew+netdev, davem, edumazet,
	pabeni, linux-usb, linux-kernel

On Thu, 8 Oct 2026 18:47:07 +0300 Ömer Mete Kaya wrote:
> On 10/8/26 18:40, Jakub Kicinski wrote:
> > Hi, please answer these questions, and try to include the answers in
> > the commit msg of future submissions.  
> 
> Hi, I couldnt add reported-by tag when it comes from sashiko,
> should I include the answers under the "---" for future submissions?

In the main body is better, this is very useful info for risk / benefit
analysis for backporters.

Single sentence like this seems suitable here:

Discovered by Sashiko, not triggered, not tested on real HW.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net v3] usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return()
  2026-10-07 22:01 [PATCH net v3] usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return() Ömer Mete Kaya
  2026-10-07 22:09 ` netdev-bot+sinfo
@ 2026-10-08 22:03 ` sashiko-bot
  2026-10-09 15:48   ` Ömer Mete Kaya
  1 sibling, 1 reply; 8+ messages in thread
From: sashiko-bot @ 2026-10-08 22:03 UTC (permalink / raw)
  To: Ömer Mete Kaya; +Cc: linux-usb

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] net: out-of-order packet delivery during RX resume
--

commit 7148b0b2b0b945f31b2120d7f4cbc269acf91635
Author: Ömer Mete Kaya <omermetekaya0@gmail.com>

usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return()

This commit addresses a race condition in usbnet_skb_return() by protecting
the EVENT_RX_PAUSED flag check and enqueue operations with a double-check
pattern under the rxq_pause lock. It also protects the clear_bit() operation
in usbnet_resume_rx() under the same lock.

> diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
> index a19ecf718f36a..d1ec3ba1e10e6 100644
> --- a/drivers/net/usb/usbnet.c
> +++ b/drivers/net/usb/usbnet.c
[ ... ]
> @@ -700,15 +705,16 @@ void usbnet_resume_rx(struct usbnet *dev)
>  	int num = 0;
>  
>  	local_bh_disable();
> +	spin_lock(&dev->rxq_pause.lock);
>  	clear_bit(EVENT_RX_PAUSED, &dev->flags);
> -
> +	spin_unlock(&dev->rxq_pause.lock);

[Severity: Medium]
If a new packet arrives concurrently on another CPU via usbnet_skb_return(),
could it observe EVENT_RX_PAUSED as false here?

If so, it would bypass the pause queue and immediately deliver the new SKB
to the network stack via netif_rx().

>  	while ((skb = skb_dequeue(&dev->rxq_pause)) != NULL) {
>  		usbnet_skb_return(dev, skb);
>  		num++;
>  	}

This seems like it would cause the newly arrived packet to be delivered before
the older packets in the rxq_pause queue are fully drained by this while loop,
leading to out-of-order delivery which can degrade TCP performance.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261007220311.113827-1-omermetekaya0@gmail.com?part=1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH net v3] usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return()
  2026-10-08 22:03 ` sashiko-bot
@ 2026-10-09 15:48   ` Ömer Mete Kaya
  0 siblings, 0 replies; 8+ messages in thread
From: Ömer Mete Kaya @ 2026-10-09 15:48 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: linux-usb



On 10/9/26 01:03, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] net: out-of-order packet delivery during RX resume
> --
> 
> commit 7148b0b2b0b945f31b2120d7f4cbc269acf91635
> Author: Ömer Mete Kaya <omermetekaya0@gmail.com>
> 
> usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return()
> 
> This commit addresses a race condition in usbnet_skb_return() by protecting
> the EVENT_RX_PAUSED flag check and enqueue operations with a double-check
> pattern under the rxq_pause lock. It also protects the clear_bit() operation
> in usbnet_resume_rx() under the same lock.
> 
>> diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
>> index a19ecf718f36a..d1ec3ba1e10e6 100644
>> --- a/drivers/net/usb/usbnet.c
>> +++ b/drivers/net/usb/usbnet.c
> [ ... ]
>> @@ -700,15 +705,16 @@ void usbnet_resume_rx(struct usbnet *dev)
>>  	int num = 0;
>>  
>>  	local_bh_disable();
>> +	spin_lock(&dev->rxq_pause.lock);
>>  	clear_bit(EVENT_RX_PAUSED, &dev->flags);
>> -
>> +	spin_unlock(&dev->rxq_pause.lock);
> 
> [Severity: Medium]
> If a new packet arrives concurrently on another CPU via usbnet_skb_return(),
> could it observe EVENT_RX_PAUSED as false here?
> 
> If so, it would bypass the pause queue and immediately deliver the new SKB
> to the network stack via netif_rx().
> 
>>  	while ((skb = skb_dequeue(&dev->rxq_pause)) != NULL) {
>>  		usbnet_skb_return(dev, skb);
>>  		num++;
>>  	}
> 
> This seems like it would cause the newly arrived packet to be delivered before
> the older packets in the rxq_pause queue are fully drained by this while loop,
> leading to out-of-order delivery which can degrade TCP performance.
> 
The out-of-order delivery window between clear_bit() and the drain loop
is a pre-existing issue in the original code, not introduced by this
patch.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-10-09 15:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-07 22:01 [PATCH net v3] usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return() Ömer Mete Kaya
2026-10-07 22:09 ` netdev-bot+sinfo
2026-10-08 15:40   ` Jakub Kicinski
2026-10-08 15:47     ` Ömer Mete Kaya
2026-10-08 18:03       ` Jakub Kicinski
2026-10-08 15:42   ` Ömer Mete Kaya
2026-10-08 22:03 ` sashiko-bot
2026-10-09 15:48   ` Ömer Mete Kaya

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox