Max Ammann 4d8b566a87
[Windows] Add libfuzzer example for windows with ASAN (#934)
* Add libfuzzer example for window with ASAN

* Fix formatting

* Add link

* Fix cpp format

* Skip windows fuzzers

* Fix format

* Fix testing fuzzer

* Fix taks name

Co-authored-by: Dongjia "toka" Zhang <tokazerkje@outlook.com>
Co-authored-by: Andrea Fioraldi <andreafioraldi@gmail.com>
Co-authored-by: Dominik Maier <domenukk@gmail.com>
2022-12-21 10:41:58 +01:00

1.8 KiB

LibFuzzer Example for Windows with ASAN

This folder contains an example fuzzer for Windows which also uses ASAN.

We are initializing LibAFL to be compatible with ASAN.

Setup

We are currently using Clang on Windows. Make sure to install Clang through the Visual Studio installer.

We recommend using Powershell and enabling the Visual Studio environment using this script:

Push-Location "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\"
& "C:\\Windows\System32\cmd.exe" /c "vcvars64.bat & set" |
ForEach-Object {
  if ($_ -match "=") {
    $v = $_.split("=", 2); set-item -force -path "ENV:\$($v[0])"  -value "$($v[1])" 
  }
}
Pop-Location
Write-Host "`nVisual Studio 2022 Command Prompt variables set." -ForegroundColor Yellow

After that clang should be available in the PATH.

Build

To build the fuzzer and link against the harness.cpp in this example run:

cargo make fuzzer

Running

.\libfuzzer_windows_asan.exe

Note on MSVC

The MSVC compiler (cl.exe) will work in the future. Currently, it is blocked because of a bug with coverage.

Note on ASAN

Using ASAN on Windows with MSVC is not trivial as of 2022. Depending on the harness and fuzzing target, the required compilation flags differ. Most notably, the usage of /MT and /MD for the CRT is important. All compilation artifacts should use the same config for the CRT (either all /MT or all /MD). Rust uses as of 2022 /MD as default. So compile everything with /MD.

Depending on the linking mode different ASAN libraries get linked. Definitely read this blog post by Microsoft.