From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793831417; b=P16pVO7eLgMhbuJtV+Ay/hA/7TBv9pDm+wg6MS0fwJbfV3iAuTe0kFIieDo2QOrOcJwa xEO0hkT2rlqwbSIiq31x4ef4GhMP6HuiPOvCjcrf95E7FvHkFOHzVFCHIGa1XeSeDleMs bqbwiaSRrh9SVCiJyVAxszaf8eWEqP73V2nXCUXL2ML6f7trYkppWGwKdFVjWwVjSacEC iLJEoRpwN75BNVbUuF/FUMOfaL9rDMTeBugF2g8AkxqE7AC9A26EOSK3spJOWtcS5udEc nUuh854o9tXnqgMFJ8FCKMXSCuBWChOqtUq5CyC6sTQiprbNfl9D0VGDGSjtNU9JImA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793831417; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=xbj0X+viKSla7UPBWb4ecermIGnlaFrBzgROIHprSpU=; b=z79ZdOxXlfcL34sN9QoVlMzZY8jBmQYMzKeg415la4G/AuxnEVjm3uDdlevvBFAfiYcg 7z6GsRt0m6dkTVoIrunKUJ7uU34sOEPYx0n5BW0zI7Mc5CJnjG56o+K5ErXRw12RQjTSP DS5Rw0LwlnOt7zMN/BvHZhC8lprEhb7+z0wd8YtF4K/J+R32JPfspNlkr2SkoPIZP9MQd IIhZMr3G9lC1diCyq6JmpTsZ+vciXlvquYCnoTgCZo3w+2kXUp6jfHh146wAIzW2T+In5 yRwL0i32NDB21OX+Cs2Nh4fBLC3Z7k8mye2mt4Idwx0N912tU68w4WrWkG51sbphE9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=WMv82cNY; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AA74606AB2C; Wed, 4 Nov 2026 22:30:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=WMv82cNY Received: by smtp.kernel.org (Postfix) with ESMTPSA id C02611F0093A; Wed, 4 Nov 2026 22:30:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793831417; bh=xbj0X+viKSla7UPBWb4ecermIGnlaFrBzgROIHprSpU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WMv82cNY0MVq7EqnGDthb/h6CdUfGh9C1gL9CMyH1xgXOJERazgr5pby52QkYIxMt 6yavOmUxhwarSHVPBSbTy59jWbC/Hr8jUTRXf79WBfNOzjZsMZwBVXQyR8q5C+3q9X eK9VueESHjLOxXgQ1713YAq/PbRyo3bbv1ZEFnyo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Lee Jones , Ping Cheng , Jiri Kosina Subject: [PATCH 6.18 0692/1005] HID: wacom: Fix Use-After-Free in wacom_intuos_pad Date: Wed, 4 Nov 2026 16:07:05 -0500 Message-ID: <20261104211102.995199088@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261104211043.516122098@linuxfoundation.org> References: <20261104211043.516122098@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lee Jones commit ef32877368a7013c060ef6bd03a30b6da2fe0c41 upstream. wacom_intuos_pad() accesses wacom->shared->touch_input locklessly inside the interrupt handler context. If the Touch sibling device is disconnected, wacom_remove_shared_data() clears 'touch_input' outside any lock, creating a Time-of-Check to Time-of-Use (TOCTOU) race condition where a preempted reader in interrupt context dereferences the freed pointer, leading to a Use-After-Free. Resolve this by introducing RCU protection for the touch_input pointer: - Annotate 'touch_input' in wacom_shared struct with __rcu - Wrap all lockless readers in wacom_wac.c with guard(rcu)() and rcu_dereference() using a unified wacom_report_touch_mute() helper - Update writers in wacom_sys.c using rcu_assign_pointer() - Call synchronize_rcu() in wacom_remove_shared_data() to ensure all active RCU readers have finished before the input device is freed Also wrap wacom_set_shared_values() and touch/pen assignments in wacom_add_shared_data() inside the wacom_udev_list_lock to serialize concurrent probe assignments, and verify that 'shared->touch == hdev' before setting touch_input to prevent concurrent sibling probe state desynchronization. Cc: stable@vger.kernel.org Fixes: 961794a00eab ("Input: wacom - add reporting of SW_MUTE_DEVICE events") Signed-off-by: Lee Jones Acked-by: Ping Cheng Tested-by: Ping Cheng Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/wacom_sys.c | 23 ++++++++++++++++------- drivers/hid/wacom_wac.c | 36 ++++++++++++++++++------------------ drivers/hid/wacom_wac.h | 2 +- 3 files changed, 35 insertions(+), 26 deletions(-) --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -880,10 +880,16 @@ static void wacom_remove_shared_data(voi 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; + } + } + + synchronize_rcu(); kref_put(&data->kref, wacom_release_shared_data); wacom_wac->shared = NULL; @@ -920,6 +926,7 @@ static int wacom_add_shared_data(struct mutex_unlock(&wacom_udev_list_lock); retval = devm_add_action_or_reset(&hdev->dev, wacom_remove_shared_data, wacom); + return retval; } @@ -2359,9 +2366,11 @@ static void wacom_set_shared_values(stru } if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH) { - wacom_wac->shared->type = wacom_wac->features.type; - wacom_wac->shared->touch_input = wacom_wac->touch_input; - wacom_wac->shared->touch = wacom->hdev; + if (wacom_wac->shared->touch == wacom->hdev || !wacom_wac->shared->touch) { + wacom_wac->shared->type = wacom_wac->features.type; + wacom_wac->shared->touch = wacom->hdev; + rcu_assign_pointer(wacom_wac->shared->touch_input, wacom_wac->touch_input); + } } else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN) { /* Pairs with smp_load_acquire() in wacom_sibling_pending() */ smp_store_release(&wacom_wac->shared->pen, wacom->hdev); --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -510,6 +510,18 @@ static void wacom_intuos_schedule_prox_e } } +static void wacom_report_touch_mute(struct wacom_wac *wacom_wac, bool mute) +{ + struct input_dev *touch_input; + + guard(rcu)(); + touch_input = rcu_dereference(wacom_wac->shared->touch_input); + if (touch_input) { + input_report_switch(touch_input, SW_MUTE_DEVICE, mute); + input_sync(touch_input); + } +} + static int wacom_intuos_pad(struct wacom_wac *wacom) { struct wacom_features *features = &wacom->features; @@ -650,12 +662,8 @@ static int wacom_intuos_pad(struct wacom input_report_key(input, KEY_CONTROLPANEL, menu); input_report_key(input, KEY_INFO, info); - if (wacom->shared && wacom->shared->touch_input) { - input_report_switch(wacom->shared->touch_input, - SW_MUTE_DEVICE, - !wacom->shared->is_touch_on); - input_sync(wacom->shared->touch_input); - } + if (wacom->shared) + wacom_report_touch_mute(wacom, !wacom->shared->is_touch_on); input_report_abs(input, ABS_RX, strip1); input_report_abs(input, ABS_RY, strip2); @@ -2168,7 +2176,7 @@ static void wacom_wac_pad_event(struct h */ if ((equivalent_usage == WACOM_HID_WD_MUTE_DEVICE) || (equivalent_usage == WACOM_HID_WD_TOUCHONOFF)) { - if (wacom_wac->shared->touch_input) { + if (wacom_wac->shared) { bool *is_touch_on = &wacom_wac->shared->is_touch_on; if (equivalent_usage == WACOM_HID_WD_MUTE_DEVICE && value) @@ -2176,9 +2184,7 @@ static void wacom_wac_pad_event(struct h else if (equivalent_usage == WACOM_HID_WD_TOUCHONOFF) *is_touch_on = value; - input_report_switch(wacom_wac->shared->touch_input, - SW_MUTE_DEVICE, !(*is_touch_on)); - input_sync(wacom_wac->shared->touch_input); + wacom_report_touch_mute(wacom_wac, !(*is_touch_on)); } return; } @@ -3396,11 +3402,8 @@ static int wacom_wireless_irq(struct wac if ((wacom->shared->type == INTUOSHT || wacom->shared->type == INTUOSHT2) && - wacom->shared->touch_input && wacom->shared->touch_max) { - input_report_switch(wacom->shared->touch_input, - SW_MUTE_DEVICE, data[5] & 0x40); - input_sync(wacom->shared->touch_input); + wacom_report_touch_mute(wacom, data[5] & 0x40); } pid = get_unaligned_be16(&data[6]); @@ -3435,11 +3438,8 @@ static int wacom_status_irq(struct wacom if ((features->type == INTUOSHT || features->type == INTUOSHT2) && - wacom_wac->shared->touch_input && features->touch_max) { - input_report_switch(wacom_wac->shared->touch_input, - SW_MUTE_DEVICE, data[8] & 0x40); - input_sync(wacom_wac->shared->touch_input); + wacom_report_touch_mute(wacom_wac, data[8] & 0x40); } if (data[9] & 0x02) { /* wireless module is attached */ --- a/drivers/hid/wacom_wac.h +++ b/drivers/hid/wacom_wac.h @@ -285,7 +285,7 @@ struct wacom_shared { /* for wireless device to access USB interfaces */ unsigned touch_max; int type; - struct input_dev *touch_input; + struct input_dev __rcu *touch_input; struct hid_device *pen; struct hid_device *touch; bool has_mute_touch_switch;