[PATCH v2] media: usb: siano: fix URB work teardown
From: Rohith Matam
Date: Mon Jun 01 2026 - 11:17:30 EST
smsusb_onresponse() reinitializes the URB work item immediately before
scheduling it. If teardown races with a queued work item,
cancel_work_sync() can observe workqueue state with WORK_STRUCT_PWQ
still set and trip the workqueue warning reported by syzbot.
The teardown path also has two related lifetime bugs: URB_FREE_BUFFER
makes USB core free a smscore-owned buffer, and a work item can submit
an URB after usb_kill_urb() has already returned.
Initialize each work item once before URB allocation, remove
URB_FREE_BUFFER, stop resubmission before killing URBs, and kill URBs
again after canceling work so any URB submitted by an already-running
worker is completed before buffers and the device are freed.
Fixes: ebad8e731c1c ("media: usb: siano: Fix use after free bugs caused by do_submit_urb")
Reported-by: syzbot+0d6ef2b7ceb6014d756c@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=0d6ef2b7ceb6014d756c
Signed-off-by: Rohith Matam <rohithmatham@xxxxxxxxx>
---
Changes in v2:
- Initialize all work items before allocating URBs.
- Remove URB_FREE_BUFFER from smscore-owned buffers.
- Stop resubmission before teardown and kill URBs again after canceling work.
drivers/media/usb/siano/smsusb.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/drivers/media/usb/siano/smsusb.c b/drivers/media/usb/siano/smsusb.c
index 0fdc2e095..e3ca51072 100644
--- a/drivers/media/usb/siano/smsusb.c
+++ b/drivers/media/usb/siano/smsusb.c
@@ -58,6 +58,7 @@ struct smsusb_device_t {
unsigned char in_ep;
unsigned char out_ep;
enum smsusb_state state;
+ bool streaming;
};
static int smsusb_submit_urb(struct smsusb_device_t *dev,
@@ -72,7 +73,8 @@ static void do_submit_urb(struct work_struct *work)
struct smsusb_urb_t *surb = container_of(work, struct smsusb_urb_t, wq);
struct smsusb_device_t *dev = surb->dev;
- smsusb_submit_urb(dev, surb);
+ if (READ_ONCE(dev->streaming))
+ smsusb_submit_urb(dev, surb);
}
/*
@@ -143,8 +145,8 @@ static void smsusb_onresponse(struct urb *urb)
exit_and_resubmit:
- INIT_WORK(&surb->wq, do_submit_urb);
- schedule_work(&surb->wq);
+ if (READ_ONCE(dev->streaming))
+ schedule_work(&surb->wq);
}
static int smsusb_submit_urb(struct smsusb_device_t *dev,
@@ -168,8 +170,6 @@ static int smsusb_submit_urb(struct smsusb_device_t *dev,
smsusb_onresponse,
surb
);
- surb->urb->transfer_flags |= URB_FREE_BUFFER;
-
return usb_submit_urb(surb->urb, GFP_ATOMIC);
}
@@ -177,10 +177,12 @@ static void smsusb_stop_streaming(struct smsusb_device_t *dev)
{
int i;
+ WRITE_ONCE(dev->streaming, false);
+
for (i = 0; i < MAX_URBS; i++) {
usb_kill_urb(dev->surbs[i].urb);
- if (dev->surbs[i].wq.func)
- cancel_work_sync(&dev->surbs[i].wq);
+ cancel_work_sync(&dev->surbs[i].wq);
+ usb_kill_urb(dev->surbs[i].urb);
if (dev->surbs[i].cb) {
smscore_putbuffer(dev->coredev, dev->surbs[i].cb);
@@ -193,6 +195,8 @@ static int smsusb_start_streaming(struct smsusb_device_t *dev)
{
int i, rc;
+ WRITE_ONCE(dev->streaming, true);
+
for (i = 0; i < MAX_URBS; i++) {
rc = smsusb_submit_urb(dev, &dev->surbs[i]);
if (rc < 0) {
@@ -468,6 +472,10 @@ static int smsusb_init_device(struct usb_interface *intf, int board_id)
/* initialize urbs */
for (i = 0; i < MAX_URBS; i++) {
dev->surbs[i].dev = dev;
+ INIT_WORK(&dev->surbs[i].wq, do_submit_urb);
+ }
+
+ for (i = 0; i < MAX_URBS; i++) {
dev->surbs[i].urb = usb_alloc_urb(0, GFP_KERNEL);
if (!dev->surbs[i].urb)
goto err_unregister_device;
--
2.54.0