BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/9] selftests/bpf: Add Memory Sanitizer support
@ 2023-02-08 20:56 Ilya Leoshkevich
  2023-02-08 20:56 ` [PATCH bpf-next 1/9] selftests/bpf: Quote host tools Ilya Leoshkevich
                   ` (8 more replies)
  0 siblings, 9 replies; 22+ messages in thread
From: Ilya Leoshkevich @ 2023-02-08 20:56 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: bpf, Heiko Carstens, Vasily Gorbik, Alexander Gordeev,
	Ilya Leoshkevich

Hi,

This series adds support for building selftests with Memory Sanitizer
[1] - a compiler instrumentation for detecting usages of undefined
memory.

The primary motivation is to make sure that such usages do not occur
during testing, since the ones that have not been caught yet are likely
to affect the CI results on s390x. The secondary motivation is to be
able to use libbpf in applications instrumented with MSan (it requires
all code running in a process to be instrumented).

MSan has found one real issue (fixed by patch 6), and of course a
number of false positives. This rest of this series deals with
preparing the build infrastructure and adding MSan annotations to
libbpf and selftests.

The setup I'm using is as follows:

- Instrumented zlib-ng and patched elfutils [2].
- Patched LLVM [3, 4].
- Clang-built kernel.
- Building tests with MSan:

      make \
          -C tools/testing/selftests/bpf \
          CC="ccache clang-17" \
          LD=ld \
          HOSTCC="ccache clang-17" \
          HOSTLD=ld \
          LLVM=1 \
          LLVM_SUFFIX=-17 \
          OBJCOPY=objcopy \
          CLANG="ccache clang-17" \
          LLVM_STRIP=llvm-strip-17 \
          LLC=llc-17 \
          BPF_GCC= \
          SAN_CFLAGS="-fsanitize=memory \
                      -fsanitize-memory-track-origins \
                      -I$PWD/../zlib-ng/dist/include \
                      -I$PWD/../elfutils/dist/include" \
          SAN_LDFLAGS="-fsanitize=memory \
                       -fsanitize-memory-track-origins \
                       -L$PWD/../zlib-ng/dist/lib \
                       -L$PWD/../elfutils/dist/lib" \
          CROSS_COMPILE=s390x-linux-gnu-

  It's a lot of options, but most of them are trivial: setting up LLVM
  toolchain, taking in account s390x quirks, setting up MSan and
  disabling bpf-gcc. The CROSS_COMPILE one is a hack: instrumenting
  bpftool turned out to be too complicated from the build system
  perspective, so having CROSS_COMPILE forces compiling the host libbpf
  uninstrumented and guest libbpf instrumented.

- Running tests with MSan on s390x:

      LD_LIBRARY_PATH=<instrumented libs> ./test_progs
      ...
      Summary: 282/1624 PASSED, 23 SKIPPED, 4 FAILED
  
  The 4 failures happen without MSan too, they are already known and
  denylisted.

Best regards,
Ilya

[1] https://clang.llvm.org/docs/MemorySanitizer.html
[2] https://sourceware.org/pipermail/elfutils-devel/2023q1/005831.html
[3] https://reviews.llvm.org/D143296
[4] https://reviews.llvm.org/D143330

