Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v2 11/12] HID: hid-core: sanitize user input in 'new_id_store'
Date: Wed, 10 Jun 2026 15:32:07 +0000	[thread overview]
Message-ID: <20260610153207.E34F91F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260610-mod-devicetable-hid_device_id-v2-11-a1d7473ccd9c@thegoodpenguin.co.uk>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Restricting `driver_data` to strictly match an existing `id_table` entry breaks backward compatibility and defeats the purpose of the `new_id` interface.
--

commit 613c086c5db811baec4d7b28a4e3757a62048b24
Author: Pawel Zalewski (The Capable Hub) <pzalewski@thegoodpenguin.co.uk>
Subject: HID: hid-core: sanitize user input in 'new_id_store'

This commit modifies the new_id sysfs interface for HID drivers. It adds a
check to ensure that any provided driver_data value strictly matches an
existing entry within the driver's id_table, preventing arbitrary values
from being passed.

> diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> index 41a79e43c82b3..e060e5ec4ea62 100644
> --- a/drivers/hid/hid-core.c
> +++ b/drivers/hid/hid-core.c
> @@ -2647,6 +2647,8 @@ static ssize_t new_id_store(struct device_driver *drv, const char *buf,
>  		size_t count)
>  {
>  	struct hid_driver *hdrv = to_hid_driver(drv);
> +	const struct hid_device_id *ids = hdrv->id_table;
> +
>  	struct hid_dynid *dynid;
>  	__u32 bus, vendor, product;
>  	unsigned long driver_data = 0;
> @@ -2657,6 +2659,22 @@ static ssize_t new_id_store(struct device_driver *drv, const char *buf,
>  	if (ret < 3)
>  		return -EINVAL;
>  
> +	/* Only accept driver_data values that match an
> +	 * existing id_table entry
> +	 */
> +	if (ids) {
> +		ret = -EINVAL;
> +		while (ids->bus) {
> +			if (driver_data == ids->driver_data) {
> +				ret = 0;
> +				break;
> +			}
> +			ids++;
> +		}
> +		if (ret)	/* No match */
> +			return ret;
> +	}
> +

[Severity: High]
Does this change break backward compatibility and the intended purpose of the
new_id interface?

Previously, users could write just the bus, vendor, and product to new_id,
leaving driver_data to default to 0. With this patch, if a driver's id_table
only contains entries with non-zero driver_data (such as quirk bitmasks in
hid-apple), wouldn't the sysfs write now fail with -EINVAL?

Additionally, does this prevent developers from testing unsupported hardware
by passing custom quirk bitmasks (or passing 0 to test without quirks) via
the driver_data field?

>  	dynid = kzalloc_obj(*dynid);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260610-mod-devicetable-hid_device_id-v2-0-a1d7473ccd9c@thegoodpenguin.co.uk?part=11

  reply	other threads:[~2026-06-10 15:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-10 15:11 [PATCH v2 00/12] HID: storing pointers in 'hid_device_id::driver_data' Pawel Zalewski (The Capable Hub)
2026-06-10 15:11 ` [PATCH v2 01/12] HID: hid-input: use named initializer for 'hid_battery_quirks[]' Pawel Zalewski (The Capable Hub)
2026-06-10 15:11 ` [PATCH v2 02/12] HID: hid-quirks: use named initializer in 'hid_quirks[]' Pawel Zalewski (The Capable Hub)
2026-06-10 15:11 ` [PATCH v2 03/12] HID: hid-asus: use named initializer for 'asus_devices[]' Pawel Zalewski (The Capable Hub)
2026-06-10 15:11 ` [PATCH v2 04/12] HID: i2c-hid-dmi-quirks: use named initializer for 'i2c_hid_elan_flipped_quirks[]' Pawel Zalewski (The Capable Hub)
2026-06-10 15:11 ` [PATCH v2 05/12] HID: hid-belkin: clean up usage of 'driver_data' Pawel Zalewski (The Capable Hub)
2026-06-10 15:11 ` [PATCH v2 06/12] HID: hid-cypress: " Pawel Zalewski (The Capable Hub)
2026-06-10 15:11 ` [PATCH v2 07/12] HID: hid-gfrm: " Pawel Zalewski (The Capable Hub)
2026-06-10 15:11 ` [PATCH v2 08/12] HID: hid-ite: " Pawel Zalewski (The Capable Hub)
2026-06-10 15:11 ` [PATCH v2 09/12] HID: hid-tmff: " Pawel Zalewski (The Capable Hub)
2026-06-10 15:11 ` [PATCH v2 10/12] HID: wacom: cleanup " Pawel Zalewski (The Capable Hub)
2026-06-10 15:11 ` [PATCH v2 11/12] HID: hid-core: sanitize user input in 'new_id_store' Pawel Zalewski (The Capable Hub)
2026-06-10 15:32   ` sashiko-bot [this message]
2026-06-10 15:11 ` [PATCH v2 12/12] HID: wacom: do not use 'driver_data' Pawel Zalewski (The Capable Hub)

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=20260610153207.E34F91F00893@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 \
    /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