Skip to content

Commit a276488

Browse files
authored
Merge branch 'MozillaSecurity:master' into master
2 parents d7db9cc + 58d7469 commit a276488

File tree

29 files changed

+950
-206
lines changed

29 files changed

+950
-206
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212
# Python egg metadata, regenerated from source files by setuptools.
1313
*.egg-info
1414
.eggs/
15+
16+
# Intellij IDEA
17+
.idea/

recipes/linux/common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function resolve-url () {
8181

8282
# wrap curl with sane defaults
8383
function retry-curl () {
84-
curl --connect-timeout 25 --fail --location --retry 5 --show-error --silent --write-out "%{stderr}[downloaded %{url_effective}]\n" "$@"
84+
curl --connect-timeout 25 --fail --location --retry 5 --retry-all-errors --show-error --silent --write-out "%{stderr}[downloaded %{url_effective}]\n" "$@"
8585
}
8686

8787
function get-deadline () {

services/afl/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ COPY \
2929
services/afl/pyproject.toml \
3030
services/nyx/nyx_utils.py \
3131
/srv/repos/nyx_utils/
32+
COPY services/afl/patches/ /home/worker/patches/
3233
RUN /srv/repos/setup/setup.sh
3334
COPY \
3435
services/afl/launch-root.sh \

services/afl/launch-worker.sh

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ fi
7575
ASAN_OPTIONS=\
7676
abort_on_error=1:\
7777
hard_rss_limit_mb=4096:\
78-
log_path=/tmp/data.log:\
7978
max_allocation_size_mb=3073:\
8079
strip_path_prefix=/builds/worker/workspace/build/src/:\
8180
symbolize=0:\
@@ -94,9 +93,20 @@ if [[ "$COVERAGE" = 1 ]]; then
9493
export SOURCE_URL
9594
REVISION="$(retry-curl --compressed "$ARTIFACT_ROOT/coverage-revision.txt")"
9695
export REVISION
96+
97+
export AFL_FAST_CAL=1
9798
fi
9899

99100
TARGET_BIN="$(./setup-target.sh)"
101+
JS="${JS:-0}"
102+
if [[ "$JS" = 1 ]] || [[ -n "$JSRT" ]]
103+
then
104+
export GCOV_PREFIX="$HOME/js"
105+
else
106+
export GCOV_PREFIX="$HOME/firefox"
107+
fi
108+
GCOV_PREFIX_STRIP="$(grep pathprefix "$HOME/${TARGET_BIN}.fuzzmanagerconf" | grep -E -o "/.+$" | tr -cd '/' | wc -c)"
109+
export GCOV_PREFIX_STRIP
100110

101111
mkdir -p corpus.out
102112

@@ -120,14 +130,19 @@ DAEMON_ARGS=(
120130
--afl-binary-dir /opt/afl-instrumentation/bin
121131
--afl-timeout "${AFL_TIMEOUT-30000}"
122132
--afl
133+
--instances "${AFL_INSTANCES:-$(ncpu)}"
123134
--stats ./stats
124135
--memory-limit "${MEMORY_LIMIT:-0}"
125136
"$TARGET_BIN"
126137
)
127138

139+
unset AFL_INSTANCES
140+
128141
S3_PROJECT="${S3_PROJECT:-afl-$FUZZER}"
129142
S3_PROJECT_ARGS=(--provider GCS --bucket guided-fuzzing-data --project "$S3_PROJECT")
130143

144+
export AFL_MAP_SIZE=8388608
145+
131146
if [[ -n "$S3_CORPUS_REFRESH" ]]
132147
then
133148
update-status "starting corpus refresh"
@@ -157,17 +172,13 @@ else
157172
echo "Hello world" > ./corpus/input0
158173
fi
159174

160-
instance_count="${AFL_INSTANCES:-$(ncpu)}"
161-
unset AFL_INSTANCES
162-
export AFL_MAP_SIZE=8388608
163175
# run and watch for results
164176
update-status "launching guided-fuzzing-daemon"
165177
time xvfb-run guided-fuzzing-daemon "${S3_PROJECT_ARGS[@]}" \
166178
--afl-log-pattern /logs/afl%d.log \
167179
--fuzzmanager \
168180
--max-runtime "$(get-target-time)" \
169181
--afl-async-corpus \
170-
--instances "$instance_count" \
171182
--queue-upload \
172183
--tool "$TOOLNAME" \
173184
--corpus-in ./corpus \
@@ -182,7 +193,20 @@ fi
182193

183194
if [[ $COVERAGE -eq 1 ]]
184195
then
185-
# TODO: coverage.json
196+
retry-curl --compressed -O "$SOURCE_URL"
197+
unzip source.zip
198+
199+
# Collect coverage count data.
200+
RUST_BACKTRACE=1 grcov "$GCOV_PREFIX" \
201+
-t coveralls+ \
202+
--commit-sha "$REVISION" \
203+
--token NONE \
204+
--guess-directory-when-missing \
205+
--ignore-not-existing \
206+
-p "$(rg -Nor '$1' "pathprefix = (.*)" "$HOME/${TARGET_BIN}.fuzzmanagerconf")" \
207+
-s "./${REPO-mozilla-central}-$REVISION" \
208+
> ./coverage.json
209+
186210
# Submit coverage data.
187211
cov-reporter \
188212
--repository mozilla-central \

services/afl/patches/afl-cmin.patch

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
diff --git a/afl-cmin b/afl-cmin
2+
index a88460a8..e43877ac 100755
3+
--- a/afl-cmin
4+
+++ b/afl-cmin
5+
@@ -258,7 +258,7 @@ BEGIN {
6+
# sanity checks
7+
if (!prog_args[0] || !in_dir || !out_dir) usage()
8+
9+
- target_bin = prog_args[0]
10+
+ target_bin = prog_args[0]
11+
12+
# Do a sanity check to discourage the use of /tmp, since we can't really
13+
# handle this safely from an awk script.
14+
@@ -330,14 +330,18 @@ BEGIN {
15+
target_bin = tnew
16+
}
17+
18+
- if (0 == system ( "grep -aq AFL_DUMP_MAP_SIZE " target_bin )) {
19+
- echo "[!] Trying to obtain the map size of the target ..."
20+
- get_map_size = "AFL_DUMP_MAP_SIZE=1 " target_bin
21+
- get_map_size | getline mapsize
22+
- close(get_map_size)
23+
- if (mapsize && mapsize > 65535 && mapsize < 100000000) {
24+
- AFL_MAP_SIZE = "AFL_MAP_SIZE="mapsize" "
25+
- print "[+] Setting "AFL_MAP_SIZE
26+
+ if (!nyx_mode) {
27+
+ if (!ENVIRON["AFL_MAP_SIZE"] && 0 == system ( "grep -aq AFL_DUMP_MAP_SIZE " target_bin )) {
28+
+ echo "[!] Trying to obtain the map size of the target ..."
29+
+ get_map_size = "AFL_DUMP_MAP_SIZE=1 " target_bin
30+
+ get_map_size | getline mapsize
31+
+ close(get_map_size)
32+
+ if (mapsize && mapsize > 65535 && mapsize < 100000000) {
33+
+ AFL_MAP_SIZE = "AFL_MAP_SIZE="mapsize" "
34+
+ print "[+] Setting "AFL_MAP_SIZE
35+
+ }
36+
+ } else {
37+
+ AFL_MAP_SIZE = "AFL_MAP_SIZE=" ENVIRON["AFL_MAP_SIZE"] " "
38+
}
39+
}
40+
41+
@@ -348,6 +352,8 @@ BEGIN {
42+
}
43+
}
44+
45+
+ AFL_PRELOAD = ("AFL_PRELOAD" in ENVIRON) ? "AFL_PRELOAD=" ENVIRON["AFL_PRELOAD"] " " : ""
46+
+
47+
if (0 != system( "test -d "in_dir )) {
48+
print "[-] Error: directory '"in_dir"' not found." > "/dev/stderr"
49+
exit 1
50+
@@ -470,10 +476,10 @@ BEGIN {
51+
print "[*] Testing the target binary..."
52+
53+
if (!stdin_file) {
54+
- system(AFL_MAP_SIZE "AFL_CMIN_ALLOW_ANY=1 "AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"/.run_test\" -Z "extra_par" -- \""target_bin"\" "prog_args_string" <\""in_dir"/"first_file"\"")
55+
+ system(AFL_MAP_SIZE AFL_PRELOAD "AFL_CMIN_ALLOW_ANY=1 "AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"/.run_test\" -Z "extra_par" -- \""target_bin"\" "prog_args_string" <\""in_dir"/"first_file"\"")
56+
} else {
57+
system("cp \""in_dir"/"first_file"\" "stdin_file)
58+
- system(AFL_MAP_SIZE "AFL_CMIN_ALLOW_ANY=1 "AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"/.run_test\" -Z "extra_par" -H \""stdin_file"\" -- \""target_bin"\" "prog_args_string" </dev/null")
59+
+ system(AFL_MAP_SIZE AFL_PRELOAD "AFL_CMIN_ALLOW_ANY=1 "AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"/.run_test\" -Z "extra_par" -H \""stdin_file"\" -- \""target_bin"\" "prog_args_string" </dev/null")
60+
}
61+
62+
first_count = 0
63+
@@ -537,12 +543,12 @@ BEGIN {
64+
for (i = 1; i <= threads; i++) {
65+
66+
if (!stdin_file) {
67+
-# print " { "AFL_MAP_SIZE AFL_CMIN_ALLOW_ANY AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -I \""tmpfile"."i"\" -- \""target_bin"\" "prog_args_string"; > "tmpfile"."i".done ; } &"
68+
- retval = system(" { "AFL_MAP_SIZE AFL_CMIN_ALLOW_ANY AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -I \""tmpfile"."i"\" -- \""target_bin"\" "prog_args_string"; > "tmpfile"."i".done ; } &")
69+
+# print " { "AFL_MAP_SIZE AFL_PRELOAD AFL_CMIN_ALLOW_ANY AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -I \""tmpfile"."i"\" -- \""target_bin"\" "prog_args_string"; > "tmpfile"."i".done ; } &"
70+
+ retval = system(" { "AFL_MAP_SIZE AFL_PRELOAD AFL_CMIN_ALLOW_ANY AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -I \""tmpfile"."i"\" -- \""target_bin"\" "prog_args_string"; > "tmpfile"."i".done ; } &")
71+
} else {
72+
stdin_file=tmpfile"."i".stdin"
73+
-# print " { "AFL_MAP_SIZE AFL_CMIN_ALLOW_ANY AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -I \""tmpfile"."i"\" -H \""stdin_file"\" -- \""target_bin"\" "prog_args_string" </dev/null; > "tmpfile"."i".done ; } &"
74+
- retval = system(" { "AFL_MAP_SIZE AFL_CMIN_ALLOW_ANY AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -I \""tmpfile"."i"\" -H \""stdin_file"\" -- \""target_bin"\" "prog_args_string" </dev/null; > "tmpfile"."i".done ; } &")
75+
+# print " { "AFL_MAP_SIZE AFL_PRELOAD AFL_CMIN_ALLOW_ANY AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -I \""tmpfile"."i"\" -H \""stdin_file"\" -- \""target_bin"\" "prog_args_string" </dev/null; > "tmpfile"."i".done ; } &"
76+
+ retval = system(" { "AFL_MAP_SIZE AFL_PRELOAD AFL_CMIN_ALLOW_ANY AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -I \""tmpfile"."i"\" -H \""stdin_file"\" -- \""target_bin"\" "prog_args_string" </dev/null; > "tmpfile"."i".done ; } &")
77+
}
78+
}
79+
print "[*] Waiting for parallel tasks to complete ..."
80+
@@ -562,11 +568,11 @@ BEGIN {
81+
if (!stdin_file) {
82+
print " Processing "in_count" files (forkserver mode)..."
83+
# print AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -i \""in_dir"\" -- \""target_bin"\" "prog_args_string
84+
- retval = system(AFL_MAP_SIZE AFL_CMIN_ALLOW_ANY AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -i \""in_dir"\" -- \""target_bin"\" "prog_args_string)
85+
+ retval = system(AFL_MAP_SIZE AFL_PRELOAD AFL_CMIN_ALLOW_ANY AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -i \""in_dir"\" -- \""target_bin"\" "prog_args_string)
86+
} else {
87+
print " Processing "in_count" files (forkserver mode)..."
88+
# print AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -i \""in_dir"\" -H \""stdin_file"\" -- \""target_bin"\" "prog_args_string" </dev/null"
89+
- retval = system(AFL_MAP_SIZE AFL_CMIN_ALLOW_ANY AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -i \""in_dir"\" -H \""stdin_file"\" -- \""target_bin"\" "prog_args_string" </dev/null")
90+
+ retval = system(AFL_MAP_SIZE AFL_PRELOAD AFL_CMIN_ALLOW_ANY AFL_CMIN_CRASHES_ONLY"\""showmap"\" -m "mem_limit" -t "timeout" -o \""trace_dir"\" -Z "extra_par" -i \""in_dir"\" -H \""stdin_file"\" -- \""target_bin"\" "prog_args_string" </dev/null")
91+
}
92+
93+
if (retval && (!AFL_CMIN_CRASHES_ONLY && !AFL_CMIN_ALLOW_ANY)) {
94+
diff --git a/afl-cmin.bash b/afl-cmin.bash
95+
index 99ae80d9..2909ebfa 100755
96+
--- a/afl-cmin.bash
97+
+++ b/afl-cmin.bash
98+
@@ -245,14 +245,16 @@ if [ "$NYX_MODE" = "" ]; then
99+
100+
fi
101+
102+
-grep -aq AFL_DUMP_MAP_SIZE "$TARGET_BIN" && {
103+
- echo "[!] Trying to obtain the map size of the target ..."
104+
- MAPSIZE=`AFL_DUMP_MAP_SIZE=1 "./$TARGET_BIN" 2>/dev/null`
105+
- test -n "$MAPSIZE" && {
106+
- export AFL_MAP_SIZE=$MAPSIZE
107+
- echo "[+] Setting AFL_MAP_SIZE=$MAPSIZE"
108+
- }
109+
-}
110+
+if [ -z "$NYX_MODE" ]; then
111+
+ if [ -z "$AFL_MAP_SIZE" ] && grep -aq AFL_DUMP_MAP_SIZE "$TARGET_BIN"; then
112+
+ echo "[!] Trying to obtain the map size of the target ..."
113+
+ MAPSIZE=`AFL_DUMP_MAP_SIZE=1 "./$TARGET_BIN" 2>/dev/null`
114+
+ test -n "$MAPSIZE" && {
115+
+ export AFL_MAP_SIZE=$MAPSIZE
116+
+ echo "[+] Setting AFL_MAP_SIZE=$MAPSIZE"
117+
+ }
118+
+ fi
119+
+fi
120+
121+
if [ "$AFL_SKIP_BIN_CHECK" = "" -a "$QEMU_MODE" = "" -a "$FRIDA_MODE" = "" -a "$UNICORN_MODE" = "" -a "$NYX_MODE" = "" ]; then
122+

services/afl/setup-target.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ FETCH_ARGS=(-o "$HOME" --afl --fuzzing)
1818
if [[ -n "$JSRT" ]] && [[ -z "$COVERAGE" ]]
1919
then
2020
FETCH_ARGS+=(--debug)
21-
else
21+
elif [[ -z "$COVERAGE" ]]
22+
then
2223
FETCH_ARGS+=(--asan)
2324
fi
2425

services/afl/setup.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pkgs=(
5151
libosmesa6
5252
libpci3
5353
openssh-client
54+
patch
5455
pipx
5556
psmisc
5657
screen
@@ -81,6 +82,9 @@ afl_ver="$(resolve-tc-alias afl-instrumentation)"
8182
retry-curl "$(resolve-tc "$afl_ver")" | zstdcat | tar -x -C /opt
8283
# shellcheck disable=SC2016
8384
echo 'PATH=$PATH:/opt/afl-instrumentation/bin' >> /etc/bash.bashrc
85+
pushd /opt/afl-instrumentation/bin
86+
patch -p1 < /home/worker/patches/afl-cmin.patch
87+
popd >/dev/null
8488

8589
cd ..
8690
su worker << EOF

0 commit comments

Comments
 (0)