Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vicki Pfau" <vi@endrift.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v5 04/11] HID: steam: Add support for sensor events on the Steam Controller (2015)
Date: Thu, 30 Jul 2026 04:37:56 +0000	[thread overview]
Message-ID: <20260730043756.BD0A01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260730041251.1659029-5-vi@endrift.com>

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

Pre-existing issues:
- [High] Global list dangling pointer and Use-After-Free when steam_register fails during probe.
- [High] Race condition leading to double-free of input devices in workqueue callbacks.
--

--- Patch [4]: [PATCH v5 04/11] HID: steam: Add support for sensor events on the Steam Controller (2015) ---
commit c819d5d2af295f0bbbbb6b163562daebd8e1a93c
Author: Vicki Pfau <vi@endrift.com>
Subject: HID: steam: Add support for sensor events on the Steam Controller (2015)

Sensor support was added for the Steam Deck previously, but Steam
Controller sensor events were never added. This adds that missing support,
bringing Steam Controller support much closer to feature parity with things
like SDL and Steam itself.

> diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c
> index 983d18d1de4fe..1ceb044e170b4 100644
> --- a/drivers/hid/hid-steam.c
> +++ b/drivers/hid/hid-steam.c

[ ... ]

> @@ -918,9 +1030,6 @@ static void steam_sensors_unregister(struct steam_device *steam)
>  {
>  	struct input_dev *sensors;
>  
> -	if (!(steam->quirks & STEAM_QUIRK_DECK))
> -		return;
> -
>  	rcu_read_lock();
>  	sensors = rcu_dereference(steam->sensors);
>  	rcu_read_unlock();

[Severity: High]
This isn't a bug introduced by this patch, but is there a race condition
leading to a double-free of the input devices in the workqueue callbacks?

If a device disconnects at the exact time a user opens the raw HID node,
steam->work_connect and steam->unregister_work can execute concurrently
on different CPUs. Both callbacks invoke steam_sensors_unregister() and
steam_input_unregister().

In steam_input_unregister(), the check-and-clear logic is not protected by a
mutex or lock:

drivers/hid/hid-steam.c:steam_input_unregister() {
	rcu_read_lock();
	input = rcu_dereference(steam->input);
	rcu_read_unlock();
	if (!input)
		return;
	RCU_INIT_POINTER(steam->input, NULL);
	synchronize_rcu();
	input_unregister_device(input);
}

Could both concurrent threads read a non-null pointer, drop the RCU lock,
and then both call input_unregister_device() on the same device?

[ ... ]

> @@ -968,6 +1077,12 @@ static int steam_register(struct steam_device *steam)
>  			strscpy(steam->serial_no, "XXXXXXXXXX",
>  					sizeof(steam->serial_no));
>  
> +		ret = steam_get_attributes(steam);
> +		if (ret < 0)
> +			hid_err(steam->hdev,
> +				"%s:steam_get_attributes failed with error %d\n",
> +				__func__, ret);
> +
>  		hid_info(steam->hdev, "Steam Controller '%s' connected",
>  				steam->serial_no);

[Severity: High]
This is a pre-existing issue, but could the error path in steam_register()
leave a dangling pointer in the global steam_devices list?

If steam_register() encounters an error during a wired device probe, such as
steam_input_register() failing to allocate memory, it returns an error code
but leaves the steam object on the global list:

drivers/hid/hid-steam.c:steam_register() {
...
steam_register_sensors_fail:
	steam_input_unregister(steam);
steam_register_input_fail:
	return ret;
}

The caller, steam_probe(), then jumps to the err_hw_close label, skipping
the err_steam_unregister label where the list state would be cleaned up:

drivers/hid/hid-steam.c:steam_probe() {
...
		ret = steam_register(steam);
		if (ret) {
			hid_err(hdev,
				"%s:steam_register failed with error %d\n",
				__func__, ret);
			goto err_hw_close;
		}
...
}

Because the steam object is managed by devm_kzalloc(), the kernel
automatically frees the memory when probe fails. A subsequent write to the
lizard_mode module parameter will trigger steam_param_set_lizard_mode(),
which iterates over the list and accesses the freed memory, leading to a
use-after-free.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260730041251.1659029-1-vi@endrift.com?part=4

  reply	other threads:[~2026-07-30  4:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30  4:12 [PATCH v5 00/10] HID: steam: General cleanup and improvements Vicki Pfau
2026-07-30  4:12 ` [PATCH v5 01/11] HID: steam: Update documentation Vicki Pfau
2026-07-30  4:12 ` [PATCH v5 02/11] HID: steam: Refactor and clean up report parsing Vicki Pfau
2026-07-30  4:52   ` sashiko-bot
2026-07-30  4:12 ` [PATCH v5 03/11] HID: steam: Rename some constants that got renamed upstream Vicki Pfau
2026-07-30  4:12 ` [PATCH v5 04/11] HID: steam: Add support for sensor events on the Steam Controller (2015) Vicki Pfau
2026-07-30  4:37   ` sashiko-bot [this message]
2026-07-30  4:12 ` [PATCH v5 05/11] HID: steam: Coalesce rumble packets Vicki Pfau
2026-07-30  4:33   ` sashiko-bot
2026-07-30  4:12 ` [PATCH v5 06/11] HID: steam: Fully unregister controller when hidraw is opened Vicki Pfau
2026-07-30  4:34   ` sashiko-bot
2026-07-30  4:12 ` [PATCH v5 07/11] HID: steam: Rearrange teardown sequence Vicki Pfau
2026-07-30  4:39   ` sashiko-bot
2026-07-30  4:12 ` [PATCH v5 08/11] HID: steam: Improve logging and other cleanup Vicki Pfau
2026-07-30  4:34   ` sashiko-bot
2026-07-30  4:12 ` [PATCH v5 09/11] HID: steam: Zero-initialize reply in serial lookup Vicki Pfau
2026-07-30  4:12 ` [PATCH v5 10/11] HID: steam: Reject short reads Vicki Pfau
2026-07-30  4:12 ` [PATCH v5 11/11] HID: steam: Retry send/recv reports if stale Vicki Pfau

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=20260730043756.BD0A01F000E9@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 \
    --cc=vi@endrift.com \
    /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