Skip to content

Commit 297502a

Browse files
keesJiri Kosina
authored andcommitted
HID: logitech-dj: validate output report details
A HID device could send a malicious output report that would cause the logitech-dj HID driver to leak kernel memory contents to the device, or trigger a NULL dereference during initialization: [ 304.424553] usb 1-1: New USB device found, idVendor=046d, idProduct=c52b ... [ 304.780467] BUG: unable to handle kernel NULL pointer dereference at 0000000000000028 [ 304.781409] IP: [<ffffffff815d50aa>] logi_dj_recv_send_report.isra.11+0x1a/0x90 CVE-2013-2895 Signed-off-by: Kees Cook <[email protected]> Cc: [email protected] Signed-off-by: Benjamin Tissoires <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent cc6b54a commit 297502a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/hid/hid-logitech-dj.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
461461
struct hid_report *report;
462462
struct hid_report_enum *output_report_enum;
463463
u8 *data = (u8 *)(&dj_report->device_index);
464-
int i;
464+
unsigned int i;
465465

466466
output_report_enum = &hdev->report_enum[HID_OUTPUT_REPORT];
467467
report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT];
@@ -471,7 +471,7 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
471471
return -ENODEV;
472472
}
473473

474-
for (i = 0; i < report->field[0]->report_count; i++)
474+
for (i = 0; i < DJREPORT_SHORT_LENGTH - 1; i++)
475475
report->field[0]->value[i] = data[i];
476476

477477
hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
@@ -791,6 +791,12 @@ static int logi_dj_probe(struct hid_device *hdev,
791791
goto hid_parse_fail;
792792
}
793793

794+
if (!hid_validate_values(hdev, HID_OUTPUT_REPORT, REPORT_ID_DJ_SHORT,
795+
0, DJREPORT_SHORT_LENGTH - 1)) {
796+
retval = -ENODEV;
797+
goto hid_parse_fail;
798+
}
799+
794800
/* Starts the usb device and connects to upper interfaces hiddev and
795801
* hidraw */
796802
retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);

0 commit comments

Comments
 (0)