Skip to content

Commit ad3e14d

Browse files
author
Jiri Kosina
committed
HID: logitech: perform bounds checking on device_id early enough
device_index is a char type and the size of paired_dj_deivces is 7 elements, therefore proper bounds checking has to be applied to device_index before it is used. We are currently performing the bounds checking in logi_dj_recv_add_djhid_device(), which is too late, as malicious device could send REPORT_TYPE_NOTIF_DEVICE_UNPAIRED early enough and trigger the problem in one of the report forwarding functions called from logi_dj_raw_event(). Fix this by performing the check at the earliest possible ocasion in logi_dj_raw_event(). Cc: [email protected] Reported-by: Ben Hawkes <[email protected]> Reviewed-by: Benjamin Tissoires <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 51217e6 commit ad3e14d

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

drivers/hid/hid-logitech-dj.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,6 @@ static void logi_dj_recv_add_djhid_device(struct dj_receiver_dev *djrcv_dev,
238238
return;
239239
}
240240

241-
if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
242-
(dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
243-
dev_err(&djrcv_hdev->dev, "%s: invalid device index:%d\n",
244-
__func__, dj_report->device_index);
245-
return;
246-
}
247-
248241
if (djrcv_dev->paired_dj_devices[dj_report->device_index]) {
249242
/* The device is already known. No need to reallocate it. */
250243
dbg_hid("%s: device is already known\n", __func__);
@@ -690,6 +683,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
690683
* device (via hid_input_report() ) and return 1 so hid-core does not do
691684
* anything else with it.
692685
*/
686+
if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
687+
(dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
688+
dev_err(&hdev->dev, "%s: invalid device index:%d\n",
689+
__func__, dj_report->device_index);
690+
return false;
691+
}
693692

694693
spin_lock_irqsave(&djrcv_dev->lock, flags);
695694
if (dj_report->report_id == REPORT_ID_DJ_SHORT) {

0 commit comments

Comments
 (0)