[PATCH 0/2] HID: bpf: fix stale device_event buffer reuse

From: Xiang Mei

Date: Mon Nov 30 2026 - 17:03:28 EST


hdev->bpf.device_data is allocated once, sized from the report descriptor
parsed at that moment, and then reused: hid_bpf_allocate_event_data()
returns early whenever the pointer is already set. If the buffer
outlives the descriptor it was sized for, the next probe binds with a
larger descriptor and dispatch_hid_bpf_device_event() copies a full
report into the stale buffer.

Two paths leave such a buffer behind:

1/2 hid_connect()'s "no listeners" exit returns without freeing the
buffer it just allocated (KASAN slab-out-of-bounds write of 1024
bytes into kmalloc-64). The leak was also pointed out by the
sashiko review in [1].

2/2 hid_bpf_reg() allocates for an unbound device, whose report enums
are empty, so the buffer is ZERO_SIZE_PTR with allocated_data 0
(NULL-pointer write at 0x10).

Both are reachable from userspace with a uhid device and HID-BPF
struct_ops programs using ->hid_rdesc_fixup and ->hid_device_event.
Each patch was tested against its own reproducer on a KASAN kernel: the
crash fires without the patch and does not with it.

These fix the buffer lifetime and are independent of the pending
change that bounds the memcpy() itself [2]; that one is still needed
for uhid reports larger than the descriptor allows.

[1] https://lore.kernel.org/all/20260908202056.698371F00A3A@xxxxxxxxxxxxxxx/
[2] https://lore.kernel.org/all/20261102112630.53400-1-alon@botanica.software/

Xiang Mei (2):
HID: core: release the HID-BPF event buffer on hid_connect()'s
no-listeners exit
HID: bpf: don't allocate the event buffer for an unbound device

drivers/hid/bpf/hid_bpf_struct_ops.c | 2 +-
drivers/hid/hid-core.c | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)

--
2.43.0