Re: [PATCH 3/4] HID: wacom: Fix Use-After-Free in wacom_bamboo_pad

[email protected] Tue, 04 Aug 2026 10:40:56 +0000
Newsgroups org.kernel.vger.linux-input
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(=
s) to consider:

Pre-existing issues:
- [High] Lockless and unprotected dereference of RCU pointers `shared->pen`=
 and `shared->touch` in `wacom_mode_change_work()` leading to Use-After-Fre=
e.
--

--- Patch [3]: [PATCH 3/4] HID: wacom: Fix Use-After-Free in wacom_bamboo_p=
ad ---
commit 767b68ab7301c7003f61a85491f11aed0373e519
Author: Lee Jones <[email protected]>

HID: wacom: Fix Use-After-Free in wacom_bamboo_pad

This commit resolves a lockless access to wacom->shared->pen by introducing
RCU protection for pen and touch pointers. It also updates writers to use
rcu_assign_pointer() and updates mode change workers to use
rcu_access_pointer().

> diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
> index cf9c12f3cff53..05d27fcd311f8 100644
> --- a/drivers/hid/wacom_sys.c
> +++ b/drivers/hid/wacom_sys.c

[ ... ]

> @@ -2810,16 +2821,19 @@ static void wacom_mode_change_work(struct work_st=
ruct *work)
>  	bool is_direct =3D wacom->wacom_wac.is_direct_mode;
>  	int error =3D 0;
> =20
> -	if (shared->pen) {
> -		wacom1 =3D hid_get_drvdata(shared->pen);
> +	struct hid_device *pen =3D rcu_access_pointer(shared->pen);
> +	struct hid_device *touch =3D rcu_access_pointer(shared->touch);
> +
> +	if (pen) {
> +		wacom1 =3D hid_get_drvdata(pen);
>  		wacom_release_resources(wacom1);
>  		hid_hw_stop(wacom1->hdev);

[Severity: High]
This is a pre-existing issue, but could this lockless access to the RCU
pointers still lead to a use-after-free if the sibling device is removed
concurrently?

Because pen and touch are fetched using rcu_access_pointer() and
dereferenced without rcu_read_lock(), synchronize_rcu() in
wacom_remove_shared_data() won't block this worker thread.

If the sibling device is removed and freed right after rcu_access_pointer()
returns a non-NULL pointer, won't hid_get_drvdata(pen), hid_hw_stop(), and
wacom_release_resources() operate on freed memory?

>  		wacom1->wacom_wac.has_mode_change =3D true;
>  		wacom1->wacom_wac.is_direct_mode =3D is_direct;
>  	}
> =20
> -	if (shared->touch) {
> -		wacom2 =3D hid_get_drvdata(shared->touch);
> +	if (touch) {
> +		wacom2 =3D hid_get_drvdata(touch);
>  		wacom_release_resources(wacom2);
>  		hid_hw_stop(wacom2->hdev);

[ ... ]

--=20
Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20260804103030.1491=
[email protected]?part=3D3