Skip to content

Commit c54def7

Browse files
author
Jiri Kosina
committed
HID: magicmouse: sanity check report size in raw_event() callback
The report passed to us from transport driver could potentially be arbitrarily large, therefore we better sanity-check it so that magicmouse_emit_touch() gets only valid values of raw_id. Cc: [email protected] Reported-by: Steven Vittitoe <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 5abfe85 commit c54def7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/hid/hid-magicmouse.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ static int magicmouse_raw_event(struct hid_device *hdev,
290290
if (size < 4 || ((size - 4) % 9) != 0)
291291
return 0;
292292
npoints = (size - 4) / 9;
293+
if (npoints > 15) {
294+
hid_warn(hdev, "invalid size value (%d) for TRACKPAD_REPORT_ID\n",
295+
size);
296+
return 0;
297+
}
293298
msc->ntouches = 0;
294299
for (ii = 0; ii < npoints; ii++)
295300
magicmouse_emit_touch(msc, ii, data + ii * 9 + 4);
@@ -307,6 +312,11 @@ static int magicmouse_raw_event(struct hid_device *hdev,
307312
if (size < 6 || ((size - 6) % 8) != 0)
308313
return 0;
309314
npoints = (size - 6) / 8;
315+
if (npoints > 15) {
316+
hid_warn(hdev, "invalid size value (%d) for MOUSE_REPORT_ID\n",
317+
size);
318+
return 0;
319+
}
310320
msc->ntouches = 0;
311321
for (ii = 0; ii < npoints; ii++)
312322
magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);

0 commit comments

Comments
 (0)