This commit is contained in:
vanhauser-thc 2021-04-04 20:05:02 +02:00
parent c23183f1dc
commit 3c846859ee
11 changed files with 55 additions and 42 deletions

View File

@ -36,6 +36,11 @@ SH_PROGS = afl-plot afl-cmin afl-cmin.bash afl-whatsup afl-system-config
MANPAGES=$(foreach p, $(PROGS) $(SH_PROGS), $(p).8) afl-as.8 MANPAGES=$(foreach p, $(PROGS) $(SH_PROGS), $(p).8) afl-as.8
ASAN_OPTIONS=detect_leaks=0 ASAN_OPTIONS=detect_leaks=0
SYS = $(shell uname -s)
ARCH = $(shell uname -m)
$(info [*] Compiling afl++ for OS $(SYS) on ARCH $(ARCH))
ifdef NO_SPLICING ifdef NO_SPLICING
override CFLAGS += -DNO_SPLICING override CFLAGS += -DNO_SPLICING
endif endif
@ -82,7 +87,7 @@ endif
# endif # endif
#endif #endif
ifneq "$(shell uname)" "Darwin" ifneq "$(SYS)" "Darwin"
#ifeq "$(HAVE_MARCHNATIVE)" "1" #ifeq "$(HAVE_MARCHNATIVE)" "1"
# SPECIAL_PERFORMANCE += -march=native # SPECIAL_PERFORMANCE += -march=native
#endif #endif
@ -92,7 +97,7 @@ ifneq "$(shell uname)" "Darwin"
endif endif
endif endif
ifeq "$(shell uname)" "SunOS" ifeq "$(SYS)" "SunOS"
CFLAGS_OPT += -Wno-format-truncation CFLAGS_OPT += -Wno-format-truncation
LDFLAGS = -lkstat -lrt LDFLAGS = -lkstat -lrt
endif endif
@ -119,11 +124,10 @@ ifdef INTROSPECTION
CFLAGS_OPT += -DINTROSPECTION=1 CFLAGS_OPT += -DINTROSPECTION=1
endif endif
ifneq "$(ARCH)" "x86_64"
ifneq "$(shell uname -m)" "x86_64" ifneq "$(patsubst i%86,i386,$(ARCH))" "i386"
ifneq "$(patsubst i%86,i386,$(shell uname -m))" "i386" ifneq "$(ARCH)" "amd64"
ifneq "$(shell uname -m)" "amd64" ifneq "$(ARCH)" "i86pc"
ifneq "$(shell uname -m)" "i86pc"
AFL_NO_X86=1 AFL_NO_X86=1
endif endif
endif endif
@ -141,27 +145,27 @@ override CFLAGS += -g -Wno-pointer-sign -Wno-variadic-macros -Wall -Wextra -Wpoi
-I include/ -DAFL_PATH=\"$(HELPER_PATH)\" \ -I include/ -DAFL_PATH=\"$(HELPER_PATH)\" \
-DBIN_PATH=\"$(BIN_PATH)\" -DDOC_PATH=\"$(DOC_PATH)\" -DBIN_PATH=\"$(BIN_PATH)\" -DDOC_PATH=\"$(DOC_PATH)\"
ifeq "$(shell uname -s)" "FreeBSD" ifeq "$(SYS)" "FreeBSD"
override CFLAGS += -I /usr/local/include/ override CFLAGS += -I /usr/local/include/
LDFLAGS += -L /usr/local/lib/ LDFLAGS += -L /usr/local/lib/
endif endif
ifeq "$(shell uname -s)" "DragonFly" ifeq "$(SYS)" "DragonFly"
override CFLAGS += -I /usr/local/include/ override CFLAGS += -I /usr/local/include/
LDFLAGS += -L /usr/local/lib/ LDFLAGS += -L /usr/local/lib/
endif endif
ifeq "$(shell uname -s)" "OpenBSD" ifeq "$(SYS)" "OpenBSD"
override CFLAGS += -I /usr/local/include/ -mno-retpoline override CFLAGS += -I /usr/local/include/ -mno-retpoline
LDFLAGS += -Wl,-z,notext -L /usr/local/lib/ LDFLAGS += -Wl,-z,notext -L /usr/local/lib/
endif endif
ifeq "$(shell uname -s)" "NetBSD" ifeq "$(SYS)" "NetBSD"
override CFLAGS += -I /usr/pkg/include/ override CFLAGS += -I /usr/pkg/include/
LDFLAGS += -L /usr/pkg/lib/ LDFLAGS += -L /usr/pkg/lib/
endif endif
ifeq "$(shell uname -s)" "Haiku" ifeq "$(SYS)" "Haiku"
SHMAT_OK=0 SHMAT_OK=0
override CFLAGS += -DUSEMMAP=1 -Wno-error=format -fPIC override CFLAGS += -DUSEMMAP=1 -Wno-error=format -fPIC
LDFLAGS += -Wno-deprecated-declarations -lgnu LDFLAGS += -Wno-deprecated-declarations -lgnu
@ -236,24 +240,24 @@ else
BUILD_DATE ?= $(shell date "+%Y-%m-%d") BUILD_DATE ?= $(shell date "+%Y-%m-%d")
endif endif
ifneq "$(filter Linux GNU%,$(shell uname))" "" ifneq "$(filter Linux GNU%,$(SYS))" ""
ifndef DEBUG ifndef DEBUG
override CFLAGS += -D_FORTIFY_SOURCE=2 override CFLAGS += -D_FORTIFY_SOURCE=2
endif endif
LDFLAGS += -ldl -lrt -lm LDFLAGS += -ldl -lrt -lm
endif endif
ifneq "$(findstring FreeBSD, $(shell uname))" "" ifneq "$(findstring FreeBSD, $(ARCH))" ""
override CFLAGS += -pthread override CFLAGS += -pthread
LDFLAGS += -lpthread LDFLAGS += -lpthread
endif endif
ifneq "$(findstring NetBSD, $(shell uname))" "" ifneq "$(findstring NetBSD, $(ARCH))" ""
override CFLAGS += -pthread override CFLAGS += -pthread
LDFLAGS += -lpthread LDFLAGS += -lpthread
endif endif
ifneq "$(findstring OpenBSD, $(shell uname))" "" ifneq "$(findstring OpenBSD, $(ARCH))" ""
override CFLAGS += -pthread override CFLAGS += -pthread
LDFLAGS += -lpthread LDFLAGS += -lpthread
endif endif
@ -485,7 +489,7 @@ unit_clean:
@rm -f ./test/unittests/unit_preallocable ./test/unittests/unit_list ./test/unittests/unit_maybe_alloc test/unittests/*.o @rm -f ./test/unittests/unit_preallocable ./test/unittests/unit_list ./test/unittests/unit_maybe_alloc test/unittests/*.o
.PHONY: unit .PHONY: unit
ifneq "$(shell uname)" "Darwin" ifneq "$(ARCH)" "Darwin"
unit: unit_maybe_alloc unit_preallocable unit_list unit_clean unit_rand unit_hash unit: unit_maybe_alloc unit_preallocable unit_list unit_clean unit_rand unit_hash
else else
unit: unit:

View File

@ -41,6 +41,8 @@ CXXEFLAGS := $(CXXFLAGS) -Wall -std=c++11
CC ?= gcc CC ?= gcc
CXX ?= g++ CXX ?= g++
SYS = $(shell uname -s)
ifeq "clang" "$(CC)" ifeq "clang" "$(CC)"
CC = gcc CC = gcc
CXX = g++ CXX = g++
@ -75,25 +77,25 @@ ifeq "$(TEST_MMAP)" "1"
override CFLAGS_SAFE += -DUSEMMAP=1 override CFLAGS_SAFE += -DUSEMMAP=1
endif endif
ifneq "$(shell uname -s)" "Haiku" ifneq "$(SYS)" "Haiku"
ifneq "$(shell uname -s)" "OpenBSD" ifneq "$(SYS)" "OpenBSD"
LDFLAGS += -lrt LDFLAGS += -lrt
endif endif
else else
CFLAGS_SAFE += -DUSEMMAP=1 CFLAGS_SAFE += -DUSEMMAP=1
endif endif
ifeq "$(shell uname -s)" "OpenBSD" ifeq "$(SYS)" "OpenBSD"
CC = egcc CC = egcc
CXX = eg++ CXX = eg++
PLUGIN_FLAGS += -I/usr/local/include PLUGIN_FLAGS += -I/usr/local/include
endif endif
ifeq "$(shell uname -s)" "DragonFly" ifeq "$(SYS)" "DragonFly"
PLUGIN_FLAGS += -I/usr/local/include PLUGIN_FLAGS += -I/usr/local/include
endif endif
ifeq "$(shell uname -s)" "SunOS" ifeq "$(SYS)" "SunOS"
PLUGIN_FLAGS += -I/usr/include/gmp PLUGIN_FLAGS += -I/usr/include/gmp
endif endif

View File

@ -30,7 +30,9 @@ BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+%Y-%m-%d" 2>/dev/nul
VERSION = $(shell grep '^$(HASH)define VERSION ' ./config.h | cut -d '"' -f2) VERSION = $(shell grep '^$(HASH)define VERSION ' ./config.h | cut -d '"' -f2)
ifeq "$(shell uname)" "OpenBSD" SYS = $(shell uname -s)
ifeq "$(SYS)" "OpenBSD"
LLVM_CONFIG ?= $(BIN_PATH)/llvm-config LLVM_CONFIG ?= $(BIN_PATH)/llvm-config
HAS_OPT = $(shell test -x $(BIN_PATH)/opt && echo 0 || echo 1) HAS_OPT = $(shell test -x $(BIN_PATH)/opt && echo 0 || echo 1)
ifeq "$(HAS_OPT)" "1" ifeq "$(HAS_OPT)" "1"
@ -275,13 +277,13 @@ CLANG_LFL = `$(LLVM_CONFIG) --ldflags` $(LDFLAGS)
# User teor2345 reports that this is required to make things work on MacOS X. # User teor2345 reports that this is required to make things work on MacOS X.
ifeq "$(shell uname)" "Darwin" ifeq "$(SYS)" "Darwin"
CLANG_LFL += -Wl,-flat_namespace -Wl,-undefined,suppress CLANG_LFL += -Wl,-flat_namespace -Wl,-undefined,suppress
else else
CLANG_CPPFL += -Wl,-znodelete CLANG_CPPFL += -Wl,-znodelete
endif endif
ifeq "$(shell uname)" "OpenBSD" ifeq "$(SYS)" "OpenBSD"
CLANG_LFL += `$(LLVM_CONFIG) --libdir`/libLLVM.so CLANG_LFL += `$(LLVM_CONFIG) --libdir`/libLLVM.so
CLANG_CPPFL += -mno-retpoline CLANG_CPPFL += -mno-retpoline
CFLAGS += -mno-retpoline CFLAGS += -mno-retpoline

View File

@ -11,6 +11,8 @@ sending a mail to <afl-users+subscribe@googlegroups.com>.
### Version ++3.13a (development) ### Version ++3.13a (development)
- frida_mode - new mode that uses frida to fuzz binary-only targets, - frida_mode - new mode that uses frida to fuzz binary-only targets,
thanks to @WorksButNotTested! thanks to @WorksButNotTested!
- create a fuzzing dictionary with the help of CodeQL thanks to
@microsvuln! see utils/autodict_ql
- afl-fuzz: - afl-fuzz:
- added patch by @realmadsci to support @@ as part of command line - added patch by @realmadsci to support @@ as part of command line
options, e.g. `afl-fuzz ... -- ./target --infile=@@` options, e.g. `afl-fuzz ... -- ./target --infile=@@`
@ -20,6 +22,7 @@ sending a mail to <afl-users+subscribe@googlegroups.com>.
- default cmplog level (-l) is now 2, better efficiency. - default cmplog level (-l) is now 2, better efficiency.
- ensure one fuzzer sync per cycle - ensure one fuzzer sync per cycle
- afl-cc: - afl-cc:
- Leak Sanitizer support (AFL_USE_LSAN) added by Joshua Rogers, thanks!
- Removed InsTrim instrumentation as it is not as good as PCGUARD - Removed InsTrim instrumentation as it is not as good as PCGUARD
### Version ++3.12c (release) ### Version ++3.12c (release)

View File

@ -13,12 +13,14 @@
#include <stdio.h> #include <stdio.h>
#define ASHMEM_DEVICE "/dev/ashmem" #define ASHMEM_DEVICE "/dev/ashmem"
int shmdt(const void* address) { int shmdt(const void *address) {
#if defined(SYS_shmdt)
#if defined(SYS_shmdt)
return syscall(SYS_shmdt, address); return syscall(SYS_shmdt, address);
#else #else
return syscall(SYS_ipc, SHMDT, 0, 0, 0, address, 0); return syscall(SYS_ipc, SHMDT, 0, 0, 0, address, 0);
#endif #endif
} }
int shmctl(int __shmid, int __cmd, struct shmid_ds *__buf) { int shmctl(int __shmid, int __cmd, struct shmid_ds *__buf) {
@ -26,7 +28,7 @@ int shmctl(int __shmid, int __cmd, struct shmid_ds *__buf) {
int ret = 0; int ret = 0;
if (__cmd == IPC_RMID) { if (__cmd == IPC_RMID) {
int length = ioctl(__shmid, ASHMEM_GET_SIZE, NULL); int length = ioctl(__shmid, ASHMEM_GET_SIZE, NULL);
struct ashmem_pin pin = {0, length}; struct ashmem_pin pin = {0, length};
ret = ioctl(__shmid, ASHMEM_UNPIN, &pin); ret = ioctl(__shmid, ASHMEM_UNPIN, &pin);
close(__shmid); close(__shmid);
@ -77,6 +79,6 @@ void *shmat(int __shmid, const void *__shmaddr, int __shmflg) {
} }
#endif /* !_ANDROID_ASHMEM_H */ #endif /* !_ANDROID_ASHMEM_H */
#endif /* !__ANDROID__ */ #endif /* !__ANDROID__ */

