From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>,
Andreas Gal <gal@cs.uni-magdeburg.de>,
Vojtech Pavlik <vojtech@ucw.cz>, "He, Bo" <bo.he@intel.com>,
"Zhang, Jun" <jun.zhang@intel.com>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 09/10] HID: debug: Hold driver_input_lock while dumping raw report descriptor
Date: Mon, 23 Nov 2026 15:50:53 +0000 [thread overview]
Message-ID: <20261123155138.2907049-10-lee@kernel.org> (raw)
In-Reply-To: <20261123155138.2907049-1-lee@kernel.org>
hid_debug_rdesc_show() reads hdev->rdesc and hdev->rsize and formats
the raw report descriptor before acquiring hdev->driver_input_lock.
When a HID driver with report_fixup() unbinds or HID-BPF reprobes the
device, hid_device_remove() and __hid_device_probe() free hdev->rdesc
and hdev->bpf_rdesc under hdev->driver_input_lock while the debugfs
entry remains accessible, causing a use-after-free in
hid_debug_rdesc_show().
Acquire hdev->driver_input_lock at the start of hid_debug_rdesc_show()
before reading hdev->rdesc and hdev->rsize.
Fixes: cef0d4948cb0 ("HID: debug: fix race condition with between rdesc_show() and device removal")
Closes: https://sashiko.dev/#/bug/linux-31c0bbf2-e4e7-41e6-ab3b-0d17dfe45389
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/hid/hid-debug.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index f44e6e708404..56207dea4aa7 100644
--- a/drivers/hid/hid-debug.c
+++ b/drivers/hid/hid-debug.c
@@ -3654,10 +3654,15 @@ static void hid_dump_input_mapping(struct hid_device *hid, struct seq_file *f)
static int hid_debug_rdesc_show(struct seq_file *f, void *p)
{
struct hid_device *hdev = f->private;
- const __u8 *rdesc = hdev->rdesc;
- unsigned rsize = hdev->rsize;
+ const __u8 *rdesc;
+ unsigned int rsize;
int i;
+ if (down_interruptible(&hdev->driver_input_lock))
+ return 0;
+
+ rdesc = hdev->rdesc;
+ rsize = hdev->rsize;
if (!rdesc) {
rdesc = hdev->dev_rdesc;
rsize = hdev->dev_rsize;
@@ -3669,9 +3674,6 @@ static int hid_debug_rdesc_show(struct seq_file *f, void *p)
seq_printf(f, "\n\n");
/* dump parsed data and input mappings */
- if (down_interruptible(&hdev->driver_input_lock))
- return 0;
-
hid_dump_device(hdev, f);
seq_printf(f, "\n");
hid_dump_input_mapping(hdev, f);
--
2.56.1.750.gf70dc682cf-goog
next prev parent reply other threads:[~2026-11-23 15:52 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 ` [PATCH 01/10] HID: core: Protect hid->inputs traversal in hid_check_keys_pressed() Lee Jones
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 ` Lee Jones [this message]
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-10-lee@kernel.org \
--to=lee@kernel.org \
--cc=bentiss@kernel.org \
--cc=bo.he@intel.com \
--cc=bpf@vger.kernel.org \
--cc=gal@cs.uni-magdeburg.de \
--cc=jikos@kernel.org \
--cc=jun.zhang@intel.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=vojtech@ucw.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