]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests/bpf: Fix realloc size in bpf_get_addrs
authorJiri Olsa <jolsa@kernel.org>
Wed, 1 Oct 2025 12:22:23 +0000 (14:22 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 1 Oct 2025 20:37:30 +0000 (13:37 -0700)
We will segfault once we call realloc in bpf_get_addrs due to
wrong size argument.

Fixes: 6302bdeb91df ("selftests/bpf: Add a kprobe_multi subtest to use addrs instead of syms")
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/trace_helpers.c

index 171987627f3a7b062514db96d7b355ef5bff89f6..eeaab7013ca2fe5de12210e435dd48aa5d826ddc 100644 (file)
@@ -732,7 +732,7 @@ int bpf_get_addrs(unsigned long **addrsp, size_t *cntp, bool kernel)
 
                if (cnt == max_cnt) {
                        max_cnt += inc_cnt;
-                       tmp_addrs = realloc(addrs, max_cnt);
+                       tmp_addrs = realloc(addrs, max_cnt * sizeof(long));
                        if (!tmp_addrs) {
                                err = -ENOMEM;
                                goto error;