View File

@ -176,7 +176,7 @@ bool AFLLTOPass::runOnModule(Module &M) {
} }
if (debug) { fprintf(stderr, "map address is 0x%lx\n", map_addr); } if (debug) { fprintf(stderr, "map address is 0x%llx\n", map_addr); }
/* Get/set the globals for the SHM region. */ /* Get/set the globals for the SHM region. */

View File

@ -833,14 +833,13 @@ static void set_up_environment(char **argv) {
"handle_sigfpe=0:" "handle_sigfpe=0:"
"handle_sigill=0", 0); "handle_sigill=0", 0);
setenv("LSAN_OPTIONS", setenv("LSAN_OPTIONS",
"exitcode=" STRINGIFY(LSAN_ERROR) ":" "exitcode=" STRINGIFY(LSAN_ERROR) ":"
"fast_unwind_on_malloc=0:" "fast_unwind_on_malloc=0:"
"symbolize=0:" "symbolize=0:"
"print_suppressions=0", "print_suppressions=0",
0); 0);
if (get_afl_env("AFL_PRELOAD")) { if (get_afl_env("AFL_PRELOAD")) {
if (qemu_mode) { if (qemu_mode) {

View File

@ -820,10 +820,11 @@ static void edit_params(u32 argc, char **argv, char **envp) {
} }
if (getenv("AFL_USE_LSAN")) { if (getenv("AFL_USE_LSAN")) {
cc_params[cc_par_cnt++] = "-fsanitize=leak"; cc_params[cc_par_cnt++] = "-fsanitize=leak";
cc_params[cc_par_cnt++] = "-includesanitizer/lsan_interface.h"; cc_params[cc_par_cnt++] = "-includesanitizer/lsan_interface.h";
cc_params[cc_par_cnt++] = cc_params[cc_par_cnt++] = "-D__AFL_LEAK_CHECK()=__lsan_do_leak_check()";
"-D__AFL_LEAK_CHECK()=__lsan_do_leak_check()";
} }
if (getenv("AFL_USE_CFISAN")) { if (getenv("AFL_USE_CFISAN")) {

View File

@ -560,7 +560,7 @@ void afl_fsrv_start(afl_forkserver_t *fsrv, char **argv,
/* LSAN, too, does not support abort_on_error=1. */ /* LSAN, too, does not support abort_on_error=1. */
if (!getenv("LSAN_OPTIONS")) if (!getenv("LSAN_OPTIONS"))
setenv("LSAN_OPTIONS", setenv("LSAN_OPTIONS",
"exitcode=" STRINGIFY(LSAN_ERROR) ":" "exitcode=" STRINGIFY(LSAN_ERROR) ":"
"fast_unwind_on_malloc=0:" "fast_unwind_on_malloc=0:"
"symbolize=0:" "symbolize=0:"
@ -1314,8 +1314,9 @@ fsrv_run_result_t afl_fsrv_run_target(afl_forkserver_t *fsrv, u32 timeout,
/* A normal crash/abort */ /* A normal crash/abort */
(WIFSIGNALED(fsrv->child_status)) || (WIFSIGNALED(fsrv->child_status)) ||
/* special handling for msan and lsan */ /* special handling for msan and lsan */
(fsrv->uses_asan && (WEXITSTATUS(fsrv->child_status) == MSAN_ERROR || (fsrv->uses_asan &&
WEXITSTATUS(fsrv->child_status) == LSAN_ERROR)) || (WEXITSTATUS(fsrv->child_status) == MSAN_ERROR ||
WEXITSTATUS(fsrv->child_status) == LSAN_ERROR)) ||
/* the custom crash_exitcode was returned by the target */ /* the custom crash_exitcode was returned by the target */
(fsrv->uses_crash_exitcode && (fsrv->uses_crash_exitcode &&
WEXITSTATUS(fsrv->child_status) == fsrv->crash_exitcode))) { WEXITSTATUS(fsrv->child_status) == fsrv->crash_exitcode))) {

View File

@ -2502,7 +2502,6 @@ void check_asan_opts(afl_state_t *afl) {
} }
} }
/* Handle stop signal (Ctrl-C, etc). */ /* Handle stop signal (Ctrl-C, etc). */

View File

@ -763,7 +763,7 @@ static void set_up_environment(afl_forkserver_t *fsrv, char **argv) {
"handle_sigfpe=0:" "handle_sigfpe=0:"
"handle_sigill=0", 0); "handle_sigill=0", 0);
setenv("LSAN_OPTIONS", setenv("LSAN_OPTIONS",
"exitcode=" STRINGIFY(LSAN_ERROR) ":" "exitcode=" STRINGIFY(LSAN_ERROR) ":"
"fast_unwind_on_malloc=0:" "fast_unwind_on_malloc=0:"
"symbolize=0:" "symbolize=0:"