afl++, rename, fix build (#5815)

This commit is contained in:
Schrijvers Luc
2021-04-05 14:18:31 +02:00
committed by GitHub
parent e269595615
commit c16f980fd5
6 changed files with 347 additions and 60 deletions

View File

@@ -0,0 +1,6 @@
#!/bin/sh
#create directory debug_server if not present
if [ ! -d ~/config/settings/system/debug_server ]; then
mkdir -p ~/config/settings/system/debug_server
fi

View File

@@ -0,0 +1,107 @@
SUMMARY="American fuzzy lop, a security-oriented fuzzer"
DESCRIPTION="A fork of AFL, the popular compile-time instrumentation fuzzer"
HOMEPAGE="https://aflplus.plus/"
COPYRIGHT="2013-2016 Google Inc.
2013-2016 Michał Zalewski
2017-2021 Marc Heuse
2017-2021 Heiko Eißfeldt
2017-2021 Andrea Fioraldi
2017-2021 Dominik Maier"
LICENSE="Apache v2"
REVISION="1"
SOURCE_URI="https://github.com/AFLplusplus/AFLplusplus/archive/refs/tags/$portVersion.tar.gz"
CHECKSUM_SHA256="0240d34a2f99d157063e31d0c2d2801a68bc015e09187d9cc197637ec8fda635"
SOURCE_FILENAME="aflplusplus-$portVersion.tar.gz"
SOURCE_DIR="AFLplusplus-$portVersion"
# Imported also Gentoo patches
PATCHES="aflplusplus-$portVersion.patchset
aflplusplus-3.0c-CFLAGS.patch
aflplusplus-3.0c-LDFLAGS.patch"
ADDITIONAL_FILES="create-aflplusplus-directory.sh"
ARCHITECTURES="!x86_gcc2 x86_64"
SECONDARY_ARCHITECTURES="x86"
POST_INSTALL_SCRIPTS="
$relativePostInstallDir/create-aflplusplus-directory.sh
"
PROVIDES="
aflplusplus$secondaryArchSuffix = $portVersion
cmd:afl_analyze = $portVersion
cmd:afl_c++ = $portVersion
cmd:afl_cc = $portVersion
cmd:afl_clang++ = $portVersion
cmd:afl_clang = $portVersion
cmd:afl_cmin = $portVersion
cmd:afl_cmin.bash = $portVersion
cmd:afl_fuzz = $portVersion
cmd:afl_g++ = $portVersion
cmd:afl_gcc = $portVersion
cmd:afl_gotcpu = $portVersion
cmd:afl_plot = $portVersion
cmd:afl_showmap = $portVersion
cmd:afl_system_config = $portVersion
cmd:afl_tmin = $portVersion
cmd:afl_whatsup = $portVersion
"
REQUIRES="
haiku$secondaryArchSuffix
lib:libgmp$secondaryArchSuffix
lib:libintl$secondaryArchSuffix
lib:libpython3.7m$secondaryArchSuffix
lib:libLLVM_9$secondaryArchSuffix
"
BUILD_REQUIRES="
haiku${secondaryArchSuffix}_devel
gcc${secondaryArchSuffix}_syslibs_devel
devel:libgmp$secondaryArchSuffix
devel:libLLVM_9$secondaryArchSuffix
"
BUILD_PREREQUIRES="
cmd:awk
cmd:clang
cmd:make
cmd:gcc$secondaryArchSuffix
"
TEST_REQUIRES="
cmd:diff
devel:libcmocka$secondaryArchSuffix
"
PATCH()
{
# grabbed from Gentoo port
sed -i -e 's/-O3 -fno-unroll-loops//' GNUmakefile
}
makeAfl()
{
make -f GNUmakefile \
PREFIX=$prefix \
BIN_PATH=$prefix/bin \
HELPER_PATH=$libDir/afl \
DOC_PATH=$docDir \
MISC_PATH=$dataDir/afl \
MAN_PATH=$manDir/man8 \
"$@"
}
BUILD()
{
makeAfl $jobArgs
}
INSTALL()
{
makeAfl install
mkdir -p $postInstallDir
cp -f $portDir/additional-files/create-aflplusplus-directory.sh $postInstallDir
}
TEST()
{
make tests
}

View File

@@ -0,0 +1,110 @@
--- a/GNUmakefile.gcc_plugin
+++ b/GNUmakefile.gcc_plugin
@@ -28,14 +28,14 @@ MAN_PATH ?= $(PREFIX)/share/man/man8
VERSION = $(shell grep '^$(HASH)define VERSION ' ./config.h | cut -d '"' -f2)
-CFLAGS ?= -O3 -g -funroll-loops -D_FORTIFY_SOURCE=2
+CFLAGS ?= -D_FORTIFY_SOURCE=2
CFLAGS_SAFE := -Wall -Iinclude -Wno-pointer-sign \
-DAFL_PATH=\"$(HELPER_PATH)\" -DBIN_PATH=\"$(BIN_PATH)\" \
-DGCC_VERSION=\"$(GCCVER)\" -DGCC_BINDIR=\"$(GCCBINDIR)\" \
-Wno-unused-function
override CFLAGS += $(CFLAGS_SAFE)
-CXXFLAGS ?= -O3 -g -funroll-loops -D_FORTIFY_SOURCE=2
+CXXFLAGS ?= -D_FORTIFY_SOURCE=2
CXXEFLAGS := $(CXXFLAGS) -Wall -std=c++11
CC ?= gcc
--- a/GNUmakefile.llvm
+++ b/GNUmakefile.llvm
@@ -237,7 +237,7 @@ else
AFL_CLANG_DEBUG_PREFIX =
endif
-CFLAGS ?= -O3 -funroll-loops -fPIC -D_FORTIFY_SOURCE=2
+CFLAGS ?= -fPIC -D_FORTIFY_SOURCE=2
CFLAGS_SAFE := -Wall -g -Wno-cast-qual -Wno-variadic-macros -Wno-pointer-sign -I ./include/ -I ./instrumentation/ \
-DAFL_PATH=\"$(HELPER_PATH)\" -DBIN_PATH=\"$(BIN_PATH)\" \
-DLLVM_BINDIR=\"$(LLVM_BINDIR)\" -DVERSION=\"$(VERSION)\" \
@@ -254,7 +254,7 @@ ifdef AFL_TRACE_PC
$(info Compile option AFL_TRACE_PC is deprecated, just set AFL_LLVM_INSTRUMENT=PCGUARD to activate when compiling targets )
endif
-CXXFLAGS ?= -O3 -funroll-loops -fPIC -D_FORTIFY_SOURCE=2
+CXXFLAGS ?= -fPIC -D_FORTIFY_SOURCE=2
override CXXFLAGS += -Wall -g -I ./include/ \
-DVERSION=\"$(VERSION)\" -Wno-variadic-macros \
-DLLVM_MINOR=$(LLVM_MINOR) -DLLVM_MAJOR=$(LLVM_MAJOR)
@@ -434,20 +434,20 @@ afl-llvm-dict2file.so: instrumentation/afl-llvm-dict2file.so.cc instrumentation/
.PHONY: document
document:
- $(CLANG_BIN) -D_AFL_DOCUMENT_MUTATIONS $(CFLAGS_SAFE) $(CPPFLAGS) $(CLANG_CFL) -O3 -Wno-unused-result -fPIC -c instrumentation/afl-compiler-rt.o.c -o ./afl-compiler-rt.o
- @$(CLANG_BIN) -D_AFL_DOCUMENT_MUTATIONS $(CFLAGS_SAFE) $(CPPFLAGS) $(CLANG_CFL) -O3 -Wno-unused-result -m32 -fPIC -c instrumentation/afl-compiler-rt.o.c -o ./afl-compiler-rt-32.o 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; else echo "failed (that's fine)"; fi
- @$(CLANG_BIN) -D_AFL_DOCUMENT_MUTATIONS $(CFLAGS_SAFE) $(CPPFLAGS) $(CLANG_CFL) -O3 -Wno-unused-result -m64 -fPIC -c instrumentation/afl-compiler-rt.o.c -o ./afl-compiler-rt-64.o 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; else echo "failed (that's fine)"; fi
+ $(CLANG_BIN) -D_AFL_DOCUMENT_MUTATIONS $(CFLAGS_SAFE) $(CPPFLAGS) $(CLANG_CFL) -Wno-unused-result -fPIC -c instrumentation/afl-compiler-rt.o.c -o ./afl-compiler-rt.o
+ @$(CLANG_BIN) -D_AFL_DOCUMENT_MUTATIONS $(CFLAGS_SAFE) $(CPPFLAGS) $(CLANG_CFL) -Wno-unused-result -m32 -fPIC -c instrumentation/afl-compiler-rt.o.c -o ./afl-compiler-rt-32.o 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; else echo "failed (that's fine)"; fi
+ @$(CLANG_BIN) -D_AFL_DOCUMENT_MUTATIONS $(CFLAGS_SAFE) $(CPPFLAGS) $(CLANG_CFL) -Wno-unused-result -m64 -fPIC -c instrumentation/afl-compiler-rt.o.c -o ./afl-compiler-rt-64.o 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; else echo "failed (that's fine)"; fi
./afl-compiler-rt.o: instrumentation/afl-compiler-rt.o.c
- $(CC) $(CLANG_CFL) $(CFLAGS_SAFE) $(CPPFLAGS) -O3 -Wno-unused-result -fPIC -c $< -o $@
+ $(CC) $(CLANG_CFL) $(CFLAGS_SAFE) $(CPPFLAGS) -Wno-unused-result -fPIC -c $< -o $@
./afl-compiler-rt-32.o: instrumentation/afl-compiler-rt.o.c
@printf "[*] Building 32-bit variant of the runtime (-m32)... "
- @$(CC) $(CLANG_CFL) $(CFLAGS_SAFE) $(CPPFLAGS) -O3 -Wno-unused-result -m32 -fPIC -c $< -o $@ 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; ln -sf afl-compiler-rt-32.o afl-llvm-rt-32.o; else echo "failed (that's fine)"; fi
+ @$(CC) $(CLANG_CFL) $(CFLAGS_SAFE) $(CPPFLAGS) -Wno-unused-result -m32 -fPIC -c $< -o $@ 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; ln -sf afl-compiler-rt-32.o afl-llvm-rt-32.o; else echo "failed (that's fine)"; fi
./afl-compiler-rt-64.o: instrumentation/afl-compiler-rt.o.c
@printf "[*] Building 64-bit variant of the runtime (-m64)... "
- @$(CC) $(CLANG_CFL) $(CFLAGS_SAFE) $(CPPFLAGS) -O3 -Wno-unused-result -m64 -fPIC -c $< -o $@ 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; ln -sf afl-compiler-rt-64.o afl-llvm-rt-64.o; else echo "failed (that's fine)"; fi
+ @$(CC) $(CLANG_CFL) $(CFLAGS_SAFE) $(CPPFLAGS) -Wno-unused-result -m64 -fPIC -c $< -o $@ 2>/dev/null; if [ "$$?" = "0" ]; then echo "success!"; ln -sf afl-compiler-rt-64.o afl-llvm-rt-64.o; else echo "failed (that's fine)"; fi
.PHONY: test_build
test_build: $(PROGS)
--- a/unicorn_mode/samples/c/Makefile
+++ b/unicorn_mode/samples/c/Makefile
@@ -35,7 +35,7 @@ clean:
rm -rf *.o harness harness-debug
harness.o: harness.c ../../unicornafl/include/unicorn/*.h
- ${MYCC} ${CFLAGS} -O3 -c harness.c
+ ${MYCC} ${CFLAGS} -c harness.c
harness-debug.o: harness.c ../../unicornafl/include/unicorn/*.h
${MYCC} ${CFLAGS} -g -c harness.c -o $@
--- a/unicorn_mode/samples/persistent/Makefile
+++ b/unicorn_mode/samples/persistent/Makefile
@@ -35,7 +35,7 @@ clean:
rm -rf *.o harness harness-debug
harness.o: harness.c ../../unicornafl/include/unicorn/*.h
- ${MYCC} ${CFLAGS} -O3 -c harness.c
+ ${MYCC} ${CFLAGS} -c harness.c
harness-debug.o: harness.c ../../unicornafl/include/unicorn/*.h
${MYCC} ${CFLAGS} -DAFL_DEBUG=1 -g -c harness.c -o $@
--- a/utils/afl_untracer/Makefile
+++ b/utils/afl_untracer/Makefile
@@ -1,7 +1,7 @@
ifdef DEBUG
OPT=-O0
else
- OPT=-O3
+ OPT?=-O2
endif
all: afl-untracer libtestinstr.so
--- a/utils/custom_mutators/Makefile
+++ b/utils/custom_mutators/Makefile
@@ -1,7 +1,7 @@
all: libexamplemutator.so
libexamplemutator.so:
- $(CC) $(CFLAGS) -D_FORTIFY_SOURCE=2 -O3 -fPIC -shared -g -I ../../include example.c -o libexamplemutator.so
+ $(CC) $(CFLAGS) -D_FORTIFY_SOURCE=2 -fPIC -shared -g -I ../../include example.c -o libexamplemutator.so
clean:
rm -rf libexamplemutator.so

View File

@@ -0,0 +1,11 @@
--- a/GNUmakefile.gcc_plugin
+++ b/GNUmakefile.gcc_plugin
@@ -129,7 +129,7 @@ afl-common.o: ./src/afl-common.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ $(LDFLAGS)
./afl-gcc-pass.so: instrumentation/afl-gcc-pass.so.cc | test_deps
- $(CXX) $(CXXEFLAGS) $(PLUGIN_FLAGS) -shared $< -o $@
+ $(CXX) $(CXXEFLAGS) $(PLUGIN_FLAGS) -shared $< -o $@ $(LDFLAGS)
ln -sf afl-cc afl-gcc-fast
ln -sf afl-cc afl-g++-fast
ln -sf afl-cc.8 afl-gcc-fast.8

View File

@@ -0,0 +1,113 @@
From aeabdfbfa833807d4913e82c3316cf717140bf50 Mon Sep 17 00:00:00 2001
From: begasus <begasus@gmail.com>
Date: Sun, 4 Apr 2021 13:49:51 +0000
Subject: Fix missing defines for "#ifndef USEMMAP"
Haiku doesn't provide <sys/syscall.h>
Fix undefind reference to SYS_write
Add -lnetwork to dependencies
diff --git a/GNUmakefile b/GNUmakefile
index ac8fe79..542097a 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -164,7 +164,7 @@ endif
ifeq "$(shell uname -s)" "Haiku"
SHMAT_OK=0
override CFLAGS += -DUSEMMAP=1 -Wno-error=format -fPIC
- LDFLAGS += -Wno-deprecated-declarations -lgnu
+ LDFLAGS += -Wno-deprecated-declarations -lgnu -lnetwork
SPECIAL_PERFORMANCE += -DUSEMMAP=1
endif
diff --git a/instrumentation/afl-compiler-rt.o.c b/instrumentation/afl-compiler-rt.o.c
index f241447..a33b351 100644
--- a/instrumentation/afl-compiler-rt.o.c
+++ b/instrumentation/afl-compiler-rt.o.c
@@ -34,8 +34,10 @@
#include <errno.h>
#include <sys/mman.h>
-#include <sys/syscall.h>
#ifndef __HAIKU__
+#include <sys/syscall.h>
+#endif
+#ifndef USEMMAP
#include <sys/shm.h>
#endif
#include <sys/wait.h>
@@ -76,6 +78,10 @@
#define MAP_INITIAL_SIZE MAP_SIZE
#endif
+#if defined(__HAIKU__)
+ extern ssize_t _kern_write(int fd, off_t pos, const void *buffer, size_t bufferSize);
+#endif // HAIKU
+
u8 __afl_area_initial[MAP_INITIAL_SIZE];
u8 * __afl_area_ptr_dummy = __afl_area_initial;
u8 * __afl_area_ptr = __afl_area_initial;
@@ -1738,7 +1744,11 @@ static int area_is_valid(void *ptr, size_t len) {
if (unlikely(!ptr || __asan_region_is_poisoned(ptr, len))) { return 0; }
- long r = syscall(SYS_write, __afl_dummy_fd[1], ptr, len);
+ #ifndef __HAIKU__
+ long r = syscall(SYS_write, __afl_dummy_fd[1], ptr, len);
+ #else
+ long r = _kern_write(__afl_dummy_fd[1], -1, ptr, len);
+ #endif // HAIKU
if (r <= 0 || r > len) return 0;
diff --git a/utils/afl_network_proxy/afl-network-server.c b/utils/afl_network_proxy/afl-network-server.c
index 0dfae65..60f174e 100644
--- a/utils/afl_network_proxy/afl-network-server.c
+++ b/utils/afl_network_proxy/afl-network-server.c
@@ -45,7 +45,6 @@
#include <sys/wait.h>
#include <sys/time.h>
-#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/resource.h>
@@ -53,7 +52,9 @@
#include <netinet/ip6.h>
#include <arpa/inet.h>
#include <sys/mman.h>
-#include <sys/shm.h>
+#ifndef USEMMAP
+ #include <sys/shm.h>
+#endif
#include <sys/socket.h>
#include <netdb.h>
--
2.30.2
From d45b1bca8d0823aa10e9af24a1cd322ec3a01716 Mon Sep 17 00:00:00 2001
From: begasus <begasus@gmail.com>
Date: Mon, 5 Apr 2021 08:52:46 +0000
Subject: Remove crashing test
diff --git a/test/test-all.sh b/test/test-all.sh
index 8df4bef..5935b76 100755
--- a/test/test-all.sh
+++ b/test/test-all.sh
@@ -10,8 +10,6 @@
. ./test-gcc-plugin.sh
-. ./test-libextensions.sh
-
. ./test-qemu-mode.sh
. ./test-unicorn-mode.sh
--
2.30.2

View File

@@ -1,60 +0,0 @@
SUMMARY="American fuzzy lop, a security-oriented fuzzer"
DESCRIPTION="American fuzzy lop is a security-oriented fuzzer that employs a \
novel type of compile-time instrumentation and genetic algorithms to \
automatically discover clean, interesting test cases that trigger new \
internal states in the targeted binary. This substantially improves the \
functional coverage for the fuzzed code. The compact synthesized corpora \
produced by the tool are also useful for seeding other, more labor- or \
resource-intensive testing regimes down the road.
Compared to other instrumented fuzzers, afl-fuzz is designed to be practical: \
it has modest performance overhead, uses a variety of highly effective \
fuzzing strategies and effort minimization tricks, requires essentially no \
configuration, and seamlessly handles complex, real-world use cases - say, \
common image parsing or file compression libraries."
HOMEPAGE="http://lcamtuf.coredump.cx/afl/"
COPYRIGHT="2013-2016 Google Inc."
LICENSE="Apache v2"
REVISION="1"
SOURCE_URI="http://lcamtuf.coredump.cx/afl/releases/afl-$portVersion.tgz"
CHECKSUM_SHA256="54b91c9704867b566599242ec00f82b5d55215d8a792a58d8d62b8486867df74"
#SOURCE_DIR="$portVersionedName"
#PATCHES="projectx-$portVersion.patchset"
ARCHITECTURES="!x86_gcc2 ?x86 !x86_64"
SECONDARY_ARCHITECTURES="!x86"
PROVIDES="
afl$secondaryArchSuffix = $portVersion
cmd:afl = $portVersion
"
REQUIRES="
haiku$secondaryArchSuffix
"
BUILD_REQUIRES="
haiku${secondaryArchSuffix}_devel
"
BUILD_PREREQUIRES="
cmd:make
cmd:gcc$secondaryArchSuffix
"
makeAfl()
{
make PREFIX=$prefix \
BIN_PATH=$prefix/bin \
HELPER_PATH=$libDir/afl \
DOC_PATH=$docDir \
"$@"
}
BUILD()
{
makeAfl $jobArgs
}
INSTALL()
{
makeAfl install
}