Skip to contentSkip to conversation

usb: cdc-wdm: close race between read and workqueue

PATCH New Oliver Neukum 1 participant 1 message Mar 14, 2024 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: cdc-wdm: close race between read and workqueue

wdm_read() cannot race with itself. However, in service_outstanding_interrupt() it can race with the workqueue, which can be triggered by error handling.

Hence we need to make sure that the WDM_RESPONDING flag is not just only set but tested.

Fixes afba937e540c9 ("USB: CDC WDM driver")
---
 drivers/usb/class/cdc-wdm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/class/cdc-wdm.c +5 -1
index c553decb5461..c8262e2f2917 100644
@@ -485,6 +485,7 @@ static ssize_t wdm_write
 static int service_outstanding_interrupt(struct wdm_device *desc)
 {
 	int rv = 0;
+	int used;
 
 	/* submit read urb only if the device is waiting for it */
 	if (!desc->resp_count || !--desc->resp_count)
@@ -499,7 +500,10 @@ static int service_outstanding_interrupt(struct wdm_device *desc)
 		goto out;
 	}
 
-	set_bit(WDM_RESPONDING, &desc->flags);
+	used = test_and_set_bit(WDM_RESPONDING, &desc->flags);
+	if (used)
+		goto out;
+
 	spin_unlock_irq(&desc->iuspin);
 	rv = usb_submit_urb(desc->response, GFP_KERNEL);
 	spin_lock_irq(&desc->iuspin);
Signature · 1 line
2.44.0