mbox series

[v3,bpf-next,0/9] Fix leaks in libbpf and selftests

Message ID 20211107164624.4137512-1-andrii@kernel.org (mailing list archive)
Headers show
Series Fix leaks in libbpf and selftests | expand

Message

Andrii Nakryiko Nov. 7, 2021, 4:46 p.m. UTC
Fix all the memory leaks reported by ASAN. All but one are just improper
resource clean up in selftests. But one memory leak was discovered in libbpf,
leaving inner map's name leaked.

First patch fixes selftests' Makefile by passing through SAN_CFLAGS to linker.
Without that compiling with SAN_CFLAGS=-fsanitize=address kept failing.

Running selftests under ASAN in BPF CI is the next step, we just need to make
sure all the necessary libraries (libasan and liblsan) are installed on the
host and inside the VM. Would be great to get some help with that, but for now
make sure that test_progs run is clean from leak sanitizer errors.

v2->v3:
  - fix per-cpu array memory leaks in btf_iter.c selftests (Hengqi);
v1->v2:
  - call bpf_map__destroy() conditionally if map->inner_map is present.

Andrii Nakryiko (9):
  selftests/bpf: pass sanitizer flags to linker through LDFLAGS
  libbpf: free up resources used by inner map definition
  selftests/bpf: fix memory leaks in btf_type_c_dump() helper
  selftests/bpf: free per-cpu values array in bpf_iter selftest
  selftests/bpf: free inner strings index in btf selftest
  selftests/bpf: clean up btf and btf_dump in dump_datasec test
  selftests/bpf: avoid duplicate btf__parse() call
  selftests/bpf: destroy XDP link correctly
  selftests/bpf: fix bpf_object leak in skb_ctx selftest

 tools/lib/bpf/libbpf.c                                   | 5 ++++-
 tools/testing/selftests/bpf/Makefile                     | 1 +
 tools/testing/selftests/bpf/btf_helpers.c                | 9 +++++++--
 tools/testing/selftests/bpf/prog_tests/bpf_iter.c        | 8 ++++----
 tools/testing/selftests/bpf/prog_tests/btf.c             | 6 ++----
 tools/testing/selftests/bpf/prog_tests/btf_dump.c        | 8 ++++++--
 tools/testing/selftests/bpf/prog_tests/core_reloc.c      | 2 +-
 .../testing/selftests/bpf/prog_tests/migrate_reuseport.c | 4 ++--
 tools/testing/selftests/bpf/prog_tests/skb_ctx.c         | 2 ++
 9 files changed, 29 insertions(+), 16 deletions(-)

Comments

Andrii Nakryiko Nov. 7, 2021, 4:50 p.m. UTC | #1
On Sun, Nov 7, 2021 at 8:46 AM Andrii Nakryiko <andrii@kernel.org> wrote:
>
> Fix all the memory leaks reported by ASAN. All but one are just improper
> resource clean up in selftests. But one memory leak was discovered in libbpf,
> leaving inner map's name leaked.
>
> First patch fixes selftests' Makefile by passing through SAN_CFLAGS to linker.
> Without that compiling with SAN_CFLAGS=-fsanitize=address kept failing.
>
> Running selftests under ASAN in BPF CI is the next step, we just need to make
> sure all the necessary libraries (libasan and liblsan) are installed on the
> host and inside the VM. Would be great to get some help with that, but for now
> make sure that test_progs run is clean from leak sanitizer errors.
>
> v2->v3:
>   - fix per-cpu array memory leaks in btf_iter.c selftests (Hengqi);
> v1->v2:
>   - call bpf_map__destroy() conditionally if map->inner_map is present.
>

Oh, I didn't notice that the bpf_prog_load() patch set went in. This
one seems to have a small Makefile conflict, I'll rebase. Sorry for
the spam.

> Andrii Nakryiko (9):
>   selftests/bpf: pass sanitizer flags to linker through LDFLAGS
>   libbpf: free up resources used by inner map definition
>   selftests/bpf: fix memory leaks in btf_type_c_dump() helper
>   selftests/bpf: free per-cpu values array in bpf_iter selftest
>   selftests/bpf: free inner strings index in btf selftest
>   selftests/bpf: clean up btf and btf_dump in dump_datasec test
>   selftests/bpf: avoid duplicate btf__parse() call
>   selftests/bpf: destroy XDP link correctly
>   selftests/bpf: fix bpf_object leak in skb_ctx selftest
>
>  tools/lib/bpf/libbpf.c                                   | 5 ++++-
>  tools/testing/selftests/bpf/Makefile                     | 1 +
>  tools/testing/selftests/bpf/btf_helpers.c                | 9 +++++++--
>  tools/testing/selftests/bpf/prog_tests/bpf_iter.c        | 8 ++++----
>  tools/testing/selftests/bpf/prog_tests/btf.c             | 6 ++----
>  tools/testing/selftests/bpf/prog_tests/btf_dump.c        | 8 ++++++--
>  tools/testing/selftests/bpf/prog_tests/core_reloc.c      | 2 +-
>  .../testing/selftests/bpf/prog_tests/migrate_reuseport.c | 4 ++--
>  tools/testing/selftests/bpf/prog_tests/skb_ctx.c         | 2 ++
>  9 files changed, 29 insertions(+), 16 deletions(-)
>
> --
> 2.30.2
>