]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
HID: bpf: prevent buffer overflow in hid_hw_request
authorBenjamin Tissoires <bentiss@kernel.org>
Fri, 13 Mar 2026 07:40:25 +0000 (08:40 +0100)
committerBenjamin Tissoires <bentiss@kernel.org>
Mon, 16 Mar 2026 15:21:06 +0000 (16:21 +0100)
right now the returned value is considered to be always valid. However,
when playing with HID-BPF, the return value can be arbitrary big,
because it's the return value of dispatch_hid_bpf_raw_requests(), which
calls the struct_ops and we have no guarantees that the value makes
sense.

Fixes: 8bd0488b5ea5 ("HID: bpf: add HID-BPF hooks for hid_hw_raw_requests")
Cc: stable@vger.kernel.org
Acked-by: Jiri Kosina <jkosina@suse.com>
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
drivers/hid/bpf/hid_bpf_dispatch.c

index 892aca026ffa3644fedd303350174f38a1b35556..33af17fdc72941e0d9546732057a2729b56d5cd0 100644 (file)
@@ -444,6 +444,8 @@ hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz,
                                              (u64)(long)ctx,
                                              true); /* prevent infinite recursions */
 
+       if (ret > size)
+               ret = size;
        if (ret > 0)
                memcpy(buf, dma_data, ret);