b88c442
From 93a2001bdfd5376c3dc2158653034c20392d15c5 Mon Sep 17 00:00:00 2001
b88c442
From: Scott Bauer <sbauer@plzdonthack.me>
b88c442
Date: Thu, 23 Jun 2016 08:59:47 -0600
b88c442
Subject: [PATCH] HID: hiddev: validate num_values for HIDIOCGUSAGES,
b88c442
 HIDIOCSUSAGES commands
b88c442
b88c442
This patch validates the num_values parameter from userland during the
b88c442
HIDIOCGUSAGES and HIDIOCSUSAGES commands. Previously, if the report id was set
b88c442
to HID_REPORT_ID_UNKNOWN, we would fail to validate the num_values parameter
b88c442
leading to a heap overflow.
b88c442
b88c442
Cc: stable@vger.kernel.org
b88c442
Signed-off-by: Scott Bauer <sbauer@plzdonthack.me>
b88c442
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
b88c442
---
b88c442
 drivers/hid/usbhid/hiddev.c | 10 +++++-----
b88c442
 1 file changed, 5 insertions(+), 5 deletions(-)
b88c442
b88c442
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
b88c442
index 2f1ddca6f2e0..700145b15088 100644
b88c442
--- a/drivers/hid/usbhid/hiddev.c
b88c442
+++ b/drivers/hid/usbhid/hiddev.c
b88c442
@@ -516,13 +516,13 @@ static noinline int hiddev_ioctl_usage(struct hiddev *hiddev, unsigned int cmd,
b88c442
 					goto inval;
b88c442
 			} else if (uref->usage_index >= field->report_count)
b88c442
 				goto inval;
b88c442
-
b88c442
-			else if ((cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) &&
b88c442
-				 (uref_multi->num_values > HID_MAX_MULTI_USAGES ||
b88c442
-				  uref->usage_index + uref_multi->num_values > field->report_count))
b88c442
-				goto inval;
b88c442
 		}
b88c442
 
b88c442
+		if ((cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) &&
b88c442
+		    (uref_multi->num_values > HID_MAX_MULTI_USAGES ||
b88c442
+		     uref->usage_index + uref_multi->num_values > field->report_count))
b88c442
+			goto inval;
b88c442
+
b88c442
 		switch (cmd) {
b88c442
 		case HIDIOCGUSAGE:
b88c442
 			uref->value = field->value[uref->usage_index];
b88c442
-- 
b88c442
2.5.5
b88c442