Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Fix memory leak in msg_alloc_iov
@ 2026-07-07  8:14 Feng Yang
  2026-07-07 14:25 ` John Fastabend
  2026-07-07 18:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Feng Yang @ 2026-07-07  8:14 UTC (permalink / raw)
  To: andrii, eddyz87, ast, daniel, memxor, martin.lau, song,
	yonghong.song, jolsa, emil
  Cc: bpf, linux-kselftest, linux-kernel

From: Feng Yang <yangfeng@kylinos.cn>

In the msg_alloc_iov function, the iov pointer is only assigned to
msg->msg_iov after all memory allocations complete successfully.
Therefore, when a calloc failure triggers the unwind_iov cleanup branch,
we should use the local variable iov instead of msg->msg_iov.

Fixes: 753fb2ee0934 ("bpf: sockmap, add msg_peek tests to test_sockmap")
Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
---
 tools/testing/selftests/bpf/test_sockmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
index 3e6be455d158..aaf2050e8845 100644
--- a/tools/testing/selftests/bpf/test_sockmap.c
+++ b/tools/testing/selftests/bpf/test_sockmap.c
@@ -435,7 +435,7 @@ static int msg_alloc_iov(struct msghdr *msg,
 	return 0;
 unwind_iov:
 	for (i--; i >= 0 ; i--)
-		free(msg->msg_iov[i].iov_base);
+		free(iov[i].iov_base);
 	free(iov);
 	return -ENOMEM;
 }
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Fix memory leak in msg_alloc_iov
  2026-07-07  8:14 [PATCH bpf-next] selftests/bpf: Fix memory leak in msg_alloc_iov Feng Yang
@ 2026-07-07 14:25 ` John Fastabend
  2026-07-07 18:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: John Fastabend @ 2026-07-07 14:25 UTC (permalink / raw)
  To: Feng Yang
  Cc: andrii, eddyz87, ast, daniel, memxor, martin.lau, song,
	yonghong.song, jolsa, emil, bpf, linux-kselftest, linux-kernel

On Tue, Jul 07, 2026 at 04:14:34PM +0800, Feng Yang wrote:
>From: Feng Yang <yangfeng@kylinos.cn>
>
>In the msg_alloc_iov function, the iov pointer is only assigned to
>msg->msg_iov after all memory allocations complete successfully.
>Therefore, when a calloc failure triggers the unwind_iov cleanup branch,
>we should use the local variable iov instead of msg->msg_iov.
>
>Fixes: 753fb2ee0934 ("bpf: sockmap, add msg_peek tests to test_sockmap")
>Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
>---
> tools/testing/selftests/bpf/test_sockmap.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c
>index 3e6be455d158..aaf2050e8845 100644
>--- a/tools/testing/selftests/bpf/test_sockmap.c
>+++ b/tools/testing/selftests/bpf/test_sockmap.c
>@@ -435,7 +435,7 @@ static int msg_alloc_iov(struct msghdr *msg,
> 	return 0;
> unwind_iov:
> 	for (i--; i >= 0 ; i--)
>-		free(msg->msg_iov[i].iov_base);
>+		free(iov[i].iov_base);
> 	free(iov);
> 	return -ENOMEM;

Thanks,

Reviewed-by: John Fastabend <john.fastabend@gmail.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Fix memory leak in msg_alloc_iov
  2026-07-07  8:14 [PATCH bpf-next] selftests/bpf: Fix memory leak in msg_alloc_iov Feng Yang
  2026-07-07 14:25 ` John Fastabend
@ 2026-07-07 18:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-07-07 18:30 UTC (permalink / raw)
  To: Feng Yang
  Cc: andrii, eddyz87, ast, daniel, memxor, martin.lau, song,
	yonghong.song, jolsa, emil, bpf, linux-kselftest, linux-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Kumar Kartikeya Dwivedi <memxor@gmail.com>:

On Tue,  7 Jul 2026 16:14:34 +0800 you wrote:
> From: Feng Yang <yangfeng@kylinos.cn>
> 
> In the msg_alloc_iov function, the iov pointer is only assigned to
> msg->msg_iov after all memory allocations complete successfully.
> Therefore, when a calloc failure triggers the unwind_iov cleanup branch,
> we should use the local variable iov instead of msg->msg_iov.
> 
> [...]

Here is the summary with links:
  - [bpf-next] selftests/bpf: Fix memory leak in msg_alloc_iov
    https://git.kernel.org/bpf/bpf-next/c/f425a0443b7f

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] 3+ messages in thread

end of thread, other threads:[~2026-07-07 18:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-07  8:14 [PATCH bpf-next] selftests/bpf: Fix memory leak in msg_alloc_iov Feng Yang
2026-07-07 14:25 ` John Fastabend
2026-07-07 18:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox