* [PATCH bpf-next 1/2] selftests/bpf: Free strdup memory in test_sockmap
2024-04-29 7:07 [PATCH bpf-next 0/2] Free strdup memory in selftests Geliang Tang
@ 2024-04-29 7:07 ` Geliang Tang
2024-04-29 15:53 ` Yonghong Song
2024-04-29 19:56 ` John Fastabend
2024-04-29 7:07 ` [PATCH bpf-next 2/2] selftests/bpf: Free strdup memory in veristat Geliang Tang
2024-04-29 23:20 ` [PATCH bpf-next 0/2] Free strdup memory in selftests patchwork-bot+netdevbpf
2 siblings, 2 replies; 8+ messages in thread
From: Geliang Tang @ 2024-04-29 7:07 UTC (permalink / raw)
To: Andrii Nakryiko, Eduard Zingerman, Mykola Lysenko,
Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Shuah Khan, Jakub Sitnicki
Cc: Geliang Tang, bpf, linux-kselftest, Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
The strdup() function returns a pointer to a new string which is a
duplicate of the string "ptr". Memory for the new string is obtained
with malloc(), and need to be freed with free().
This patch adds these missing "free(ptr)" in check_whitelist() and
check_blacklist() to avoid memory leaks in test_sockmap.c.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
tools/testing/selftests/bpf/test_sockmap.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
index 43612de44fbf..92752f5eeded 100644
--- a/tools/testing/selftests/bpf/test_sockmap.c
+++ b/tools/testing/selftests/bpf/test_sockmap.c
@@ -1887,10 +1887,13 @@ static int check_whitelist(struct _test *t, struct sockmap_options *opt)
while (entry) {
if ((opt->prepend && strstr(opt->prepend, entry) != 0) ||
strstr(opt->map, entry) != 0 ||
- strstr(t->title, entry) != 0)
+ strstr(t->title, entry) != 0) {
+ free(ptr);
return 0;
+ }
entry = strtok(NULL, ",");
}
+ free(ptr);
return -EINVAL;
}
@@ -1907,10 +1910,13 @@ static int check_blacklist(struct _test *t, struct sockmap_options *opt)
while (entry) {
if ((opt->prepend && strstr(opt->prepend, entry) != 0) ||
strstr(opt->map, entry) != 0 ||
- strstr(t->title, entry) != 0)
+ strstr(t->title, entry) != 0) {
+ free(ptr);
return 0;
+ }
entry = strtok(NULL, ",");
}
+ free(ptr);
return -EINVAL;
}
--
2.40.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH bpf-next 1/2] selftests/bpf: Free strdup memory in test_sockmap
2024-04-29 7:07 ` [PATCH bpf-next 1/2] selftests/bpf: Free strdup memory in test_sockmap Geliang Tang
@ 2024-04-29 15:53 ` Yonghong Song
2024-04-29 19:56 ` John Fastabend
1 sibling, 0 replies; 8+ messages in thread
From: Yonghong Song @ 2024-04-29 15:53 UTC (permalink / raw)
To: Geliang Tang, Andrii Nakryiko, Eduard Zingerman, Mykola Lysenko,
Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Shuah Khan, Jakub Sitnicki
Cc: Geliang Tang, bpf, linux-kselftest
On 4/29/24 12:07 AM, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> The strdup() function returns a pointer to a new string which is a
> duplicate of the string "ptr". Memory for the new string is obtained
> with malloc(), and need to be freed with free().
>
> This patch adds these missing "free(ptr)" in check_whitelist() and
> check_blacklist() to avoid memory leaks in test_sockmap.c.
>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH bpf-next 1/2] selftests/bpf: Free strdup memory in test_sockmap
2024-04-29 7:07 ` [PATCH bpf-next 1/2] selftests/bpf: Free strdup memory in test_sockmap Geliang Tang
2024-04-29 15:53 ` Yonghong Song
@ 2024-04-29 19:56 ` John Fastabend
1 sibling, 0 replies; 8+ messages in thread
From: John Fastabend @ 2024-04-29 19:56 UTC (permalink / raw)
To: Geliang Tang, Andrii Nakryiko, Eduard Zingerman, Mykola Lysenko,
Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Shuah Khan, Jakub Sitnicki
Cc: Geliang Tang, bpf, linux-kselftest, Geliang Tang
Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> The strdup() function returns a pointer to a new string which is a
> duplicate of the string "ptr". Memory for the new string is obtained
> with malloc(), and need to be freed with free().
>
> This patch adds these missing "free(ptr)" in check_whitelist() and
> check_blacklist() to avoid memory leaks in test_sockmap.c.
>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
Acked-by: John Fastabend <john.fastabend@gmail.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH bpf-next 2/2] selftests/bpf: Free strdup memory in veristat
2024-04-29 7:07 [PATCH bpf-next 0/2] Free strdup memory in selftests Geliang Tang
2024-04-29 7:07 ` [PATCH bpf-next 1/2] selftests/bpf: Free strdup memory in test_sockmap Geliang Tang
@ 2024-04-29 7:07 ` Geliang Tang
2024-04-29 15:53 ` Yonghong Song
2024-04-29 19:57 ` John Fastabend
2024-04-29 23:20 ` [PATCH bpf-next 0/2] Free strdup memory in selftests patchwork-bot+netdevbpf
2 siblings, 2 replies; 8+ messages in thread
From: Geliang Tang @ 2024-04-29 7:07 UTC (permalink / raw)
To: Andrii Nakryiko, Eduard Zingerman, Mykola Lysenko,
Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Shuah Khan, Jakub Sitnicki
Cc: Geliang Tang, bpf, linux-kselftest, Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
The strdup() function returns a pointer to a new string which is a
duplicate of the string "input". Memory for the new string is obtained
with malloc(), and need to be freed with free().
This patch adds these missing "free(input)" in parse_stats() to avoid
memory leak in veristat.c.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
tools/testing/selftests/bpf/veristat.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/veristat.c b/tools/testing/selftests/bpf/veristat.c
index 244d4996e06e..b2854238d4a0 100644
--- a/tools/testing/selftests/bpf/veristat.c
+++ b/tools/testing/selftests/bpf/veristat.c
@@ -792,10 +792,13 @@ static int parse_stats(const char *stats_str, struct stat_specs *specs)
while ((next = strtok_r(state ? NULL : input, ",", &state))) {
err = parse_stat(next, specs);
- if (err)
+ if (err) {
+ free(input);
return err;
+ }
}
+ free(input);
return 0;
}
--
2.40.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH bpf-next 2/2] selftests/bpf: Free strdup memory in veristat
2024-04-29 7:07 ` [PATCH bpf-next 2/2] selftests/bpf: Free strdup memory in veristat Geliang Tang
@ 2024-04-29 15:53 ` Yonghong Song
2024-04-29 19:57 ` John Fastabend
1 sibling, 0 replies; 8+ messages in thread
From: Yonghong Song @ 2024-04-29 15:53 UTC (permalink / raw)
To: Geliang Tang, Andrii Nakryiko, Eduard Zingerman, Mykola Lysenko,
Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Shuah Khan, Jakub Sitnicki
Cc: Geliang Tang, bpf, linux-kselftest
On 4/29/24 12:07 AM, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> The strdup() function returns a pointer to a new string which is a
> duplicate of the string "input". Memory for the new string is obtained
> with malloc(), and need to be freed with free().
>
> This patch adds these missing "free(input)" in parse_stats() to avoid
> memory leak in veristat.c.
>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH bpf-next 2/2] selftests/bpf: Free strdup memory in veristat
2024-04-29 7:07 ` [PATCH bpf-next 2/2] selftests/bpf: Free strdup memory in veristat Geliang Tang
2024-04-29 15:53 ` Yonghong Song
@ 2024-04-29 19:57 ` John Fastabend
1 sibling, 0 replies; 8+ messages in thread
From: John Fastabend @ 2024-04-29 19:57 UTC (permalink / raw)
To: Geliang Tang, Andrii Nakryiko, Eduard Zingerman, Mykola Lysenko,
Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Shuah Khan, Jakub Sitnicki
Cc: Geliang Tang, bpf, linux-kselftest, Geliang Tang
Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> The strdup() function returns a pointer to a new string which is a
> duplicate of the string "input". Memory for the new string is obtained
> with malloc(), and need to be freed with free().
>
> This patch adds these missing "free(input)" in parse_stats() to avoid
> memory leak in veristat.c.
>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
Acked-by: John Fastabend <john.fastabend@gmail.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH bpf-next 0/2] Free strdup memory in selftests
2024-04-29 7:07 [PATCH bpf-next 0/2] Free strdup memory in selftests Geliang Tang
2024-04-29 7:07 ` [PATCH bpf-next 1/2] selftests/bpf: Free strdup memory in test_sockmap Geliang Tang
2024-04-29 7:07 ` [PATCH bpf-next 2/2] selftests/bpf: Free strdup memory in veristat Geliang Tang
@ 2024-04-29 23:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-29 23:20 UTC (permalink / raw)
To: Geliang Tang
Cc: andrii, eddyz87, mykolal, ast, daniel, martin.lau, song,
yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa, shuah,
jakub, tanggeliang, bpf, linux-kselftest
Hello:
This series was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Mon, 29 Apr 2024 15:07:32 +0800 you wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> Two fixes to free strdup memory in selftests to avoid memory leaks.
>
> Geliang Tang (2):
> selftests/bpf: Free strdup memory in test_sockmap
> selftests/bpf: Free strdup memory in veristat
>
> [...]
Here is the summary with links:
- [bpf-next,1/2] selftests/bpf: Free strdup memory in test_sockmap
https://git.kernel.org/bpf/bpf-next/c/237c522c1d5d
- [bpf-next,2/2] selftests/bpf: Free strdup memory in veristat
https://git.kernel.org/bpf/bpf-next/c/25927d0a1bec
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 8+ messages in thread