Skip to content

Commit ebb2342

Browse files
Kars Muldergregkh
authored andcommitted
usb: core: fix quirks_param_set() writing to a const pointer
[ Upstream commit b1b6bed ] The function quirks_param_set() takes as argument a const char* pointer to the new value of the usbcore.quirks parameter. It then casts this pointer to a non-const char* pointer and passes it to the strsep() function, which overwrites the value. Fix this by creating a copy of the value using kstrdup() and letting that copy be written to by strsep(). Fixes: 027bd6c ("usb: core: Add "quirks" parameter for usbcore") Signed-off-by: Kars Mulder <kerneldev@karsmulder.nl> Link: https://lore.kernel.org/r/5ee2-5f048a00-21-618c5c00@230659773 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ac780c2 commit ebb2342

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

drivers/usb/core/quirks.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,23 @@ static unsigned int quirk_count;
2525

2626
static char quirks_param[128];
2727

28-
static int quirks_param_set(const char *val, const struct kernel_param *kp)
28+
static int quirks_param_set(const char *value, const struct kernel_param *kp)
2929
{
30-
char *p, *field;
30+
char *val, *p, *field;
3131
u16 vid, pid;
3232
u32 flags;
3333
size_t i;
3434
int err;
3535

36+
val = kstrdup(value, GFP_KERNEL);
37+
if (!val)
38+
return -ENOMEM;
39+
3640
err = param_set_copystring(val, kp);
37-
if (err)
41+
if (err) {
42+
kfree(val);
3843
return err;
44+
}
3945

4046
mutex_lock(&quirk_mutex);
4147

@@ -60,10 +66,11 @@ static int quirks_param_set(const char *val, const struct kernel_param *kp)
6066
if (!quirk_list) {
6167
quirk_count = 0;
6268
mutex_unlock(&quirk_mutex);
69+
kfree(val);
6370
return -ENOMEM;
6471
}
6572

66-
for (i = 0, p = (char *)val; p && *p;) {
73+
for (i = 0, p = val; p && *p;) {
6774
/* Each entry consists of VID:PID:flags */
6875
field = strsep(&p, ":");
6976
if (!field)
@@ -144,6 +151,7 @@ static int quirks_param_set(const char *val, const struct kernel_param *kp)
144151

145152
unlock:
146153
mutex_unlock(&quirk_mutex);
154+
kfree(val);
147155

148156
return 0;
149157
}

0 commit comments

Comments
 (0)