Skip to content

Commit 2b658c1

Browse files
author
Benjamin Tissoires
committed
HID: bpf: prevent buffer overflow in hid_hw_request
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: 8bd0488 ("HID: bpf: add HID-BPF hooks for hid_hw_raw_requests") Cc: [email protected] Acked-by: Jiri Kosina <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 5d4c6c1 commit 2b658c1

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

drivers/hid/bpf/hid_bpf_dispatch.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ hid_bpf_hw_request(struct hid_bpf_ctx *ctx, __u8 *buf, size_t buf__sz,
444444
(u64)(long)ctx,
445445
true); /* prevent infinite recursions */
446446

447+
if (ret > size)
448+
ret = size;
447449
if (ret > 0)
448450
memcpy(buf, dma_data, ret);
449451

0 commit comments

Comments
 (0)