Skip to content

Commit 6d3c721

Browse files
lag-linarogregkh
authored andcommitted
usb: gadget: configfs: Prevent OOB read/write in usb_string_copy()
Userspace provided string 's' could trivially have the length zero. Left unchecked this will firstly result in an OOB read in the form `if (str[0 - 1] == '\n') followed closely by an OOB write in the form `str[0 - 1] = '\0'`. There is already a validating check to catch strings that are too long. Let's supply an additional check for invalid strings that are too short. Signed-off-by: Lee Jones <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2bf35ea commit 6d3c721

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/usb/gadget/configfs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,12 @@ static int usb_string_copy(const char *s, char **s_copy)
115115
int ret;
116116
char *str;
117117
char *copy = *s_copy;
118+
118119
ret = strlen(s);
119120
if (ret > USB_MAX_STRING_LEN)
120121
return -EOVERFLOW;
122+
if (ret < 1)
123+
return -EINVAL;
121124

122125
if (copy) {
123126
str = copy;

0 commit comments

Comments
 (0)