Skip to contentSkip to conversation

media: mceusb: fix race between device disconnection and urb callback

PATCH In review Haotian Zhang 2 participants 2 messages Nov 14, 2025 – Dec 20, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: mceusb: fix race between device disconnection and urb callback

The mceusb_disconnect() function calls rc_unregister_device() before usb_kill_urb(), creating a race condition similar to the one fixed in commit 'f656cfbc7a29'. If rc_unregister_device() executes while the URB callback mceusb_dev_recv() is still running, mceusb_process_ir_data() may call ir_raw_event_store_with_filter() or ir_raw_event_handle() with a freed ir->rc->raw pointer, leading to a NULL pointer dereference.

Call usb_kill_urb() before rc_unregister_device() to ensure all URB callbacks complete before freeing device resources.

Fixes d8b4b5822f51 ("[media] ir-core: make struct rc_dev the primary interface")
---
 drivers/media/rc/mceusb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/rc/mceusb.c +1 -1
index 044767eb3a38..fb5c393dcb94 100644
@@ -1845,8 +1845,8 @@ static void mceusb_dev_disconnect(struct usb_interface *intf)
 
 	ir->usbdev = NULL;
 	cancel_work_sync(&ir->kevent);
-	rc_unregister_device(ir->rc);
 	usb_kill_urb(ir->urb_in);
+	rc_unregister_device(ir->rc);
 	usb_free_urb(ir->urb_in);
 	usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in);
 	usb_put_dev(dev);
Signature · 1 line
2.50.1.windows.1
maintainer
#1 lore raw
Quoted 9 lines · Haotian Zhang

The mceusb_disconnect() function calls rc_unregister_device() before usb_kill_urb(), creating a race condition similar to the one fixed in commit 'f656cfbc7a29'. If rc_unregister_device() executes while the URB callback mceusb_dev_recv() is still running, mceusb_process_ir_data() may call ir_raw_event_store_with_filter() or ir_raw_event_handle() with a freed ir->rc->raw pointer, leading to a NULL pointer dereference.

Call usb_kill_urb() before rc_unregister_device() to ensure all URB callbacks complete before freeing device resources.

First of all, I must apologise for not responding earlier. Haotian, you have found a real issue here, thank you for finding and reporting it.

I've been thinking about this for some time now. I think I've found an alternative solution, which I'l shortly be posting to the list.

Thank you

Sean

Quoted 23 lines
Fixes d8b4b5822f51 ("[media] ir-core: make struct rc_dev the primary interface")
---
 drivers/media/rc/mceusb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/rc/mceusb.c +1 -1
index 044767eb3a38..fb5c393dcb94 100644
@@ -1845,8 +1845,8 @@ static void mceusb_dev_disconnect(struct usb_interface *intf)
 
 	ir->usbdev = NULL;
 	cancel_work_sync(&ir->kevent);
-	rc_unregister_device(ir->rc);
 	usb_kill_urb(ir->urb_in);
+	rc_unregister_device(ir->rc);
 	usb_free_urb(ir->urb_in);
 	usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in);
 	usb_put_dev(dev);
Signature · 1 line
2.50.1.windows.1