Skip to contentSkip to conversation

hid: usbhid: fix deadlock in hid_post_reset()

PATCH In review Oliver Neukum 2 participants 4 messages Mar 24 – Apr 9

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

PATCH 1/1 hid: usbhid: fix deadlock in hid_post_reset()

You can build a USB device that includes a HID component and a storage or UAS component. The components can be reset only together. That means that hid_pre_reset() and hid_post_reset() are in the block IO error handling. Hence no memory allocation used in them may do block IO because the IO can deadlock on the mutex held while resetting a device and calling the interface drivers.
Use GFP_NOIO for all allocations in them.

Fixes dc3c78e434690 ("HID: usbhid: Check HID report descriptor contents after device reset")
---
 drivers/hid/usbhid/hid-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/usbhid/hid-core.c +1 -1
index ddd5d77fb5a5..fd3e1aedc5cb 100644
@@ -1552,7 +1552,7 @@ static int hid_post_reset(struct usb_interface *intf)
 	 * configuration descriptors passed, we already know that
 	 * the size of the HID report descriptor has not changed.
 	 */
-	rdesc = kmalloc(hid->dev_rsize, GFP_KERNEL);
+	rdesc = kmalloc(hid->dev_rsize, GFP_NOIO);
 	if (!rdesc)
 		return -ENOMEM;
 
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 11 lines · Oliver Neukum

You can build a USB device that includes a HID component and a storage or UAS component. The components can be reset only together. That means that hid_pre_reset() and hid_post_reset() are in the block IO error handling. Hence no memory allocation used in them may do block IO because the IO can deadlock on the mutex held while resetting a device and calling the interface drivers.
Use GFP_NOIO for all allocations in them.

Fixes dc3c78e434690 ("HID: usbhid: Check HID report descriptor contents after device reset")

Thanks Oliver.

Did you find this just by code inspection, or was this reported with a real device?

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs
#2 lore raw
Quoted 2 lines · Jiri Kosina

Did you find this just by code inspection, or was this reported with a real device?

Pure inspection. We are looking at USB error handling in general right now.

Regards
Oliver

maintainer
#3 lore raw
Quoted 5 lines · Oliver Neukum
Quoted 2 lines

Did you find this just by code inspection, or was this reported with a real device?

Pure inspection. We are looking at USB error handling in general right now.

OK, thanks. Now queued in hid.git.

Signature · 2 lines
Jiri Kosina
SUSE Labs