Source repository by Mr.Cupcake (mscupcakegkill): https://gitlab.com/mscupcakegkill/wrfuzz

This is Part 1 of the wrfuzz engineering notes, covering how the in-process runner recovers from faults without fork(), avoids per-iteration timer syscalls under PRoot, and catches 1-byte heap overflows in ~256 KB of memory without AddressSanitizer.

Execution harness (run.cpp)

run_ex(buf, deadline) performs one execution.

  1. Deadline check. If the deadline has already passed, it returns at once. RunResult defaults to Timeout status.
  2. Reset. Clear the hit counters of the previous run through the touched list, so the cost is proportional to coverage, not map size. Reset the I2S ring and the recent-PC ring. Reset the guard-heap bump pointer.
  3. Call the target.
    • sigsetjmp(jmp_env, 1), then set in_target = 1.
    • Call fuzz_target.
    • Run gpool_verify(), then clear in_target.
  4. Fault path. The handler is installed with SA_SIGINFO | SA_NODEFER | SA_RESTART for SEGV, ABRT, FPE, ILL, BUS and TRAP. It records the signal and si_addr, then jumps back with value 1, which becomes Crash.
  5. Timeout path. The same handler serves SIGALRM. While in_target is set, each tick increments hang_ticks. When it reaches timeout_ticks, the handler jumps back with value 2, which becomes Timeout. Because the timer runs freely, the real limit falls between (ticks-1)*25 and ticks*25 ms.
  6. Late check. If the outer deadline has passed by the time the target returns, the result is discarded and keeps the default Timeout status. With the main loop's 1 s deadline, the effective hang limit is therefore about min(TIMEOUT_MS, 1000 ms).
  7. Success. Compute the coverage signature and return Ok with the target's return code.

run(buf, deadline) is the thin adapter used by colorize(). It maps any non-Ok result to nullopt.

On Windows, the call is wrapped in SEH instead. There is no timeout, guard heap or libc comparison hook on that path.

Guard heap (GUARD_HEAP=1)

Layout. One mmap reserves 2*64+1 pages with no access. The odd-numbered pages are then made read-write, giving 64 slots, each followed by a guard page.

Allocation. While in_target is set, any allocation of up to one page is bump-allocated into the next free slot.

  • The block is placed at the end of its page, aligned to 16 bytes. An overflow past the aligned end hits the guard page.
  • The slack between the requested size and the aligned end is filled with the canary 0xA5.

Free.

  • free checks the canary and fills the block with 0xFE.
  • Double frees, frees of interior pointers and frees of stale slots call __builtin_trap.
  • realloc on a pool pointer allocates a new block, copies and frees the old one.
  • calloc checks for multiplication overflow.

End-of-run check. gpool_verify checks every canary and every freed block. This catches small overflows and use-after-free writes. Reads after free, and underflows within the page, are not detected.

Limits. Slots are not reused within a run. Once 64 are used, further allocations go to the system allocator.

Crash triage

A run counts as a bug if it crashed, timed out, or returned 2.

Signature.

  • The code is the signal number. Timeouts use SIGALRM, and rc == 2 uses the code 2.
  • The address is normally replaced by an FNV-1a hash of the recent-PC ring. So in practice, two bugs count as distinct when they have the same signal but different last-eight-block path suffixes.
  • Up to 64 signatures are kept.

Saving. The first 8 unique bugs are saved as crash_<id>_<code>.bin. With STOP_ON_CRASH=1, the fuzzer stops at the first new one.

Full source code (fuzz.cpp, run.cpp, Code.cpp) and architecture docs by Mr.Cupcake (mscupcakegkill): https://gitlab.com/mscupcakegkill/wrfuzz