From e509dbbd21fbe5e68370ac186c31c022af69e039 Mon Sep 17 00:00:00 2001 From: Colton Willey Date: Mon, 26 Oct 2026 17:06:54 -0700 Subject: [PATCH] ci: leak-check the unit tests under ASan The test binaries link libasan, so drop the preload after env-setup and run make test with detect_leaks=1. make and the shell tools stay unchecked. --- .github/workflows/README.md | 10 +++++----- .github/workflows/sanitizers.yml | 7 +++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 1fce1e03..b7ca7037 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -266,14 +266,14 @@ wolfProvider and the test is dead weight. | Job | Flags | What it catches | |-----|-------|-----------------| -| `sanitizers` (ASan + UBSan) | `-fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize-recover=all` | use-after-free, double-free, out-of-bounds read/write, signed overflow, misaligned access, NULL deref, etc. | +| `sanitizers` (ASan + UBSan) | `-fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize-recover=all` | use-after-free, double-free, out-of-bounds read/write, signed overflow, misaligned access, NULL deref, etc.; leaks in `make test` (LeakSanitizer). | | `tsan` (Thread Sanitizer) | `-fsanitize=thread` | data races + lock-ordering violations in the multi-threaded unit tests in `test/unit.c` (`pthread_create` fan-out). | ASan and TSan can't coexist in one binary, so they're separate jobs -with separate caches. Both use `LD_PRELOAD=libasan.so` / `libtsan.so` -for the unit-test run because wolfProvider is loaded via `dlopen()` -from OpenSSL and the runtime needs the sanitizer interceptors live -before any provider code runs. `ASAN_OPTIONS=detect_odr_violation=0` +with separate caches. The unit-test binaries link the sanitizer +runtime. The ASan job preloads `libasan.so` only for `scripts/env-setup` +and the cmd-tests, and runs `make test` with `detect_leaks=1`. +`ASAN_OPTIONS=detect_odr_violation=0` is set to suppress a known false positive from the provider's static ASN.1 table being linked into both `libwolfprov.so` and the test binary. diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml index 335d9950..9fd5bf48 100644 --- a/.github/workflows/sanitizers.yml +++ b/.github/workflows/sanitizers.yml @@ -51,7 +51,8 @@ jobs: matrix: wolfssl_ref: ${{ fromJson(needs.discover_versions.outputs.wolfssl_latest_ref_array) }} env: - # detect_leaks=0: OpenSSL keeps provider-registry allocs alive. + # detect_leaks=0: the libasan preload would also leak-check shell + # tools; the unit-test step enables it for the test binaries only. # detect_odr_violation=0: libwolfprov is linked + dlopen'd in # test/unit.test -- false-positive ODR. ASAN_OPTIONS: detect_leaks=0:halt_on_error=1:abort_on_error=0:print_stacktrace=1:detect_odr_violation=0 @@ -111,7 +112,9 @@ jobs: run: | export LD_PRELOAD="$(gcc -print-file-name=libasan.so)" source scripts/env-setup - make test + # Preload is only for env-setup's openssl; test binaries link libasan. + unset LD_PRELOAD + ASAN_OPTIONS="${ASAN_OPTIONS}:detect_leaks=1" make test - name: Run cmd-tests under sanitizers shell: bash