Skip to content

Commit abd1d3a

Browse files
committed
hash pc counter
1 parent 4eb8c66 commit abd1d3a

File tree

9 files changed

+5745
-60
lines changed

9 files changed

+5745
-60
lines changed

accel/tcg/tcg-runtime.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ void HELPER(afl_cmplog_rtn)(CPUArchState *env) {
282282
uintptr_t k = 0;
283283
#endif
284284

285-
k = (k >> 4) ^ (k << 8);
286-
k &= CMP_MAP_W - 1;
285+
k = (uintptr_t)(XXH64((u8 *)&k, sizeof(uintptr_t), HASH_CONST));
286+
k &= (CMP_MAP_W - 1);
287287

288288
u32 hits = 0;
289289

accel/tcg/translate-all.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ static void afl_gen_trace(target_ulong cur_loc) {
106106

107107
// cur_loc = (cur_loc >> 4) ^ (cur_loc << 8);
108108
// cur_loc &= MAP_SIZE - 1;
109-
cur_loc = pc_hash(cur_loc) & (MAP_SIZE -1);
109+
cur_loc = (uintptr_t)(XXH64((u8 *)&cur_loc, sizeof(uintptr_t), HASH_CONST));
110+
cur_loc &= (MAP_SIZE - 1);
110111

111112
/* Implement probabilistic instrumentation by looking at scrambled block
112113
address. This keeps the instrumented locations stable across runs. */

qemuafl/common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
#include "imported/types.h"
3939
#include "imported/cmplog.h"
4040

41+
#define XXH_INLINE_ALL
42+
#include "xxhash.h"
43+
#undef XXH_INLINE_ALL
44+
4145
#include "api.h"
4246

4347
#define AFL_G2H g2h_untagged

qemuafl/cpu-translate.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ static void afl_gen_compcov(target_ulong cur_loc, TCGv arg1, TCGv arg2,
4848

4949
if (__afl_cmp_map) {
5050

51-
cur_loc = (cur_loc >> 4) ^ (cur_loc << 8);
52-
cur_loc &= CMP_MAP_W - 1;
51+
cur_loc = (uintptr_t)(XXH64((u8 *)&cur_loc, sizeof(uintptr_t), HASH_CONST));
52+
cur_loc &= (CMP_MAP_W - 1);
5353

5454
TCGv cur_loc_v = tcg_const_tl(cur_loc);
5555

@@ -78,8 +78,8 @@ static void afl_gen_compcov(target_ulong cur_loc, TCGv arg1, TCGv arg2,
7878

7979
if (!is_imm && afl_compcov_level < 2) return;
8080

81-
cur_loc = (cur_loc >> 4) ^ (cur_loc << 8);
82-
cur_loc &= MAP_SIZE - 7;
81+
cur_loc = (uintptr_t)(XXH64((u8 *)&cur_loc, sizeof(uintptr_t), HASH_CONST));
82+
cur_loc &= (MAP_SIZE - 1);
8383

8484
TCGv cur_loc_v = tcg_const_tl(cur_loc);
8585

qemuafl/imported/cmplog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
you may not use this file except in compliance with the License.
1919
You may obtain a copy of the License at:
2020
21-
http://www.apache.org/licenses/LICENSE-2.0
21+
https://www.apache.org/licenses/LICENSE-2.0
2222
2323
Shared code to handle the shared memory. This is used by the fuzzer
2424
as well the other components like afl-tmin, afl-showmap, etc...

qemuafl/imported/config.h

Lines changed: 132 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,113 @@
1010
Dominik Maier <[email protected]>
1111
1212
Copyright 2016, 2017 Google Inc. All rights reserved.
13-
Copyright 2019-2020 AFLplusplus Project. All rights reserved.
13+
Copyright 2019-2021 AFLplusplus Project. All rights reserved.
1414
1515
Licensed under the Apache License, Version 2.0 (the "License");
1616
you may not use this file except in compliance with the License.
1717
You may obtain a copy of the License at:
1818
19-
http://www.apache.org/licenses/LICENSE-2.0
19+
https://www.apache.org/licenses/LICENSE-2.0
2020
2121
*/
2222

2323
#ifndef _HAVE_CONFIG_H
2424
#define _HAVE_CONFIG_H
2525

26-
#include "types.h"
27-
2826
/* Version string: */
2927

30-
// c = release, d = volatile github dev, e = experimental branch
31-
#define VERSION "++2.66d"
28+
// c = release, a = volatile github dev, e = experimental branch
29+
#define VERSION "++3.15a"
3230

3331
/******************************************************
3432
* *
3533
* Settings that may be of interest to power users: *
3634
* *
3735
******************************************************/
3836

37+
/* Default shared memory map size. Most targets just need a coverage map
38+
between 20-250kb. Plus there is an auto-detection feature in afl-fuzz.
39+
However if a target has problematic constructors and init arrays then
40+
this can fail. Hence afl-fuzz deploys a larger default map. The largest
41+
map seen so far is the xlsx fuzzer for libreoffice which is 5MB.
42+
At runtime this value can be overriden via AFL_MAP_SIZE.
43+
Default: 8MB (defined in bytes) */
44+
#define DEFAULT_SHMEM_SIZE (8 * 1024 * 1024)
45+
46+
/* Default file permission umode when creating files (default: 0600) */
47+
#define DEFAULT_PERMISSION 0600
48+
49+
/* CMPLOG/REDQUEEN TUNING
50+
*
51+
* Here you can modify tuning and solving options for CMPLOG.
52+
* Note that these are run-time options for afl-fuzz, no target
53+
* recompilation required.
54+
*
55+
*/
56+
57+
/* if TRANSFORM is enabled with '-l T', this additionally enables base64
58+
encoding/decoding */
59+
// #define CMPLOG_SOLVE_TRANSFORM_BASE64
60+
61+
/* If a redqueen pass finds more than one solution, try to combine them? */
62+
#define CMPLOG_COMBINE
63+
64+
/* Minimum % of the corpus to perform cmplog on. Default: 10% */
65+
#define CMPLOG_CORPUS_PERCENT 5U
66+
67+
/* Number of potential positions from which we decide if cmplog becomes
68+
useless, default 8096 */
69+
#define CMPLOG_POSITIONS_MAX (12 * 1024)
70+
71+
/* Maximum allowed fails per CMP value. Default: 128 */
72+
#define CMPLOG_FAIL_MAX 96
73+
74+
/* -------------------------------------*/
75+
/* Now non-cmplog configuration options */
76+
/* -------------------------------------*/
77+
78+
/* If a persistent target keeps state and found crashes are not reproducable
79+
then enable this option and set the AFL_PERSISTENT_RECORD env variable
80+
to a number. These number of testcases prior and including the crash case
81+
will be kept and written to the crash/ directory as RECORD:... files.
82+
Note that every crash will be written, not only unique ones! */
83+
84+
//#define AFL_PERSISTENT_RECORD
85+
86+
/* console output colors: There are three ways to configure its behavior
87+
* 1. default: colored outputs fixed on: defined USE_COLOR && defined
88+
* ALWAYS_COLORED The env var. AFL_NO_COLOR will have no effect
89+
* 2. defined USE_COLOR && !defined ALWAYS_COLORED
90+
* -> depending on env var AFL_NO_COLOR=1 colors can be switched off
91+
* at run-time. Default is to use colors.
92+
* 3. colored outputs fixed off: !defined USE_COLOR
93+
* The env var. AFL_NO_COLOR will have no effect
94+
*/
95+
3996
/* Comment out to disable terminal colors (note that this makes afl-analyze
4097
a lot less nice): */
4198

4299
#define USE_COLOR
43100

101+
#ifdef USE_COLOR
102+
/* Comment in to always enable terminal colors */
103+
/* Comment out to enable runtime controlled terminal colors via AFL_NO_COLOR
104+
*/
105+
#define ALWAYS_COLORED 1
106+
#endif
107+
108+
/* StatsD config
109+
Config can be adjusted via AFL_STATSD_HOST and AFL_STATSD_PORT environment
110+
variable.
111+
*/
112+
#define STATSD_UPDATE_SEC 1
113+
#define STATSD_DEFAULT_PORT 8125
114+
#define STATSD_DEFAULT_HOST "127.0.0.1"
115+
44116
/* If you want to have the original afl internal memory corruption checks.
45117
Disabled by default for speed. it is better to use "make ASAN_BUILD=1". */
46118

47-
//#define _WANT_ORIGINAL_AFL_ALLOC
119+
// #define _WANT_ORIGINAL_AFL_ALLOC
48120

49121
/* Comment out to disable fancy ANSI boxes and use poor man's 7-bit UI: */
50122

@@ -55,69 +127,61 @@
55127
/* Default timeout for fuzzed code (milliseconds). This is the upper bound,
56128
also used for detecting hangs; the actual value is auto-scaled: */
57129

58-
#define EXEC_TIMEOUT 1000
130+
#define EXEC_TIMEOUT 1000U
59131

60132
/* Timeout rounding factor when auto-scaling (milliseconds): */
61133

62-
#define EXEC_TM_ROUND 20
134+
#define EXEC_TM_ROUND 20U
63135

64136
/* 64bit arch MACRO */
65137
#if (defined(__x86_64__) || defined(__arm64__) || defined(__aarch64__))
66138
#define WORD_SIZE_64 1
67139
#endif
68140

69-
/* Default memory limit for child process (MB): */
70-
71-
#ifndef __NetBSD__
72-
#ifndef WORD_SIZE_64
73-
#define MEM_LIMIT 25
74-
#else
75-
#define MEM_LIMIT 50
76-
#endif /* ^!WORD_SIZE_64 */
77-
#else /* NetBSD's kernel needs more space for stack, see discussion for issue \
78-
#165 */
79-
#define MEM_LIMIT 200
80-
#endif
81-
/* Default memory limit when running in QEMU mode (MB): */
141+
/* Default memory limit for child process (MB) 0 = disabled : */
142+
143+
#define MEM_LIMIT 0U
144+
145+
/* Default memory limit when running in QEMU mode (MB) 0 = disabled : */
82146

83-
#define MEM_LIMIT_QEMU 200
147+
#define MEM_LIMIT_QEMU 0U
84148

85-
/* Default memory limit when running in Unicorn mode (MB): */
149+
/* Default memory limit when running in Unicorn mode (MB) 0 = disabled : */
86150

87-
#define MEM_LIMIT_UNICORN 200
151+
#define MEM_LIMIT_UNICORN 0U
88152

89153
/* Number of calibration cycles per every new test case (and for test
90154
cases that show variable behavior): */
91155

92-
#define CAL_CYCLES 8
93-
#define CAL_CYCLES_LONG 40
156+
#define CAL_CYCLES 8U
157+
#define CAL_CYCLES_LONG 20U
94158

95159
/* Number of subsequent timeouts before abandoning an input file: */
96160

97-
#define TMOUT_LIMIT 250
161+
#define TMOUT_LIMIT 250U
98162

99163
/* Maximum number of unique hangs or crashes to record: */
100164

101-
#define KEEP_UNIQUE_HANG 500
102-
#define KEEP_UNIQUE_CRASH 5000
165+
#define KEEP_UNIQUE_HANG 500U
166+
#define KEEP_UNIQUE_CRASH 10000U
103167

104168
/* Baseline number of random tweaks during a single 'havoc' stage: */
105169

106-
#define HAVOC_CYCLES 256
107-
#define HAVOC_CYCLES_INIT 1024
170+
#define HAVOC_CYCLES 256U
171+
#define HAVOC_CYCLES_INIT 1024U
108172

109173
/* Maximum multiplier for the above (should be a power of two, beware
110174
of 32-bit int overflows): */
111175

112-
#define HAVOC_MAX_MULT 16
113-
#define HAVOC_MAX_MULT_MOPT 32
176+
#define HAVOC_MAX_MULT 64U
177+
#define HAVOC_MAX_MULT_MOPT 64U
114178

115179
/* Absolute minimum number of havoc cycles (after all adjustments): */
116180

117-
#define HAVOC_MIN 16
181+
#define HAVOC_MIN 12U
118182

119183
/* Power Schedule Divisor */
120-
#define POWER_BETA 1
184+
#define POWER_BETA 1U
121185
#define MAX_FACTOR (POWER_BETA * 32)
122186

123187
/* Maximum stacking for havoc-stage tweaks. The actual value is calculated
@@ -126,22 +190,22 @@
126190
n = random between 1 and HAVOC_STACK_POW2
127191
stacking = 2^n
128192
129-
In other words, the default (n = 7) produces 2, 4, 8, 16, 32, 64, or
130-
128 stacked tweaks: */
193+
In other words, the default (n = 4) produces 2, 4, 8, 16
194+
stacked tweaks: */
131195

132-
#define HAVOC_STACK_POW2 7
196+
#define HAVOC_STACK_POW2 4U
133197

134198
/* Caps on block sizes for cloning and deletion operations. Each of these
135199
ranges has a 33% probability of getting picked, except for the first
136200
two cycles where smaller blocks are favored: */
137201

138-
#define HAVOC_BLK_SMALL 32
139-
#define HAVOC_BLK_MEDIUM 128
140-
#define HAVOC_BLK_LARGE 1500
202+
#define HAVOC_BLK_SMALL 32U
203+
#define HAVOC_BLK_MEDIUM 128U
204+
#define HAVOC_BLK_LARGE 1500U
141205

142206
/* Extra-large blocks, selected very rarely (<5% of the time): */
143207

144-
#define HAVOC_BLK_XL 32768
208+
#define HAVOC_BLK_XL 32768U
145209

146210
/* Probabilities of skipping non-favored entries in the queue, expressed as
147211
percentages: */
@@ -169,13 +233,15 @@
169233
#define TRIM_START_STEPS 16
170234
#define TRIM_END_STEPS 1024
171235

172-
/* Maximum size of input file, in bytes (keep under 100MB): */
236+
/* Maximum size of input file, in bytes (keep under 100MB, default 1MB):
237+
(note that if this value is changed, several areas in afl-cc.c, afl-fuzz.c
238+
and afl-fuzz-state.c have to be changed as well! */
173239

174-
#define MAX_FILE (1 * 1024 * 1024)
240+
#define MAX_FILE (1 * 1024 * 1024L)
175241

176242
/* The same, for the test case minimizer: */
177243

178-
#define TMIN_MAX_FILE (10 * 1024 * 1024)
244+
#define TMIN_MAX_FILE (10 * 1024 * 1024L)
179245

180246
/* Block normalization steps for afl-tmin: */
181247

@@ -195,14 +261,14 @@
195261
steps; past this point, the "extras/user" step will be still carried out,
196262
but with proportionally lower odds: */
197263

198-
#define MAX_DET_EXTRAS 200
264+
#define MAX_DET_EXTRAS 256
199265

200266
/* Maximum number of auto-extracted dictionary tokens to actually use in fuzzing
201267
(first value), and to keep in memory as candidates. The latter should be much
202268
higher than the former. */
203269

204-
#define USE_AUTO_EXTRAS 128
205-
#define MAX_AUTO_EXTRAS (USE_AUTO_EXTRAS * 64)
270+
#define USE_AUTO_EXTRAS 4096
271+
#define MAX_AUTO_EXTRAS (USE_AUTO_EXTRAS * 8)
206272

207273
/* Scaling factor for the effector map used to skip some of the more
208274
expensive deterministic steps. The actual divisor is set to
@@ -236,6 +302,11 @@
236302

237303
#define SYNC_INTERVAL 8
238304

305+
/* Sync time (minimum time between syncing in ms, time is halfed for -M main
306+
nodes) - default is 30 minutes: */
307+
308+
#define SYNC_TIME (30 * 60 * 1000)
309+
239310
/* Output directory reuse grace period (minutes): */
240311

241312
#define OUTPUT_GRACE 25
@@ -295,6 +366,13 @@
295366

296367
#define RESEED_RNG 100000
297368

369+
/* The default maximum testcase cache size in MB, 0 = disable.
370+
A value between 50 and 250 is a good default value. Note that the
371+
number of entries will be auto assigned if not specified via the
372+
AFL_TESTCACHE_ENTRIES env variable */
373+
374+
#define TESTCASE_CACHE_SIZE 50
375+
298376
/* Maximum line length passed from GCC to 'as' and used for parsing
299377
configuration files: */
300378

@@ -328,6 +406,10 @@
328406

329407
#define MSAN_ERROR 86
330408

409+
/* Distinctive exit code used to indicate LSAN trip condition: */
410+
411+
#define LSAN_ERROR 23
412+
331413
/* Designated file descriptors for forkserver commands (the application will
332414
use FORKSRV_FD and FORKSRV_FD + 1): */
333415

@@ -356,7 +438,7 @@
356438
after changing this - otherwise, SEGVs may ensue. */
357439

358440
#define MAP_SIZE_POW2 16
359-
#define MAP_SIZE (1 << MAP_SIZE_POW2)
441+
#define MAP_SIZE (1U << MAP_SIZE_POW2)
360442

361443
/* Maximum allocator request size (keep well under INT_MAX): */
362444

qemuafl/imported/snapshot-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
you may not use this file except in compliance with the License.
1919
You may obtain a copy of the License at:
2020
21-
http://www.apache.org/licenses/LICENSE-2.0
21+
https://www.apache.org/licenses/LICENSE-2.0
2222
2323
*/
2424

0 commit comments

Comments
 (0)