|
| 1 | +name: Fuzz Testing |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 4 * * 1' # Weekly Monday 4am UTC |
| 6 | + workflow_dispatch: # Manual trigger |
| 7 | + pull_request: |
| 8 | + branches: [ '*' ] |
| 9 | + |
| 10 | +jobs: |
| 11 | + fuzz: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + timeout-minutes: 30 |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + include: |
| 18 | + # Full fuzz run (weekly/manual) - 10 minutes |
| 19 | + - name: fuzz-full |
| 20 | + fuzz_time: 600 |
| 21 | + smoke_only: false |
| 22 | + # Quick smoke test (PR) - 60 seconds |
| 23 | + - name: fuzz-smoke |
| 24 | + fuzz_time: 60 |
| 25 | + smoke_only: true |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout wolfTPM |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Checkout wolfSSL |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + repository: wolfssl/wolfssl |
| 35 | + path: wolfssl |
| 36 | + |
| 37 | + - name: ASLR workaround |
| 38 | + run: sudo sysctl vm.mmap_rnd_bits=28 |
| 39 | + |
| 40 | + - name: Build wolfSSL with fuzzer support |
| 41 | + working-directory: ./wolfssl |
| 42 | + run: | |
| 43 | + ./autogen.sh |
| 44 | + CC=clang ./configure --enable-wolftpm --enable-pkcallbacks --enable-keygen \ |
| 45 | + CFLAGS="-fsanitize=fuzzer-no-link,address -fno-omit-frame-pointer -g -O1" \ |
| 46 | + LDFLAGS="-fsanitize=address" |
| 47 | + make -j$(nproc) |
| 48 | + sudo make install |
| 49 | + sudo ldconfig |
| 50 | +
|
| 51 | + - name: Build fuzz target |
| 52 | + run: | |
| 53 | + ./autogen.sh |
| 54 | + CC=clang ./configure --enable-fwtpm --enable-fuzz \ |
| 55 | + CFLAGS="-fsanitize=fuzzer-no-link,address -fno-omit-frame-pointer -g -O1" \ |
| 56 | + LDFLAGS="-fsanitize=address" |
| 57 | + make -j$(nproc) |
| 58 | +
|
| 59 | + - name: Generate seed corpus |
| 60 | + run: python3 tests/fuzz/gen_corpus.py |
| 61 | + |
| 62 | + - name: Run fuzzer |
| 63 | + env: |
| 64 | + ASAN_OPTIONS: "detect_leaks=1:abort_on_error=1:symbolize=1" |
| 65 | + run: | |
| 66 | + echo "Fuzzing for ${{ matrix.fuzz_time }} seconds..." |
| 67 | + timeout ${{ matrix.fuzz_time }} \ |
| 68 | + ./tests/fuzz/fwtpm_fuzz \ |
| 69 | + tests/fuzz/corpus/ \ |
| 70 | + -dict=tests/fuzz/tpm2.dict \ |
| 71 | + -max_len=4096 \ |
| 72 | + -timeout=10 \ |
| 73 | + -rss_limit_mb=2048 \ |
| 74 | + -print_final_stats=1 \ |
| 75 | + || FUZZ_RC=$? |
| 76 | + # timeout returns 124 on normal expiry, fuzzer returns 0 on no crash |
| 77 | + if [ "${FUZZ_RC:-0}" -eq 124 ] || [ "${FUZZ_RC:-0}" -eq 0 ]; then |
| 78 | + echo "Fuzzer completed without crashes" |
| 79 | + else |
| 80 | + echo "Fuzzer found crashes (exit code $FUZZ_RC)" |
| 81 | + ls -la crash-* 2>/dev/null || true |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | +
|
| 85 | + - name: Upload crash artifacts |
| 86 | + if: failure() |
| 87 | + uses: actions/upload-artifact@v4 |
| 88 | + with: |
| 89 | + name: fuzz-crashes-${{ matrix.name }} |
| 90 | + path: | |
| 91 | + crash-* |
| 92 | + oom-* |
| 93 | + timeout-* |
| 94 | + retention-days: 30 |
| 95 | + if-no-files-found: ignore |
0 commit comments