Skip to content

Commit f01abb7

Browse files
Marc Zyngierwebgeek1234
Marc Zyngier
authored andcommitted
HID: core: Correctly handle ReportSize being zero
commit bce1305c0ece3dc549663605e567655dd701752c upstream. It appears that a ReportSize value of zero is legal, even if a bit non-sensical. Most of the HID code seems to handle that gracefully, except when computing the total size in bytes. When fed as input to memset, this leads to some funky outcomes. Detect the corner case and correctly compute the size. Cc: [email protected] Signed-off-by: Marc Zyngier <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Change-Id: I0a1ae2d069cc8be1c1411ca25fb5c7bfec2ec2a2
1 parent 35c024f commit f01abb7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Diff for: drivers/hid/hid-core.c

+13-2
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,17 @@ static void hid_output_field(const struct hid_device *hid,
13431343
}
13441344
}
13451345

1346+
/*
1347+
* Compute the size of a report.
1348+
*/
1349+
static size_t hid_compute_report_size(struct hid_report *report)
1350+
{
1351+
if (report->size)
1352+
return ((report->size - 1) >> 3) + 1;
1353+
1354+
return 0;
1355+
}
1356+
13461357
/*
13471358
* Create a report. 'data' has to be allocated using
13481359
* hid_alloc_report_buf() so that it has proper size.
@@ -1355,7 +1366,7 @@ void hid_output_report(struct hid_report *report, __u8 *data)
13551366
if (report->id > 0)
13561367
*data++ = report->id;
13571368

1358-
memset(data, 0, ((report->size - 1) >> 3) + 1);
1369+
memset(data, 0, hid_compute_report_size(report));
13591370
for (n = 0; n < report->maxfield; n++)
13601371
hid_output_field(report->device, report->field[n], data);
13611372
}
@@ -1482,7 +1493,7 @@ int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size,
14821493
csize--;
14831494
}
14841495

1485-
rsize = ((report->size - 1) >> 3) + 1;
1496+
rsize = hid_compute_report_size(report);
14861497

14871498
if (rsize > HID_MAX_BUFFER_SIZE)
14881499
rsize = HID_MAX_BUFFER_SIZE;

0 commit comments

Comments
 (0)