All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pawel Zalewski (The Capable Hub)" <pzalewski@thegoodpenguin.co.uk>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v3 6/8] HID: wacom: cleanup usage of 'driver_data'
Date: Mon, 27 Jul 2026 15:11:44 +0000	[thread overview]
Message-ID: <20260727151145.5EAC11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260727-mod-devicetable-hid_device_id-v3-6-980896ca283e@thegoodpenguin.co.uk>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing lower-bound check on the enum index allows an attacker to bypass bounds checking and trigger an out-of-bounds read by injecting a large value via the `new_id` sysfs interface.
--

--- Patch [6]: [PATCH v3 6/8] HID: wacom: cleanup usage of 'driver_data' ---
commit b219fca8b4be38408fca90649c9b3228cd0bfa8c
Author: Pawel Zalewski (The Capable Hub) <pzalewski@thegoodpenguin.co.uk>

HID: wacom: cleanup usage of 'driver_data'

This commit changes the driver_data field in the HID device ID table
from a direct pointer to an integer index. This index is then used to
look up the appropriate wacom_features struct from a static array.
This change aims to make it safer to inject new device IDs from userspace.

> diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
> index 0eafa483b7f75..834519751a5cf 100644
> --- a/drivers/hid/wacom_sys.c
> +++ b/drivers/hid/wacom_sys.c
[ ... ]
> @@ -2843,7 +2847,15 @@ static int wacom_probe(struct hid_device *hdev,
>  	wacom->hdev = hdev;
>  
>  	wacom_wac = &wacom->wacom_wac;
> -	wacom_wac->features = *((struct wacom_features *)id->driver_data);
> +
> +	const struct wacom_features *id_features = get_wacom_features(id->driver_data);
> +
> +	if (!id_features) {
> +		hid_err(wacom->hdev, "could not get wacom id_features.\n");
> +		return -EINVAL;
> +	}
> +	wacom_wac->features = *id_features;

[Severity: High]
If a large value is injected here via the new_id sysfs interface, it gets
passed as id->driver_data to get_wacom_features(). Could the returned
id_features pointer be out of bounds, causing a memory access violation
when dereferenced during this assignment in wacom_probe()?

> diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
> index da1f0ea85625d..d0a864d525098 100644
> --- a/drivers/hid/wacom_wac.c
> +++ b/drivers/hid/wacom_wac.c
[ ... ]
> +const struct wacom_features *get_wacom_features(enum wacom_features_table_index index)
> +{
> +	if (index >= NUM_OF_WACOM_FEATURES_IN_TABLE)
> +		return NULL;
> +
> +	return wacom_features_table[index];
> +}

[Severity: High]
Since the enum constants fit within a signed 32-bit integer, the compiler
typically implements the enum wacom_features_table_index as a signed int.

If id->driver_data is a large enough value, it could be implicitly downcast
to a negative signed integer when passed to get_wacom_features(). A negative
value would bypass the upper-bound check here since a negative number is
less than NUM_OF_WACOM_FEATURES_IN_TABLE.

Does this missing lower-bound check allow get_wacom_features() to return
an invalid pointer from before the wacom_features_table array? Would it be
safer to check if index is less than zero, or change the parameter to an
unsigned type?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260727-mod-devicetable-hid_device_id-v3-0-980896ca283e@thegoodpenguin.co.uk?part=6

  reply	other threads:[~2026-07-27 15:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27 14:55 [PATCH v3 0/8] HID: storing pointers in 'hid_device_id::driver_data' Pawel Zalewski (The Capable Hub)
2026-07-27 14:55 ` [PATCH v3 1/8] HID: hid-input: use named initializer for 'hid_battery_quirks[]' Pawel Zalewski (The Capable Hub)
2026-07-27 14:55 ` [PATCH v3 2/8] HID: hid-quirks: use named initializer in 'hid_quirks[]' Pawel Zalewski (The Capable Hub)
2026-07-27 14:55 ` [PATCH v3 3/8] HID: hid-asus: use named initializer for 'asus_devices[]' Pawel Zalewski (The Capable Hub)
2026-07-27 14:55 ` [PATCH v3 4/8] HID: i2c-hid-dmi-quirks: use named initializer for 'i2c_hid_elan_flipped_quirks[]' Pawel Zalewski (The Capable Hub)
2026-07-27 14:55 ` [PATCH v3 5/8] HID: hid-tmff: clean up usage of 'driver_data' Pawel Zalewski (The Capable Hub)
2026-07-27 15:08   ` sashiko-bot
2026-07-27 14:55 ` [PATCH v3 6/8] HID: wacom: cleanup " Pawel Zalewski (The Capable Hub)
2026-07-27 15:11   ` sashiko-bot [this message]
2026-07-27 14:55 ` [PATCH v3 7/8] HID: hid-core: sanitize user input in 'new_id_store' Pawel Zalewski (The Capable Hub)
2026-07-27 15:08   ` sashiko-bot
2026-07-27 14:55 ` [PATCH v3 8/8] HID: wacom: do not use 'driver_data' Pawel Zalewski (The Capable Hub)
2026-07-27 15:18   ` sashiko-bot

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=20260727151145.5EAC11F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=pzalewski@thegoodpenguin.co.uk \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.