Skip to content
/ linux Public

Commit 73c5b5a

Browse files
Benjamin Tissoiresgregkh
authored andcommitted
HID: bpf: prevent buffer overflow in hid_hw_request
commit 2b658c1 upstream. 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: stable@vger.kernel.org Acked-by: Jiri Kosina <jkosina@suse.com> Signed-off-by: Benjamin Tissoires <bentiss@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6487774 commit 73c5b5a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/hid/bpf/hid_bpf_dispatch.c

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

450+
if (ret > size)
451+
ret = size;
450452
if (ret > 0)
451453
memcpy(buf, dma_data, ret);
452454

0 commit comments

Comments
 (0)