[PATCH] media: mceusb: fix NULL dereference on disconnect during IR transmit
From: YuanZhe Liu
Date: Fri Nov 20 2026 - 05:58:29 EST
mceusb_dev_disconnect() clears ir->usbdev before unregistering the rc
device. An IR transmit runs mceusb_tx_ir() under rc_dev->lock, and a
single lirc write may issue several mce_write() calls, each of which
waits up to USB_TX_TIMEOUT for the URB to complete. If the device is
disconnected while such a write is in progress, the next mce_write()
passes the now-NULL ir->usbdev to usb_fill_int_urb(), which
dereferences it:
general protection fault, probably for non-canonical address
0xdffffc0000000003
KASAN: null-ptr-deref in range [0x18-0x1f]
RIP: usb_fill_int_urb
RIP: mce_write
Call Trace:
mceusb_tx_ir
lirc_transmit
A write that starts after ir->usbdev has been cleared but before
rc_unregister_device() marks the device as unregistered can hit the
same NULL pointer.
rc_unregister_device() sets dev->registered under rc_dev->lock and
waits for an in-flight tx_ir() to finish, so clearing ir->usbdev
after it returns closes both windows.
Fixes: d8b4b5822f51 ("[media] ir-core: make struct rc_dev the primary interface")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
drivers/media/rc/mceusb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/rc/mceusb.c b/drivers/media/rc/mceusb.c
index 39ba7f6a2549..645ce0d0cbc6 100644
--- a/drivers/media/rc/mceusb.c
+++ b/drivers/media/rc/mceusb.c
@@ -1844,9 +1844,9 @@ static void mceusb_dev_disconnect(struct usb_interface *intf)
if (!ir)
return;
- ir->usbdev = NULL;
cancel_work_sync(&ir->kevent);
rc_unregister_device(ir->rc);
+ ir->usbdev = NULL;
usb_kill_urb(ir->urb_in);
usb_free_urb(ir->urb_in);
usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in);
--
2.34.1