dispatch_hid_bpf_device_event() copies the incoming report into the per-device scratch buffer hdev->bpf.device_data with: memcpy(ctx_kern.data, data, *size); hdev->bpf.device_data is allocated to the largest parsed report length rounded up to 64 bytes (DIV_ROUND_UP(max_report_len, 64) * 64). *size is the length supplied by the transport and is never checked against hdev->bpf.allocated_data before the copy; the only size check in the function is applied afterwards, to the value the BPF program returns. For transports that bound the report to the parsed model (usbhid, i2c-hid) this is harmless. But uhid accepts up to 4096 bytes per UHID_INPUT2 and hidp up to 16384 bytes per interrupt frame regardless of the descriptor. A report larger than the buffer therefore overflows the slab allocation with attacker-controlled length and content, in kernel context, whenever any HID-BPF program with a hid_device_event hook is attached to the device. This is reachable over Bluetooth with no local access. BlueZ feeds remote HID devices to the kernel through uhid, the remote device supplies its own bus/vendor/product ids, and udev-hid-bpf auto-attaches shipped programs by those ids. On a host with udev-hid-bpf installed (common on machines used with drawing tablets), bonding with a device that claims to be a Huion KeyDial K20 over Bluetooth (BUS_BLUETOOTH, 0x256C:0x8251) causes the shipped Huion__KeydialK20-Bluetooth program to be attached, after which a single oversized report corrupts kernel heap memory. Reproduced on Ubuntu 24.04 (6.8.0-134) and Ubuntu 26.10 (7.3.0-10) with slub_debug=FZPU. Driving /dev/uhid: create a device whose largest report is 8 bytes (64-byte scratch buffer), attach a hid_device_event program, and send a 120-byte UHID_INPUT2. slub reports "Right Redzone overwritten" on free via hid_bpf_disconnect_device; the same report with no program attached, or at the exact 64-byte size, is clean. Also reproduced end-to-end with the shipped Huion__KeydialK20-Bluetooth program auto-attached by udev-hid-bpf 2.3.0, presenting the K20's Bluetooth ids. The missing check was noted by automated review on this list on 2026-07-04 but left unaddressed; the copy is still unguarded in master. Reject reports larger than the allocated buffer before the copy, the same way an over-sized program return value is already rejected. Fixes: f5c27da4e3c8 ("HID: initial BPF implementation") Cc: stable@vger.kernel.org Signed-off-by: Alon Livne --- drivers/hid/bpf/hid_bpf_dispatch.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c --- a/drivers/hid/bpf/hid_bpf_dispatch.c +++ b/drivers/hid/bpf/hid_bpf_dispatch.c @@ -49,7 +49,10 @@ dispatch_hid_bpf_device_event(struct hid_device *hdev, enum hid_report_type type, /* no program has been attached yet */ if (!hdev->bpf.device_data) return data; + if (unlikely(*size > hdev->bpf.allocated_data)) + return ERR_PTR(-EINVAL); + memset(ctx_kern.data, 0, hdev->bpf.allocated_data); memcpy(ctx_kern.data, data, *size);