aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-12-16 10:55:22 -0500
committerJiri Kosina <jkosina@suse.cz>2014-12-17 02:51:52 -0500
commit0b3f6569a560aa68c9c50cae0e1bc401f7ee699f (patch)
treee3372f9fe5bcf4f4d30db907e74501d194162941
parentf254ae938ea479739572790a4e9b0ca86d16249f (diff)
HID: logitech-hidpp: check WTP report length
Malicious USB devices can send bogus reports smaller than the expected buffer size. Ensure that the length for WTP reports is valid to avoid reading out of bounds. Signed-off-by: Peter Wu <peter@lekensteyn.nl> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--drivers/hid/hid-logitech-hidpp.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 2f420c0b6609..dd3c21b52de3 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -794,6 +794,11 @@ static int wtp_raw_event(struct hid_device *hdev, u8 *data, int size)
794 794
795 switch (data[0]) { 795 switch (data[0]) {
796 case 0x02: 796 case 0x02:
797 if (size < 2) {
798 hid_err(hdev, "Received HID report of bad size (%d)",
799 size);
800 return 1;
801 }
797 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) { 802 if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) {
798 input_event(wd->input, EV_KEY, BTN_LEFT, 803 input_event(wd->input, EV_KEY, BTN_LEFT,
799 !!(data[1] & 0x01)); 804 !!(data[1] & 0x01));
@@ -806,6 +811,7 @@ static int wtp_raw_event(struct hid_device *hdev, u8 *data, int size)
806 return wtp_mouse_raw_xy_event(hidpp, &data[7]); 811 return wtp_mouse_raw_xy_event(hidpp, &data[7]);
807 } 812 }
808 case REPORT_ID_HIDPP_LONG: 813 case REPORT_ID_HIDPP_LONG:
814 /* size is already checked in hidpp_raw_event. */
809 if ((report->fap.feature_index != wd->mt_feature_index) || 815 if ((report->fap.feature_index != wd->mt_feature_index) ||
810 (report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY)) 816 (report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY))
811 return 1; 817 return 1;