driver: powermate: kill urb in the disconnect function
Subsystems (2)
PATCH 1/1 driver: powermate: kill urb in the disconnect function
In powermate_disconnect, powermate_pulse_led will invoke powermate_sync_state and submit one urb with pm as its context. If powermate disconnect before the execution of complete handler, the pm will become a dangling pointer and lead to UAF.
Fix this by calling usb_kill_urb(pm->config) in the disconnect function. Note that, the error handling error does not need to take care of this.
--- drivers/input/misc/powermate.c | 1 + 1 file changed, 1 insertion(+)
drivers/input/misc/powermate.c +1 -0
@@ -424,6 +424,7 @@ static void powermate_disconnect(struct usb_interface *intf)if (pm) { pm->requires_update =0 ;usb_kill_urb (pm->irq); +usb_kill_urb (pm->config);input_unregister_device (pm->input);usb_free_urb (pm->irq);usb_free_urb (pm->config);
Signature · 1 line
2.25.1
Dmitry Torokhov
maintainerHi Dongliang,
Quoted 7 lines · Dongliang Mu
In
powermate_disconnect,powermate_pulse_ledwill invokepowermate_sync_stateand submit one urb with pm as its context. If powermate disconnect before the execution of complete handler, the pm will become a dangling pointer and lead to UAF.Fix this by calling
usb_kill_urb(pm->config)in the disconnect function. Note that, the error handling error does not need to take care of this.
Unfortunately this analysis is not correct and adding usb_kill_urb() does not really help, as while input device is registered there may be new events coming into the driver that may cause config URB be submitted again.
What actually happens is that call to usb_free_urb(pm->config) below tries to properly shutdown and destroy URB, but unfortunately powermate_config_complete() handler only uses urb->status to print error message, and resubmits the URB that is about to be freed again.
The URB completion handler needs to check for -ESHUTDOWN (-108) and other terminal error codes before attempting to resubmit the URB.
Quoted 23 lines
Reported-by [email protected]Fixes ba0acb5ee318901 ("Input: move USB miscellaneous devices under drivers/input/misc")Signed-off-by Dongliang Mu <[email protected]>--- drivers/input/misc/powermate.c | 1 + 1 file changed, 1 insertion(+)drivers/input/misc/powermate.c +1
-0@@ -424,6 +424,7 @@ static void powermate_disconnect(struct usb_interface *intf)if (pm) { pm->requires_update =0 ;usb_kill_urb (pm->irq); +usb_kill_urb (pm->config);input_unregister_device (pm->input);usb_free_urb (pm->irq);usb_free_urb (pm->config);Signature · 1 line
2.25.1
Thanks.
Signature · 1 line
Dmitry