Revert "CHROMIUM: usb: gadget: configfs: Fix KASAN use-after-free"

This reverts commit d7b2c97fd0.

Relpaced by commit c3a4fc9f37 ("usb: gadget: configfs: Fix KASAN use-after-free").

Signed-off-by: Tao Huang <huangtao@rock-chips.com>
Change-Id: I838bfe4ef5d3a7ba3ce4296f76434cfc3d33c991
This commit is contained in:
Tao Huang
2021-06-10 18:37:43 +08:00
parent 51d8f2cdef
commit d42add27c8

View File

@@ -140,28 +140,21 @@ struct gadget_config_name {
struct list_head list;
};
#define MAX_USB_STRING_LEN 126
#define MAX_USB_STRING_WITH_NULL_LEN (MAX_USB_STRING_LEN+1)
static int usb_string_copy(const char *s, char **s_copy)
{
int ret;
char *str;
char *copy = *s_copy;
ret = strlen(s);
if (ret > MAX_USB_STRING_LEN)
if (ret > 126)
return -EOVERFLOW;
if (copy) {
str = copy;
} else {
str = kmalloc(MAX_USB_STRING_WITH_NULL_LEN, GFP_KERNEL);
if (!str)
return -ENOMEM;
}
strncpy(str, s, MAX_USB_STRING_WITH_NULL_LEN);
str = kstrdup(s, GFP_KERNEL);
if (!str)
return -ENOMEM;
if (str[ret - 1] == '\n')
str[ret - 1] = '\0';
kfree(copy);
*s_copy = str;
return 0;
}