Skip to content

Windows Support for LibAFL-LibFuzzer #3130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
May 20, 2025

Conversation

novafacing
Copy link
Contributor

@novafacing novafacing commented Apr 4, 2025

Description

Support for Windows with LibAFL-LibFuzzer. This is a draft with a couple issues still persisting.

  • No maps available when running fuzzer

Checklist

  • I have run ./scripts/precommit.sh and addressed all comments


[target.'cfg(not(windows))'.features]
## Enable the `fork` feature on non-windows platforms
default = ["fork", "tui_monitor"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think we need tui_monitor on non-win

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to put in a few libs anyway to get this to work so I'll just revert this part of the changes and make tui_monitor work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't fully get the tui monitor thing - it's just not working on Win yet?

@novafacing
Copy link
Contributor Author

novafacing commented Apr 4, 2025

This is in MVP working state now with some updates still needed:

  • It runs for a moment then panics at mutations.rs:1164 ("Corpus may not be empty!"). Unsure why.
  • Revert changes to cargo.toml and add import libs for required libraries
  • Fix argparsing so -help=1 works (maybe separate PR)

Howto test:

.\build.ps1 dev
cd test
# Write a test.cpp
cl /c /EHsc /std:c++17 /MDd /fsanitize=fuzzer-no-link test.cpp #(if you don't have fuzzer-no-link on Windows, use /fsanitize-coverage=inline-8bit-counters /fsanitize-coverage=edge /fsanitize-coverage=trace-cmp /fsanitize-coverage=trace-div` instead).
link test.obj ..\target\debug\afl_libfuzzer_runtime.lib /OUT:fuzzer.exe

@domenukk
Copy link
Member

domenukk commented Apr 5, 2025

FWIW the fork feature should not do anything on windows

@novafacing
Copy link
Contributor Author

This seems to be 100% working now! Just need to do a style pass.

@tokatoka
Copy link
Member

tokatoka commented Apr 7, 2025

Nice 💯
Can you create a CI job?
Just like this guy
https://github.com/AFLplusplus/LibAFL/blob/main/.github/workflows/build_and_test.yml#L515

@novafacing
Copy link
Contributor Author

Ok, adding a CI workflow today or maybe tomorrow (I have actual work to do but it should be relatively quick).

@domenukk
Copy link
Member

domenukk commented Apr 9, 2025

Nice 💯 Can you create a CI job? Just like this guy https://github.com/AFLplusplus/LibAFL/blob/main/.github/workflows/build_and_test.yml#L515

Please do a justfile entry that is easy to run locally

@domenukk
Copy link
Member

domenukk commented Apr 9, 2025

We need to land #3099

@tokatoka
Copy link
Member

do you have any update?

@novafacing
Copy link
Contributor Author

novafacing commented Apr 22, 2025

Not yet, sorry :) I've been super busy with some other stuff. Still on my radar, I'll finish it up when I have a chance.

@tokatoka tokatoka added this to the LibAFL 1.0 milestone Apr 28, 2025
@domenukk
Copy link
Member

Status? We're going to do a new release soon

[features]
default = ["fork"]
default = []
Copy link
Member

@domenukk domenukk May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think fork as default is good for perf on non-windows, it's a nop on win

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have it set below that on non-windows to keep things explicit and because tui_monitor needs to be default on non-win anyway, but I can change it if wanted.

@tokatoka
Copy link
Member

@novafacing any update?

@novafacing
Copy link
Contributor Author

Ok, added. Let's see if I can one-shot the test working :)

@novafacing novafacing marked this pull request as ready for review May 20, 2025 20:18
@novafacing
Copy link
Contributor Author

Ok, looks like test is passing so this is ready for a real look :)

destroy_output_fds(options);

fuzz_with!(options, harness, do_fuzz, |fuzz_single| {
let mgr = SimpleEventManager::new(MultiMonitor::new(create_monitor_closure()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LibAFL_Libfuzzer doesn't support Llmp?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it doesn't right now but no reason we couldn't add it. Could use llmp+multiprocessing on windows where we can't fork

@@ -358,6 +363,47 @@ impl<'a> LibfuzzerOptionsBuilder<'a> {
}
"runs" => self.runs = parse_or_bail!(name, value, usize),
"close_fd_mask" => self.close_fd_mask = parse_or_bail!(name, value, u8),
"help" => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will go out of date at some time but I don't have a good solution either

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah unfortunately using e.g. clap is blocked on clap-rs/clap#1210 and I don't know of another good arg parsing library that supports this arg format

@@ -0,0 +1,89 @@
#!/usr/bin/env pwsh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call that guy from a justfile?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I'll add a justfile for libafl_libfuzzer and libafl_libfuzzer_runtime.

@domenukk
Copy link
Member

Looks pretty good, awesome!

@novafacing
Copy link
Contributor Author

Ok! I think we're good

@domenukk domenukk merged commit 0b25d72 into AFLplusplus:main May 20, 2025
110 checks passed
@novafacing novafacing deleted the libafl-libfuzzer-windows branch May 20, 2025 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants