From: Daniel Rosenberg Date: Mon, 2 Jul 2018 23:59:37 +0000 (-0700) Subject: HID: debug: check length before copy_to_user() X-Git-Tag: v4.1.12-124.31.3~362 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=fb7c4ce95e66b6dbbaab6bdac01b0d20e51b3b10;p=users%2Fjedix%2Flinux-maple.git HID: debug: check length before copy_to_user() If our length is greater than the size of the buffer, we overflow the buffer Cc: stable@vger.kernel.org Signed-off-by: Daniel Rosenberg Reviewed-by: Benjamin Tissoires Signed-off-by: Jiri Kosina (cherry picked from commit 717adfdaf14704fd3ec7fa2c04520c0723247eac) Orabug: 29128165 CVE: CVE-2018-9516 Signed-off-by: Somasundaram Krishnasamy Reviewed-by: John.Donnelly Signed-off-by: Brian Maly --- diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c index 2886b645ced7..6c60f4b63d21 100644 --- a/drivers/hid/hid-debug.c +++ b/drivers/hid/hid-debug.c @@ -1152,6 +1152,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; @@ -1161,6 +1163,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; @@ -1168,7 +1172,9 @@ copy_rest: } list->head = 0; ret += len; - goto copy_rest; + count -= len; + if (count > 0) + goto copy_rest; } }