Skip to content

Commit ad90ece

Browse files
theihorAlexei Starovoitov
authored andcommitted
selftests/bpf: Fix out-of-bounds array access bugs reported by ASAN
- 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>
1 parent 3e711c8 commit ad90ece

3 files changed

Lines changed: 4 additions & 7 deletions

File tree

tools/testing/selftests/bpf/prog_tests/kmem_cache_iter.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,8 @@ void test_kmem_cache_iter(void)
104104
if (!ASSERT_GE(iter_fd, 0, "iter_create"))
105105
goto destroy;
106106

107-
memset(buf, 0, sizeof(buf));
108-
while (read(iter_fd, buf, sizeof(buf)) > 0) {
109-
/* Read out all contents */
110-
printf("%s", buf);
111-
}
107+
while (read(iter_fd, buf, sizeof(buf)) > 0)
108+
; /* Read out all contents */
112109

113110
/* Next reads should return 0 */
114111
ASSERT_EQ(read(iter_fd, buf, sizeof(buf)), 0, "read");

tools/testing/selftests/bpf/prog_tests/lwt_seg6local.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void test_lwt_seg6local(void)
117117
const char *ns1 = NETNS_BASE "1";
118118
const char *ns6 = NETNS_BASE "6";
119119
struct nstoken *nstoken = NULL;
120-
const char *foobar = "foobar";
120+
const char foobar[] = "foobar";
121121
ssize_t bytes;
122122
int sfd, cfd;
123123
char buf[7];

tools/testing/selftests/bpf/prog_tests/verifier_log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static int load_prog(struct bpf_prog_load_opts *opts, bool expect_load_error)
4747
static void verif_log_subtest(const char *name, bool expect_load_error, int log_level)
4848
{
4949
LIBBPF_OPTS(bpf_prog_load_opts, opts);
50-
char *exp_log, prog_name[16], op_name[32];
50+
char *exp_log, prog_name[24], op_name[32];
5151
struct test_log_buf *skel;
5252
struct bpf_program *prog;
5353
size_t fixed_log_sz;

0 commit comments

Comments
 (0)