Skip to content

Commit 93a2001

Browse files
ScottyBauerJiri Kosina
authored and
Jiri Kosina
committed
HID: hiddev: validate num_values for HIDIOCGUSAGES, HIDIOCSUSAGES commands
This patch validates the num_values parameter from userland during the HIDIOCGUSAGES and HIDIOCSUSAGES commands. Previously, if the report id was set to HID_REPORT_ID_UNKNOWN, we would fail to validate the num_values parameter leading to a heap overflow. Cc: stable@vger.kernel.org Signed-off-by: Scott Bauer <sbauer@plzdonthack.me> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent a80e803 commit 93a2001

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Diff for: drivers/hid/usbhid/hiddev.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -516,13 +516,13 @@ static noinline int hiddev_ioctl_usage(struct hiddev *hiddev, unsigned int cmd,
516516
goto inval;
517517
} else if (uref->usage_index >= field->report_count)
518518
goto inval;
519-
520-
else if ((cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) &&
521-
(uref_multi->num_values > HID_MAX_MULTI_USAGES ||
522-
uref->usage_index + uref_multi->num_values > field->report_count))
523-
goto inval;
524519
}
525520

521+
if ((cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) &&
522+
(uref_multi->num_values > HID_MAX_MULTI_USAGES ||
523+
uref->usage_index + uref_multi->num_values > field->report_count))
524+
goto inval;
525+
526526
switch (cmd) {
527527
case HIDIOCGUSAGE:
528528
uref->value = field->value[uref->usage_index];

0 commit comments

Comments
 (0)