[PATCH v3 0/4] usb: gadget: f_hid: three GET_REPORT fixes

From: Shunbo Shi

Date: Wed Nov 11 2026 - 20:11:30 EST


Cover-letter:

Hi Greg,

v3 of this series. The only change from v2 is in patch 3: the
dedicated GET_REPORT response buffer is now allocated in
hidg_alloc() and freed in hidg_release() instead of being managed
across bind/unbind. This eliminates the use-after-free window on
unbind that the Sashiko AI review found in v2 (the buffer can
no longer be freed while a request is still queued on ep0), and
it also removes the need for buffer cleanup on the bind() error
paths. Patches 1, 2 and 4 are unchanged.

Original description:

While reviewing the f_hid GET_REPORT userspace ioctl feature
(a139c98f760e, v6.11) I found these bugs in it:

1. sleep-in-atomic-context: the second copy_from_user() in
f_hidg_get_report() runs under spin_lock_irqsave(); a page
fault on the user buffer deadlocks the scheduler.

2. memory leak: report_list entries allocated by the ioctl are
never freed in hidg_release().

3. data race: the GET_REPORT response is served by pointing
get_req->buf directly at a report_list entry's data; the
request completes asynchronously after the spinlock is
dropped, so a concurrent ioctl updating the same entry
corrupts the data on the wire (a torn write).

4. memory leak: get_req is leaked when usb_gstrings_attach()
fails in hidg_bind().

All four were introduced by the same commit and are fixable
deterministically from the code.

Shunbo Shi (4):
usb: gadget: f_hid: fix sleep-in-atomic-context in f_hidg_get_report()
usb: gadget: f_hid: fix report_list entries leak
usb: gadget: f_hid: fix race between userspace report update and
GET_REPORT response
usb: gadget: f_hid: fix get_req leak when usb_gstrings_attach() fails

drivers/usb/gadget/function/f_hid.c | 61 +++++++++++++++++++++++++++++++++----
1 file changed, 48 insertions(+), 13 deletions(-)

--
2.53.0