Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vicki Pfau" <vi@endrift.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v5 06/11] HID: steam: Fully unregister controller when hidraw is opened
Date: Thu, 30 Jul 2026 04:34:43 +0000	[thread overview]
Message-ID: <20260730043443.960E31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260730041251.1659029-7-vi@endrift.com>

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

New issues:
- [Medium] The local variable `do_add` in `steam_register()` can be evaluated uninitialized.

Pre-existing issues:
- [High] Teardown order in `steam_remove()` causes Use-After-Free and double-free vulnerabilities.
--

--- Patch [6]: [PATCH v5 06/11] HID: steam: Fully unregister controller when hidraw is opened ---
commit 14e48fa0937746f55f6b26048f8ecca7fe02bb3e
Author: Vicki Pfau <vi@endrift.com>
Subject: HID: steam: Fully unregister controller when hidraw is opened

This patch changes the driver to fully unregister the controller
internally when hidraw is opened, leaving only the hidraw active until
it is closed. It also unifies the unregister and connect callbacks to
share identical logic.

> diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c
> index 87b3817a2f69d..12203d61922f7 100644
> --- a/drivers/hid/hid-steam.c
> +++ b/drivers/hid/hid-steam.c

[ ... ]

> @@ -1084,6 +1085,7 @@ static int steam_register(struct steam_device *steam)
>  	int ret;
>  	unsigned long client_opened;
>  	unsigned long flags;
> +	bool do_add;
>  
>  	/*
>  	 * This function can be called several times in a row with the
> @@ -1113,10 +1115,7 @@ static int steam_register(struct steam_device *steam)
>  		if (steam->quirks & STEAM_QUIRK_WIRELESS)
>  			steam_battery_register(steam);
>  
> -		mutex_lock(&steam_devices_lock);
> -		if (list_empty(&steam->list))
> -			list_add(&steam->list, &steam_devices);
> -		mutex_unlock(&steam_devices_lock);
> +		do_add = true;
>  	}
>  
>  	spin_lock_irqsave(&steam->lock, flags);
> @@ -1132,6 +1131,13 @@ static int steam_register(struct steam_device *steam)
>  		if (ret != 0)
>  			goto steam_register_sensors_fail;
>  	}
> +
> +	if (do_add) {

[Severity: Medium]
Is it possible for do_add to be evaluated uninitialized here?

When steam_register() is invoked on an already-registered device,
steam->serial_no[0] is already populated. This causes the initialization block
for "if (!steam->serial_no[0])" to be skipped, meaning do_add is never
assigned a value. Could this undefined behavior lead to compiler
optimizations altering the control flow or causing redundant lock
acquisitions?

> +		mutex_lock(&steam_devices_lock);
> +		if (list_empty(&steam->list))
> +			list_add(&steam->list, &steam_devices);
> +		mutex_unlock(&steam_devices_lock);
> +	}
>  	return 0;

[ ... ]

> @@ -1470,7 +1452,6 @@ static void steam_remove(struct hid_device *hdev)
>  	cancel_work_sync(&steam->work_connect);
>  	cancel_work_sync(&steam->rumble_work);
>  	cancel_delayed_work_sync(&steam->coalesce_rumble_work);
> -	cancel_work_sync(&steam->unregister_work);

[Severity: High]
This is a pre-existing issue, but does the teardown order in steam_remove()
cause a Use-After-Free and double-free vulnerability?

Currently, work items like steam->work_connect are canceled before calling
hid_hw_stop(). Since the HID event stream is still active, an incoming
interrupt (such as a connection status report) can trigger steam_raw_event():

steam_raw_event()
  steam_do_connect_event()
    schedule_work(&steam->work_connect)

When steam_remove() completes, devres frees the steam_device struct, leaving
a dangling work item in the queue that triggers a UAF when executed.

Furthermore, if the rescheduled work executes concurrently with the end of
steam_remove(), both threads can invoke steam_unregister() simultaneously.
Because steam_unregister() lacks mutual exclusion, does this lead to
concurrent double-frees of the input and sensor devices?

>  	steam->client_hdev = NULL;
>  	steam->client_opened = 0;
>  	if (steam->quirks & STEAM_QUIRK_WIRELESS) {

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

  reply	other threads:[~2026-07-30  4:34 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
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 [this message]
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=20260730043443.960E31F000E9@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