Skip to content

Commit 50b4d98

Browse files
drosen-googlegregkh
authored andcommitted
HID: debug: check length before copy_to_user()
commit 717adfd upstream. If our length is greater than the size of the buffer, we overflow the buffer Cc: [email protected] Signed-off-by: Daniel Rosenberg <[email protected]> Reviewed-by: Benjamin Tissoires <[email protected]> Signed-off-by: Jiri Kosina <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c1d21fe commit 50b4d98

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/hid/hid-debug.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,8 @@ static ssize_t hid_debug_events_read(struct file *file, char __user *buffer,
11541154
goto out;
11551155
if (list->tail > list->head) {
11561156
len = list->tail - list->head;
1157+
if (len > count)
1158+
len = count;
11571159

11581160
if (copy_to_user(buffer + ret, &list->hid_debug_buf[list->head], len)) {
11591161
ret = -EFAULT;
@@ -1163,14 +1165,18 @@ static ssize_t hid_debug_events_read(struct file *file, char __user *buffer,
11631165
list->head += len;
11641166
} else {
11651167
len = HID_DEBUG_BUFSIZE - list->head;
1168+
if (len > count)
1169+
len = count;
11661170

11671171
if (copy_to_user(buffer, &list->hid_debug_buf[list->head], len)) {
11681172
ret = -EFAULT;
11691173
goto out;
11701174
}
11711175
list->head = 0;
11721176
ret += len;
1173-
goto copy_rest;
1177+
count -= len;
1178+
if (count > 0)
1179+
goto copy_rest;
11741180
}
11751181

11761182
}

0 commit comments

Comments
 (0)