* [PATCH] usbhid: free raw_report buffers in usbhid_stop
@ 2021-06-23 18:40 Anirudh Rayabharam
2021-07-28 9:31 ` Jiri Kosina
0 siblings, 1 reply; 2+ messages in thread
From: Anirudh Rayabharam @ 2021-06-23 18:40 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires
Cc: gregkh, linux-kernel-mentees, Anirudh Rayabharam,
syzbot+47b26cd837ececfc666d, linux-usb, linux-input,
linux-kernel
Free the unsent raw_report buffers when the device is removed.
Fixes a memory leak reported by syzbot at:
https://syzkaller.appspot.com/bug?id=7b4fa7cb1a7c2d3342a2a8a6c53371c8c418ab47
Reported-by: syzbot+47b26cd837ececfc666d@syzkaller.appspotmail.com
Tested-by: syzbot+47b26cd837ececfc666d@syzkaller.appspotmail.com
Signed-off-by: Anirudh Rayabharam <mail@anirudhrb.com>
---
drivers/hid/usbhid/hid-core.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 4e9077363c96..9c970e63670e 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -505,7 +505,7 @@ static void hid_ctrl(struct urb *urb)
if (unplug) {
usbhid->ctrltail = usbhid->ctrlhead;
- } else {
+ } else if (usbhid->ctrlhead != usbhid->ctrltail) {
usbhid->ctrltail = (usbhid->ctrltail + 1) & (HID_CONTROL_FIFO_SIZE - 1);
if (usbhid->ctrlhead != usbhid->ctrltail &&
@@ -1223,9 +1223,20 @@ static void usbhid_stop(struct hid_device *hid)
mutex_lock(&usbhid->mutex);
clear_bit(HID_STARTED, &usbhid->iofl);
+
spin_lock_irq(&usbhid->lock); /* Sync with error and led handlers */
set_bit(HID_DISCONNECTED, &usbhid->iofl);
+ while (usbhid->ctrltail != usbhid->ctrlhead) {
+ if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_OUT) {
+ kfree(usbhid->ctrl[usbhid->ctrltail].raw_report);
+ usbhid->ctrl[usbhid->ctrltail].raw_report = NULL;
+ }
+
+ usbhid->ctrltail = (usbhid->ctrltail + 1) &
+ (HID_CONTROL_FIFO_SIZE - 1);
+ }
spin_unlock_irq(&usbhid->lock);
+
usb_kill_urb(usbhid->urbin);
usb_kill_urb(usbhid->urbout);
usb_kill_urb(usbhid->urbctrl);
--
2.26.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] usbhid: free raw_report buffers in usbhid_stop
2021-06-23 18:40 [PATCH] usbhid: free raw_report buffers in usbhid_stop Anirudh Rayabharam
@ 2021-07-28 9:31 ` Jiri Kosina
0 siblings, 0 replies; 2+ messages in thread
From: Jiri Kosina @ 2021-07-28 9:31 UTC (permalink / raw)
To: Anirudh Rayabharam
Cc: Benjamin Tissoires, gregkh, linux-kernel-mentees,
syzbot+47b26cd837ececfc666d, linux-usb, linux-input,
linux-kernel
On Thu, 24 Jun 2021, Anirudh Rayabharam wrote:
> Free the unsent raw_report buffers when the device is removed.
>
> Fixes a memory leak reported by syzbot at:
> https://syzkaller.appspot.com/bug?id=7b4fa7cb1a7c2d3342a2a8a6c53371c8c418ab47
>
> Reported-by: syzbot+47b26cd837ececfc666d@syzkaller.appspotmail.com
> Tested-by: syzbot+47b26cd837ececfc666d@syzkaller.appspotmail.com
> Signed-off-by: Anirudh Rayabharam <mail@anirudhrb.com>
Applied, thank you.
--
Jiri Kosina
SUSE Labs
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-07-28 9:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-23 18:40 [PATCH] usbhid: free raw_report buffers in usbhid_stop Anirudh Rayabharam
2021-07-28 9:31 ` Jiri Kosina
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).