]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
selftests/bpf: Fix out-of-bounds array access bugs reported by ASAN
authorIhor Solodrai <ihor.solodrai@linux.dev>
Mon, 23 Feb 2026 19:11:16 +0000 (11:11 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 24 Feb 2026 16:19:49 +0000 (08:19 -0800)
- kmem_cache_iter: remove unnecessary debug output
- lwt_seg6local: change the type of foobar to char[]
  - the sizeof(foobar) returned the pointer size and not a string
    length as intended
- verifier_log: increase prog_name buffer size in verif_log_subtest()
  - compiler has a conservative estimate of fixed_log_sz value, making
    ASAN complain on snprint() call

Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Link: https://lore.kernel.org/r/20260223191118.655185-1-ihor.solodrai@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/kmem_cache_iter.c
tools/testing/selftests/bpf/prog_tests/lwt_seg6local.c
tools/testing/selftests/bpf/prog_tests/verifier_log.c

index 6e35e13c20220ecb4d5a27ecde932a2c8c40fb8a..399fe9103f83e95171522d931798aa3817044192 100644 (file)
@@ -104,11 +104,8 @@ void test_kmem_cache_iter(void)
        if (!ASSERT_GE(iter_fd, 0, "iter_create"))
                goto destroy;
 
-       memset(buf, 0, sizeof(buf));
-       while (read(iter_fd, buf, sizeof(buf)) > 0) {
-               /* Read out all contents */
-               printf("%s", buf);
-       }
+       while (read(iter_fd, buf, sizeof(buf)) > 0)
+               ; /* Read out all contents */
 
        /* Next reads should return 0 */
        ASSERT_EQ(read(iter_fd, buf, sizeof(buf)), 0, "read");
index 3bc730b7c7fa0c4809c7c4ed6e00e7a7d12cb555..1b25d5c5f8fb8246d0801e2b0a8a60f5b11b53f5 100644 (file)
@@ -117,7 +117,7 @@ void test_lwt_seg6local(void)
        const char *ns1 = NETNS_BASE "1";
        const char *ns6 = NETNS_BASE "6";
        struct nstoken *nstoken = NULL;
-       const char *foobar = "foobar";
+       const char foobar[] = "foobar";
        ssize_t bytes;
        int sfd, cfd;
        char buf[7];
index 8337c6bc5b95b60e6423a331078992c4fb53fce1..aaa2854974c0a91cbbb9fc13ae0f966de1bcc818 100644 (file)
@@ -47,7 +47,7 @@ static int load_prog(struct bpf_prog_load_opts *opts, bool expect_load_error)
 static void verif_log_subtest(const char *name, bool expect_load_error, int log_level)
 {
        LIBBPF_OPTS(bpf_prog_load_opts, opts);
-       char *exp_log, prog_name[16], op_name[32];
+       char *exp_log, prog_name[24], op_name[32];
        struct test_log_buf *skel;
        struct bpf_program *prog;
        size_t fixed_log_sz;