Skip to content

Commit 9b3469d

Browse files
lag-linarogregkh
authored andcommitted
HID: magicmouse: Prevent out-of-bounds (OOB) read during DOUBLE_REPORT_ID
commit d93ba91 upstream. It is currently possible for a malicious or misconfigured USB device to cause an out-of-bounds (OOB) read when submitting reports using DOUBLE_REPORT_ID by specifying a large report length and providing a smaller one. Let's prevent that by comparing the specified report length with the actual size of the data read in from userspace. If the actual data length ends up being smaller than specified, we'll politely warn the user and prevent any further processing. Signed-off-by: Lee Jones <lee@kernel.org> Reviewed-by: Günther Noack <gnoack@google.com> Signed-off-by: Jiri Kosina <jkosina@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3d7a7ba commit 9b3469d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

drivers/hid/hid-magicmouse.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ static int magicmouse_raw_event(struct hid_device *hdev,
384384
struct input_dev *input = msc->input;
385385
int x = 0, y = 0, ii, clicks = 0, npoints;
386386

387+
/* Protect against zero sized recursive calls from DOUBLE_REPORT_ID */
388+
if (size < 1)
389+
return 0;
390+
387391
switch (data[0]) {
388392
case TRACKPAD_REPORT_ID:
389393
case TRACKPAD2_BT_REPORT_ID:
@@ -484,6 +488,18 @@ static int magicmouse_raw_event(struct hid_device *hdev,
484488
/* Sometimes the trackpad sends two touch reports in one
485489
* packet.
486490
*/
491+
492+
/* Ensure that we have at least 2 elements (report type and size) */
493+
if (size < 2)
494+
return 0;
495+
496+
if (size < data[1] + 2) {
497+
hid_warn(hdev,
498+
"received report length (%d) was smaller than specified (%d)",
499+
size, data[1] + 2);
500+
return 0;
501+
}
502+
487503
magicmouse_raw_event(hdev, report, data + 2, data[1]);
488504
magicmouse_raw_event(hdev, report, data + 2 + data[1],
489505
size - 2 - data[1]);

0 commit comments

Comments
 (0)