OSDN Git Service

hid: usbhid: Changes to prevent buffer overflow
authorSriharsha Allenki <sallenki@codeaurora.org>
Thu, 22 Dec 2016 09:27:44 +0000 (14:57 +0530)
committerSriharsha Allenki <sallenki@codeaurora.org>
Fri, 6 Jul 2018 10:52:02 +0000 (16:22 +0530)
Moved some value checks to right positions to prevent
buffer flow, which may be possible before. Previously
these value checks are in an else statement which may
not be executed.

Change-Id: I02dbecd074183581a6bdae6377097bc004bd3d3c
CRs-fixed: 1102936
Signed-off-by: Sriharsha Allenki <sallenki@codeaurora.org>
drivers/hid/usbhid/hiddev.c

index 700145b..da8fd95 100644 (file)
@@ -510,13 +510,13 @@ static noinline int hiddev_ioctl_usage(struct hiddev *hiddev, unsigned int cmd,
                                goto inval;
 
                        field = report->field[uref->field_index];
+               }
 
-                       if (cmd == HIDIOCGCOLLECTIONINDEX) {
-                               if (uref->usage_index >= field->maxusage)
-                                       goto inval;
-                       } else if (uref->usage_index >= field->report_count)
+               if (cmd == HIDIOCGCOLLECTIONINDEX) {
+                       if (uref->usage_index >= field->maxusage)
                                goto inval;
-               }
+               } else if (uref->usage_index >= field->report_count)
+                       goto inval;
 
                if ((cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) &&
                    (uref_multi->num_values > HID_MAX_MULTI_USAGES ||