All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aditya Dash" <mradityadash@gmail.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v3 2/7] HID: hid-lenovo-go: use the right controller selectors
Date: Tue, 01 Sep 2026 06:46:16 +0000	[thread overview]
Message-ID: <20260901064616.BEB3C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <ec070d00bfb9c9a83b2883ccee62cba7da62028b.1788222001.git.mradityadash@gmail.com>

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

Pre-existing issues:
- [High] The driver relies on static global structures (`drvdata`, `go_cdev_rgb`) to maintain per-device state and register LED devices, breaking multi-device support and causing memory corruption.
- [High] Hardware is left in an active, open state if `hid_go_cfg_probe()` fails, due to missing `hid_hw_stop()` and `hid_hw_close()` calls in the `hid_go_probe()` error path.
- [High] Hardware cleanup and workcancellation are bypassed in `hid_go_remove()` for generic endpoints, leaving unmanaged active hardware and risking use-after-free.
- [High] Out-of-bounds array read in `get_endpoint_address()` if an interface has no endpoints.
--

commit e72b397410199e2e2416cfeb7ba8e9af743302f7
Author: Aditya Dash <mradityadash@gmail.com>

HID: hid-lenovo-go: use the right controller selectors

This commit corrects the right controller selectors by changing the
imu_enabled attribute to select FEATURE_IMU_ENABLE. It also fixes the right
reset attribute to target the right controller instead of the left.

> diff --git a/drivers/hid/hid-lenovo-go.c b/drivers/hid/hid-lenovo-go.c
> index b8248bf8965c6..b937d11dd6f6a 100644
> --- a/drivers/hid/hid-lenovo-go.c
> +++ b/drivers/hid/hid-lenovo-go.c

[ ... ]

[Severity: High]
This is a pre-existing issue, but does relying on static global structures
for per-device state break multi-device support and cause memory corruption?

Looking at drivers/hid/hid-lenovo-go.c, the driver defines global structures
rather than allocating per-device structures with devm_kzalloc():

} drvdata;
...
static struct led_classdev_mc go_cdev_rgb = {

And in hid_go_cfg_probe(), it forces all probed instances to share this
state by overwriting drvdata.hdev:

	hid_set_drvdata(hdev, &drvdata);
	drvdata.hdev = hdev;
	mutex_init(&drvdata.cfg_mutex);

If multiple gamepads are plugged in, will concurrent probes overwrite active
locks and the delayed work struct?

Also, will calling devm_led_classdev_multicolor_register() on the same
global go_cdev_rgb multiple times double-add its embedded list_head node
into the core LED subsystem lists, causing linked-list corruption?

[Severity: High]
This isn't a bug introduced by this patch, but does hid_go_probe() leak
the hardware state if hid_go_cfg_probe() fails?

In hid_go_probe(), after hid_hw_start() and hid_hw_open() are successfully
called, if hid_go_cfg_probe() fails, the error path returns without calling
hid_hw_close() and hid_hw_stop():

	ret = hid_go_cfg_probe(hdev, id);
	if (ret)
		dev_err_probe(&hdev->dev, ret, "Failed to start configuration interface\n");

	dev_dbg(&hdev->dev, "Started Legion Go HID Device: %x\n", ep);

	return ret;

Could this leave the device unmanaged but actively running, causing resource
leaks and potential use-after-free when devres cleanup frees structures?

[Severity: High]
This is a pre-existing issue, but is hardware cleanup bypassed in
hid_go_remove() for generic endpoints?

In hid_go_remove(), the driver unconditionally returns early for
non-configured generic endpoints:

	int ep = get_endpoint_address(hdev);

	if (ep <= 0)
		return;

Since hid_go_probe() accepts devices even if get_endpoint_address() returns
an error, leaving the generic device bound, started, and opened, does this
early return in hid_go_remove() bypass hid_hw_close() and hid_hw_stop()
entirely?

According to HID subsystem rules, omitting hid_hw_stop() in remove() leaves
the input and hidraw devices registered and active while the driver's devres
memory is freed. Can this lead to a use-after-free if userspace interacts
with the node?

[Severity: High]
This isn't a bug introduced by this patch, but can get_endpoint_address()
cause an out-of-bounds array read if an interface has no endpoints?

The function fetches the endpoint array and checks if ep is NULL, but it
dereferences it without checking if desc.bNumEndpoints > 0:

	ep = intf->cur_altsetting->endpoint;
	if (!ep)
		return -ENODEV;

	return ep->desc.bEndpointAddress;

If the interface has bNumEndpoints == 0, the USB core allocates a
zero-length array, returning ZERO_SIZE_PTR.

Since if (!ep) evaluates to false for ZERO_SIZE_PTR, will dereferencing it
cause an out-of-bounds read?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1788222001.git.mradityadash@gmail.com?part=2

  reply	other threads:[~2026-09-01  6:46 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01  6:36 [PATCH v3 0/7] HID: hid-lenovo-go: fix controller configuration Aditya Dash
2026-09-01  6:36 ` [PATCH v3 1/7] HID: hid-lenovo-go: use the correct calibration commands Aditya Dash
2026-09-01  6:50   ` sashiko-bot
2026-09-01  6:36 ` [PATCH v3 2/7] HID: hid-lenovo-go: use the right controller selectors Aditya Dash
2026-09-01  6:46   ` sashiko-bot [this message]
2026-09-01  6:36 ` [PATCH v3 3/7] HID: hid-lenovo-go: initialize command completion before hardware Aditya Dash
2026-09-01  6:48   ` sashiko-bot
2026-09-01  6:36 ` [PATCH v3 4/7] HID: hid-lenovo-go: return configuration request errors Aditya Dash
2026-09-01  6:50   ` sashiko-bot
2026-09-01  6:36 ` [PATCH v3 5/7] HID: hid-lenovo-go: normalize calibration failure status Aditya Dash
2026-09-01  6:50   ` sashiko-bot
2026-09-01 15:57   ` Derek John Clark
2026-09-01 17:06     ` Aditya
2026-09-02 12:40       ` Derek J. Clark
2026-09-05  6:10         ` Aditya Dash
2026-09-01  6:36 ` [PATCH v3 6/7] HID: hid-lenovo-go: reject unknown calibration action Aditya Dash
2026-09-01  6:48   ` sashiko-bot
2026-09-01  6:36 ` [PATCH v3 7/7] HID: hid-lenovo-go: clear calibration status on start Aditya Dash
2026-09-01  7:00   ` 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=20260901064616.BEB3C1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=mradityadash@gmail.com \
    --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 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.