2023-01-04 08:23:49

by Miaoqian Lin

[permalink] [raw]
Subject: [PATCH v2] um: vector: Fix memory leak in vector_config

kstrdup() return newly allocated copy of the string.
Call kfree() to release the memory when uml_parse_vector_ifspec() fails.

Fixes: 49da7e64f33e ("High Performance UML Vector Network Driver")
Signed-off-by: Miaoqian Lin <[email protected]>
---
changes in v2:
- only call kfree() when uml_parse_vector_ifspec() fails.
---
arch/um/drivers/vector_kern.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c
index ded7c47d2fbe..131b7cb29576 100644
--- a/arch/um/drivers/vector_kern.c
+++ b/arch/um/drivers/vector_kern.c
@@ -767,6 +767,7 @@ static int vector_config(char *str, char **error_out)

if (parsed == NULL) {
*error_out = "vector_config failed to parse parameters";
+ kfree(params);
return -EINVAL;
}

--
2.25.1


2023-01-04 08:46:10

by Anton Ivanov

[permalink] [raw]
Subject: Re: [PATCH v2] um: vector: Fix memory leak in vector_config



On 04/01/2023 08:14, Miaoqian Lin wrote:
> kstrdup() return newly allocated copy of the string.
> Call kfree() to release the memory when uml_parse_vector_ifspec() fails.
>
> Fixes: 49da7e64f33e ("High Performance UML Vector Network Driver")
> Signed-off-by: Miaoqian Lin <[email protected]>
> ---
> changes in v2:
> - only call kfree() when uml_parse_vector_ifspec() fails.
> ---
> arch/um/drivers/vector_kern.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c
> index ded7c47d2fbe..131b7cb29576 100644
> --- a/arch/um/drivers/vector_kern.c
> +++ b/arch/um/drivers/vector_kern.c
> @@ -767,6 +767,7 @@ static int vector_config(char *str, char **error_out)
>
> if (parsed == NULL) {
> *error_out = "vector_config failed to parse parameters";
> + kfree(params);
> return -EINVAL;
> }
>

Acked-By: Anton Ivanov <[email protected]>

--
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

2023-01-04 10:46:25

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH v2] um: vector: Fix memory leak in vector_config

On Wed, Jan 4, 2023 at 9:18 AM Miaoqian Lin <[email protected]> wrote:
> kstrdup() return newly allocated copy of the string.
> Call kfree() to release the memory when uml_parse_vector_ifspec() fails.
>
> Fixes: 49da7e64f33e ("High Performance UML Vector Network Driver")
> Signed-off-by: Miaoqian Lin <[email protected]>
> ---
> changes in v2:
> - only call kfree() when uml_parse_vector_ifspec() fails.

Reviewed-by: Geert Uytterhoeven <[email protected]>

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds