Skip to contentSkip to conversation

HID: logitech-dj: shared receiver keeps unreferenced HID devices

DISCUSSION Jinmo Yang 1 participant 1 message Nov 28 HID

lore
Share & tools
lore

Jinmo Yang

author
#0 lore raw

Found by coverage-guided fuzzing of the HID subsystem through /dev/uhid. No patch is attached; I am reporting the lifetime issue first and can test candidate fixes with the standalone reproducer.

Kernel: mainline 7.2.0-ge46c86b19f4b (arm64, KASAN)
File:   drivers/hid/hid-logitech-dj.c
Impact: use-after-free read and NULL/wild pointer dereferences
Repro:  standalone C, approximately 57 seconds

## Report

  BUG: KASAN: slab-use-after-free in __dev_printk
  Read of size 8
   dev_driver_string
   __dev_printk
   hid_err
   logi_dj_recv_switch_to_dj_mode
   logi_dj_probe
   hid_device_probe
   uhid_device_add_worker

The freed object was a struct hid_device allocated by uhid_dev_create2() and released through hid_device_release() by a different task.

## Analysis

dj_receiver_dev is shared by interfaces whose phys paths have the same prefix. It stores raw mouse, keyboard and hidpp hid_device pointers without taking references. During concurrent probes, one interface can overwrite a shared pointer that another interface later latches.

The reproduced order is:

1. receiver A begins probing;
2. receiver B overwrites the shared hidpp pointer;
3. A latches B's hdev and enters switch_to_dj_mode();
4. A's hid_hw_raw_request blocks waiting for uhid userspace;
5. B is destroyed and its hid_device is freed;
6. A's request returns and hid_err() dereferences B's freed hdev.

cancel_work_sync() in B's destruction does not help because the stale pointer is held by A's worker. The existing remove path clears current back-pointers under dj_hdev_list_lock, but that does not protect a pointer already latched by another probe and held across the blocking raw request.

The shared pointer needs an object reference or exclusion that remains valid for the complete operation, not only while finding or clearing the receiver entry.

## Upstream status

Rechecked against mainline, linux-next, HID maintainer branches, and lore through 2026-11-28. The defect remains unpatched and I found no matching submission.