[PATCH 3.4 30/45] HID: picolcd: sanity check report size in raw_event() callback

From: Zefan Li
Date: Mon Sep 22 2014 - 22:45:09 EST


From: Jiri Kosina <jkosina@xxxxxxx>

3.4.104-rc1 review patch. If anyone has any objections, please let me know.

------------------

commit 844817e47eef14141cf59b8d5ac08dd11c0a9189 upstream.

The report passed to us from transport driver could potentially be
arbitrarily large, therefore we better sanity-check it so that raw_data
that we hold in picolcd_pending structure are always kept within proper
bounds.

Reported-by: Steven Vittitoe <scvitti@xxxxxxxxxx>
Signed-off-by: Jiri Kosina <jkosina@xxxxxxx>
[lizf: Backported to 3.4: adjust filename]
Signed-off-by: Zefan Li <lizefan@xxxxxxxxxx>
---
drivers/hid/hid-picolcd.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/hid/hid-picolcd.c b/drivers/hid/hid-picolcd.c
index 95f9047..4e37b1f 100644
--- a/drivers/hid/hid-picolcd.c
+++ b/drivers/hid/hid-picolcd.c
@@ -2370,6 +2370,12 @@ static int picolcd_raw_event(struct hid_device *hdev,
if (!data)
return 1;

+ if (size > 64) {
+ hid_warn(hdev, "invalid size value (%d) for picolcd raw event\n",
+ size);
+ return 0;
+ }
+
if (report->id == REPORT_KEY_STATE) {
if (data->input_keys)
ret = picolcd_raw_keypad(data, report, raw_data+1, size-1);
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/