-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-eval.sh
More file actions
executable file
·101 lines (77 loc) · 2.83 KB
/
Copy pathrun-eval.sh
File metadata and controls
executable file
·101 lines (77 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
set -eu
set -o pipefail
DIR="$(dirname $(readlink -f $0))"
readonly ROOT_DIR="$(readlink -f "$DIR/..")"
source $ROOT_DIR/config.sh
FISH_FUZZ_ROOT=$ROOT_DIR/FishFuzz-upstream
FUZZ_OUT_DIR="$DIR/eval-results"
FUZZERS=('ffafl' 'ffapp' 'afl' 'aflpp')
TARGETS=('cflow' 'cxxfilt' 'w3m' 'mujs' 'mutool' 'tic' 'dwarfdump')
########## Configuration ##########
# Number of available CPUs.
# This determine the number of parallel fuzzing instances.
readonly CPUS=10
# LAST_TRIAL-FIRST_TRIAL determines the number of repetitions.
# Choosing disjoint intervals allows to run multiple evaluations in parallel.
readonly FIRST_TRIAL=1
readonly LAST_TRIAL=10
# Timeout of each individual fuzzing run.
readonly DURATION=24h
###################################
if ! command -v parallel > /dev/null || ! parallel --version | grep -q "GNU parallel"; then
echo "Please install GNU parallel"
exit 1
fi
if [[ -d "$FUZZ_OUT_DIR" ]]; then
echo "$FUZZ_OUT_DIR exists, please delete and rerun"
exit 1
fi
mkdir -p "$FUZZ_OUT_DIR"
args=""
core_idx=0
for trial in $(seq $FIRST_TRIAL $LAST_TRIAL); do
for target in "${TARGETS[@]}"; do
for fuzzer in "${FUZZERS[@]}"; do
args+="$target@$fuzzer@$trial@$core_idx "
core_idx=$(((core_idx+1) % CPUS))
done
done
done
echo -ne $args
function run_fuzzer () {
set -eu
set -o pipefail
# Trim trailing whitespace from last element.
local arg="$(echo -ne $1 | tr -d ' ')"
# Args are seperated by the '@' character.
target="$(echo -ne $arg | cut -d '@' -f 1)"
fuzzer="$(echo -ne $arg | cut -d '@' -f 2)"
trial="$(echo -nw $arg | cut -d '@' -f 3)"
core="$(echo -nw $arg | cut -d '@' -f 4)"
echo "fuzzer: $fuzzer"
echo "target: $target"
echo "trial: $trial"
echo "core: $core"
out_dir="${FUZZ_OUT_DIR}/${fuzzer}-${target}-$DURATION-${trial}"
rm -rf "$out_dir"
cp -a "$FISH_FUZZ_ROOT/paper/artifact/two-stage" "$out_dir"
cd "$out_dir"
# Generate the scripts for each fuzzer harness
python3 scripts/generate_script.py -b "$PWD/runtime/fuzz_script" > /dev/null
# Create the folder structure expected by the fuzzer/scripts
python3 scripts/generate_runtime.py -b "$PWD/runtime" > /dev/null
cmd="docker run -t -v "${out_dir}/runtime:/work" -e AFL_NO_UI=1 --name ${fuzzer}_${target}_${trial} --cpuset-cpus $core $TWO_STAGE_ARTIFACT_DOCKER_IMAGE_NAME timeout $DURATION "/work/fuzz_script/$fuzzer/${target}.sh""
echo $cmd
$cmd
}
# Export the `run_fuzzer` function such that it can be passed to `parallel`.
export -f run_fuzzer
# Export variables used in the `run_fuzzer` function.
export DURATION
export TWO_STAGE_ARTIFACT_DOCKER_IMAGE_NAME
export FUZZ_OUT_DIR
export WORK_DIR
export FISH_FUZZ_ROOT
# Start processing the tasks.
echo -ne $args | parallel -j $CPUS --bar -kd' ' -- run_fuzzer {} ';' || true