HID: validate feature and input report details
When dealing with usage_index, be sure to properly use unsigned instead of int to avoid overflows. When working on report fields, always validate that their report_counts are in bounds. Without this, a HID device could report a malicious feature report that could trick the driver into a heap overflow: [ 634.885003] usb 1-1: New USB device found, idVendor=0596, idProduct=0500 ... [ 676.469629] BUG kmalloc-192 (Tainted: G W ): Redzone overwritten CVE-2013-2897 Cc: stable@vger.kernel.org Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
This commit is contained in:

committed by
Jiri Kosina

parent
0a9cd0a80a
commit
cc6b54aa54
@@ -485,6 +485,10 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
|
||||
if (field->flags & HID_MAIN_ITEM_CONSTANT)
|
||||
goto ignore;
|
||||
|
||||
/* Ignore if report count is out of bounds. */
|
||||
if (field->report_count < 1)
|
||||
goto ignore;
|
||||
|
||||
/* only LED usages are supported in output fields */
|
||||
if (field->report_type == HID_OUTPUT_REPORT &&
|
||||
(usage->hid & HID_USAGE_PAGE) != HID_UP_LED) {
|
||||
@@ -1236,7 +1240,11 @@ static void report_features(struct hid_device *hid)
|
||||
|
||||
rep_enum = &hid->report_enum[HID_FEATURE_REPORT];
|
||||
list_for_each_entry(rep, &rep_enum->report_list, list)
|
||||
for (i = 0; i < rep->maxfield; i++)
|
||||
for (i = 0; i < rep->maxfield; i++) {
|
||||
/* Ignore if report count is out of bounds. */
|
||||
if (rep->field[i]->report_count < 1)
|
||||
continue;
|
||||
|
||||
for (j = 0; j < rep->field[i]->maxusage; j++) {
|
||||
/* Verify if Battery Strength feature is available */
|
||||
hidinput_setup_battery(hid, HID_FEATURE_REPORT, rep->field[i]);
|
||||
@@ -1245,6 +1253,7 @@ static void report_features(struct hid_device *hid)
|
||||
drv->feature_mapping(hid, rep->field[i],
|
||||
rep->field[i]->usage + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static struct hid_input *hidinput_allocate(struct hid_device *hid)
|
||||
|
Reference in New Issue
Block a user