Skip to content

Commit 40bd080

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 6e5d340 + de2bc16 commit 40bd080

File tree

13 files changed

+919
-5
lines changed

13 files changed

+919
-5
lines changed

.github/workflows/build_and_test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ jobs:
275275
- ./fuzzers/forkserver/forkserver_libafl_cc
276276
- ./fuzzers/forkserver/fuzzbench_forkserver
277277
- ./fuzzers/forkserver/fuzzbench_forkserver_cmplog
278+
- ./fuzzers/forkserver/fuzzbench_forkserver_sand
278279
- ./fuzzers/forkserver/libafl-fuzz
279280
- ./fuzzers/forkserver/baby_fuzzer_with_forkexecutor
280281

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
libpng-*
2+
fuzzer
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[package]
2+
name = "fuzzbench_forkserver_sand"
3+
version = "0.15.1"
4+
authors = [
5+
"Andrea Fioraldi <[email protected]>",
6+
"Dominik Maier <[email protected]>",
7+
"Ziqiao Kong <[email protected]>",
8+
]
9+
edition = "2021"
10+
11+
[profile.release]
12+
lto = true
13+
codegen-units = 1
14+
opt-level = 3
15+
debug = true
16+
17+
[profile.release-fuzzbench]
18+
inherits = "release"
19+
debug = false
20+
strip = true
21+
22+
[build-dependencies]
23+
cc = { version = "1.1.22", features = ["parallel"] }
24+
which = "6.0.3"
25+
26+
[dependencies]
27+
libafl = { path = "../../../libafl" }
28+
libafl_bolts = { path = "../../../libafl_bolts" }
29+
libafl_targets = { path = "../../../libafl_targets", features = [
30+
"sancov_pcguard_hitcounts",
31+
"libfuzzer",
32+
"pointer_maps",
33+
] }
34+
libafl_cc = { path = "../../../libafl_cc" }
35+
log = { version = "0.4.22", features = ["release_max_level_info"] }
36+
clap = { version = "4.5.18", features = ["default"] }
37+
nix = { version = "0.29.0", features = ["signal"] }
38+
39+
[[bin]]
40+
name = "sand_cc"
41+
path = "src/cc.rs"
42+
43+
[[bin]]
44+
name = "sand_cxx"
45+
path = "src/cxx.rs"
46+
47+
[[bin]]
48+
name = "fuzzbench_forkserver_sand"
49+
path = "src/main.rs"
50+
51+
[lib]
52+
name = "forkserver_sand"
53+
crate-type = ["staticlib"]
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
FUZZER_NAME := 'fuzzbench_forkserver_sand'
2+
FORKSERVER_NAME := 'fuzzbench_forkserver_sand'
3+
CARGO_TARGET_DIR := env("CARGO_TARGET_DIR", "target")
4+
PROFILE := env("PROFILE", "release")
5+
PROFILE_DIR := if PROFILE == "release" { "release" } else if PROFILE == "dev" { "debug" } else { "debug" }
6+
LIBAFL_CC := PROJECT_DIR / CARGO_TARGET_DIR / PROFILE_DIR / "sand_cc"
7+
LIBAFL_CXX := PROJECT_DIR / CARGO_TARGET_DIR / PROFILE_DIR / "sand_cxx"
8+
FUZZER := PROJECT_DIR / CARGO_TARGET_DIR / PROFILE_DIR / FUZZER_NAME
9+
FORKSERVER := PROJECT_DIR / CARGO_TARGET_DIR / PROFILE_DIR / FORKSERVER_NAME
10+
PROJECT_DIR := absolute_path(".")
11+
12+
13+
alias cc := cxx
14+
15+
[linux]
16+
[macos]
17+
cxx:
18+
cargo build --profile {{PROFILE}}
19+
20+
[windows]
21+
cxx:
22+
echo "Unsupported on this platform"
23+
24+
[linux]
25+
[macos]
26+
fuzzer: cxx
27+
{{LIBAFL_CC}} {{PROJECT_DIR}}/src/vuln.c -o vuln_native -lm -lz
28+
29+
[windows]
30+
fuzzer:
31+
echo "Unsupported on this platform"
32+
33+
[linux]
34+
[macos]
35+
fuzzer_asan: cxx
36+
AFL_SAN_NO_INST=1 {{LIBAFL_CC}} {{PROJECT_DIR}}/src/vuln.c -fsanitize=address -o vuln_asan -lm -lz
37+
38+
[windows]
39+
fuzzer_asan:
40+
echo "Unsupported on this platform"
41+
42+
[linux]
43+
[macos]
44+
run: fuzzer fuzzer_asan
45+
#!/bin/bash
46+
mkdir -p input && echo "a" >> input/a
47+
taskset -c 1 {{FUZZER}} -i input -o /tmp/out -a ./vuln_asan -t 1000 ./vuln_native
48+
49+
[windows]
50+
run: fuzzer fuzzer_asan
51+
echo "Unsupported on this platform"
52+
53+
[linux]
54+
[macos]
55+
test: fuzzer fuzzer_asan
56+
#!/bin/bash
57+
mkdir -p input && echo "a" >> input/a
58+
timeout 10s {{FUZZER}} -i input -o /tmp/out -a ./vuln_asan -t 1000 ./vuln_native | tee fuzz_stdout.log || true
59+
if grep -qa "objectives: 1" fuzz_stdout.log; then
60+
echo "Fuzzer is working"
61+
else
62+
echo "Fuzzer does not generate any testcases or any crashes"
63+
exit 1
64+
fi
65+
66+
[windows]
67+
test: fuzzer fuzzer_asan
68+
echo "Unsupported on this platform"
69+
70+
clean:
71+
rm -rf {{FUZZER}}
72+
rm -rf vuln_native vuln_asan
73+
cargo clean
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use std::env;
2+
3+
use libafl_cc::{ClangWrapper, CompilerWrapper, ToolWrapper};
4+
5+
pub fn main() {
6+
let args: Vec<String> = env::args().collect();
7+
if args.len() > 1 {
8+
let mut dir = env::current_exe().unwrap();
9+
let wrapper_name = dir.file_name().unwrap().to_str().unwrap();
10+
11+
let is_cpp = match wrapper_name[wrapper_name.len()-2..].to_lowercase().as_str() {
12+
"cc" => false,
13+
"++" | "pp" | "xx" => true,
14+
_ => panic!("Could not figure out if c or c++ wrapper was called. Expected {dir:?} to end with c or cxx"),
15+
};
16+
17+
let no_inst = std::env::var("AFL_SAN_NO_INST").ok().is_some();
18+
19+
dir.pop();
20+
21+
let mut cc = ClangWrapper::new();
22+
if !no_inst {
23+
cc.add_arg("-fsanitize-coverage=trace-pc-guard");
24+
}
25+
if let Some(code) = cc
26+
.cpp(is_cpp)
27+
// silence the compiler wrapper output, needed for some configure scripts.
28+
.silence(true)
29+
.parse_args(&args)
30+
.expect("Failed to parse the command line")
31+
// Imitate afl-cc's compile definitions
32+
.add_arg("-D__AFL_FUZZ_INIT()=int __afl_sharedmem_fuzzing = 1;extern unsigned int *__afl_fuzz_len;extern unsigned char *__afl_fuzz_ptr;unsigned char __afl_fuzz_alt[1048576];unsigned char *__afl_fuzz_alt_ptr = __afl_fuzz_alt;void libafl_start_forkserver(void)")
33+
.add_arg("-D__AFL_FUZZ_TESTCASE_BUF=(__afl_fuzz_ptr ? __afl_fuzz_ptr : __afl_fuzz_alt_ptr)")
34+
.add_arg("-D__AFL_FUZZ_TESTCASE_LEN=(__afl_fuzz_ptr ? *__afl_fuzz_len : (*__afl_fuzz_len = read(0, __afl_fuzz_alt_ptr, 1048576)) == 0xffffffff ? 0 : *__afl_fuzz_len)")
35+
.add_arg("-D__AFL_INIT()=libafl_start_forkserver()")
36+
// Link with libafl's forkserver implementation
37+
.link_staticlib(&dir, "forkserver_sand")
38+
.run()
39+
.expect("Failed to run the wrapped compiler")
40+
{
41+
std::process::exit(code);
42+
}
43+
} else {
44+
panic!("LibAFL CC: No Arguments given");
45+
}
46+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub mod cc;
2+
3+
fn main() {
4+
cc::main();
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use libafl_targets::{map_shared_memory, start_forkserver};
2+
3+
#[no_mangle]
4+
pub extern "C" fn libafl_start_forkserver() {
5+
// Map shared memory region for the edge coverage map
6+
map_shared_memory();
7+
// Start the forkserver
8+
start_forkserver();
9+
}

0 commit comments

Comments
 (0)