Linux USB
 help / color / mirror / Atom feed
From: Timo Joannin <timo.joannin@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Oliver Neukum" <oneukum@suse.com>, "Bjørn Mork" <bjorn@mork.no>,
	"Greg Suarez" <gpsuarez2512@gmail.com>,
	"Gui-Dong Han" <hanguidong02@gmail.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Timo Joannin" <timo.joannin@gmail.com>,
	syzbot+eb8f169da355a394fe04@syzkaller.appspotmail.com
Subject: [PATCH] usb: cdc-wdm: fix double submission of URB
Date: Wed,  2 Dec 2026 22:04:31 +0100	[thread overview]
Message-ID: <20261202210431.242596-1-timo.joannin@gmail.com> (raw)

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


                 reply	other threads:[~2026-12-02 21:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202210431.242596-1-timo.joannin@gmail.com \
    --to=timo.joannin@gmail.com \
    --cc=bjorn@mork.no \
    --cc=gpsuarez2512@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hanguidong02@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=oneukum@suse.com \
    --cc=syzbot+eb8f169da355a394fe04@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox