Skip to content

Commit 8ca0e35

Browse files
committed
2.37b
1 parent c091d4a commit 8ca0e35

10 files changed

+62
-70
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ install: all
123123
install -m 755 $(PROGS) $(SH_PROGS) $${DESTDIR}$(BIN_PATH)
124124
rm -f $${DESTDIR}$(BIN_PATH)/afl-as
125125
if [ -f afl-qemu-trace ]; then install -m 755 afl-qemu-trace $${DESTDIR}$(BIN_PATH); fi
126+
ifndef AFL_TRACE_PC
126127
if [ -f afl-clang-fast -a -f afl-llvm-pass.so -a -f afl-llvm-rt.o ]; then set -e; install -m 755 afl-clang-fast $${DESTDIR}$(BIN_PATH); ln -sf afl-clang-fast $${DESTDIR}$(BIN_PATH)/afl-clang-fast++; install -m 755 afl-llvm-pass.so afl-llvm-rt.o $${DESTDIR}$(HELPER_PATH); fi
128+
else
129+
if [ -f afl-clang-fast -a -f afl-llvm-rt.o ]; then set -e; install -m 755 afl-clang-fast $${DESTDIR}$(BIN_PATH); ln -sf afl-clang-fast $${DESTDIR}$(BIN_PATH)/afl-clang-fast++; install -m 755 afl-llvm-rt.o $${DESTDIR}$(HELPER_PATH); fi
130+
endif
127131
if [ -f afl-llvm-rt-32.o ]; then set -e; install -m 755 afl-llvm-rt-32.o $${DESTDIR}$(HELPER_PATH); fi
128132
if [ -f afl-llvm-rt-64.o ]; then set -e; install -m 755 afl-llvm-rt-64.o $${DESTDIR}$(HELPER_PATH); fi
129133
set -e; for i in afl-g++ afl-clang afl-clang++; do ln -sf afl-gcc $${DESTDIR}$(BIN_PATH)/$$i; done

afl-showmap.c

-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ static u32 write_results(void) {
189189

190190
if (binary_mode) {
191191

192-
u8 shifted_map[MAP_SIZE];
193-
194192
for (i = 0; i < MAP_SIZE; i++)
195193
if (trace_bits[i]) ret++;
196194

afl-tmin.c

+1
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,7 @@ int main(int argc, char** argv) {
10751075
The option may be extended and made more official if it proves
10761076
to be useful. */
10771077

1078+
if (mask_bitmap) FATAL("Multiple -B options not supported");
10781079
mask_bitmap = ck_alloc(MAP_SIZE);
10791080
read_bitmap(optarg);
10801081
break;

config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/* Version string: */
2323

24-
#define VERSION "2.36b"
24+
#define VERSION "2.37b"
2525

2626
/******************************************************
2727
* *

docs/ChangeLog

+16
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ Not sure if you should upgrade? The lowest currently recommended version
1616
is 2.31b. If you're stuck on an earlier release, it's strongly advisable
1717
to get on with the times.
1818

19+
--------------
20+
Version 2.37b:
21+
--------------
22+
23+
- Fixed a typo. Spotted by Jakub Wilk.
24+
25+
- Fixed support for make install when using trace-pc. Spotted by
26+
Kurt Roeckx.
27+
28+
- Switched trace-pc to trace-pc-guard, which should be considerably
29+
faster and is less quirky. Kudos to Konstantin Serebryany (and sorry
30+
for dragging my feet).
31+
32+
Note that for some reason, this mode doesn't perform as well as
33+
"vanilla" afl-clang-fast / afl-clang.
34+
1935
--------------
2036
Version 2.36b:
2137
--------------

llvm_mode/README.llvm

+8-11
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ PS. Because there are task switches still involved, the mode isn't as fast as
166166
faster than the normal fork() model, and compared to in-process fuzzing,
167167
should be a lot more robust.
168168

169-
6) Bonus feature #3: new 'trace-pc' mode
170-
----------------------------------------
169+
6) Bonus feature #3: new 'trace-pc-guard' mode
170+
----------------------------------------------
171171

172172
Recent versions of LLVM are shipping with a built-in execution tracing feature
173-
that is fairly usable for AFL, without the need to post-process the assembly
174-
or install any compiler plugins. See:
173+
that provides AFL with the necessary tracing data without the need to
174+
post-process the assembly or install any compiler plugins. See:
175175

176-
http://clang.llvm.org/docs/SanitizerCoverage.html#tracing-pcs
176+
http://clang.llvm.org/docs/SanitizerCoverage.html#tracing-pcs-with-guards
177177

178178
As of this writing, the feature is only available on SVN trunk, and is yet to
179179
make it to an official release of LLVM. Nevertheless, if you have a
@@ -182,10 +182,7 @@ this way:
182182

183183
AFL_TRACE_PC=1 make clean all
184184

185-
Since a form of 'trace-pc' is also supported in GCC, this mode may become a
186-
longer-term solution to all our needs.
185+
Note that this mode is currently about 20-30% slower than "vanilla"
186+
afl-clang-fast, and about 5-10% slower than afl-clang. I am not entirely sure
187+
why.
187188

188-
Note that this mode supports AFL_INST_RATIO at run time, not at compilation
189-
time. This is somewhat similar to the behavior of the QEMU mode. Because of
190-
the need to support it at run time, the mode is also a tad slower than the
191-
plugin-based approach.

llvm_mode/afl-clang-fast.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ static void edit_params(u32 argc, char** argv) {
114114

115115
/* There are two ways to compile afl-clang-fast. In the traditional mode, we
116116
use afl-llvm-pass.so to inject instrumentation. In the experimental
117-
'trace-pc' mode, we use native LLVM instrumentation callbacks instead.
118-
The latter is a very recent addition - see:
117+
'trace-pc-guard' mode, we use native LLVM instrumentation callbacks
118+
instead. The latter is a very recent addition - see:
119119
120-
http://clang.llvm.org/docs/SanitizerCoverage.html#tracing-pcs */
120+
http://clang.llvm.org/docs/SanitizerCoverage.html#tracing-pcs-with-guards */
121121

122122
#ifdef USE_TRACE_PC
123-
cc_params[cc_par_cnt++] = "-fsanitize-coverage=bb,trace-pc";
123+
cc_params[cc_par_cnt++] = "-fsanitize-coverage=trace-pc-guard";
124124
#else
125125
cc_params[cc_par_cnt++] = "-Xclang";
126126
cc_params[cc_par_cnt++] = "-load";

llvm_mode/afl-llvm-pass.so.cc

-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ namespace {
4949

5050
bool runOnModule(Module &M) override;
5151

52-
/* Ugh, the return type changed in recent versions of LLVM
53-
(const char* -> StringRef). Commenting out until the situation
54-
stabilizes, since we don't strictly need this anyway. */
55-
5652
// StringRef getPassName() const override {
5753
// return "American Fuzzy Lop Instrumentation";
5854
// }

llvm_mode/afl-llvm-rt.o.c

+27-47
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
#include <sys/wait.h>
3535
#include <sys/types.h>
3636

37+
#ifdef USE_TRACE_PC
38+
# define CONST_PRIO 5
39+
#else
40+
# define CONST_PRIO 0
41+
#endif /* ^USE_TRACE_PC */
42+
3743

3844
/* Globals needed by the injected instrumentation. The __afl_area_initial region
3945
is used for instrumentation output before __afl_map_shm() has a chance to run.
@@ -234,81 +240,55 @@ void __afl_manual_init(void) {
234240
}
235241

236242

237-
static void __afl_trace_pc_init(void);
238-
239-
240243
/* Proper initialization routine. */
241244

242-
__attribute__((constructor(0))) void __afl_auto_init(void) {
245+
__attribute__((constructor(CONST_PRIO))) void __afl_auto_init(void) {
243246

244247
is_persistent = !!getenv(PERSIST_ENV_VAR);
245248

246-
__afl_trace_pc_init();
247-
248249
if (getenv(DEFER_ENV_VAR)) return;
249250

250251
__afl_manual_init();
251252

252253
}
253254

254255

255-
/* The following stuff deals with support for -fsanitize-coverage=bb,trace-pc.
256+
/* The following stuff deals with supporting -fsanitize-coverage=trace-pc-guard.
256257
It remains non-operational in the traditional, plugin-backed LLVM mode.
257-
For more info about 'trace-pc', see README.llvm.
258-
259-
The first function (__sanitizer_cov_trace_pc) is called back on every
260-
basic block. Since LLVM is not giving us any stable IDs for the blocks,
261-
we use 12 least significant bits of the return address (which should be
262-
stable even with ASLR; more significant bits may vary across runs).
263-
264-
Since MAP_SIZE is usually larger than 12 bits, we "pad" it by combining
265-
left-shifted __afl_prev_loc. This gives us a theoretical maximum of 24
266-
bits, although instruction alignment likely reduces this somewhat. */
267-
268-
269-
static u32 inst_ratio_scaled = MIN(4096, MAP_SIZE);
258+
For more info about 'trace-pc-guard', see README.llvm.
270259
271-
void __sanitizer_cov_trace_pc(void) {
260+
The first function (__sanitizer_cov_trace_pc_guard) is called back on every
261+
edge (as opposed to every basic block). */
272262

273-
u32 cur = ((u32)__builtin_return_address(0)) & MIN(4095, MAP_SIZE - 1);
274-
275-
if (cur > inst_ratio_scaled) return;
276-
277-
__afl_area_ptr[cur ^ __afl_prev_loc]++;
278-
279-
#if MAP_SIZE_POW2 > 12
280-
__afl_prev_loc = cur << (MAP_SIZE_POW2 - 12);
281-
#else
282-
__afl_prev_loc = cur >> 1;
283-
#endif /* ^MAP_SIZE_POW2 > 12 */
284263

264+
void __sanitizer_cov_trace_pc_guard(uint32_t* guard) {
265+
__afl_area_ptr[*guard]++;
285266
}
286267

287268

288-
/* Init callback. Unfortunately, LLVM does not support compile-time
289-
instrumentation density scaling, at least not just yet. This means
290-
taking some performance hit by checking inst_ratio_scaled at runtime. */
291-
292-
static void __afl_trace_pc_init(void) {
269+
/* Init callback. Populates instrumentation IDs. Note that we're using
270+
ID of 0 as a special value to indicate non-instrumented bits. */
293271

294-
u8* x = getenv("AFL_INST_RATIO");
272+
void __sanitizer_cov_trace_pc_guard_init(uint32_t* start, uint32_t* stop) {
295273

296-
if (!x) return;
274+
u32 inst_ratio = 100;
275+
u8* x;
297276

298-
inst_ratio_scaled = atoi(x);
277+
x = getenv("AFL_INST_RATIO");
278+
if (x) inst_ratio = atoi(x);
299279

300-
if (!inst_ratio_scaled || inst_ratio_scaled > 100) {
280+
if (!inst_ratio || inst_ratio > 100) {
301281
fprintf(stderr, "[-] ERROR: Invalid AFL_INST_RATIO (must be 1-100).\n");
302282
abort();
303283
}
304284

305-
inst_ratio_scaled = inst_ratio_scaled * MIN(4096, MAP_SIZE) / 100;
306-
307-
}
285+
while (start < stop) {
308286

287+
if (R(100) < inst_ratio) *start = R(MAP_SIZE - 1) + 1;
288+
else *start = 0;
309289

310-
/* Work around a short-lived bug in LLVM with -fsanitize-coverage=trace-pc. */
290+
start++;
311291

312-
void __sanitizer_cov_module_init(void) __attribute__((weak));
313-
void __sanitizer_cov_module_init(void) { }
292+
}
314293

294+
}

qemu_mode/README.qemu

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ somehow need to fuzz an untrusted binary, put everything in a sandbox first.
100100

101101
QEMU does not necessarily support all CPU or hardware features that your
102102
target program may be utilizing. In particular, it does not appear to have
103-
full support for AVX2 / FMA3. Using binaries for older CPUs, or recompling them
103+
full support for AVX2 / FMA3. Using binaries for older CPUs, or recompiling them
104104
with -march=core2, can help.
105105

106106
Beyond that, this is an early-stage mechanism, so fields reports are welcome.

0 commit comments

Comments
 (0)