Skip to content

Commit 75feedd

Browse files
authored
Add builder and tests for QASAN (#2898)
* Add tests for QASAN from aflplusplus * refactor asan module to use the builder pattern * move injection tests to the new tests directory
1 parent 37fc43f commit 75feedd

File tree

19 files changed

+574
-245
lines changed

19 files changed

+574
-245
lines changed

fuzzers/binary_only/qemu_launcher/Makefile.toml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
env_scripts = ['''
2+
#!@duckscript
3+
profile = get_env PROFILE
4+
5+
if eq ${profile} "dev"
6+
set_env PROFILE_DIR debug
7+
else
8+
set_env PROFILE_DIR ${profile}
9+
end
10+
''']
11+
112
[env]
213
PROFILE = { value = "release", condition = { env_not_set = ["PROFILE"] } }
314
PROFILE_DIR = { source = "${PROFILE}", default_value = "release", mapping = { "release" = "release", "dev" = "debug" }, condition = { env_not_set = [
@@ -360,21 +371,11 @@ windows_alias = "unsupported"
360371
script_runner = "@shell"
361372
script = '''
362373
echo "Profile: ${PROFILE}"
363-
cd injection_test || exit 1
364-
make
365-
mkdir in || true
366-
echo aaaaaaaaaa > in/a
367-
timeout 10s "$(find ${TARGET_DIR} -name 'qemu_launcher')" -o out -i in -j ../injections.toml -v -- ./static >/dev/null 2>fuzz.log || true
368-
if [ -z "$(grep -Ei "found.*injection" fuzz.log)" ]; then
369-
echo "Fuzzer does not generate any testcases or any crashes"
370-
echo "Logs:"
371-
cat fuzz.log
372-
exit 1
373-
else
374-
echo "Fuzzer is working"
375-
fi
376-
make clean
377-
#rm -rf in out fuzz.log || true
374+
375+
export QEMU_LAUNCHER=${TARGET_DIR}/${PROFILE_DIR}/qemu_launcher
376+
377+
./tests/injection/test.sh || exit 1
378+
./tests/qasan/test.sh || exit 1
378379
'''
379380
dependencies = ["build_unix"]
380381

fuzzers/binary_only/qemu_launcher/src/client.rs

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ impl Client<'_> {
9494

9595
let is_cmplog = self.options.is_cmplog_core(core_id);
9696

97+
let is_drcov = self.options.drcov.is_some();
98+
9799
let extra_tokens = if cfg!(feature = "injections") {
98100
injection_module
99101
.as_ref()
@@ -109,32 +111,58 @@ impl Client<'_> {
109111
.client_description(client_description)
110112
.extra_tokens(extra_tokens);
111113

112-
if self.options.rerun_input.is_some() && self.options.drcov.is_some() {
113-
// Special code path for re-running inputs with DrCov.
114-
// TODO: Add ASan support, injection support
115-
let drcov = self.options.drcov.as_ref().unwrap();
116-
let drcov = DrCovModule::builder()
117-
.filename(drcov.clone())
118-
.full_trace(true)
119-
.build();
120-
instance_builder
121-
.build()
122-
.run(args, tuple_list!(drcov), state)
114+
if self.options.rerun_input.is_some() {
115+
if is_drcov {
116+
// Special code path for re-running inputs with DrCov and Asan.
117+
// TODO: Add injection support
118+
let drcov = self.options.drcov.as_ref().unwrap();
119+
120+
if is_asan {
121+
let modules = tuple_list!(
122+
DrCovModule::builder()
123+
.filename(drcov.clone())
124+
.full_trace(true)
125+
.build(),
126+
unsafe { AsanModule::builder().env(&env).asan_report().build() }
127+
);
128+
129+
instance_builder.build().run(args, modules, state)
130+
} else {
131+
let modules = tuple_list!(DrCovModule::builder()
132+
.filename(drcov.clone())
133+
.full_trace(true)
134+
.build(),);
135+
136+
instance_builder.build().run(args, modules, state)
137+
}
138+
} else if is_asan {
139+
let modules =
140+
tuple_list!(unsafe { AsanModule::builder().env(&env).asan_report().build() });
141+
142+
instance_builder.build().run(args, modules, state)
143+
} else {
144+
let modules = tuple_list!();
145+
146+
instance_builder.build().run(args, modules, state)
147+
}
123148
} else if is_asan && is_cmplog {
124149
if let Some(injection_module) = injection_module {
125150
instance_builder.build().run(
126151
args,
127152
tuple_list!(
128153
CmpLogModule::default(),
129-
AsanModule::default(&env),
154+
AsanModule::builder().env(&env).build(),
130155
injection_module,
131156
),
132157
state,
133158
)
134159
} else {
135160
instance_builder.build().run(
136161
args,
137-
tuple_list!(CmpLogModule::default(), AsanModule::default(&env),),
162+
tuple_list!(
163+
CmpLogModule::default(),
164+
AsanModule::builder().env(&env).build()
165+
),
138166
state,
139167
)
140168
}
@@ -160,13 +188,15 @@ impl Client<'_> {
160188
if let Some(injection_module) = injection_module {
161189
instance_builder.build().run(
162190
args,
163-
tuple_list!(AsanModule::default(&env), injection_module),
191+
tuple_list!(AsanModule::builder().env(&env).build(), injection_module),
164192
state,
165193
)
166194
} else {
167-
instance_builder
168-
.build()
169-
.run(args, tuple_list!(AsanModule::default(&env),), state)
195+
instance_builder.build().run(
196+
args,
197+
tuple_list!(AsanModule::builder().env(&env).build()),
198+
state,
199+
)
170200
}
171201
} else if is_asan_guest {
172202
instance_builder
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
5+
6+
if [[ ! -x "$QEMU_LAUNCHER" ]]; then
7+
echo "env variable QEMU_LAUNCHER does not point to a valid executable"
8+
echo "QEMU_LAUNCHER should point to qemu_launcher location, but points to ${QEMU_LAUNCHER} instead."
9+
exit 1
10+
fi
11+
12+
cd "$SCRIPT_DIR"
13+
14+
make
15+
16+
mkdir in || true
17+
18+
echo aaaaaaaaaa > in/a
19+
20+
timeout 10s "$QEMU_LAUNCHER" -o out -i in -j ../../injections.toml -v -- ./static >/dev/null 2>fuzz.log || true
21+
if ! grep -Ei "found.*injection" fuzz.log; then
22+
echo "Fuzzer does not generate any testcases or any crashes"
23+
echo "Logs:"
24+
cat fuzz.log
25+
exit 1
26+
else
27+
echo "Fuzzer is working"
28+
fi
29+
30+
make clean
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
all: qasan
2+
3+
qasan: qasan.c
4+
gcc qasan.c -o qasan
5+
6+
clean:
7+
rm -rf qasan out stats.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
D

0 commit comments

Comments
 (0)