Skip to contentSkip to conversation

um: vector: Fix memory leak in vector_config

PATCH Superseded Miaoqian Lin 3 participants 5 messages Dec 29, 2022 – Jan 3, 2023 User-mode Linux (UML)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 um: vector: Fix memory leak in vector_config

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

Fixes 49da7e64f33e ("High Performance UML Vector Network Driver")
---
 arch/um/drivers/vector_kern.c | 1 +
 1 file changed, 1 insertion(+)
arch/um/drivers/vector_kern.c +1 -0
index ded7c47d2fbe..78f32005dd90 100644
@@ -765,6 +765,7 @@ static int vector_config(char *str, char **error_out)
 
 	parsed = uml_parse_vector_ifspec(params);
 
+	kfree(params);
 	if (parsed == NULL) {
 		*error_out = "vector_config failed to parse parameters";
 		return -EINVAL;
Signature · 7 lines
2.25.1


_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
#1 lore raw

Hi Miaoqian,

Quoted 5 lines · Miaoqian Lin

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

Fixes 49da7e64f33e ("High Performance UML Vector Network Driver")

Thanks for your patch!

arch/um/drivers/vector_kern.c static int vector_config(char *str, char **error_out) · line 768

Quoted 7 lines
arch/um/drivers/vector_kern.c +1 -0
@@ -765,6 +765,7 @@ static int vector_config(char *str, char **error_out)
 
        parsed = uml_parse_vector_ifspec(params);
 
+       kfree(params);

Are you sure the memory pointed to by "params" is no longer used? "parsed" seems to contain pointers pointing to (parts of) the string pointed to by "params", so it cannot be freed.

arch/um/drivers/vector_kern.c static int vector_config(char *str, char **error_out) · line 771

Quoted 3 lines
arch/um/drivers/vector_kern.c +0 -0
        if (parsed == NULL) {
                *error_out = "vector_config failed to parse parameters";
                return -EINVAL;

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

maintainer
#2 lore raw
Quoted 14 lines · Geert Uytterhoeven

Hi Miaoqian,

Quoted 5 lines · Miaoqian Lin

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

Fixes 49da7e64f33e ("High Performance UML Vector Network Driver")

Thanks for your patch!

Quoted 4 lines
arch/um/drivers/vector_kern.c +0 -0
@@ -765,6 +765,7 @@ static int vector_config(char *str, char **error_out)
 
Quoted 6 lines

arch/um/drivers/vector_kern.c static int vector_config(char *str, char **error_out) · line 768

Quoted 3 lines
arch/um/drivers/vector_kern.c +1 -0
         parsed = uml_parse_vector_ifspec(params);
 
+       kfree(params);

Are you sure the memory pointed to by "params" is no longer used? "parsed" seems to contain pointers pointing to (parts of) the string pointed to by "params", so it cannot be freed.

+1.

I was just about to send the same comment.

Quoted 15 lines

arch/um/drivers/vector_kern.c static int vector_config(char *str, char **error_out) · line 771

Quoted 4 lines
arch/um/drivers/vector_kern.c +0 -0
         if (parsed == NULL) {
                 *error_out = "vector_config failed to parse parameters";
                 return -EINVAL;

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

Signature · 3 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/
#3 lore raw
Quoted 18 lines · Anton Ivanov
Quoted 16 lines · Geert Uytterhoeven

Hi Miaoqian,

Quoted 5 lines · Miaoqian Lin

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

Fixes 49da7e64f33e ("High Performance UML Vector Network Driver")

Thanks for your patch!

Quoted 6 lines
arch/um/drivers/vector_kern.c +0 -0
@@ -765,6 +765,7 @@ static int vector_config(char *str, char **error_out)
 
          parsed = uml_parse_vector_ifspec(params);
 
Quoted 9 lines
Quoted 4 lines

arch/um/drivers/vector_kern.c static int vector_config(char *str, char **error_out) · line 768

Quoted 1 line
arch/um/drivers/vector_kern.c +1 -0
+       kfree(params);

Are you sure the memory pointed to by "params" is no longer used? "parsed" seems to contain pointers pointing to (parts of) the string pointed to by "params", so it cannot be freed.

+1.

I was just about to send the same comment.

Oh yes, thanks for spotting this. We should only perform release when uml_parse_vector_ifspec() fails (returns NULL). In this situation, 'params' is no longer used. Do you agree?

Thanks,

Quoted 15 lines
Quoted 15 lines

arch/um/drivers/vector_kern.c static int vector_config(char *str, char **error_out) · line 771

Quoted 4 lines
arch/um/drivers/vector_kern.c +0 -0
          if (parsed == NULL) {
                  *error_out = "vector_config failed to parse parameters";
                  return -EINVAL;

Gr{oetje,eeting}s,

                         Geert

Signature · 5 lines
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
#4 lore raw

Hi Miaoqian,

Quoted 21 lines · Miaoqian Lin
Quoted 20 lines · Anton Ivanov
Quoted 18 lines · Geert Uytterhoeven
Quoted 5 lines · Miaoqian Lin

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

Fixes 49da7e64f33e ("High Performance UML Vector Network Driver")

Thanks for your patch!

arch/um/drivers/vector_kern.c static int vector_config(char *str, char **error_out) · line 768

Quoted 7 lines
arch/um/drivers/vector_kern.c +1 -0
@@ -765,6 +765,7 @@ static int vector_config(char *str, char **error_out)
 
         parsed = uml_parse_vector_ifspec(params);
 
+       kfree(params);

Are you sure the memory pointed to by "params" is no longer used? "parsed" seems to contain pointers pointing to (parts of) the string pointed to by "params", so it cannot be freed.

Quoted 5 lines
Quoted 4 lines

+1.

I was just about to send the same comment.

Oh yes, thanks for spotting this. We should only perform release when uml_parse_vector_ifspec() fails (returns NULL). In this situation, 'params' is no longer used. Do you agree?

Yes, that sounds fine to me.

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