selftests/bpf: pass sanitizer flags to linker through LDFLAGS
Subsystems (4)
Andrii Nakryiko
maintainerPATCH 1/9 selftests/bpf: pass sanitizer flags to linker through LDFLAGS
When adding -fsanitize=address to SAN_CFLAGS, it has to be passed both to compiler through CFLAGS as well as linker through LDFLAGS. Add SAN_CFLAGS into LDFLAGS to allow building selftests with ASAN.
--- tools/testing/selftests/bpf/Makefile | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/Makefile +1 -0
@@ -26,6 +26,7 @@ CFLAGS += -g -O0 -rdynamic -Wall $(GENFLAGS) $(SAN_CFLAGS) \ -I$(TOOLSINCDIR) -I$(APIDIR) -I$(OUTPUT) \ -Dbpf_prog_load=bpf_prog_test_load \ -Dbpf_load_program=bpf_test_load_program +LDFLAGS += $(SAN_CFLAGS) LDLIBS += -lcap -lelf -lz -lrt -lpthread # Silence some warnings when compiled with clang
Signature · 1 line
2.30.2
Andrii Nakryiko
maintainerPATCH 2/9 libbpf: free up resources used by inner map definition
It's not enough to just free(map->inner_map), as inner_map itself can have extra memory allocated, like map name.
--- tools/lib/bpf/libbpf.c | 1 + 1 file changed, 1 insertion(+)
tools/lib/bpf/libbpf.c +1 -0
@@ -9053,6 +9053,7 @@ int bpf_map__set_inner_map_fd(struct bpf_map *map, int fd)pr_warn ("error: inner_map_fd already specified\n" );return libbpf_err (-EINVAL ); } +bpf_map__destroy (map->inner_map);zfree (&map->inner_map); map->inner_map_fd = fd;return 0 ;
Signature · 1 line
2.30.2
Andrii Nakryiko
maintainerPATCH 3/9 selftests/bpf: fix memory leaks in btf_type_c_dump() helper
In reply to Andrii NakryikoFree up memory and resources used by temporary allocated memstream and btf_dump instance.
--- tools/testing/selftests/bpf/btf_helpers.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/btf_helpers.c +7 -2
@@ -251,18 +251,23 @@ const char *btf_type_c_dump(const struct btf *btf) d =btf_dump__new (btf,NULL , &opts, btf_dump_printf);if (libbpf_get_error (d)) {fprintf (stderr,"Failed to create btf_dump instance: %ld\n" ,libbpf_get_error (d)); -return NULL ; + goto err_out; }for (i =1 ; i <btf__type_cnt (btf); i++) { err =btf_dump__dump_type (d, i);if (err) {fprintf (stderr,"Failed to dump type [%d]: %d\n" , i, err); -return NULL ; + goto err_out; } } +btf_dump__free (d);fflush (buf_file);fclose (buf_file);return buf; +err_out: +btf_dump__free (d); +fclose (buf_file); +return NULL ; }
Signature · 1 line
2.30.2
Andrii Nakryiko
maintainerPATCH 4/9 selftests/bpf: free per-cpu values array in bpf_iter selftest
In reply to Andrii NakryikoArray holding per-cpu values wasn't freed. Fix that.
--- tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +1 -0
@@ -770,6 +770,7 @@ static void test_bpf_percpu_hash_map(void)bpf_link__destroy (link); out:bpf_iter_bpf_percpu_hash_map__destroy (skel); +free (val); }static void test_bpf_array_map (void )
Signature · 1 line
2.30.2
Andrii Nakryiko
maintainerPATCH 5/9 selftests/bpf: free inner strings index in btf selftest
In reply to Andrii NakryikoInner array of allocated strings wasn't freed on success. Now it's always freed.
--- tools/testing/selftests/bpf/prog_tests/btf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/prog_tests/btf.c +2 -4
@@ -4046,11 +4046,9 @@ static void *btf_raw_create(const struct btf_header *hdr, next_str_idx < strs_cnt ? strs_idx[next_str_idx] :NULL ; done: +free (strs_idx);if (err) { -if (raw_btf) -free (raw_btf); -if (strs_idx) -free (strs_idx); +free (raw_btf);return NULL ; }return raw_btf;
Signature · 1 line
2.30.2
Andrii Nakryiko
maintainerPATCH 6/9 selftests/bpf: clean up btf and btf_dump in dump_datasec test
In reply to Andrii NakryikoFree up used resources at the end and on error. Also make it more obvious that there is btf__parse() call that creates struct btf instance.
--- tools/testing/selftests/bpf/prog_tests/btf_dump.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/btf_dump.c +6 -2
@@ -814,21 +814,25 @@ static void test_btf_datasec(struct btf *btf, struct btf_dump *d, char *str,static void test_btf_dump_datasec_data (char *str) { -struct btf *btf =btf__parse ("xdping_kern.o" ,NULL ); +struct btf *btf;struct btf_dump_opts opts = { .ctx = str };char license[4 ] ="GPL" ;struct btf_dump *d; + btf =btf__parse ("xdping_kern.o" ,NULL );if (!ASSERT_OK_PTR (btf,"xdping_kern.o BTF not found" ))return ; d =btf_dump__new (btf,NULL , &opts, btf_dump_snprintf);if (!ASSERT_OK_PTR (d,"could not create BTF dump" )) -return ; + goto out;test_btf_datasec (btf, d, str,"license" ,"SEC(\"license\") char[4] _license = (char[4])['G','P','L',];" , license,sizeof (license)); +out: +btf_dump__free (d); +btf__free (btf); }void test_btf_dump () {
Signature · 1 line
2.30.2
Andrii Nakryiko
maintainerPATCH 7/9 selftests/bpf: avoid duplicate btf__parse() call
In reply to Andrii Nakryikobtf__parse() is repeated after successful setup, leaving the first instance leaked. Remove redundant and premature call.
--- tools/testing/selftests/bpf/prog_tests/core_reloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/core_reloc.c +1 -1
@@ -433,7 +433,7 @@ static int setup_type_id_case_local(struct core_reloc_test_case *test)static int setup_type_id_case_success (struct core_reloc_test_case *test) {struct core_reloc_type_id_output *exp = (void *)test->output; -struct btf *targ_btf =btf__parse (test->btf_src_file,NULL ); +struct btf *targ_btf;int err; err =setup_type_id_case_local (test);
Signature · 1 line
2.30.2
Andrii Nakryiko
maintainerPATCH 8/9 selftests/bpf: destroy XDP link correctly
In reply to Andrii Nakryikobpf_link__detach() was confused with bpf_link__destroy() and leaves leaked FD in the process. Fix the problem.
--- tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/migrate_reuseport.c +2 -2
@@ -204,8 +204,8 @@ static int pass_ack(struct migrate_reuseport_test_case *test_case) {int err; - err =bpf_link__detach (test_case->link); -if (!ASSERT_OK (err,"bpf_link__detach" )) + err =bpf_link__destroy (test_case->link); +if (!ASSERT_OK (err,"bpf_link__destroy" ))return -1 ; test_case->link =NULL ;
Signature · 1 line
2.30.2
Andrii Nakryiko
maintainerPATCH 9/9 selftests/bpf: fix bpf_object leak in skb_ctx selftest
In reply to Andrii Nakryikoskb_ctx selftest didn't close bpf_object implicitly allocated by bpf_prog_test_load() helper. Fix the problem by explicitly calling bpf_object__close() at the end of the test.
--- tools/testing/selftests/bpf/prog_tests/skb_ctx.c | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/bpf/prog_tests/skb_ctx.c +2 -0
@@ -111,4 +111,6 @@ void test_skb_ctx(void)"ctx_out_mark" ,"skb->mark == %u, expected %d\n" , skb.mark, 10); + +bpf_object__close (obj); }
Signature · 1 line
2.30.2