Skip to content

Commit be7484a

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
Pull HID fixes from Jiri Kosina: - fix for potential out-of-bounds memory access (found by fuzzing, likely requires specially crafted device to trigger) by Jaejoong Kim - two new device IDs for elecom driver from Alex Manoussakis * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid: HID: hid-elecom: extend to fix descriptor for HUGE trackball HID: usbhid: fix out-of-bounds bug
2 parents 7702f47 + a0933a4 commit be7484a

5 files changed

Lines changed: 25 additions & 5 deletions

File tree

‎drivers/hid/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ config HID_ELECOM
281281
Support for ELECOM devices:
282282
- BM084 Bluetooth Mouse
283283
- DEFT Trackball (Wired and wireless)
284+
- HUGE Trackball (Wired and wireless)
284285

285286
config HID_ELO
286287
tristate "ELO USB 4000/4500 touchscreen"

‎drivers/hid/hid-core.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,8 @@ static const struct hid_device_id hid_have_special_driver[] = {
20322032
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
20332033
{ HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_DEFT_WIRED) },
20342034
{ HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_DEFT_WIRELESS) },
2035+
{ HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_HUGE_WIRED) },
2036+
{ HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_HUGE_WIRELESS) },
20352037
#endif
20362038
#if IS_ENABLED(CONFIG_HID_ELO)
20372039
{ HID_USB_DEVICE(USB_VENDOR_ID_ELO, 0x0009) },

‎drivers/hid/hid-elecom.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (c) 2010 Richard Nauber <Richard.Nauber@gmail.com>
44
* Copyright (c) 2016 Yuxuan Shui <yshuiv7@gmail.com>
55
* Copyright (c) 2017 Diego Elio Pettenò <flameeyes@flameeyes.eu>
6+
* Copyright (c) 2017 Alex Manoussakis <amanou@gnu.org>
67
*/
78

89
/*
@@ -32,9 +33,11 @@ static __u8 *elecom_report_fixup(struct hid_device *hdev, __u8 *rdesc,
3233
break;
3334
case USB_DEVICE_ID_ELECOM_DEFT_WIRED:
3435
case USB_DEVICE_ID_ELECOM_DEFT_WIRELESS:
35-
/* The DEFT trackball has eight buttons, but its descriptor only
36-
* reports five, disabling the three Fn buttons on the top of
37-
* the mouse.
36+
case USB_DEVICE_ID_ELECOM_HUGE_WIRED:
37+
case USB_DEVICE_ID_ELECOM_HUGE_WIRELESS:
38+
/* The DEFT/HUGE trackball has eight buttons, but its descriptor
39+
* only reports five, disabling the three Fn buttons on the top
40+
* of the mouse.
3841
*
3942
* Apply the following diff to the descriptor:
4043
*
@@ -62,7 +65,7 @@ static __u8 *elecom_report_fixup(struct hid_device *hdev, __u8 *rdesc,
6265
* End Collection, End Collection,
6366
*/
6467
if (*rsize == 213 && rdesc[13] == 5 && rdesc[21] == 5) {
65-
hid_info(hdev, "Fixing up Elecom DEFT Fn buttons\n");
68+
hid_info(hdev, "Fixing up Elecom DEFT/HUGE Fn buttons\n");
6669
rdesc[13] = 8; /* Button/Variable Report Count */
6770
rdesc[21] = 8; /* Button/Variable Usage Maximum */
6871
rdesc[29] = 0; /* Button/Constant Report Count */
@@ -76,6 +79,8 @@ static const struct hid_device_id elecom_devices[] = {
7679
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) },
7780
{ HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_DEFT_WIRED) },
7881
{ HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_DEFT_WIRELESS) },
82+
{ HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_HUGE_WIRED) },
83+
{ HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_HUGE_WIRELESS) },
7984
{ }
8085
};
8186
MODULE_DEVICE_TABLE(hid, elecom_devices);

‎drivers/hid/hid-ids.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@
368368
#define USB_DEVICE_ID_ELECOM_BM084 0x0061
369369
#define USB_DEVICE_ID_ELECOM_DEFT_WIRED 0x00fe
370370
#define USB_DEVICE_ID_ELECOM_DEFT_WIRELESS 0x00ff
371+
#define USB_DEVICE_ID_ELECOM_HUGE_WIRED 0x010c
372+
#define USB_DEVICE_ID_ELECOM_HUGE_WIRELESS 0x010d
371373

372374
#define USB_VENDOR_ID_DREAM_CHEEKY 0x1d34
373375
#define USB_DEVICE_ID_DREAM_CHEEKY_WN 0x0004

‎drivers/hid/usbhid/hid-core.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,8 @@ static int usbhid_parse(struct hid_device *hid)
975975
unsigned int rsize = 0;
976976
char *rdesc;
977977
int ret, n;
978+
int num_descriptors;
979+
size_t offset = offsetof(struct hid_descriptor, desc);
978980

979981
quirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor),
980982
le16_to_cpu(dev->descriptor.idProduct));
@@ -997,10 +999,18 @@ static int usbhid_parse(struct hid_device *hid)
997999
return -ENODEV;
9981000
}
9991001

1002+
if (hdesc->bLength < sizeof(struct hid_descriptor)) {
1003+
dbg_hid("hid descriptor is too short\n");
1004+
return -EINVAL;
1005+
}
1006+
10001007
hid->version = le16_to_cpu(hdesc->bcdHID);
10011008
hid->country = hdesc->bCountryCode;
10021009

1003-
for (n = 0; n < hdesc->bNumDescriptors; n++)
1010+
num_descriptors = min_t(int, hdesc->bNumDescriptors,
1011+
(hdesc->bLength - offset) / sizeof(struct hid_class_descriptor));
1012+
1013+
for (n = 0; n < num_descriptors; n++)
10041014
if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT)
10051015
rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength);
10061016

0 commit comments

Comments
 (0)