Skip to contentSkip to conversation

USB: gadget: f_hid: fix deadlock in f_hidg_write()

DISCUSSION James Bottomley 1 participant 1 message Mar 14, 2019 USB

lore
Share & tools
lore

James Bottomley

author Reviewed-by Tested-by
#0 lore raw
Quoted 15 lines · Radoslav Gerganov

In f_hidg_write() the write_spinlock is acquired before calling usb_ep_queue() which causes a deadlock when dummy_hcd is being used. This is because dummy_queue() callbacks into f_hidg_req_complete() which tries to acquire the same spinlock. This is (part of) the backtrace when the deadlock occurs:

0xffffffffc06b1410 in f_hidg_req_complete 0xffffffffc06a590a in usb_gadget_giveback_request 0xffffffffc06cfff2 in dummy_queue 0xffffffffc06a4b96 in usb_ep_queue 0xffffffffc06b1eb6 in f_hidg_write 0xffffffff8127730b in __vfs_write 0xffffffff812774d1 in vfs_write 0xffffffff81277725 in SYSC_write

Quoted 2 lines

Fix this by releasing the write_spinlock before calling usb_ep_queue()

This fixes a usb_f_hid deadlock I've also been seeing with a FIDO key emulator. This is a serious bug in that it brings down my entire system if I use the hid gadget in any way, so can we please get it applied? It turns out to have been introduced by this commit:

commit 749494b6bdbbaf0899aa1c62a1ad74cd747bce47

Author: Krzysztof Opasiak <[email protected]>
Date:   Tue Jan 24 03:27:24 2017 +0100

usb: gadget: f_hid: fix: Move IN request allocation to set_alt()

So you can add

Fixes 749494b6bdbb ("usb: gadget: f_hid: fix: Move IN request allocation to set_alt()")

James