[PATCH 09/10] HID: debug: Hold driver_input_lock while dumping raw report descriptor
From: Lee Jones
Date: Mon Nov 23 2026 - 10:53:10 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
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