BPF List
 help / color / mirror / Atom feed
From: Feng Yang <yangfeng59949@163.com>
To: andrii@kernel.org, eddyz87@gmail.com, ast@kernel.org,
	daniel@iogearbox.net, memxor@gmail.com, martin.lau@linux.dev,
	song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org,
	emil@etsalapatis.com
Cc: bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v3 bpf-next 4/5] selftests/bpf: Use calloc to allocate subtest_states
Date: Thu, 23 Jul 2026 16:50:59 +0800	[thread overview]
Message-ID: <20260723085100.482147-5-yangfeng59949@163.com> (raw)
In-Reply-To: <20260723085100.482147-1-yangfeng59949@163.com>

From: Feng Yang <yangfeng@kylinos.cn>

An early return triggered by read_prog_test_msg leaves uninitialized elements,
which leads to memory corruption during free_test_states cleanup.

Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
---
 tools/testing/selftests/bpf/test_progs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index 301c6e11ceaf..07da45230c4b 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -1516,7 +1516,7 @@ static int dispatch_thread_send_subtests(int sock_fd, struct test_state *state)
 	struct subtest_state *subtest_state;
 	int subtest_num = state->subtest_num;
 
-	state->subtest_states = malloc(subtest_num * sizeof(*subtest_state));
+	state->subtest_states = calloc(subtest_num, sizeof(*subtest_state));
 	if (!state->subtest_states) {
 		state->subtest_num = 0;
 		return -ENOMEM;
@@ -1525,8 +1525,6 @@ static int dispatch_thread_send_subtests(int sock_fd, struct test_state *state)
 	for (int i = 0; i < subtest_num; i++) {
 		subtest_state = &state->subtest_states[i];
 
-		memset(subtest_state, 0, sizeof(*subtest_state));
-
 		if (read_prog_test_msg(sock_fd, &msg, MSG_SUBTEST_DONE))
 			return 1;
 
-- 
2.43.0


  parent reply	other threads:[~2026-07-23  8:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23  8:50 [PATCH v3 bpf-next 0/5] selftests/bpf: Fix several issues in test_progs.c Feng Yang
2026-07-23  8:50 ` [PATCH v3 bpf-next 1/5] selftests/bpf: Fix double free of subtest_state->name Feng Yang
2026-07-23  8:50 ` [PATCH v3 bpf-next 2/5] selftests/bpf: Fix incorrect error checking for pthread_create Feng Yang
2026-07-23  8:50 ` [PATCH v3 bpf-next 3/5] selftests/bpf: Fix missing allocation null checks in test_progs.c Feng Yang
2026-07-23  9:17   ` sashiko-bot
2026-07-24  7:32     ` Feng Yang
2026-07-23  8:50 ` Feng Yang [this message]
2026-07-23  8:51 ` [PATCH v3 bpf-next 5/5] selftests/bpf: Fix memory leak on subtest_states reallocation Feng Yang
2026-07-24 21:33 ` [PATCH v3 bpf-next 0/5] selftests/bpf: Fix several issues in test_progs.c patchwork-bot+netdevbpf
     [not found] <20260723092855.0EAB01F00A3A@smtp.kernel.org>
2026-07-24  7:39 ` [PATCH v3 bpf-next 4/5] selftests/bpf: Use calloc to allocate subtest_states Feng Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260723085100.482147-5-yangfeng59949@163.com \
    --to=yangfeng59949@163.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox