Skip to content

Commit 5318251

Browse files
bentissJiri Kosina
authored andcommitted
HID: core: check parameters when sending/receiving data from the device
It is better to check them soon enough before triggering any kernel panic. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Reviewed-by: David Herrmann <dh.herrmann@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 7e0bc88 commit 5318251

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

‎drivers/hid/i2c-hid/i2c-hid.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static int i2c_hid_set_or_send_report(struct i2c_client *client, u8 reportType,
276276
u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister);
277277
u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength);
278278

279-
/* hidraw already checked that data_len < HID_MAX_BUFFER_SIZE */
279+
/* hid_hw_* already checked that data_len < HID_MAX_BUFFER_SIZE */
280280
u16 size = 2 /* size */ +
281281
(reportID ? 1 : 0) /* reportID */ +
282282
data_len /* buf */;

‎include/linux/hid.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,9 @@ static inline int hid_hw_raw_request(struct hid_device *hdev,
989989
unsigned char reportnum, __u8 *buf,
990990
size_t len, unsigned char rtype, int reqtype)
991991
{
992+
if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf)
993+
return -EINVAL;
994+
992995
if (hdev->ll_driver->raw_request)
993996
return hdev->ll_driver->raw_request(hdev, reportnum, buf, len,
994997
rtype, reqtype);
@@ -1008,6 +1011,9 @@ static inline int hid_hw_raw_request(struct hid_device *hdev,
10081011
static inline int hid_hw_output_report(struct hid_device *hdev, __u8 *buf,
10091012
size_t len)
10101013
{
1014+
if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf)
1015+
return -EINVAL;
1016+
10111017
if (hdev->ll_driver->output_report)
10121018
return hdev->ll_driver->output_report(hdev, buf, len);
10131019

0 commit comments

Comments
 (0)