diff options
author | Benjamin Tissoires <benjamin.tissoires@redhat.com> | 2014-02-10 12:58:59 -0500 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2014-02-17 08:58:59 -0500 |
commit | 5318251744b2c8a288f91f4e53ed69f2a01d6412 (patch) | |
tree | 48fe1594feac12afa0832b271460ad58b0596afc | |
parent | 7e0bc880fce51ba3bd9128b8df9dc59567c5f73a (diff) |
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>
-rw-r--r-- | drivers/hid/i2c-hid/i2c-hid.c | 2 | ||||
-rw-r--r-- | include/linux/hid.h | 6 |
2 files changed, 7 insertions, 1 deletions
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, | |||
276 | u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister); | 276 | u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister); |
277 | u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength); | 277 | u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength); |
278 | 278 | ||
279 | /* hidraw already checked that data_len < HID_MAX_BUFFER_SIZE */ | 279 | /* hid_hw_* already checked that data_len < HID_MAX_BUFFER_SIZE */ |
280 | u16 size = 2 /* size */ + | 280 | u16 size = 2 /* size */ + |
281 | (reportID ? 1 : 0) /* reportID */ + | 281 | (reportID ? 1 : 0) /* reportID */ + |
282 | data_len /* buf */; | 282 | 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, | |||
989 | unsigned char reportnum, __u8 *buf, | 989 | unsigned char reportnum, __u8 *buf, |
990 | size_t len, unsigned char rtype, int reqtype) | 990 | size_t len, unsigned char rtype, int reqtype) |
991 | { | 991 | { |
992 | if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf) | ||
993 | return -EINVAL; | ||
994 | |||
992 | if (hdev->ll_driver->raw_request) | 995 | if (hdev->ll_driver->raw_request) |
993 | return hdev->ll_driver->raw_request(hdev, reportnum, buf, len, | 996 | return hdev->ll_driver->raw_request(hdev, reportnum, buf, len, |
994 | rtype, reqtype); | 997 | rtype, reqtype); |
@@ -1008,6 +1011,9 @@ static inline int hid_hw_raw_request(struct hid_device *hdev, | |||
1008 | static inline int hid_hw_output_report(struct hid_device *hdev, __u8 *buf, | 1011 | static inline int hid_hw_output_report(struct hid_device *hdev, __u8 *buf, |
1009 | size_t len) | 1012 | size_t len) |
1010 | { | 1013 | { |
1014 | if (len < 1 || len > HID_MAX_BUFFER_SIZE || !buf) | ||
1015 | return -EINVAL; | ||
1016 | |||
1011 | if (hdev->ll_driver->output_report) | 1017 | if (hdev->ll_driver->output_report) |
1012 | return hdev->ll_driver->output_report(hdev, buf, len); | 1018 | return hdev->ll_driver->output_report(hdev, buf, len); |
1013 | 1019 | ||