Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dmitry Torokhov" <dmitry.torokhov@gmail.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH 03/11] Input: ims-pcu - fix type confusion in CDC union descriptor parsing
Date: Sat, 23 May 2026 05:52:04 +0000	[thread overview]
Message-ID: <20260523055205.8B3421F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260523050634.501509-3-dmitry.torokhov@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The size parameter passed to `usb_free_coherent()` when freeing `urb_in_buf` is incorrect.
- [High] The driver does not properly clean up or stop I/O when the secondary (data) interface is unbound.
--

commit af29ec151c71a12e07665974e6faf5b8ab15fa16
Author: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Input: ims-pcu - fix type confusion in CDC union descriptor parsing

The driver currently trusts the bMasterInterface0 from the CDC union
descriptor without verifying that it matches the interface being probed.
Validate that the control interface found in the descriptor is indeed the
one we are probing to avoid overwriting private data.

> diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
> index 2ad72fe4a51d9..5d1df07ac2a2a 100644
> --- a/drivers/input/misc/ims-pcu.c
> +++ b/drivers/input/misc/ims-pcu.c
> @@ -1693,7 +1693,7 @@ static int ims_pcu_parse_cdc_data(struct usb_interface *intf, struct ims_pcu *pc
>  
>  	pcu->ctrl_intf = usb_ifnum_to_if(pcu->udev,
>  					 union_desc->bMasterInterface0);
> -	if (!pcu->ctrl_intf)
> +	if (pcu->ctrl_intf != intf)
>  		return -EINVAL;
>  
>  	alt = pcu->ctrl_intf->cur_altsetting;

[Severity: High]
This isn't a bug introduced by this patch, but pre-exists in the driver:
the size parameter passed to usb_free_coherent() when freeing urb_in_buf
appears incorrect.

Does this mismatch result in partial memory unmapping or page leaks if the
max packet sizes for IN and OUT endpoints differ?

In ims_pcu_buffers_alloc(), pcu->urb_in_buf is allocated using
pcu->max_in_size:

drivers/input/misc/ims-pcu.c:ims_pcu_buffers_alloc() {
	...
	pcu->urb_in_buf = usb_alloc_coherent(pcu->udev, pcu->max_in_size,
					     GFP_KERNEL, &pcu->read_dma);
	...
}

However, in ims_pcu_buffers_free(), it is freed using pcu->max_out_size:

drivers/input/misc/ims-pcu.c:ims_pcu_buffers_free() {
	...
	usb_free_coherent(pcu->udev, pcu->max_out_size,
			  pcu->urb_in_buf, pcu->read_dma);
	...
}

Because USB devices can have different max packet sizes for IN and OUT
endpoints, max_in_size and max_out_size are not guaranteed to be equal.
The DMA API requires that the exact size passed to the allocator is
provided to the free function.

[Severity: High]
This is a pre-existing issue, but the driver does not appear to properly
clean up or stop I/O when the secondary (data) interface is unbound.

If a user manually unbinds the data interface via sysfs, will the driver
continue submitting URBs to the unbound interface's endpoints?

Looking at ims_pcu_disconnect(), if the unbound interface is not the
control interface, it returns early without stopping URBs:

drivers/input/misc/ims-pcu.c:ims_pcu_disconnect() {
	...
	/*
	 * See if we are dealing with control or data interface. The cleanup
	 * happens when we unbind primary (control) interface.
	 */
	if (intf != pcu->ctrl_intf)
		return;

	ims_pcu_stop_io(pcu);
	...
}

This means the control interface remains bound and the driver will continue
to submit URBs (such as urb_out in ims_pcu_send_cmd_chunk()) to the data
interface's endpoints.

This unstopped I/O can lead to state corruption if the data interface is
subsequently claimed.

Note that a later patch 'Input: ims-pcu - fix use-after-free and double-free
in disconnect' alters the early return condition to compare pointers instead
of class types, but it maintains the fundamentally flawed behavior of
skipping cleanup when the data interface is unbound.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260523050634.501509-1-dmitry.torokhov@gmail.com?part=3

  reply	other threads:[~2026-05-23  5:52 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-23  5:06 [PATCH 01/11] Input: ims-pcu - release data interface on disconnect Dmitry Torokhov
2026-05-23  5:06 ` [PATCH 02/11] Input: ims-pcu - fix use-after-free and double-free in disconnect Dmitry Torokhov
2026-05-23  5:45   ` sashiko-bot
2026-05-23  5:06 ` [PATCH 03/11] Input: ims-pcu - fix type confusion in CDC union descriptor parsing Dmitry Torokhov
2026-05-23  5:52   ` sashiko-bot [this message]
2026-05-23  5:06 ` [PATCH 04/11] Input: ims-pcu - fix firmware leak in async update Dmitry Torokhov
2026-05-23  5:37   ` sashiko-bot
2026-05-23  5:06 ` [PATCH 05/11] Input: ims-pcu - fix race condition in reset_device sysfs callback Dmitry Torokhov
2026-05-23  7:12   ` sashiko-bot
2026-05-23  5:06 ` [PATCH 06/11] Input: ims-pcu - validate control endpoint type Dmitry Torokhov
2026-05-23  5:44   ` sashiko-bot
2026-05-23  5:06 ` [PATCH 07/11] Input: ims-pcu - fix logic error in packet reset Dmitry Torokhov
2026-05-23  6:25   ` sashiko-bot
2026-05-23  5:06 ` [PATCH 08/11] Input: ims-pcu - fix out-of-bounds read in ims_pcu_irq() debug logging Dmitry Torokhov
2026-05-23  5:39   ` sashiko-bot
2026-05-23  5:06 ` [PATCH 09/11] Input: ims-pcu - fix DMA mapping violation in line setup Dmitry Torokhov
2026-05-23  5:37   ` sashiko-bot
2026-05-23  5:06 ` [PATCH 10/11] Input: ims-pcu - add response length checks Dmitry Torokhov
2026-05-23  5:54   ` sashiko-bot
2026-05-23  5:06 ` [PATCH 11/11] Input: ims-pcu - fix potential infinite loop in CDC union descriptor parsing Dmitry Torokhov
2026-05-23  6:02   ` sashiko-bot
2026-05-23  5:46 ` [PATCH 01/11] Input: ims-pcu - release data interface on disconnect 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=20260523055205.8B3421F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --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