Re: [PATCH v4 2/3] HID: wacom: Fix Use-After-Free in wacom_bamboo_pad
From: sashiko-bot@kernel.org
Date: 2026-06-16 09:43:12
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: Pre-existing issues: - [High] Lockless access to `shared->pen` and `shared->touch` in `wacom_mode_change_work()` can lead to Use-After-Free. -- commit e951961530e94aa8b795598b1d198c32fdbac428 Author: Lee Jones [off-list ref] HID: wacom: Fix Use-After-Free in wacom_bamboo_pad Resolves a use-after-free when events are processed while a sibling device is removed by introducing RCU protection for the shared pen and touch pointers.
quoted hunk ↗ jump to hunk
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 86895f13dbaea..3990d8d0b40c0 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c
[ ... ]
quoted hunk ↗ jump to hunk
@@ -2795,16 +2806,19 @@ static void wacom_mode_change_work(struct work_struct *work) bool is_direct = wacom->wacom_wac.is_direct_mode; int error = 0; - if (shared->pen) { - wacom1 = hid_get_drvdata(shared->pen); + struct hid_device *pen = rcu_access_pointer(shared->pen); + struct hid_device *touch = rcu_access_pointer(shared->touch); + + if (pen) { + wacom1 = hid_get_drvdata(pen); wacom_release_resources(wacom1); hid_hw_stop(wacom1->hdev); wacom1->wacom_wac.has_mode_change = true; wacom1->wacom_wac.is_direct_mode = is_direct; }
[Severity: High] This is a pre-existing issue, but can this lockless access to the sibling device pointers lead to a use-after-free if the sibling is concurrently disconnected? In wacom_mode_change_work(), rcu_access_pointer() reads the pointer outside of an RCU read-side critical section. Since the pointer is then dereferenced to fetch wacom1 via hid_get_drvdata(), what happens if wacom_remove_shared_data() runs concurrently on the sibling? The removal path would clear the shared pointer and call synchronize_rcu(). Because wacom_mode_change_work() is not holding the RCU read lock, synchronize_rcu() will not wait for the work item to complete. This could allow wacom1's driver data to be freed while wacom_mode_change_work() is still using it to call wacom_release_resources(wacom1) and hid_hw_stop(). Since wacom_release_resources() and hid_hw_stop() can sleep, simply wrapping this block in rcu_read_lock() wouldn't be sufficient. Is there a plan to use reference counting or SRCU here to safely access the sibling device?
- if (shared->touch) {
- wacom2 = hid_get_drvdata(shared->touch);
+ if (touch) {
+ wacom2 = hid_get_drvdata(touch);
wacom_release_resources(wacom2);
hid_hw_stop(wacom2->hdev);
wacom2->wacom_wac.has_mode_change = true;-- Sashiko AI review · https://sashiko.dev/#/patchset/20260616092658.1714548-1-lee@kernel.org?part=2