From: Benjamin Tissoires Date: Mon, 10 Feb 2014 17:58:59 +0000 (-0500) Subject: HID: core: check parameters when sending/receiving data from the device X-Git-Tag: MMI-PSA29.97-13-9~12475^2~1^2~7 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5318251744b2c8a288f91f4e53ed69f2a01d6412;p=GitHub%2FMotorolaMobilityLLC%2Fkernel-slsi.git 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 Reviewed-by: David Herrmann Signed-off-by: Jiri Kosina --- diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index 5308656eec2e..1a955317d05f 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -276,7 +276,7 @@ static int i2c_hid_set_or_send_report(struct i2c_client *client, u8 reportType, u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister); u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength); - /* hidraw already checked that data_len < HID_MAX_BUFFER_SIZE */ + /* hid_hw_* already checked that data_len < HID_MAX_BUFFER_SIZE */ u16 size = 2 /* size */ + (reportID ? 1 : 0) /* reportID */ + data_len /* buf */; diff --git a/include/linux/hid.h b/include/linux/hid.h index 09fbbd7fb784..60f3ff762376 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -989,6 +989,9 @@ static inline int hid_hw_raw_request(struct hid_device *hdev, unsigned char reportnum, __u8 *buf, size_t len, unsigned char rtype, int reqtype) { + if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf) + return -EINVAL; + if (hdev->ll_driver->raw_request) return hdev->ll_driver->raw_request(hdev, reportnum, buf, len, rtype, reqtype); @@ -1008,6 +1011,9 @@ static inline int hid_hw_raw_request(struct hid_device *hdev, static inline int hid_hw_output_report(struct hid_device *hdev, __u8 *buf, size_t len) { + if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf) + return -EINVAL; + if (hdev->ll_driver->output_report) return hdev->ll_driver->output_report(hdev, buf, len);