important InsTrim fixes!
MODIFY
docs/Changelog.md
docs/Changelog.md
@@ -17,6 +17,7 @@ sending a mail to <afl-users+subscribe@googlegroups.com>.
- the memory safety checks are now disabled for a little more speed during
fuzzing (only affects creating queue entries), can be toggled in config.h
- afl-fuzz:
+ - MOpt out of bounds writing crash fixed
- now prints the real python version support compiled in
- set stronger performance compile options and little tweaks
- Android: prefer bigcores when selecting a CPU
@@ -28,7 +29,12 @@ sending a mail to <afl-users+subscribe@googlegroups.com>.
- bugfix for dictionary insert stage count (fix via Google repo PR)
- added warning if -M is used together with custom mutators with _ONLY option
- AFL_TMPDIR checks are now later and better explained if they fail
- - llvm_mode InsTrim: no pointless instrumentation of 1 block functions
+ - llvm_mode
+ - InsTrim: three bug fixes:
+ 1. (minor) no pointless instrumentation of 1 block functions
+ 2. (medium) path bug that leads a few blocks not instrumented that
+ should be
+ 3. (major) incorrect prev_loc was written, fixed!
- afl-clang-fast:
- show in the help output for which llvm version it was compiled for
- now does not need to be recompiled between trace-pc and pass

MODIFY
llvm_mode/LLVMInsTrim.so.cc
llvm_mode/LLVMInsTrim.so.cc
@@ -382,19 +382,64 @@ struct InsTrim : public ModulePass {
}
- auto *EBB = &F.getEntryBlock();
- if (succ_begin(EBB) == succ_end(EBB)) {
+ // Bugfix #1: remove single block function instrumentation
- MS.insert(EBB);
+ for (BasicBlock &BB : F) {
+
+ if (MarkSetOpt && MS.find(&BB) == MS.end()) {
+
+ // Bugfix #2: instrument blocks that should be but InsTrim
+ // doesn't due to an algorithmic bug
+ int more_than_one = -1;
+
+ for (pred_iterator PI = pred_begin(&BB), E = pred_end(&BB); PI != E;
+ ++PI) {
+
+ BasicBlock *Pred = *PI;
+ int count = 0;
+
+ if (more_than_one == -1) more_than_one = 0;
+ for (succ_iterator SI = succ_begin(Pred), E = succ_end(Pred);
+ SI != E; ++SI) {
+
+ BasicBlock *Succ = *SI;
+ if (Succ != NULL) count++;
+
+ }
+
+ if (count > 1) more_than_one = 1;
+
+ }
+
+ if (more_than_one != 1) continue;
+ for (succ_iterator SI = succ_begin(&BB), E = succ_end(&BB); SI != E;
+ ++SI) {
+
+ BasicBlock *Succ = *SI;
+ if (Succ != NULL && MS.find(Succ) == MS.end()) {
+
+ int cnt = 0;
+ for (succ_iterator SI2 = succ_begin(Succ), E2 = succ_end(Succ);
+ SI2 != E2; ++SI2) {
+
+ BasicBlock *Succ2 = *SI2;
+ if (Succ2 != NULL) cnt++;
+
+ }
+
+ if (cnt == 0) {
+
+ // fprintf(stderr, "INSERT!\n");
+ MS.insert(Succ);
total_rs += 1;
}
- for (BasicBlock &BB : F) {
+ }
- if (MS.find(&BB) == MS.end()) { continue; }
- IRBuilder<> IRB(&*BB.getFirstInsertionPt());
- IRB.CreateStore(ConstantInt::get(Int32Ty, genLabel()), OldPrev);
+ }
+
+ }
}
@@ -402,17 +447,10 @@ struct InsTrim : public ModulePass {
for (BasicBlock &BB : F) {
- auto PI = pred_begin(&BB);
- auto PE = pred_end(&BB);
if (MarkSetOpt && MS.find(&BB) == MS.end()) { continue; }
IRBuilder<> IRB(&*BB.getFirstInsertionPt());
Value * L = NULL;
- if (PI == PE) {
-
- L = ConstantInt::get(Int32Ty, genLabel());
-
- } else {
auto *PN = PHINode::Create(Int32Ty, 0, "", &*BB.begin());
DenseMap<BasicBlock *, unsigned> PredMap;
@@ -427,8 +465,6 @@ struct InsTrim : public ModulePass {
L = PN;
- }
-
/* Load prev_loc */
LoadInst *PrevLoc = IRB.CreateLoad(OldPrev);
PrevLoc->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
@@ -475,6 +511,11 @@ struct InsTrim : public ModulePass {
IRB.CreateStore(Incr, MapPtrIdx)
->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
+ // Bugfix #3: save the actually location ID to OldPrev
+ Value *Shr = IRB.CreateLShr(L, One);
+ IRB.CreateStore(Shr, OldPrev)
+ ->setMetadata(M.getMDKindID("nosanitize"), MDNode::get(C, None));
+
total_instr++;
}

MODIFY
src/afl-as.c
src/afl-as.c
@@ -530,7 +530,8 @@ int main(int argc, char** argv) {
"Rarely, when dealing with extremely complex projects, it may be "
"advisable\n"
- "to set AFL_INST_RATIO to a value less than 100 in order to reduce the\n"
+ "to set AFL_INST_RATIO to a value less than 100 in order to reduce "
+ "the\n"
"odds of instrumenting every discovered branch.\n\n"
"Environment variables used:\n"
"AFL_AS: path to assembler to use for instrumented files\n"

MODIFY
src/afl-fuzz-redqueen.c
src/afl-fuzz-redqueen.c
@@ -261,7 +261,8 @@ u8 cmp_extend_encoding(struct cmp_header* h, u64 pattern, u64 repl, u32 idx,
if (SHAPE_BYTES(h->shape) == 4 || *status == 2) {
- if (its_len >= 4 && *buf_32 == (u32)pattern) {// && *o_buf_32 == (u32)pattern) {
+ if (its_len >= 4 &&
+ *buf_32 == (u32)pattern) { // && *o_buf_32 == (u32)pattern) {
*buf_32 = (u32)repl;
if (unlikely(its_fuzz(buf, len, status))) return 1;
@@ -279,7 +280,8 @@ u8 cmp_extend_encoding(struct cmp_header* h, u64 pattern, u64 repl, u32 idx,
if (SHAPE_BYTES(h->shape) == 2 || *status == 2) {
- if (its_len >= 2 && *buf_16 == (u16)pattern) {// && *o_buf_16 == (u16)pattern) {
+ if (its_len >= 2 &&
+ *buf_16 == (u16)pattern) { // && *o_buf_16 == (u16)pattern) {
*buf_16 = (u16)repl;
if (unlikely(its_fuzz(buf, len, status))) return 1;

important InsTrim fixes!