]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usb: cdc-wdm: close race between read and workqueue
authorOliver Neukum <oneukum@suse.com>
Thu, 14 Mar 2024 11:50:48 +0000 (12:50 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 13 Apr 2024 10:59:05 +0000 (12:59 +0200)
commit 339f83612f3a569b194680768b22bf113c26a29d upstream.

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")
Cc: stable <stable@kernel.org>
Signed-off-by: Oliver Neukum <oneukum@suse.com>
Link: https://lore.kernel.org/r/20240314115132.3907-1-oneukum@suse.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/class/cdc-wdm.c

index 80332b6a1963e6a1923988f39658194c83fe4fd4..58423b16022b49d08abaf967a23d86db5e4b901e 100644 (file)
@@ -471,6 +471,7 @@ out_free_mem:
 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)
@@ -485,7 +486,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);