All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: cdc-wdm: close race between read and workqueue
@ 2024-03-14 11:50 Oliver Neukum
  0 siblings, 0 replies; 12+ messages in thread
From: Oliver Neukum @ 2024-03-14 11:50 UTC (permalink / raw)
  To: gregkh, linux-usb; +Cc: Oliver Neukum

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")
Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
 drivers/usb/class/cdc-wdm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index c553decb5461..c8262e2f2917 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -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);
-- 
2.44.0


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

end of thread, other threads:[~2024-04-15 12:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20240314115132.3907-1-oneukum () suse ! com>
2024-04-15  5:42 ` [PATCH] usb: cdc-wdm: close race between read and workqueue Aleksander Morgado
2024-04-15  6:47   ` Bjørn Mork
2024-04-15  9:06     ` Oliver Neukum
2024-04-15  9:26       ` Bjørn Mork
2024-04-15  9:52         ` Greg KH
2024-04-15 10:07           ` Oliver Neukum
2024-04-15 10:14         ` Oliver Neukum
2024-04-15 10:53           ` Bjørn Mork
2024-04-15 11:08             ` Oliver Neukum
2024-04-15  8:42   ` Oliver Neukum
2024-04-15 12:08     ` Aleksander Morgado
2024-03-14 11:50 Oliver Neukum

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.