Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v1 8/9] HID: wacom: Benefit from pointer typed driver_data in hid_device_id
Date: Wed, 25 Nov 2026 07:34:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-232815@kernel.org> (raw)
In-Reply-To: <23d19d751aea2d855bf1360fd4e84cc30d0fc8ca.1795589119.git.u.kleine-koenig@baylibre.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] HID: wacom: missed driver_data_ptr conversion in
  wacom_wireless_work()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] HID: wacom: use-after-free in wacom_probe() [1]
--

commit 67663f15c12fe1c2768a835c0c04be50ea91f5c9
Author: Uwe Kleine-König <u.kleine-koenig@baylibre.com>

HID: wacom: Benefit from pointer typed driver_data in hid_device_id

This commit converts wacom_ids[] and its consumers from .driver_data to
.driver_data_ptr to avoid integer-to-pointer casts.

> diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
> index 2e3ce9b63d7af..d826a6b4d41e9 100644
> --- a/drivers/hid/wacom_sys.c
> +++ b/drivers/hid/wacom_sys.c
> @@ -2657,7 +2657,7 @@ static void wacom_wireless_work(struct work_struct *work)
>  
>  		/* Stylus interface */
>  		wacom_wac1->features =
> -			*((struct wacom_features *)id->driver_data);
> +			*(const struct wacom_features *)id->driver_data_ptr;
>  
>  		wacom_wac1->pid = wacom_wac->pid;
>  		hid_hw_stop(hdev1);
> @@ -2670,7 +2670,7 @@ static void wacom_wireless_work(struct work_struct *work)
>  		    (wacom_wac1->features.type >= INTUOSHT &&
>  		    wacom_wac1->features.type <= BAMBOO_PT)) {
>  			wacom_wac2->features =
> -				*((struct wacom_features *)id->driver_data);
> +				*(const struct wacom_features *)id->driver_data;

[Severity: Low]
Should this touch interface assignment also use id->driver_data_ptr instead
of id->driver_data, matching the stylus interface assignment above?

>  			wacom_wac2->pid = wacom_wac->pid;
>  			hid_hw_stop(hdev2);
>  			error = wacom_parse_and_register(wacom2, true);
> @@ -2927,7 +2927,7 @@ static int wacom_probe(struct hid_device *hdev,
>  	struct wacom_features *features;
>  	int error;
>  
> -	if (!id->driver_data)
> +	if (!id->driver_data_ptr)
>  		return -EINVAL;
>  
>  	hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
> @@ -2943,7 +2943,7 @@ 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);
> +	wacom_wac->features = *(const struct wacom_features *)id->driver_data_ptr;
>  	features = &wacom_wac->features;
>  
>  	if (features->check_for_hid_type && features->hid_type != hdev->type)

[Severity: Critical]
This problem wasn't introduced by this patch, but can wacom_probe() cause a
use-after-free on wacom [1] if wacom_parse_and_register() fails after
hid_hw_start()?

wacom_probe() allocates wacom with devm_kzalloc_obj() and initializes
wacom->idleprox_timer and several work items without devres cleanup actions:

drivers/hid/wacom_sys.c:wacom_probe() {
    ...
	INIT_DELAYED_WORK(&wacom->init_work, wacom_init_work);
	INIT_DELAYED_WORK(&wacom->aes_battery_work, wacom_aes_battery_handler);
	INIT_WORK(&wacom->wireless_work, wacom_wireless_work);
	INIT_WORK(&wacom->battery_work, wacom_battery_work);
	INIT_WORK(&wacom->remote_work, wacom_remote_work);
	INIT_WORK(&wacom->mode_change_work, wacom_mode_change_work);
	timer_setup(&wacom->idleprox_timer, &wacom_idleprox_timeout, TIMER_DEFERRABLE);
    ...
	error = wacom_parse_and_register(wacom, false);
	if (error)
		return error;
    ...
}

Once wacom_parse_and_register() calls hid_hw_start(), incoming events can
run wacom_wac_pen_event() and arm wacom->idleprox_timer or schedule work.
If a later step in wacom_parse_and_register() fails, only wacom->init_work
is canceled before wacom_probe() returns and devres frees wacom, leaving
any armed timer or other queued work to dereference freed memory.

[1] https://sashiko.dev/#/bug/linux-9d77fc11-57b4-4580-8967-6e5d9db474d3

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795589119.git.u.kleine-koenig@baylibre.com?part=8

  reply	other threads:[~2026-11-25  7:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  7:21 [PATCH v1 0/9] HID: Make driver_data in hid_device_id a union Uwe Kleine-König
2026-11-25  7:21 ` [PATCH v1 1/9] HID: asus: Use designated initializer for hid_device_id Uwe Kleine-König
2026-11-25  7:21 ` [PATCH v1 2/9] HID: i2c-hid: " Uwe Kleine-König
2026-11-25  7:21 ` [PATCH v1 3/9] HID: input: " Uwe Kleine-König
2026-11-25  7:21 ` [PATCH v1 4/9] HID: quirks: " Uwe Kleine-König
2026-11-25  7:21 ` [PATCH v1 5/9] HID: core: Make driver_data in hid_device_id a union Uwe Kleine-König
2026-11-25  7:21 ` [PATCH v1 6/9] HID: steelseries: Benefit from pointer typed driver_data in hid_device_id Uwe Kleine-König
2026-11-25  7:21 ` [PATCH v1 7/9] HID: tmff: " Uwe Kleine-König
2026-11-25  7:21 ` [PATCH v1 8/9] HID: wacom: " Uwe Kleine-König
2026-11-25  7:34   ` sashiko-bot [this message]
2026-11-25  7:21 ` [PATCH v1 9/9] hwmon: (asus_rog_ryujin) " Uwe Kleine-König

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-232815@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=u.kleine-koenig@baylibre.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