From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B28651382C5 for ; Fri, 16 Apr 2021 19:26:52 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id EE404E081A; Fri, 16 Apr 2021 19:26:51 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D2896E081E for ; Fri, 16 Apr 2021 19:26:51 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B2344340931 for ; Fri, 16 Apr 2021 19:26:50 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 645645D2 for ; Fri, 16 Apr 2021 19:26:49 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1618600919.d56b0a6dd878cd451ee258844fd70c2099cd19bd.vapier@gentoo> Subject: [gentoo-commits] proj/pax-utils:master commit in: / X-VCS-Repository: proj/pax-utils X-VCS-Files: Makefile paxinc.h porting.h X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: d56b0a6dd878cd451ee258844fd70c2099cd19bd X-VCS-Branch: master Date: Fri, 16 Apr 2021 19:26:49 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: dbad96f2-2e29-49a4-9f7a-1bca085884c2 X-Archives-Hash: 41d71523e116a18bae2f039c5e3088ad commit: d56b0a6dd878cd451ee258844fd70c2099cd19bd Author: Mike Frysinger gentoo org> AuthorDate: Sat Mar 4 23:45:43 2017 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Fri Apr 16 19:21:59 2021 +0000 URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=d56b0a6d fuzz: add basic framework for using libFuzzer By itself, this commit doesn't do anything useful. We have to update each tool to hook into libFuzzer, so we'll do that in follow up commits. Signed-off-by: Mike Frysinger gentoo.org> Makefile | 20 +++++++++++++++++++- paxinc.h | 6 ++++++ porting.h | 5 +++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8a54faf..8e7b183 100644 --- a/Makefile +++ b/Makefile @@ -102,12 +102,30 @@ debug: clean analyze: clean scan-build $(MAKE) all -fuzz: clean +fuzz: + @echo "Pick a fuzzer backend:" + @echo "$$ make afl-fuzz" + @echo "$$ make libfuzzer" + @false + +afl-fuzz: clean $(MAKE) AFL_HARDEN=1 CC=afl-gcc all @rm -rf findings @printf '\nNow run:\n%s\n' \ "afl-fuzz -t 100 -i tests/fuzz/small/ -o findings/ ./scanelf -s '*' -axetrnibSDIYZB @@" +# Not all objects support libfuzzer. +LIBFUZZER_TARGETS = +LIBFUZZER_FLAGS = \ + -fsanitize=fuzzer \ + -fsanitize-coverage=edge +libfuzzer: clean + $(MAKE) \ + CC="clang" \ + CFLAGS="-g3 -ggdb $(call check_compiler_many,$(DEBUG_FLAGS)) $(LIBFUZZER_FLAGS)" \ + CPPFLAGS="-DPAX_UTILS_LIBFUZZ=1" \ + $(LIBFUZZER_TARGETS) + compile.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(CPPFLAGS-$<) -o $@ -c $< ifeq ($(V),) diff --git a/paxinc.h b/paxinc.h index 6d433b9..620ad68 100644 --- a/paxinc.h +++ b/paxinc.h @@ -108,6 +108,12 @@ const char *strfileperms(const char *fname); #define PTR_ALIGN_DOWN(base, size) ((__typeof__(base))ALIGN_DOWN((uintptr_t)(base), (size))) #define PTR_ALIGN_UP(base, size) ((__typeof__(base))ALIGN_UP ((uintptr_t)(base), (size))) +/* Support for libFuzzer: http://llvm.org/docs/LibFuzzer.html */ +#if PAX_UTILS_LIBFUZZ +int LLVMFuzzerInitialize(__unused__ int *argc, __unused__ char ***argv); +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); +#endif + /* helper functions for showing errors */ extern const char *NORM, *RED, *YELLOW; void color_init(bool disable); diff --git a/porting.h b/porting.h index 17bbbbc..c4f5fc6 100644 --- a/porting.h +++ b/porting.h @@ -94,6 +94,11 @@ # define PAX_UTILS_CLEANUP 0 #endif +/* Support for libFuzzer: https://llvm.org/docs/LibFuzzer.html */ +#ifndef PAX_UTILS_LIBFUZZ +# define PAX_UTILS_LIBFUZZ 0 +#endif + /* Few arches can safely do unaligned accesses */ #if defined(__cris__) || \ defined(__i386__) || \