diff options
author | Kees Cook <keescook@chromium.org> | 2013-08-28 16:29:55 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2013-08-29 05:01:25 -0400 |
commit | 43622021d2e2b82ea03d883926605bdd0525e1d1 (patch) | |
tree | eb347fb9b63e544151787d58f8940bdd957961a0 /drivers/hid | |
parent | 58c59bc997d86593f0bea41845885917cf304d22 (diff) |
HID: validate HID report id size
The "Report ID" field of a HID report is used to build indexes of
reports. The kernel's index of these is limited to 256 entries, so any
malicious device that sets a Report ID greater than 255 will trigger
memory corruption on the host:
[ 1347.156239] BUG: unable to handle kernel paging request at ffff88094958a878
[ 1347.156261] IP: [<ffffffff813e4da0>] hid_register_report+0x2a/0x8b
CVE-2013-2888
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: stable@kernel.org
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r-- | drivers/hid/hid-core.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 36668d1aca8f..5ea7d51e45b9 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c | |||
@@ -63,6 +63,8 @@ struct hid_report *hid_register_report(struct hid_device *device, unsigned type, | |||
63 | struct hid_report_enum *report_enum = device->report_enum + type; | 63 | struct hid_report_enum *report_enum = device->report_enum + type; |
64 | struct hid_report *report; | 64 | struct hid_report *report; |
65 | 65 | ||
66 | if (id >= HID_MAX_IDS) | ||
67 | return NULL; | ||
66 | if (report_enum->report_id_hash[id]) | 68 | if (report_enum->report_id_hash[id]) |
67 | return report_enum->report_id_hash[id]; | 69 | return report_enum->report_id_hash[id]; |
68 | 70 | ||
@@ -404,8 +406,10 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item) | |||
404 | 406 | ||
405 | case HID_GLOBAL_ITEM_TAG_REPORT_ID: | 407 | case HID_GLOBAL_ITEM_TAG_REPORT_ID: |
406 | parser->global.report_id = item_udata(item); | 408 | parser->global.report_id = item_udata(item); |
407 | if (parser->global.report_id == 0) { | 409 | if (parser->global.report_id == 0 || |
408 | hid_err(parser->device, "report_id 0 is invalid\n"); | 410 | parser->global.report_id >= HID_MAX_IDS) { |
411 | hid_err(parser->device, "report_id %u is invalid\n", | ||
412 | parser->global.report_id); | ||
409 | return -1; | 413 | return -1; |
410 | } | 414 | } |
411 | return 0; | 415 | return 0; |
@@ -575,7 +579,7 @@ static void hid_close_report(struct hid_device *device) | |||
575 | for (i = 0; i < HID_REPORT_TYPES; i++) { | 579 | for (i = 0; i < HID_REPORT_TYPES; i++) { |
576 | struct hid_report_enum *report_enum = device->report_enum + i; | 580 | struct hid_report_enum *report_enum = device->report_enum + i; |
577 | 581 | ||
578 | for (j = 0; j < 256; j++) { | 582 | for (j = 0; j < HID_MAX_IDS; j++) { |
579 | struct hid_report *report = report_enum->report_id_hash[j]; | 583 | struct hid_report *report = report_enum->report_id_hash[j]; |
580 | if (report) | 584 | if (report) |
581 | hid_free_report(report); | 585 | hid_free_report(report); |