Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lee Jones" <lee@kernel.org>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH 2/4] HID: wacom: Fix Use-After-Free in wacom_intuos_pad
Date: Tue, 04 Aug 2026 10:54:11 +0000	[thread overview]
Message-ID: <20260804105412.772DA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260804103030.1491356-2-lee@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Lockless accesses to `shared->pen` and `shared->touch` cause a TOCTOU Use-After-Free race condition during concurrent sibling device removal.
- [High] Improper `kref_put()` usage during shared data removal causes a Use-After-Free of `wacom_hdev_data` due to a race with list traversal.
--

--- Patch [2]: [PATCH 2/4] HID: wacom: Fix Use-After-Free in wacom_intuos_pad ---
commit b17a0dd077bc2659cd08a43647ccf55bb0fc7cb0
Author: Lee Jones <lee@kernel.org>
Subject: HID: wacom: Fix Use-After-Free in wacom_intuos_pad

This commit resolves a time-of-check to time-of-use race condition by
introducing rcu protection for the touch_input pointer. It also wraps
concurrent probe assignments in wacom_udev_list_lock.

> diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
> index 92b73ed0028f1..cf9c12f3cff53 100644
> --- a/drivers/hid/wacom_sys.c
> +++ b/drivers/hid/wacom_sys.c
> @@ -875,10 +875,16 @@ static void wacom_remove_shared_data(void *res)
>  		data = container_of(wacom_wac->shared, struct wacom_hdev_data,
>  				    shared);
>  
> -		if (wacom_wac->shared->touch == wacom->hdev)
> -			wacom_wac->shared->touch = NULL;
> -		else if (wacom_wac->shared->pen == wacom->hdev)
> -			wacom_wac->shared->pen = NULL;
> +		scoped_guard(mutex, &wacom_udev_list_lock) {
> +			if (wacom_wac->shared->touch == wacom->hdev) {
> +				wacom_wac->shared->touch = NULL;
> +				rcu_assign_pointer(wacom_wac->shared->touch_input, NULL);
> +			} else if (wacom_wac->shared->pen == wacom->hdev) {
> +				wacom_wac->shared->pen = NULL;

[Severity: High]
This is a pre-existing issue, but was not introduced by this patch. Should
shared->pen (and shared->touch) also be annotated and cleared with
rcu_assign_pointer()?

There appear to be lockless readers of shared->pen and shared->touch in
the input event handlers, such as wacom_bamboo_pad_pen_event() calling
hid_input_report() or wacom_mode_change_work() dereferencing it via
hid_get_drvdata(). If a sibling device is unbound concurrently, those
readers might access a freed hid_device.

Since they don't hold rcu read locks, the synchronize_rcu() added below
won't wait for them unless they are also updated.

> +			}
> +		}
> +
> +		synchronize_rcu();
>  
>  		kref_put(&data->kref, wacom_release_shared_data);

[Severity: High]
This is a pre-existing issue, but can this kref_put() cause a use-after-free
due to a race with list traversal?

If this drops the reference count to 0, wacom_release_shared_data() is
called. Concurrently, wacom_add_shared_data() might acquire the
wacom_udev_list_lock and iterate the list.

If it finds this data object before it is removed from the list, it will
call kref_get() on a 0-refcount object via wacom_get_hdev_data() and return
it.

Once the lock is released, the release function could proceed to kfree()
the data object, and the probe thread would access the freed struct.
Should this use kref_put_mutex() with wacom_udev_list_lock to safely
synchronize with the list iteration?

>  		wacom_wac->shared = NULL;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260804103030.1491356-1-lee@kernel.org?part=2

  reply	other threads:[~2026-08-04 10:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04 10:30 [PATCH 1/4] HID: wacom: Advertise SW_MUTE_DEVICE capability prior to registration Lee Jones
2026-08-04 10:30 ` [PATCH 2/4] HID: wacom: Fix Use-After-Free in wacom_intuos_pad Lee Jones
2026-08-04 10:54   ` sashiko-bot [this message]
2026-08-04 10:30 ` [PATCH 3/4] HID: wacom: Fix Use-After-Free in wacom_bamboo_pad Lee Jones
2026-08-04 10:40   ` sashiko-bot
2026-08-04 10:30 ` [PATCH 4/4] HID: wacom: Redesign shared sibling data lifecycle Lee Jones
2026-08-04 10:33 ` [PATCH 1/4] HID: wacom: Advertise SW_MUTE_DEVICE capability prior to registration Lee Jones
  -- strict thread matches above, loose matches on Subject: below --
2026-07-07 12:10 Lee Jones
2026-07-07 12:10 ` [PATCH 2/4] HID: wacom: Fix Use-After-Free in wacom_intuos_pad Lee Jones
2026-07-07 12:26   ` 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=20260804105412.772DA1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=lee@kernel.org \
    --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