mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-29 15:14:18 +08:00
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 <drosen@google.com> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
This commit is contained in:
parent
8f732850df
commit
717adfdaf1
@ -1154,6 +1154,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;
|
||||
@ -1163,6 +1165,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;
|
||||
@ -1170,6 +1174,8 @@ copy_rest:
|
||||
}
|
||||
list->head = 0;
|
||||
ret += len;
|
||||
count -= len;
|
||||
if (count > 0)
|
||||
goto copy_rest;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user