Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: cdc-wdm: fix double submission of URB
@ 2026-12-02 21:04 Timo Joannin
  2026-12-02 21:19 ` sashiko-bot
  2026-12-03  8:44 ` Oliver Neukum
  0 siblings, 2 replies; 5+ messages in thread
From: Timo Joannin @ 2026-12-02 21:04 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Oliver Neukum, Bjørn Mork, Greg Suarez, Gui-Dong Han,
	linux-usb, linux-kernel, Timo Joannin,
	syzbot+eb8f169da355a394fe04

Syzbot found a bug where "URB submitted while active".
This is because service_outstanding_interrupt() doesn't check whether
WDM_RESPONDING is already set and allows it to resubmit an already
active URB triggering the warning.

An earlier attempt to check responding in service_outstanding_interrupt()
was reverted in commit 1607830dadee
("Revert "usb: cdc-wdm: close race between read and workqueue""),
because wdm_int_callback() left WDM_RESPONDING stuck at 1 while
the driver wasn't responding,
and service_outstanding_interrupt() decremented desc->resp_count
before checking the WDM_RESPONDING bit.

In wdm_int_callback check the desc->resp_count before setting
the WDM_RESPONDING bit so that when desc->resp_count >= 1,
we leave WDM_RESPONDING unchanged.
In service_outstanding_interrupt() bail if WDM_RESPONDING is set
before decrementing desc->resp_count.

Reported-by: syzbot+eb8f169da355a394fe04@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=eb8f169da355a394fe04
Fixes: 73e06865ead1 ("USB: cdc-wdm: support back-to-back USB_CDC_NOTIFY_RESPONSE_AVAILABLE notifications")
Signed-off-by: Timo Joannin <timo.joannin@gmail.com>
---
Compile tested only, there is no C reproducer
for this issue, and #syz test is still down.

 drivers/usb/class/cdc-wdm.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 7556c0dac908..87de4e7e0196 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -252,7 +252,6 @@ static void wdm_int_callback(struct urb *urb)
 {
 	unsigned long flags;
 	int rv = 0;
-	int responding;
 	int status = urb->status;
 	struct wdm_device *desc;
 	struct usb_cdc_notification *dr;
@@ -311,10 +310,10 @@ static void wdm_int_callback(struct urb *urb)
 	}
 
 	spin_lock_irqsave(&desc->iuspin, flags);
