From: sashiko-bot@kernel.org
To: "Shunbo Shi" <shishunbo@cmss.chinamobile.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 3/4] usb: gadget: f_hid: fix race between userspace report update and GET_REPORT response
Date: Wed, 11 Nov 2026 08:32:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-208608@kernel.org> (raw)
In-Reply-To: <20261111081313.16626-4-shishunbo@cmss.chinamobile.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: gadget: f_hid: use-after-free of get_req_buf in
hidg_unbind()
--
commit e3eb22ae89791d0f4572b69a78a39ec433f7be8d
Author: Shunbo Shi <shishunbo@cmss.chinamobile.com>
usb: gadget: f_hid: fix race between userspace report update and GET_REPORT response
This commit allocates a dedicated buffer (get_req_buf) at bind time and
copies GET_REPORT response data into it before queueing hidg->get_req on
ep0, avoiding a race with userspace report updates.
> diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
> index d7ba30323414c..426bc1743cbb9 100644
> --- a/drivers/usb/gadget/function/f_hid.c
> +++ b/drivers/usb/gadget/function/f_hid.c
[ ... ]
> @@ -1593,6 +1619,8 @@ static void hidg_unbind(struct usb_configuration *c, struct usb_function *f)
>
> cdev_device_del(hidg->cdev, &hidg->dev);
> destroy_workqueue(hidg->workqueue);
> + kfree(hidg->get_req_buf);
> + hidg->get_req_buf = NULL;
> usb_free_all_descriptors(f);
> }
[Severity: Medium]
Can freeing hidg->get_req_buf here cause a use-after-free if hidg->get_req
is still queued on cdev->gadget->ep0?
get_report_workqueue_handler() queues hidg->get_req (with req->buf set to
hidg->get_req_buf) asynchronously on ep0 and sets hidg->get_report_returned
to true before the transfer completes. During gadget unbind,
hidg_disable() skips hidg->get_req when hidg->get_report_returned is true,
and destroy_workqueue(hidg->workqueue) in hidg_unbind() can also drain a
pending work item that queues hidg->get_req onto ep0 right before
kfree(hidg->get_req_buf) runs. Because hidg_unbind() neither dequeues nor
frees hidg->get_req, the UDC can access freed slab memory via req->buf and
hidg->get_req is leaked with a dangling buffer pointer.
Should hidg_unbind() dequeue and free hidg->get_req on ep0 before freeing
hidg->get_req_buf?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261111081313.16626-1-shishunbo@cmss.chinamobile.com?part=3
next prev parent reply other threads:[~2026-11-11 8:32 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 2:16 [PATCH 0/3] usb: gadget: f_hid: three GET_REPORT fixes Shunbo Shi
2026-11-11 2:16 ` [PATCH 1/3] usb: gadget: f_hid: fix sleep-in-atomic-context in f_hidg_get_report() Shunbo Shi
2026-11-11 2:48 ` sashiko-bot
2026-11-11 2:16 ` [PATCH 2/3] usb: gadget: f_hid: fix report_list entries leak Shunbo Shi
2026-11-11 2:52 ` sashiko-bot
2026-11-11 2:16 ` [PATCH 3/3] usb: gadget: f_hid: fix race between userspace report update and GET_REPORT response Shunbo Shi
2026-11-11 3:03 ` sashiko-bot
2026-11-11 8:13 ` [PATCH v2 0/4] usb: gadget: f_hid: three GET_REPORT fixes Shunbo Shi
2026-11-11 8:13 ` [PATCH v2 1/4] usb: gadget: f_hid: fix sleep-in-atomic-context in f_hidg_get_report() Shunbo Shi
2026-11-11 8:19 ` sashiko-bot
2026-11-11 8:13 ` [PATCH v2 2/4] usb: gadget: f_hid: fix report_list entries leak Shunbo Shi
2026-11-11 8:17 ` sashiko-bot
2026-11-11 8:13 ` [PATCH v2 3/4] usb: gadget: f_hid: fix race between userspace report update and GET_REPORT response Shunbo Shi
2026-11-11 8:32 ` sashiko-bot [this message]
2026-11-11 8:13 ` [PATCH v2 4/4] usb: gadget: f_hid: fix get_req leak when usb_gstrings_attach() fails Shunbo Shi
2026-11-11 8:22 ` sashiko-bot
2026-11-12 1:09 ` [PATCH v3 0/4] usb: gadget: f_hid: three GET_REPORT fixes Shunbo Shi
2026-11-12 1:09 ` [PATCH v3 1/4] usb: gadget: f_hid: fix sleep-in-atomic-context in f_hidg_get_report() Shunbo Shi
2026-11-12 1:15 ` sashiko-bot
2026-11-12 1:09 ` [PATCH v3 2/4] usb: gadget: f_hid: fix report_list entries leak Shunbo Shi
2026-11-12 1:14 ` sashiko-bot
2026-11-12 1:09 ` [PATCH v3 3/4] usb: gadget: f_hid: fix race between userspace report update and GET_REPORT response Shunbo Shi
2026-11-12 1:53 ` sashiko-bot
2026-11-12 1:09 ` [PATCH v3 4/4] usb: gadget: f_hid: fix get_req leak when usb_gstrings_attach() fails Shunbo Shi
2026-11-12 1:17 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-208608@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shishunbo@cmss.chinamobile.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.