Skip to content

Commit e92e5aa

Browse files
committed
Broker fuzzing
1 parent a7841b6 commit e92e5aa

11 files changed

Lines changed: 697 additions & 29 deletions

File tree

.github/workflows/Disabled/cifuzz.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/fuzz.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 wolfMQTT
29+
uses: actions/checkout@v4
30+
31+
- name: ASLR workaround
32+
run: sudo sysctl vm.mmap_rnd_bits=28
33+
34+
- name: Build fuzz target
35+
run: |
36+
./autogen.sh
37+
CC=clang ./configure --enable-broker --enable-v5 --enable-fuzz \
38+
--disable-tls --disable-examples \
39+
CFLAGS="-fsanitize=fuzzer-no-link,address -fno-omit-frame-pointer -g -O1" \
40+
LDFLAGS="-fsanitize=address"
41+
make -j$(nproc)
42+
43+
- name: Generate seed corpus
44+
run: python3 src/fuzz/gen_corpus.py
45+
46+
- name: Run fuzzer
47+
env:
48+
ASAN_OPTIONS: "detect_leaks=1:abort_on_error=1:symbolize=1"
49+
run: |
50+
echo "Fuzzing for ${{ matrix.fuzz_time }} seconds..."
51+
timeout ${{ matrix.fuzz_time }} \
52+
./src/fuzz/broker_fuzz \
53+
src/fuzz/corpus/ \
54+
-dict=src/fuzz/mqtt.dict \
55+
-max_len=4096 \
56+
-timeout=10 \
57+
-rss_limit_mb=2048 \
58+
-print_final_stats=1 \
59+
|| FUZZ_RC=$?
60+
# timeout returns 124 on normal expiry, fuzzer returns 0 on no crash
61+
if [ "${FUZZ_RC:-0}" -eq 124 ] || [ "${FUZZ_RC:-0}" -eq 0 ]; then
62+
echo "Fuzzer completed without crashes"
63+
else
64+
echo "Fuzzer found crashes (exit code $FUZZ_RC)"
65+
ls -la crash-* 2>/dev/null || true
66+
exit 1
67+
fi
68+
69+
- name: Upload crash artifacts
70+
if: failure()
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: fuzz-crashes-${{ matrix.name }}
74+
path: |
75+
crash-*
76+
oom-*
77+
timeout-*
78+
retention-days: 30
79+
if-no-files-found: ignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,4 @@ examples/websocket/websocket_client
125125
!/IDE/Espressif/**/config.h
126126

127127
src/mqtt_broker
128+
src/fuzz/broker_fuzz

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,4 @@ dist-hook:
118118
$(MKDIR_P) $(distdir)/examples/multithread
119119
$(MKDIR_P) $(distdir)/examples/pub-sub
120120
$(MKDIR_P) $(distdir)/examples/websocket
121+
$(MKDIR_P) $(distdir)/src/fuzz

configure.ac

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,14 @@ AM_CONDITIONAL([BUILD_MULTITHREAD], [test "x$ENABLED_MULTITHREAD" = "xyes"])
491491
AM_CONDITIONAL([BUILD_WEBSOCKET], [test "x$ENABLED_WEBSOCKET" = "xyes"])
492492
AM_CONDITIONAL([BUILD_BROKER], [test "x$ENABLED_BROKER" = "xyes"])
493493

494+
# Fuzz target
495+
AC_ARG_ENABLE([fuzz],
496+
[AS_HELP_STRING([--enable-fuzz],[Enable libFuzzer targets (default: disabled)])],
497+
[ ENABLED_FUZZ=$enableval ],
498+
[ ENABLED_FUZZ=no ]
499+
)
500+
AM_CONDITIONAL([BUILD_FUZZ], [test "x$ENABLED_FUZZ" = "xyes"])
501+
494502

495503

496504
# HARDEN FLAGS
@@ -619,3 +627,4 @@ echo " * Multi-thread: $ENABLED_MULTITHREAD"
619627
echo " * Stress: $ENABLED_STRESS"
620628
echo " * WebSocket: $ENABLED_WEBSOCKET"
621629
echo " * Broker: $ENABLED_BROKER"
630+
echo " * Fuzz: $ENABLED_FUZZ"

src/fuzz/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
corpus/

0 commit comments

Comments
 (0)