-	responding = test_and_set_bit(WDM_RESPONDING, &desc->flags);
-	if (!desc->resp_count++ && !responding
+	if (!desc->resp_count++
 		&& !test_bit(WDM_DISCONNECTING, &desc->flags)
-		&& !test_bit(WDM_SUSPENDING, &desc->flags)) {
+		&& !test_bit(WDM_SUSPENDING, &desc->flags)
+		&& !test_and_set_bit(WDM_RESPONDING, &desc->flags)) {
 		rv = usb_submit_urb(desc->response, GFP_ATOMIC);
 		dev_dbg(&desc->intf->dev, "submit response URB %d\n", rv);
 	}
@@ -491,6 +490,10 @@ static int service_outstanding_interrupt(struct wdm_device *desc)
 {
 	int rv = 0;
 
+	/* don't submit or consume interrupt if URB already active */
+	if (test_bit(WDM_RESPONDING, &desc->flags))
+		goto out;
+
 	/* submit read urb only if the device is waiting for it */
 	if (!desc->resp_count || !--desc->resp_count)
 		goto out;
-- 
2.56.1


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

* Re: [PATCH] usb: cdc-wdm: fix double submission of URB
  2026-12-02 21:04 [PATCH] usb: cdc-wdm: fix double submission of URB Timo Joannin
@ 2026-12-02 21:19 ` sashiko-bot
  2026-12-03  8:44 ` Oliver Neukum
  1 sibling, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-02 21:19 UTC (permalink / raw)
  To: Timo Joannin; +Cc: linux-usb

> Syzbot found a bug where "URB submitted while active".
> This is because service_outstanding_interrupt() doesn't check whether
> WDM_RESPONDING is already set and allows it to resubmit an already
> active URB triggering the warning.
> 
> An earlier attempt to check responding in service_outstanding_interrupt()
> was reverted in commit 1607830dadee
> ("Revert "usb: cdc-wdm: close race between read and workqueue""),
> because wdm_int_callback() left WDM_RESPONDING stuck at 1 while
> the driver wasn't responding,
> and service_outstanding_interrupt() decremented desc->resp_count
> before checking the WDM_RESPONDING bit.
> 
> In wdm_int_callback check the desc->resp_count before setting
> the WDM_RESPONDING bit so that when desc->resp_count >= 1,
> we leave WDM_RESPONDING unchanged.
> In service_outstanding_interrupt() bail if WDM_RESPONDING is set
> before decrementing desc->resp_count.
> 
> Reported-by: syzbot+eb8f169da355a394fe04@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=eb8f169da355a394fe04
> Fixes: 73e06865ead1 ("USB: cdc-wdm: support back-to-back USB_CDC_NOTIFY_RESPONSE_AVAILABLE notifications")
> Signed-off-by: Timo Joannin <timo.joannin@gmail.com>

Sashiko has reviewed this patch and found no issues.

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

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

* Re: [PATCH] usb: cdc-wdm: fix double submission of URB
  2026-12-02 21:04 [PATCH] usb: cdc-wdm: fix double submission of URB Timo Joannin
  2026-12-02 21:19 ` sashiko-bot
@ 2026-12-03  8:44 ` Oliver Neukum
  2026-12-03  9:21   ` Timo Joannin
  1 sibling, 1 reply; 5+ messages in thread
From: Oliver Neukum @ 2026-12-03  8:44 UTC (permalink / raw)
  To: Timo Joannin, Greg Kroah-Hartman
  Cc: Oliver Neukum, Bjørn Mork, Greg Suarez, Gui-Dong Han,
	linux-usb, linux-kernel, syzbot+eb8f169da355a394fe04



On 02.12.26 22:04, Timo Joannin wrote:
> Syzbot found a bug where "URB submitted while active".
> This is because service_outstanding_interrupt() doesn't check whether
> WDM_RESPONDING is already set and allows it to resubmit an already
> active URB triggering the warning.

Hi,

thank you for looking into this.

> @@ -491,6 +490,10 @@ static int service_outstanding_interrupt(struct wdm_device *desc)
>   {
>   	int rv = 0;
>   
> +	/* don't submit or consume interrupt if URB already active */
> +	if (test_bit(WDM_RESPONDING, &desc->flags))
> +		goto out;

Are you sure we can divorce testing and setting the bit?
It seems to me that this leaves the race open the open way
round.

	Regards
			Oliver


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

* Re: [PATCH] usb: cdc-wdm: fix double submission of URB
  2026-12-03  8:44 ` Oliver Neukum
@ 2026-12-03  9:21   ` Timo Joannin
  2026-12-03 10:02     ` Oliver Neukum
  0 siblings, 1 reply; 5+ messages in thread
From: Timo Joannin @ 2026-12-03  9:21 UTC (permalink / raw)
  To: oneukum
  Cc: bjorn, gpsuarez2512, gregkh, hanguidong02, linux-kernel,
	linux-usb, syzbot+eb8f169da355a394fe04, timo.joannin

Hi Oliver,

Thanks for your reply.

> Are you sure we can divorce testing and setting the bit?
> It seems to me that this leaves the race open the open way
> round.

Yes I believe we can divorce testing and setting the bit
in service_outstanding_interrupt(). I verified and every
path entering service_outstanding_interrupt() holds
the desc->iuspin lock throughout the test_bit(),
desc->resp_count decrement and the set_bit() sequence.
And every other path that sets WDM_RESPONDING (wdm_int_callback()
and wdm_rxwork()) also holds desc->iuspin.

Does that seem valid to you, or did you refer to another path?

Thanks,
Timo Joannin

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

* Re: [PATCH] usb: cdc-wdm: fix double submission of URB
  2026-12-03  9:21   ` Timo Joannin
@ 2026-12-03 10:02     ` Oliver Neukum
  0 siblings, 0 replies; 5+ messages in thread
From: Oliver Neukum @ 2026-12-03 10:02 UTC (permalink / raw)
  To: Timo Joannin
  Cc: bjorn, gpsuarez2512, gregkh, hanguidong02, linux-kernel,
	linux-usb, syzbot+eb8f169da355a394fe04



On 03.12.26 10:21, Timo Joannin wrote:
  
> Yes I believe we can divorce testing and setting the bit
> in service_outstanding_interrupt(). I verified and every
> path entering service_outstanding_interrupt() holds
> the desc->iuspin lock throughout the test_bit(),
> desc->resp_count decrement and the set_bit() sequence.
> And every other path that sets WDM_RESPONDING (wdm_int_callback()
> and wdm_rxwork()) also holds desc->iuspin.
> 
> Does that seem valid to you, or did you refer to another path?
Hi,

OK, that is valid. But it is not obvious to a casual reader.
Could you add a comment stating that we are protected by
the spinlock and resubmit?

	Regards
		Oliver


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

end of thread, other threads:[~2026-12-03 10:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 21:04 [PATCH] usb: cdc-wdm: fix double submission of URB Timo Joannin
2026-12-02 21:19 ` sashiko-bot
2026-12-03  8:44 ` Oliver Neukum
2026-12-03  9:21   ` Timo Joannin
2026-12-03 10:02     ` Oliver Neukum

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