[lvc-project] [PATCH v3 2/2] HID: usbhid: free unsent raw output reports in usbhid_stop()
Dmitry Antipov
dmantipov at yandex.ru
Thu Nov 19 13:55:51 MSK 2026
When HID device is stalled or disconnected, there might be an
unsent (i.e. never passed via hid_submit_out()) output reports.
So free their raw buffers in usbhid_stop() to avoid memory leaks.
Adjust hid_irq_out() to prevent hid_submit_out() from using an
uninitialized output pipe slot as well.
This is a companion of commit f7744fa16b96 ("HID: usbhid: free
raw_report buffers in usbhid_stop") and inspired by that one.
Reported-by: syzbot+e2c057ea576d2644e2be at syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e2c057ea576d2644e2be
Fixes: c500c9714011 ("HID: hid, make parsing event driven")
Assisted-by: Sashiko-0.2.5:gemini-3.1-pro-preview
Signed-off-by: Dmitry Antipov <dmantipov at yandex.ru>
---
v3: tweak hid_irq_out() to follow logic in hid_ctrl() (Sashiko)
v2: adjust loop to match actual FIFO size and tweak commit message
---
drivers/hid/usbhid/hid-core.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index d7cf2b56e117..bb3cb80d908b 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -452,7 +452,7 @@ static void hid_irq_out(struct urb *urb)
if (unplug) {
usbhid->outtail = usbhid->outhead;
- } else {
+ } else if (usbhid->outhead != usbhid->outtail) {
usbhid->outtail = (usbhid->outtail + 1) & (HID_OUTPUT_FIFO_SIZE - 1);
if (usbhid->outhead != usbhid->outtail &&
@@ -1260,6 +1260,14 @@ static void usbhid_stop(struct hid_device *hid)
usbhid->ctrltail = (usbhid->ctrltail + 1) &
(HID_CONTROL_FIFO_SIZE - 1);
}
+
+ while (usbhid->outtail != usbhid->outhead) {
+ kfree(usbhid->out[usbhid->outtail].raw_report);
+ usbhid->out[usbhid->outtail].raw_report = NULL;
+
+ usbhid->outtail = (usbhid->outtail + 1) &
+ (HID_OUTPUT_FIFO_SIZE - 1);
+ }
spin_unlock_irq(&usbhid->lock);
usb_kill_urb(usbhid->urbin);
--
2.56.1
More information about the lvc-project
mailing list