From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Vojtech Pavlik <vojtech@suse.cz>,
Michael Haboustak <mike-@cinci.rr.com>,
Marcel Holtmann <marcel@holtmann.org>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 01/10] HID: core: Protect hid->inputs traversal in hid_check_keys_pressed()
Date: Mon, 23 Nov 2026 15:50:45 +0000 [thread overview]
Message-ID: <20261123155138.2907049-2-lee@kernel.org> (raw)
In-Reply-To: <20261123155138.2907049-1-lee@kernel.org>
hid_check_keys_pressed() is invoked from USB HID interrupt URB
completion in softirq context without holding hid->driver_input_lock.
During driver unbind or device removal, hid_device_remove() holds
hid->driver_input_lock and calls hid_hw_stop() -> hid_disconnect() ->
hidinput_disconnect(), which unlinks and frees hid_input entries from
hid->inputs before hid->claimed clears HID_CLAIMED_INPUT and before the
low-level transport stops interrupt URBs when another user such as
hidraw keeps the device open, leading to a use-after-free.
Guard hid_check_keys_pressed() with down_trylock() on
hid->driver_input_lock, matching __hid_input_report().
Fixes: c4c259bcc27c ("HID: consolidate connect and disconnect into core code")
Closes: https://sashiko.dev/#/bug/linux-bf47a448-239f-4b68-ac24-60b8b6baf724
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/hid/hid-core.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index b4fd482d39d2..03511cddd44f 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -3216,18 +3216,26 @@ EXPORT_SYMBOL_GPL(hid_unregister_driver);
int hid_check_keys_pressed(struct hid_device *hid)
{
struct hid_input *hidinput;
+ int ret = 0;
int i;
+ if (down_trylock(&hid->driver_input_lock))
+ return 0;
+
if (!(hid->claimed & HID_CLAIMED_INPUT))
- return 0;
+ goto out;
list_for_each_entry(hidinput, &hid->inputs, list) {
for (i = 0; i < BITS_TO_LONGS(KEY_MAX); i++)
- if (hidinput->input->key[i])
- return 1;
+ if (hidinput->input->key[i]) {
+ ret = 1;
+ goto out;
+ }
}
- return 0;
+out:
+ up(&hid->driver_input_lock);
+ return ret;
}
EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
--
2.56.1.750.gf70dc682cf-goog
next prev parent reply other threads:[~2026-11-23 15:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 15:50 [PATCH 00/10] HID: Assorted bug fixes across HID core and drivers Lee Jones
2026-11-23 15:50 ` Lee Jones [this message]
2026-11-23 15:50 ` [PATCH 02/10] HID: mcp2221: Synchronise rxbuf access against raw_event callback Lee Jones
2026-11-23 15:50 ` [PATCH 03/10] HID: logitech-hidpp: Synchronise send_receive_buf against raw events Lee Jones
2026-11-23 15:50 ` [PATCH 04/10] HID: sensor-hub: Serialise synchronous read teardown under data->lock Lee Jones
2026-11-23 15:50 ` [PATCH 05/10] HID: roccat: pyra: Resolve USB device from parent in actual_profile Lee Jones
2026-11-23 15:50 ` [PATCH 06/10] HID: hyperv: Validate VMBus packet and payload bounds on receive Lee Jones
2026-11-23 15:50 ` [PATCH 07/10] HID: hid-goodix-spi: Validate package sizes in goodix_hid_irq() Lee Jones
2026-11-23 15:50 ` [PATCH 08/10] HID: wacom: Stop HID hardware before releasing resources on mode change Lee Jones
2026-11-23 15:50 ` [PATCH 09/10] HID: debug: Hold driver_input_lock while dumping raw report descriptor Lee Jones
2026-11-23 15:50 ` [PATCH 10/10] HID: playstation: Cancel DualSense output worker on create failure Lee Jones
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=20261123155138.2907049-2-lee@kernel.org \
--to=lee@kernel.org \
--cc=bentiss@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcel@holtmann.org \
--cc=mike-@cinci.rr.com \
--cc=stable@vger.kernel.org \
--cc=vojtech@suse.cz \
/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