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 v2 10/10] HID: steam: Retry send/recv reports if stale
Date: Tue, 07 Jul 2026 23:48:39 +0000	[thread overview]
Message-ID: <20260707234839.A32831F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707233241.2644971-11-vi@endrift.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] Log spam in expected retry path due to unconditional `hid_err` in `steam_recv_report`.
- [Medium] Out-of-bounds stack read in `hid_dbg` when the device report exceeds the caller's buffer.
- [Medium] `steam_recv_report` reads uninitialized stack memory on short hardware reads.
--

--- Patch [10]: [PATCH v2 10/10] HID: steam: Retry send/recv reports if stale ---
commit 181ac85173536f44d1a324b3bc0042d43fa8238e
Author: Vicki Pfau <vi@endrift.com>

HID: steam: Retry send/recv reports if stale

Sometimes recv report will reply with a stale result from a previous send
report. Instead of failing out, we should retry them, as they generally
reply correctly after three tries, give or take.

> diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c
> index 49f6733d89359..ba2dd40a79763 100644
> --- a/drivers/hid/hid-steam.c
> +++ b/drivers/hid/hid-steam.c
> @@ -497,6 +497,43 @@ static int steam_write_settings(struct steam_device *steam,
>  	return steam_recv_report(steam, cmd, 2 + cmd[1]);
>  }
>  
> +static int steam_exchange_report(struct steam_device *steam, u8 *cmd, int csize,
> +		u8 *reply, int rsize)
> +{
> +	unsigned int retries = 5;
> +	int ret;
> +
> +	guard(mutex)(&steam->report_mutex);
> +	do {
> +		ret = steam_send_report(steam, cmd, csize);
> +		if (ret < 0)
> +			return ret;
> +		ret = steam_recv_report(steam, reply, rsize);

[Severity: Medium]
Does this call cause an out-of-bounds stack read in steam_recv_report()?

When a device sends a padded report that is larger than the caller's buffer
(like the 36-byte reply buffer in steam_get_serial()), steam_recv_report()
copies the correct size but logs using the unbounded ret length:

steam_recv_report() {
    ...
    size = min(size, ret);
    memcpy(data, buf + 1, size);
    ...
    hid_dbg(steam->hdev, "Received report %*ph\n", ret, data);
    ...
}

Since ret can be larger than size, won't hid_dbg() read past the end of the
reply buffer on the stack?

[Severity: Medium]
Can this also result in reading uninitialized stack memory on short reads?

If the hardware sends a short report where hid_hw_raw_request() returns
0 or 1, memcpy() copies 0 bytes, leaving the caller's reply buffer
uninitialized.

steam_recv_report() {
    ...
    if (ret < 2 || ret < data[1] + 2) {
        hid_err(steam->hdev, "%s: expected %u bytes, read %i\n",
                __func__, data[1] + 2, ret);
        return -EPROTO;
    }
}

When ret < 2, data[1] has not been populated. Won't this read and log an
uninitialized byte from the stack?

> +		/*
> +		 * Sometimes this can fail on the first few tries on the Steam
> +		 * Controller (2015). It appears to be a firmware bug, and Steam
> +		 * itself just retries, so we should also retry a few times to
> +		 * see if we get it.
> +		 */
> +		if (ret == -EPROTO)

[Severity: Medium]
Will this retry logic cause log spam during normal operation?

Because steam_recv_report() unconditionally calls hid_err() before returning
-EPROTO:

steam_recv_report() {
    ...
    if (ret < 2 || ret < data[1] + 2) {
        hid_err(steam->hdev, "%s: expected %u bytes, read %i\n",
                __func__, data[1] + 2, ret);
        return -EPROTO;
    }
}

Won't every expected retry here flood the kernel log with error messages?

> +			continue;
> +		if (ret < 0) {
> +			hid_err(steam->hdev, "%s: error reading reply (%*ph)\n",
> +					__func__, csize, cmd);
> +			return ret;
> +		}
> +		if (reply[0] == cmd[0] && reply[1] >= 1)
> +			break;
> +		if (retries > 0)
> +			continue;
> +		hid_err(steam->hdev, "%s: invalid reply (%*ph)\n", __func__,
> +				rsize, reply);
> +		return -EPROTO;
> +	} while (retries--);
> +
> +	return ret;
> +}

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

      reply	other threads:[~2026-07-07 23:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 23:32 [PATCH v2 00/10] HID: steam: General cleanup and improvements Vicki Pfau
2026-07-07 23:32 ` [PATCH v2 01/10] HID: steam: Update documentation Vicki Pfau
2026-07-07 23:32 ` [PATCH v2 02/10] HID: steam: Refactor and clean up report parsing Vicki Pfau
2026-07-07 23:32 ` [PATCH v2 03/10] HID: steam: Rename some constants that got renamed upstream Vicki Pfau
2026-07-07 23:32 ` [PATCH v2 04/10] HID: steam: Add support for sensor events on the Steam Controller (2015) Vicki Pfau
2026-07-07 23:50   ` sashiko-bot
2026-07-07 23:32 ` [PATCH v2 05/10] HID: steam: Coalesce rumble packets Vicki Pfau
2026-07-07 23:46   ` sashiko-bot
2026-07-07 23:32 ` [PATCH v2 06/10] HID: steam: Fully unregister controller when hidraw is opened Vicki Pfau
2026-07-07 23:52   ` sashiko-bot
2026-07-07 23:32 ` [PATCH v2 07/10] HID: steam: Rearrange deinitialization sequence Vicki Pfau
2026-07-07 23:32 ` [PATCH v2 08/10] HID: steam: Improve logging and other cleanup Vicki Pfau
2026-07-07 23:47   ` sashiko-bot
2026-07-07 23:32 ` [PATCH v2 09/10] HID: steam: Reject short reads Vicki Pfau
2026-07-07 23:47   ` sashiko-bot
2026-07-07 23:32 ` [PATCH v2 10/10] HID: steam: Retry send/recv reports if stale Vicki Pfau
2026-07-07 23:48   ` 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=20260707234839.A32831F000E9@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