Skip to content

Commit 5ebdffd

Browse files
Johan KorsnesJiri Kosina
authored andcommitted
HID: core: fix off-by-one memset in hid_report_raw_event()
In case a report is greater than HID_MAX_BUFFER_SIZE, it is truncated, but the report-number byte is not correctly handled. This results in a off-by-one in the following memset, causing a kernel Oops and ensuing system crash. Note: With commit 8ec321e ("HID: Fix slab-out-of-bounds read in hid_field_extract") I no longer hit the kernel Oops as we instead fail "controlled" at probe if there is a report too long in the HID report-descriptor. hid_report_raw_event() is an exported symbol, so presumabely we cannot always rely on this being the case. Fixes: 966922f ("HID: fix a crash in hid_report_raw_event() function.") Signed-off-by: Johan Korsnes <[email protected]> Cc: Armando Visconti <[email protected]> Cc: Jiri Kosina <[email protected]> Cc: Alan Stern <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent e433be9 commit 5ebdffd

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/hid/hid-core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,9 @@ int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size,
17411741

17421742
rsize = ((report->size - 1) >> 3) + 1;
17431743

1744-
if (rsize > HID_MAX_BUFFER_SIZE)
1744+
if (report_enum->numbered && rsize >= HID_MAX_BUFFER_SIZE)
1745+
rsize = HID_MAX_BUFFER_SIZE - 1;
1746+
else if (rsize > HID_MAX_BUFFER_SIZE)
17451747
rsize = HID_MAX_BUFFER_SIZE;
17461748

17471749
if (csize < rsize) {

0 commit comments

Comments
 (0)