Commit fd9c40c5 authored by Alexei Starovoitov's avatar Alexei Starovoitov
Browse files

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: default avatarAlexei Starovoitov <ast@kernel.org>
parents 3271e8f3 e4e8f4d0
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -59,7 +59,14 @@ struct hashmap *hashmap__new(hashmap_hash_fn hash_fn,

void hashmap__clear(struct hashmap *map)
{
	struct hashmap_entry *cur, *tmp;
	int bkt;

	hashmap__for_each_entry_safe(map, cur, tmp, bkt) {
		free(cur);
	}
	free(map->buckets);
	map->buckets = NULL;
	map->cap = map->cap_bits = map->sz = 0;
}

+4 −1
Original line number Diff line number Diff line
@@ -6934,6 +6934,7 @@ int libbpf_find_vmlinux_btf_id(const char *name,
			       enum bpf_attach_type attach_type)
{
	struct btf *btf;
	int err;

	btf = libbpf_find_kernel_btf();
	if (IS_ERR(btf)) {
@@ -6941,7 +6942,9 @@ int libbpf_find_vmlinux_btf_id(const char *name,
		return -EINVAL;
	}

	return __find_vmlinux_btf_id(btf, name, attach_type);
	err = __find_vmlinux_btf_id(btf, name, attach_type);
	btf__free(btf);
	return err;
}

static int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd)
+1 −3
Original line number Diff line number Diff line
@@ -30,8 +30,6 @@ test_tcpnotify_user
test_libbpf
test_tcp_check_syncookie_user
test_sysctl
test_hashmap
test_btf_dump
test_current_pid_tgid_new_ns
xdping
test_cpp
@@ -39,4 +37,4 @@ test_cpp
/no_alu32
/bpf_gcc
/tools
/runqslower
+6 −5
Original line number Diff line number Diff line
@@ -20,9 +20,10 @@ CLANG ?= clang
LLC		?= llc
LLVM_OBJCOPY	?= llvm-objcopy
BPF_GCC		?= $(shell command -v bpf-gcc;)
CFLAGS += -g -rdynamic -Wall -O2 $(GENFLAGS) -I$(CURDIR)		\
	  -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) -I$(TOOLSINCDIR)	\
	  -I$(APIDIR)							\
SAN_CFLAGS	?=
CFLAGS += -g -rdynamic -Wall -O2 $(GENFLAGS) $(SAN_CFLAGS)		\
	  -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR)		\
	  -I$(TOOLSINCDIR) -I$(APIDIR)					\
	  -Dbpf_prog_load=bpf_prog_test_load				\
	  -Dbpf_load_program=bpf_test_load_program
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
	test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \
	test_sock test_btf test_sockmap get_cgroup_id_user test_socket_cookie \
	test_cgroup_storage \
	test_netcnt test_tcpnotify_user test_sock_fields test_sysctl test_hashmap \
	test_netcnt test_tcpnotify_user test_sock_fields test_sysctl \
	test_progs-no_alu32 \
	test_current_pid_tgid_new_ns

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

$(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o:				\
		       %.c						\
+1 −1
Original line number Diff line number Diff line
@@ -392,7 +392,7 @@ static struct core_reloc_test_case test_cases[] = {
		.input = STRUCT_TO_CHAR_PTR(core_reloc_existence___minimal) {
			.a = 42,
		},
		.input_len = sizeof(struct core_reloc_existence),
		.input_len = sizeof(struct core_reloc_existence___minimal),
		.output = STRUCT_TO_CHAR_PTR(core_reloc_existence_output) {
			.a_exists = 1,
			.b_exists = 0,
Loading