Commit ad90eced authored by Ihor Solodrai's avatar Ihor Solodrai Committed by Alexei Starovoitov
Browse files

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: default avatarEduard Zingerman <eddyz87@gmail.com>
Signed-off-by: default avatarIhor Solodrai <ihor.solodrai@linux.dev>
Link: https://lore.kernel.org/r/20260223191118.655185-1-ihor.solodrai@linux.dev


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 3e711c8e
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -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");
+1 −1
Original line number Diff line number Diff line
@@ -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];
+1 −1
Original line number Diff line number Diff line
@@ -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;