diff options
author | Kees Cook <keescook@chromium.org> | 2013-08-28 16:29:55 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-09-26 20:18:16 -0400 |
commit | 56085cec9ef90f5133effbcf71149d19ea2f5170 (patch) | |
tree | 2b8d3c977757d67ff0d21874337606dc67fc7583 | |
parent | a3957df756ccf3a46c24c8e2d4f8b26c932357b3 (diff) |
HID: validate HID report id size
commit 43622021d2e2b82ea03d883926605bdd0525e1d1 upstream.
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>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/hid/hid-core.c | 10 | ||||
-rw-r--r-- | include/linux/hid.h | 4 |
2 files changed, 10 insertions, 4 deletions
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 402f48689943..eb202481fb09 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); |
diff --git a/include/linux/hid.h b/include/linux/hid.h index 0c48991b0402..ff545cc33c3a 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h | |||
@@ -393,10 +393,12 @@ struct hid_report { | |||
393 | struct hid_device *device; /* associated device */ | 393 | struct hid_device *device; /* associated device */ |
394 | }; | 394 | }; |
395 | 395 | ||
396 | #define HID_MAX_IDS 256 | ||
397 | |||
396 | struct hid_report_enum { | 398 | struct hid_report_enum { |
397 | unsigned numbered; | 399 | unsigned numbered; |
398 | struct list_head report_list; | 400 | struct list_head report_list; |
399 | struct hid_report *report_id_hash[256]; | 401 | struct hid_report *report_id_hash[HID_MAX_IDS]; |
400 | }; | 402 | }; |
401 | 403 | ||
402 | #define HID_REPORT_TYPES 3 | 404 | #define HID_REPORT_TYPES 3 |