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=1793799845; b=QJ5W9jgkmPvORKCzYf2sGdyma++zRLOoLKWCuA8zzEAnb288hLN1g4zkU2hMEizx3CIb DzWjZ0puZ5rDJdVYd7Peevj/UtOg1gpg8TGpj0LWo0zVOQ0iHxKxRM6dYd4PLhujSVi+7 HacKrM1s81p2DJzsz9XehxTIyKXhRdKsJLQtt8xS9UUaXYq/4NqR0TmS7vhknOPLNff4y nB9zLseEd0NRX73KRyJxQv4+rxk0zYAJJko/YwwEHV8yaaD35bfiey5AcaHG/aOwZ6+SR 8kEISzl+aocFjV8gZCS7Te83T+Abls5q2J1P3s76ZkWHjX+gPhJu7m46dfBUuoxnH5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793799845; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=J+Gr16sN5cob+vYIOo8rv6JSFlTjvd80KxYr8v+xXm4=; b=G+9afuEYC5QcxFAHf5gddGZJL1HL0XTIAAIvMmusnt5RgnAqPUawkysTun4q8hJlarhw O2PSf8v9MNK3+wiMEBQ/Gkbe7PXaRHWvzSGsx6yG79wFgDneInPcZd2K+vOAUduJJJaIT yw2I++eeJX3Y9TEkzOb8qKKpGPKx+2OF+PG+aUgX2fS+fbfE926/Tc5lSHxOvEGV5TRLq 3qI/8raMdpk66MYRX61r+EsLsEGQTMl2lSutV+f6MdMyNSCAcX9dHQJX8lnyyBtviiZGv FRlEvPti5c7y5dKm1WrVuNe+z5/8j0Sok8kKvgPZVXHwdTxjwCtuqZunmip1C6fAxsQ== 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=byz69siG; 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 9DC32606A326 for ; Wed, 4 Nov 2026 13:44:05 +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=byz69siG Received: by smtp.kernel.org (Postfix) with ESMTPSA id F18C21F000C1; Wed, 4 Nov 2026 13:44:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793799845; bh=J+Gr16sN5cob+vYIOo8rv6JSFlTjvd80KxYr8v+xXm4=; h=Subject:To:Cc:From:Date; b=byz69siGWyyaO3e6FdImxSOElT6/0RczHTQIDWjU3uSocGev76OOKQvo1yIfg6p+t LJMQsMJBCfvbtKVa8d4GiwLU02Ouhr+FfbRjH6QplLbIJd0YWWDd4uSAkBJXT6uw+B FR0w2doCwHPq/RadWS2ZRhovNaly+FeWY8bIm7mc= Subject: FAILED: patch "[PATCH] HID: wacom: Fix Use-After-Free in wacom_bamboo_pad" failed to apply to 5.10-stable tree To: lee@kernel.org,jkosina@suse.com,ping.cheng@wacom.com Cc: From: Date: Wed, 04 Nov 2026 14:43:55 +0100 Message-ID: <2026110455-rounding-freedom-459f@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 5.10-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y git checkout FETCH_HEAD git cherry-pick -x 3a523ecf9ac3fdd33f5eb31c43937ee44135395b # git commit -s git send-email --to '' --in-reply-to '2026110455-rounding-freedom-459f@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..' Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 3a523ecf9ac3fdd33f5eb31c43937ee44135395b Mon Sep 17 00:00:00 2001 From: Lee Jones Date: Wed, 9 Sep 2026 11:12:26 +0000 Subject: [PATCH] HID: wacom: Fix Use-After-Free in wacom_bamboo_pad wacom_bamboo_pad_pen_event() accesses wacom->shared->pen locklessly relative to wacom_remove_shared_data() which nullifies it. This can lead to a Use-After-Free if the sibling device is removed while events are being processed. Resolve this by introducing RCU protection for pen and touch pointers: - Annotate 'pen' and 'touch' in wacom_shared struct with __rcu. - Wrap lockless readers in wacom_bamboo_pad_pen_event() with rcu_read_lock() and rcu_dereference(). - Update writers in wacom_sys.c using rcu_assign_pointer(). - Use rcu_dereference_protected for comparisons under wacom_udev_list_lock. - Also use rcu_access_pointer in wacom_sibling_pending() and wacom_mode_change_work() to avoid warnings (while lockless access in the latter remains a pre-existing issue). Cc: stable@vger.kernel.org Fixes: 8c97a765467c ("HID: wacom: add full support of the Wacom Bamboo PAD") Signed-off-by: Lee Jones Acked-by: Ping Cheng Tested-by: Ping Cheng Signed-off-by: Jiri Kosina diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 10f7de515ea2..307eda9bbdd0 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -876,11 +876,18 @@ static void wacom_remove_shared_data(void *res) shared); scoped_guard(mutex, &wacom_udev_list_lock) { - if (wacom_wac->shared->touch == wacom->hdev) { - wacom_wac->shared->touch = NULL; + struct hid_device *touch = + rcu_dereference_protected(wacom_wac->shared->touch, + lockdep_is_held(&wacom_udev_list_lock)); + struct hid_device *pen = + rcu_dereference_protected(wacom_wac->shared->pen, + lockdep_is_held(&wacom_udev_list_lock)); + + if (touch == wacom->hdev) { + rcu_assign_pointer(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; + } else if (pen == wacom->hdev) { + rcu_assign_pointer(wacom_wac->shared->pen, NULL); } } @@ -2361,14 +2368,17 @@ static void wacom_set_shared_values(struct wacom_wac *wacom_wac) } if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH) { - if (wacom_wac->shared->touch == wacom->hdev || !wacom_wac->shared->touch) { + struct hid_device *touch = + rcu_dereference_protected(wacom_wac->shared->touch, + lockdep_is_held(&wacom_udev_list_lock)); + + if (touch == wacom->hdev || !touch) { wacom_wac->shared->type = wacom_wac->features.type; - wacom_wac->shared->touch = wacom->hdev; + rcu_assign_pointer(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); + rcu_assign_pointer(wacom_wac->shared->pen, wacom->hdev); } } @@ -2384,8 +2394,7 @@ static bool wacom_sibling_pending(struct wacom *wacom) return false; if (wacom->wacom_wac.shared) { - /* Pairs with smp_store_release() in wacom_set_shared_values() */ - if (smp_load_acquire(&wacom->wacom_wac.shared->pen)) + if (rcu_access_pointer(wacom->wacom_wac.shared->pen)) return false; } @@ -2852,16 +2861,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; } - 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; diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index c5227530f291..c4cd87b781c4 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -3307,6 +3307,7 @@ static int wacom_bpt_irq(struct wacom_wac *wacom, size_t len) static void wacom_bamboo_pad_pen_event(struct wacom_wac *wacom, unsigned char *data) { + struct hid_device *pen; unsigned char prefix; /* @@ -3319,13 +3320,11 @@ static void wacom_bamboo_pad_pen_event(struct wacom_wac *wacom, prefix = data[0]; data[0] = WACOM_REPORT_BPAD_PEN; - /* - * actually reroute the event. - * No need to check if wacom->shared->pen is valid, hid_input_report() - * will check for us. - */ - hid_input_report(wacom->shared->pen, HID_INPUT_REPORT, data, - WACOM_PKGLEN_PENABLED, 1); + guard(rcu)(); + pen = rcu_dereference(wacom->shared->pen); + if (pen) + hid_input_report(pen, HID_INPUT_REPORT, data, + WACOM_PKGLEN_PENABLED, 1); data[0] = prefix; } diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h index a8bbba4a6f37..170d6adbe02a 100644 --- a/drivers/hid/wacom_wac.h +++ b/drivers/hid/wacom_wac.h @@ -286,8 +286,8 @@ struct wacom_shared { unsigned touch_max; int type; struct input_dev __rcu *touch_input; - struct hid_device *pen; - struct hid_device *touch; + struct hid_device __rcu *pen; + struct hid_device __rcu *touch; bool has_mute_touch_switch; bool is_touch_on; };