From: Yassine Ouamer A device whose own report descriptor the HID core refuses (for instance one with a report size over 256 bits) has no reports until a HID-BPF report descriptor fixup is attached and the device is probed again. If the struct_ops carrying the fixup also has a hid_device_event hook, hid_bpf_allocate_event_data() runs when it is attached, before that probe, finds no report, and kzalloc(0) returns ZERO_SIZE_PTR. When the probe then connects the device, hid_bpf_connect_device() sees a non-NULL device_data, takes it as already allocated and keeps it, so the first input report is copied to ZERO_SIZE_PTR: BUG: kernel NULL pointer dereference, address: 0000000000000010 #PF: supervisor write access in kernel mode RIP: 0010:memcpy_orig+0xcd/0x140 Call Trace: dispatch_hid_bpf_device_event __hid_input_report hid_safe_input_report uhid_char_write Seen with the Apple Siri Remote (4th generation, 004C:0316) over Bluetooth LE, whose report descriptor declares a single 1664-bit report, and a HID-BPF program replacing it: the machine had to be rebooted, bluetoothd being stuck in D state. Allocate nothing while the device has no reports: device_data stays NULL, which dispatch_hid_bpf_device_event() already takes as no buffer yet, and hid_bpf_connect_device() allocates it once the fixed report descriptor has been parsed. The bug was found while writing a HID-BPF program for that device; the analysis, this change and its commit message were written with an AI coding assistant (Claude, by Anthropic). Fixes: 658ee5a64fcf ("HID: bpf: allocate data memory for device_event BPF programs") Cc: stable@vger.kernel.org Signed-off-by: Yassine Ouamer --- drivers/hid/bpf/hid_bpf_dispatch.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c index 6b467c74601c..714014560fb8 100644 --- a/drivers/hid/bpf/hid_bpf_dispatch.c +++ b/drivers/hid/bpf/hid_bpf_dispatch.c @@ -243,6 +243,15 @@ static int __hid_bpf_allocate_data(struct hid_device *hdev, u8 **data, u32 *size } } + /* + * A device whose own report descriptor was refused has no reports + * until a report descriptor fixup makes them and the device is probed + * again: nothing to allocate before, hid_bpf_connect_device() does it + * then. kzalloc(0) would give ZERO_SIZE_PTR, which looks allocated. + */ + if (!max_report_len) + return 0; + /* * Give us a little bit of extra space and some predictability in the * buffer length we create. This way, we can tell users that they can -- 2.53.0