Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dmitry Antipov" <dmantipov@yandex.ru>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [RESEND PATCH v2 2/2] HID: usbhid: free unsent raw output reports in usbhid_stop()
Date: Mon, 07 Sep 2026 10:19:28 +0000	[thread overview]
Message-ID: <20260907101928.845251F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260907100645.86990-2-dmantipov@yandex.ru>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Emptying the output queue in `usbhid_stop()` causes the URB completion handler `hid_irq_out()` to advance `outtail` past `outhead`, leading to a NULL pointer dereference in `hid_submit_out()`.
--

commit fa290a16b56c6527830ed98c05dc263369208959
Author: Dmitry Antipov <dmantipov@yandex.ru>

HID: usbhid: free unsent raw output reports in usbhid_stop()

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.

Closes: https://syzkaller.appspot.com/bug?extid=e2c057ea576d2644e2be

> diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
> index 96b0181cf8194..60662616fd2a0 100644
> --- a/drivers/hid/usbhid/hid-core.c
> +++ b/drivers/hid/usbhid/hid-core.c
> @@ -1253,6 +1253,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);
> +	}

[Severity: High]
Does emptying the output queue here cause a NULL pointer dereference
when usb_kill_urb() subsequently cancels the in-flight URB?

When usb_kill_urb(usbhid->urbout) invokes the hid_irq_out() completion
handler with -ENOENT, unplug is 0. Unlike hid_ctrl(), hid_irq_out()
unconditionally advances outtail without checking if the queue is empty:

drivers/hid/usbhid/hid-core.c:hid_irq_out() {
	...
	if (unplug) {
		usbhid->outtail = usbhid->outhead;
	} else {
		usbhid->outtail = (usbhid->outtail + 1) & (HID_OUTPUT_FIFO_SIZE - 1);

		if (usbhid->outhead != usbhid->outtail &&
				hid_submit_out(hid) == 0) {
	...
}

Because this loop in usbhid_stop() already made outtail equal to outhead,
advancing it moves outtail into an uninitialized slot and makes the
outhead != outtail condition true.

This then triggers hid_submit_out(), which dereferences the NULL report
pointer from the uninitialized slot:

drivers/hid/usbhid/hid-core.c:hid_submit_out() {
	...
	report = usbhid->out[usbhid->outtail].report;
	...
	usbhid->urbout->transfer_buffer_length = hid_report_len(report);
	...
}

Should hid_irq_out() be updated to check if outhead != outtail before
advancing the queue, similar to what hid_ctrl() does?

>  	spin_unlock_irq(&usbhid->lock);
>  
>  	usb_kill_urb(usbhid->urbin);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260907100645.86990-1-dmantipov@yandex.ru?part=2

      reply	other threads:[~2026-09-07 10:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07 10:06 [RESEND PATCH v2 1/2] HID: usbhid: adjust output pipe FIFO size Dmitry Antipov
2026-09-07 10:06 ` [RESEND PATCH v2 2/2] HID: usbhid: free unsent raw output reports in usbhid_stop() Dmitry Antipov
2026-09-07 10:19   ` sashiko-bot [this message]

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=20260907101928.845251F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmantipov@yandex.ru \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox