Skip to content

Commit fd9c40c

Browse files
author
Alexei Starovoitov
committed
Merge branch 'test_progs-asan'
Andrii Nakryiko says: ==================== Add necessary infra to build selftests with ASAN (or any other sanitizer). Fix a bunch of found memory leaks and other memory access issues. v1->v2: - don't add ASAN flavor, but allow extra flags for build (Alexei); - fix few more found issues, which somehow were missed first time. ==================== Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2 parents 3271e8f + e4e8f4d commit fd9c40c

File tree

9 files changed

+181
-159
lines changed

9 files changed

+181
-159
lines changed

tools/lib/bpf/hashmap.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ struct hashmap *hashmap__new(hashmap_hash_fn hash_fn,
5959

6060
void hashmap__clear(struct hashmap *map)
6161
{
62+
struct hashmap_entry *cur, *tmp;
63+
int bkt;
64+
65+
hashmap__for_each_entry_safe(map, cur, tmp, bkt) {
66+
free(cur);
67+
}
6268
free(map->buckets);
69+
map->buckets = NULL;
6370
map->cap = map->cap_bits = map->sz = 0;
6471
}
6572

tools/lib/bpf/libbpf.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6934,14 +6934,17 @@ int libbpf_find_vmlinux_btf_id(const char *name,
69346934
enum bpf_attach_type attach_type)
69356935
{
69366936
struct btf *btf;
6937+
int err;
69376938

69386939
btf = libbpf_find_kernel_btf();
69396940
if (IS_ERR(btf)) {
69406941
pr_warn("vmlinux BTF is not found\n");
69416942
return -EINVAL;
69426943
}
69436944

6944-
return __find_vmlinux_btf_id(btf, name, attach_type);
6945+
err = __find_vmlinux_btf_id(btf, name, attach_type);
6946+
btf__free(btf);
6947+
return err;
69456948
}
69466949

69476950
static int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd)

tools/testing/selftests/bpf/.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ test_tcpnotify_user
3030
test_libbpf
3131
test_tcp_check_syncookie_user
3232
test_sysctl
33-
test_hashmap
34-
test_btf_dump
3533
test_current_pid_tgid_new_ns
3634
xdping
3735
test_cpp
3836
*.skel.h
3937
/no_alu32
4038
/bpf_gcc
4139
/tools
42-
40+
/runqslower

tools/testing/selftests/bpf/Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ CLANG ?= clang
2020
LLC ?= llc
2121
LLVM_OBJCOPY ?= llvm-objcopy
2222
BPF_GCC ?= $(shell command -v bpf-gcc;)
23-
CFLAGS += -g -rdynamic -Wall -O2 $(GENFLAGS) -I$(CURDIR) \
24-
-I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) -I$(TOOLSINCDIR) \
25-
-I$(APIDIR) \
23+
SAN_CFLAGS ?=
24+
CFLAGS += -g -rdynamic -Wall -O2 $(GENFLAGS) $(SAN_CFLAGS) \
25+
-I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \
26+
-I$(TOOLSINCDIR) -I$(APIDIR) \
2627
-Dbpf_prog_load=bpf_prog_test_load \
2728
-Dbpf_load_program=bpf_test_load_program
2829
LDLIBS += -lcap -lelf -lz -lrt -lpthread
@@ -32,7 +33,7 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test
3233
test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \
3334
test_sock test_btf test_sockmap get_cgroup_id_user test_socket_cookie \
3435
test_cgroup_storage \
35-
test_netcnt test_tcpnotify_user test_sock_fields test_sysctl test_hashmap \
36+
test_netcnt test_tcpnotify_user test_sock_fields test_sysctl \
3637
test_progs-no_alu32 \
3738
test_current_pid_tgid_new_ns
3839

@@ -324,7 +325,7 @@ $(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \
324325
$(TRUNNER_BPF_SKELS) \
325326
$$(BPFOBJ) | $(TRUNNER_OUTPUT)
326327
$$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@)
327-
cd $$(@D) && $$(CC) $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F)
328+
cd $$(@D) && $$(CC) -I. $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F)
328329

329330
$(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: \
330331
%.c \

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ static struct core_reloc_test_case test_cases[] = {
392392
.input = STRUCT_TO_CHAR_PTR(core_reloc_existence___minimal) {
393393
.a = 42,
394394
},
395-
.input_len = sizeof(struct core_reloc_existence),
395+
.input_len = sizeof(struct core_reloc_existence___minimal),
396396
.output = STRUCT_TO_CHAR_PTR(core_reloc_existence_output) {
397397
.a_exists = 1,
398398
.b_exists = 0,

0 commit comments

Comments
 (0)