Ilya Leoshkevich (9):
  selftests/bpf: Quote host tools
  tools: runqslower: Add EXTRA_CFLAGS and EXTRA_LDFLAGS support
  selftests/bpf: Split SAN_CFLAGS and SAN_LDFLAGS
  selftests/bpf: Forward SAN_CFLAGS and SAN_LDFLAGS to runqslower and
    libbpf
  selftests/bpf: Attach to fopen()/fclose() in uprobe_autoattach
  selftests/bpf: Attach to fopen()/fclose() in attach_probe
  libbpf: Fix alen calculation in libbpf_nla_dump_errormsg()
  libbpf: Add MSan annotations
  selftests/bpf: Add MSan annotations

 tools/bpf/runqslower/Makefile                 |  6 ++
 tools/lib/bpf/bpf.c                           | 70 +++++++++++++++++--
 tools/lib/bpf/btf.c                           |  1 +
 tools/lib/bpf/libbpf.c                        |  1 +
 tools/lib/bpf/libbpf_internal.h               | 14 ++++
 tools/lib/bpf/nlattr.c                        |  2 +-
 tools/testing/selftests/bpf/Makefile          | 17 +++--
 tools/testing/selftests/bpf/cap_helpers.c     |  3 +
 .../selftests/bpf/prog_tests/attach_probe.c   | 10 +--
 .../selftests/bpf/prog_tests/bpf_obj_id.c     | 10 +++
 .../selftests/bpf/prog_tests/bpf_tcp_ca.c     |  3 +
 tools/testing/selftests/bpf/prog_tests/btf.c  | 11 +++
 .../selftests/bpf/prog_tests/send_signal.c    |  2 +
 .../bpf/prog_tests/tp_attach_query.c          |  6 ++
 .../bpf/prog_tests/uprobe_autoattach.c        | 12 ++--
 .../selftests/bpf/prog_tests/xdp_bonding.c    |  3 +
 .../selftests/bpf/progs/test_attach_probe.c   |  8 ++-
 .../bpf/progs/test_uprobe_autoattach.c        | 10 +--
 tools/testing/selftests/bpf/xdp_synproxy.c    |  2 +
 19 files changed, 161 insertions(+), 30 deletions(-)

-- 
2.39.1


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2023-02-09 19:37 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-08 20:56 [PATCH bpf-next 0/9] selftests/bpf: Add Memory Sanitizer support Ilya Leoshkevich
2023-02-08 20:56 ` [PATCH bpf-next 1/9] selftests/bpf: Quote host tools Ilya Leoshkevich
2023-02-08 20:56 ` [PATCH bpf-next 2/9] tools: runqslower: Add EXTRA_CFLAGS and EXTRA_LDFLAGS support Ilya Leoshkevich
2023-02-09  1:00   ` Andrii Nakryiko
2023-02-08 20:56 ` [PATCH bpf-next 3/9] selftests/bpf: Split SAN_CFLAGS and SAN_LDFLAGS Ilya Leoshkevich
2023-02-08 20:56 ` [PATCH bpf-next 4/9] selftests/bpf: Forward SAN_CFLAGS and SAN_LDFLAGS to runqslower and libbpf Ilya Leoshkevich
2023-02-09  1:03   ` Andrii Nakryiko
2023-02-09  9:55     ` Ilya Leoshkevich
2023-02-09 17:17       ` Andrii Nakryiko
2023-02-08 20:56 ` [PATCH bpf-next 5/9] selftests/bpf: Attach to fopen()/fclose() in uprobe_autoattach Ilya Leoshkevich
2023-02-09  1:05   ` Andrii Nakryiko
2023-02-08 20:56 ` [PATCH bpf-next 6/9] selftests/bpf: Attach to fopen()/fclose() in attach_probe Ilya Leoshkevich
2023-02-09  1:06   ` Andrii Nakryiko
2023-02-08 20:56 ` [PATCH bpf-next 7/9] libbpf: Fix alen calculation in libbpf_nla_dump_errormsg() Ilya Leoshkevich
2023-02-09  1:14   ` Andrii Nakryiko
2023-02-08 20:56 ` [PATCH bpf-next 8/9] libbpf: Add MSan annotations Ilya Leoshkevich
2023-02-09  1:29   ` Andrii Nakryiko
2023-02-09 10:01     ` Ilya Leoshkevich
2023-02-09 19:37       ` Andrii Nakryiko
2023-02-08 20:56 ` [PATCH bpf-next 9/9] selftests/bpf: " Ilya Leoshkevich
2023-02-09  1:34   ` Andrii Nakryiko
2023-02-09 10:30     ` Ilya Leoshkevich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox