From: Feng Yang <[email protected]>

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 <[email protected]>
---
 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 88c65ce5b018..ed9ad7ad3352 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -1516,15 +1516,13 @@ 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)
                return -ENOMEM;
 
        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


Reply via email to