Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Denis Benato" <denis.benato@linux.dev>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v11 14/18] HID: asus: expose XG Mobile identity and firmware information
Date: Mon, 26 Oct 2026 00:05:52 +0000	[thread overview]
Message-ID: <sashiko-outbox-184548@kernel.org> (raw)
In-Reply-To: <20261025235232.129945-15-denis.benato@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] HID: asus: unchecked return and unaligned scan in asus_xgm_tlv_str()
--

commit a88274a1b2531f51181e1da6036282f6753460c3
Author: Denis Benato <benato.denis96@gmail.com>

HID: asus: expose XG Mobile identity and firmware information

This commit queries the XG Mobile station for its firmware version and
generation at probe time and exposes the station's identity and firmware
fields through read-only sysfs attributes on the HID device.

> diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c
> index e751bf1634349..f438cad13264a 100644
> --- a/drivers/hid/hid-asus.c
> +++ b/drivers/hid/hid-asus.c
[ ... ]
> @@ -6204,6 +6206,148 @@ static bool asus_xgm_is_supported_model(const struct asus_xgm_info *info)
>  	return false;
>  }
>  
> +/**
> + * asus_xgm_tlv_str() - Extract a "tag, length, data" field
> + * @dst: destination buffer
> + * @dst_len: size of @dst, including the trailing NUL
> + * @buf: answer of a version query
> + * @len: size of @buf
> + * @tag: three characters tag to look for
> + *
> + * The version query answers with an 8-byte binary blob followed by
> + * "tag, length, data" fields, where GEN holds the station generation and
> + * VER the firmware version.
> + *
> + * Return: 0 on success, -ENOENT if @tag is missing or its data does not
> + * fit @dst
> + */
> +static int asus_xgm_tlv_str(char *dst, size_t dst_len, const u8 *buf,
> +			    size_t len, const char *tag)
> +{
> +	size_t i;
> +	u8 n;
> +
> +	for (i = 3; i + 4 <= len; i++) {
> +		if (memcmp(buf + i, tag, 3))
> +			continue;
> +
> +		n = buf[i + 3];
> +		if (i + 4 + n > len || n >= dst_len)
> +			return -ENOENT;
> +
> +		memcpy(dst, buf + i + 4, n);
> +		dst[n] = '\0';
> +
> +		return 0;
> +	}
> +
> +	return -ENOENT;
> +}
> +
> +/**
> + * asus_xgm_get_version() - Query the firmware version of a station
> + * @hdev: HID device
> + * @info: identity structure whose generation and firmware_version fields
> + * get filled in
> + *
> + * Return: 0 on success, negative errno on failure
> + */
> +static int asus_xgm_get_version(struct hid_device *hdev,
> +				struct asus_xgm_info *info)
> +{
> +	size_t len = asus_report_len(hdev, FEATURE_KBD_LED_REPORT_ID2);
> +	int ret;
> +
> +	if (!len)
> +		return -EINVAL;
> +
> +	u8 *buf __free(kfree) = kzalloc(len, GFP_KERNEL);
> +	if (!buf)
> +		return -ENOMEM;
> +
> +	ret = asus_xgm_query(hdev, ASUS_XGM_QUERY_VERSION, buf, len);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (len < 4 || buf[1] != ASUS_XGM_CMD_QUERY ||
> +	    buf[2] != ASUS_XGM_QUERY_VERSION)
> +		return -ENODEV;
> +
> +	asus_xgm_tlv_str(info->generation, sizeof(info->generation),
> +			 buf, len, "GEN");
> +	asus_xgm_tlv_str(info->firmware_version, sizeof(info->firmware_version),
> +			 buf, len, "VER");
> +
> +	return 0;
> +}

[Severity: Medium]
In drivers/hid/hid-asus.c, asus_xgm_tlv_str() is documented to follow an
8-byte binary blob after the 3-byte report/command header (buf[0..2]) and
return -ENOENT when a tag is missing or its length is out of bounds.

However, in the asus_probe() -> asus_xgm_init() -> asus_xgm_get_version() ->
asus_xgm_tlv_str() path, two things stand out:

1. asus_xgm_tlv_str() starts scanning at i = 3 (inside the 8-byte binary blob
at buf[3..10]) and increments byte-by-byte (i++) rather than starting at
offset 11 and advancing across record boundaries by 4 + n. If the binary blob
or an earlier field's payload happens to contain the bytes "GEN" or "VER",
could asus_xgm_tlv_str() treat the following byte as the length and either
abort early with -ENOENT or copy unintended bytes into dst?

2. asus_xgm_get_version() ignores the return values of both
asus_xgm_tlv_str() calls and unconditionally returns 0. When a tag is missing
or truncated, asus_xgm_init() will log empty strings for
info->firmware_version and info->generation via hid_info() instead of taking
the ret < 0 warning branch:

	ret = asus_xgm_get_version(hdev, info);
	if (ret < 0)
		hid_warn(hdev, "Failed to query XG Mobile version: %d\n", ret);
	else
		hid_info(hdev, "XG Mobile: firmware %s, generation %s\n",
			 info->firmware_version, info->generation);

Should asus_xgm_tlv_str() start after the 8-byte binary header (or step by
TLV record length), and should asus_xgm_get_version() check and propagate the
return values of asus_xgm_tlv_str()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261025235232.129945-1-denis.benato@linux.dev?part=14

  reply	other threads:[~2026-10-26  0:05 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-25 23:52 [PATCH v11 00/18] HID: asus: add support for ROG Ally handhelds Denis Benato
2026-10-25 23:52 ` [PATCH v11 01/18] " Denis Benato
2026-10-26  0:10   ` sashiko-bot
2026-10-26 12:38   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 02/18] HID: asus: add gamepad configuration Denis Benato
2026-10-26  0:10   ` sashiko-bot
2026-10-26 12:56   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 03/18] HID: asus: add vibration strength configuration Denis Benato
2026-10-25 23:52 ` [PATCH v11 04/18] HID: asus: add joysticks inner and outer range configuration Denis Benato
2026-10-26 13:00   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 05/18] HID: asus: add triggers " Denis Benato
2026-10-25 23:52 ` [PATCH v11 06/18] HID: asus: add joysticks anti-deadzone configuration Denis Benato
2026-10-25 23:52 ` [PATCH v11 07/18] HID: asus: add support for response curve Denis Benato
2026-10-26 13:06   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 08/18] HID: asus: add support to force feedback Denis Benato
2026-10-26  0:19   ` sashiko-bot
2026-10-26 12:36   ` Sakari Ailus
2026-10-26 18:21     ` Ilpo Järvinen
2026-10-26 18:27       ` Sakari Ailus
2026-10-26 13:13   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 09/18] HID: asus: add support for gamepad mode Denis Benato
2026-10-26 13:20   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 10/18] HID: asus: add support for turbo buttons Denis Benato
2026-10-26 13:29   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 11/18] HID: asus: add support for btn remapping Denis Benato
2026-10-26  0:06   ` sashiko-bot
2026-10-26 14:03   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 12/18] HID: asus: size feature reports from the HID report descriptor Denis Benato
2026-10-26  0:06   ` sashiko-bot
2026-10-26 13:06   ` Rebecca Mara Müller
2026-10-26 19:38     ` Denis Benato
2026-10-25 23:52 ` [PATCH v11 13/18] HID: asus: identify XG Mobile stations and bind the LED to the reported model Denis Benato
2026-10-25 23:52 ` [PATCH v11 14/18] HID: asus: expose XG Mobile identity and firmware information Denis Benato
2026-10-26  0:05   ` sashiko-bot [this message]
2026-10-26 14:10   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 15/18] HID: asus: size ally gamepad commands from the HID report descriptor Denis Benato
2026-10-26  0:10   ` sashiko-bot
2026-10-25 23:52 ` [PATCH v11 16/18] platform/x86: asus-armoury: pick the eGPU activation from the reported GPU Denis Benato
2026-10-25 23:52 ` [PATCH v11 17/18] HID: asus: report the XG Mobile GPU vendor to asus-wmi Denis Benato
2026-10-26  0:03   ` sashiko-bot
2026-10-26 14:15   ` Ilpo Järvinen
2026-10-25 23:52 ` [PATCH v11 18/18] MAINTAINERS: add maintainer for the ASUS HID driver Denis Benato
2026-10-26 14:24 ` [PATCH v11 00/18] HID: asus: add support for ROG Ally handhelds Ilpo Järvinen
2026-10-26 18:03   ` Denis Benato

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=sashiko-outbox-184548@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=denis.benato@linux.dev \
    --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