ANDROID: HID: debug: check length in hid_debug_events_read() before copy_to_user()

If our length is greater than the size of the buffer, we
overflow the buffer

Change-Id: I113a1955a2bac83c83084d5cd28d886175673219
Bug: 71361580
Signed-off-by: Daniel Rosenberg <drosen@google.com>
CVE-2018-9516
Signed-off-by: Kevin F. Haggerty <haggertk@lineageos.org>
This commit is contained in:
Daniel Rosenberg 2018-03-12 15:57:54 -07:00 committed by Francescodario Cuzzocrea
parent ca2d6dd04b
commit 8b6702e108

View file

@ -1021,6 +1021,8 @@ copy_rest:
goto out;
if (list->tail > list->head) {
len = list->tail - list->head;
if (len > count)
len = count;
if (copy_to_user(buffer + ret, &list->hid_debug_buf[list->head], len)) {
ret = -EFAULT;
@ -1030,6 +1032,8 @@ copy_rest:
list->head += len;
} else {
len = HID_DEBUG_BUFSIZE - list->head;
if (len > count)
len = count;
if (copy_to_user(buffer, &list->hid_debug_buf[list->head], len)) {
ret = -EFAULT;
@ -1037,7 +1041,9 @@ copy_rest:
}
list->head = 0;
ret += len;
goto copy_rest;
count -= len;
if (count > 0)
goto copy_rest;
}
}