From patchwork Fri Jan 19 21:38:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 13524196 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB69858217 for ; Fri, 19 Jan 2024 21:38:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705700299; cv=none; b=JsJxgiW83IYsi29Cx0gKobRMEoz7xMnp69NfpO85Dlsx3FYoLrB33U7snnIerg05PcZm0KTlHVgcZVnr2gwexEdttQaNDySeM/iHMot1Cq19ZVtdf7q7xwSv6DTAUs5c5xTQiQi/cbooAcay5+PvasS3AnLeqVZMCWw7jwEmy5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705700299; c=relaxed/simple; bh=w99Bbuu7ym+WN3qHG/0ggf9L6fio6HR/B750yqp5jS4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=lbxiytgS2Jjq0+VEPTALXywntwVZ+jLkGKohrXzL8KK5YX3wuRJL4u1QkTrQy2APV58GpGSvNx8I1686KZOfP2bjEf4niY9QYY1Do1FVIhCFTmhRG5l1CcoBnPNifdNvDbKCwUOYqTLR9gjFfX4YNR1WY/sFxkU7mvUCasFGvvQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--steadmon.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=oAjCrIK/; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--steadmon.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oAjCrIK/" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5ffa078355bso16690627b3.2 for ; Fri, 19 Jan 2024 13:38:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705700297; x=1706305097; darn=vger.kernel.org; h=content-transfer-encoding:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=d3kkhdZa3GGuEn3JvOK/h0ZHibOey7KaISISVpfcmfo=; b=oAjCrIK/h7t/i8MDBT8DeW9qVKCU6cQZnvAyqY0FCTS+5SBeN1/e7sc2tGsG8zDrEN 8fTkmSzKl1g3PahAGOrfaEQPRWd8FSCdxK70rI2caybjsxCdK3cfggcZpEBF6ZXdU7Iy UxLXxvCepbKWo3j0sXxP56uK2pAd61MDZ1WFma/0EUCbS37hYPB74KsFN5IRn+GGwwZX 1D1tTt2mbzNVopnM+cI/SChSOZMuG0oWcVOPvy/klGadJoKh62RM3Rvp0oQADw7mM9W3 wYWngUlfSN/qYPMWTN48kGdRrtJFtK/+K9XEAhIuNTnT1FkLSjWs4EXb2IfbXrRTRG16 9fJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705700297; x=1706305097; h=content-transfer-encoding:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=d3kkhdZa3GGuEn3JvOK/h0ZHibOey7KaISISVpfcmfo=; b=aFQ/+9vak3tdtd82gEEdjneq+hnETxcrwofmhAI2ntjTQ0uCzfhuwTfSvs7DcdaFb6 grN9Zvw6lIeONF1d5EljWM5ydZH4Dryirt8DzcMNjqqmM2qPKQUBPoSSaK1cpgGmUMqU pt8LRgQeK5/QGj7m9Up4xCUxXOdfj2OJB3jjIodB+NiAvEuxgchkJxQav6D5KDQ+yQUF gYDNsF54CqKQauu8YUwqcsc0kN+F10XWuFXlPq4f/8PWl4kzjWlfxuzFvDu8+v4XOTzw l6tV/mOu0DqIFenTCf0cSackfnAmTSYK1t9eWWVbzSkDLV+orCbFe4Ys7ZzsJZflYM1D ACNA== X-Gm-Message-State: AOJu0YyZAqpg6eV113KDyB2oyM92Y5Snaw4P1sb6lZJgTJ79Gt8Tz9ws hRp9KdUab0YIS8kM1dwuQRQ8v48iyWXW1MgNV2v6XOWczfc5FuW3VGTIeK3PbM5X0tuTbZTuS9+ uYlHX1bOL+kVVqyFqj76U1F/J6AHFU7zxiT7nyzimAbloE/6e/GX8R0I6EMI+xS5sV4OfgoNKq9 7YFq8Lgu+qj/gl+PG8ByjCq3x/ds3Tp2Xa+4vaAso= X-Google-Smtp-Source: AGHT+IHMTnW6j6eTDZ9+m/3Xm/rK4MWM/pVWnv2jMyH6Q31MnmMu3uuLoD11cTt/T4TlLSzBSGL9Hhm9WjcRmA== X-Received: from lunarfall.svl.corp.google.com ([2620:15c:2d3:204:3aa6:e329:52e1:bd8c]) (user=steadmon job=sendgmr) by 2002:a0d:dd92:0:b0:5ff:9df0:2a4 with SMTP id g140-20020a0ddd92000000b005ff9df002a4mr242246ywe.7.1705700296822; Fri, 19 Jan 2024 13:38:16 -0800 (PST) Date: Fri, 19 Jan 2024 13:38:12 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <9332e225e44b29be25d10229b05f0b9775b85568.1705700054.git.steadmon@google.com> Subject: [PATCH 1/2] fuzz: fix fuzz test build rules From: Josh Steadmon To: git@vger.kernel.org When we originally added the fuzz tests in 5e47215080 (fuzz: add basic fuzz testing target., 2018-10-12), we went to some trouble to create a Makefile rule that allowed linking the fuzz executables without pulling in common-main.o. This was necessary to prevent the fuzzing-engine-provided main() from clashing with Git's main(). However, since 19d75948ef (common-main.c: move non-trace2 exit() behavior out of trace2.c, 2022-06-02), it has been necessary to link common-main.o due to moving the common_exit() function to that file. Ævar suggested a set of compiler flags to allow this in [1], but this was never reflected in the Makefile. Since we now must include common-main.o, there's no reason to pick and choose a subset of object files to link, so simplify the Makefile rule for the fuzzer executables to just use libgit.a. While we're at it, include the necessary linker flag to allow multiple definitions directly in the Makefile rule, rather than requiring it to be passed on the command-line each time. This means the Makefile rule as written is now more compiler-specific, but this was already the case for the fuzzers themselves anyway. [1] https://lore.kernel.org/git/220607.8635ggupws.gmgdl@evledraar.gmail.com/ Signed-off-by: Josh Steadmon --- Makefile | 14 ++++++++------ oss-fuzz/dummy-cmd-main.c | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 oss-fuzz/dummy-cmd-main.c diff --git a/Makefile b/Makefile index 15990ff312..1e9bd6430f 100644 --- a/Makefile +++ b/Makefile @@ -752,6 +752,7 @@ SCRIPTS = $(SCRIPT_SH_GEN) \ ETAGS_TARGET = TAGS +FUZZ_OBJS += oss-fuzz/dummy-cmd-main.o FUZZ_OBJS += oss-fuzz/fuzz-commit-graph.o FUZZ_OBJS += oss-fuzz/fuzz-date.o FUZZ_OBJS += oss-fuzz/fuzz-pack-headers.o @@ -762,7 +763,7 @@ fuzz-objs: $(FUZZ_OBJS) # Always build fuzz objects even if not testing, to prevent bit-rot. all:: $(FUZZ_OBJS) -FUZZ_PROGRAMS += $(patsubst %.o,%,$(FUZZ_OBJS)) +FUZZ_PROGRAMS += $(patsubst %.o,%,$(filter-out %dummy-cmd-main.o,$(FUZZ_OBJS))) # Empty... EXTRA_PROGRAMS = @@ -3850,16 +3851,17 @@ cover_db_html: cover_db # # make CC=clang CXX=clang++ \ # CFLAGS="-fsanitize=fuzzer-no-link,address" \ -# LIB_FUZZING_ENGINE="-fsanitize=fuzzer" \ +# LIB_FUZZING_ENGINE="-fsanitize=fuzzer,address" \ # fuzz-all # -FUZZ_CXXFLAGS ?= $(CFLAGS) +FUZZ_CXXFLAGS ?= $(ALL_CFLAGS) .PHONY: fuzz-all -$(FUZZ_PROGRAMS): all - $(QUIET_LINK)$(CXX) $(FUZZ_CXXFLAGS) $(LIB_OBJS) $(BUILTIN_OBJS) \ - $(XDIFF_OBJS) $(EXTLIBS) git.o $@.o $(LIB_FUZZING_ENGINE) -o $@ +$(FUZZ_PROGRAMS): %: %.o oss-fuzz/dummy-cmd-main.o $(GITLIBS) GIT-LDFLAGS + $(QUIET_LINK)$(CXX) $(FUZZ_CXXFLAGS) -o $@ $(ALL_LDFLAGS) \ + -Wl,--allow-multiple-definition \ + $(filter %.o,$^) $(filter %.a,$^) $(LIBS) $(LIB_FUZZING_ENGINE) fuzz-all: $(FUZZ_PROGRAMS) diff --git a/oss-fuzz/dummy-cmd-main.c b/oss-fuzz/dummy-cmd-main.c new file mode 100644 index 0000000000..071cb231ba --- /dev/null +++ b/oss-fuzz/dummy-cmd-main.c @@ -0,0 +1,14 @@ +#include "git-compat-util.h" + +/* + * When linking the fuzzers, we link against common-main.o to pick up some + * symbols. However, even though we ignore common-main:main(), we still need to + * provide all the symbols it references. In the fuzzers' case, we need to + * provide a dummy cmd_main() for the linker to be happy. It will never be + * executed. + */ + +int cmd_main(int argc, const char **argv) { + BUG("We should not execute cmd_main() from a fuzz target"); + return 1; +} From patchwork Fri Jan 19 21:38:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 13524197 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75B925822A for ; Fri, 19 Jan 2024 21:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705700301; cv=none; b=VgStsD+zaYVCo1Wq8E3OHBZkkbe/mDZdKH+cqM0yCv1pUCYDS5PnD2uCpVAHRIV6i1de8XJ8+Nc5SnFsjU0PYxoJcTJiXzV9GTllepr/6A5EJ9xYnoa8e89Ao1IOvi1KHzDSa6OvxaWzvIemFKA0M6q2KQyrOKyC15plq4KrqPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705700301; c=relaxed/simple; bh=nVmyaKZynHzo/ToTeVVyJrhUNPjCWGMmIP6rlcz3pbg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=kwuh8/JLs2YWKDs0Lj+QHl+cu5lOMnYLgHbM38r6DcWrrGpihdWYANFH+w8khW71/0ZafZX4pHjm4++alMy1RgRE8Zm4C8QGK+Fzbflv+uP6wcCSgnQt5sL9WL6HtFUOfbYo6w6SBp96W+NQoTgit6YMPbDZm4ZUd1BTsRODtro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--steadmon.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MokJHVcC; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--steadmon.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MokJHVcC" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbeac1f5045so1619199276.1 for ; Fri, 19 Jan 2024 13:38:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705700298; x=1706305098; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=t9LUE2QthDNMgJrv6JCYlADg9RVBvQz/tYSx0Mvcszw=; b=MokJHVcCyIevaOtKeWray5g8S4zvP8lkIvFQN89RrxBcSPB5CB8lopUDtQ0sjYMuWE vAhaZg6OFT6tPG9BsHYv8k3xlivVKjpKmOOvPlEXWTJPerBTF999fE2z8dtdw3oolAgW TXFMi+i4jF5uPEPFxwtelB5QG7eorUM6qMD4jjq184feygIZVJuL5V7S7rDS/sOGwWsD FLeLnV2xGB+veHcxIHl2AmvKqRKoaKdYXrQtq0ZFgEoo3+nqTdEdvKzPScmMQRiN8Ndm BCwRinKow3zNk7bN7JAkZ8juUIHTIepSLV1ulv0YQjvAtyh5CWXJeIqvHmv8c4LefcKM pUkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705700298; x=1706305098; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t9LUE2QthDNMgJrv6JCYlADg9RVBvQz/tYSx0Mvcszw=; b=duF1WL8/oyHASFvq5zj6f+afp/hYGNN8ljwOujD6fMG71BZg69kQgmOMNvsi9rwcFP SAhf18pfgLh7FV9/jao3WrLKpvLdQm90lWx+sa0qG/0ahfpeTDoWXup5fDSRr25upTU6 v7rqjxZK2+gWRXOEQgsYpJ0WM/aE7j4nt+igw8ZuF65FYxeBflF7FD7zDhlPozBvUUyI 1mkD/BDCj11d66ZnBj0Y3aok6uvB2j5KolXzfKO363JsKjcQ+anYxrH/BlJQrlD19KbR 8rMR6fAYdrAQ2xp5rV0Qh1lrDq9ytI39IKQEGhScTq4Fa5ZVe54uZxz2WYs3xbTrWZqr DGsQ== X-Gm-Message-State: AOJu0YwbPh2mQKN9DAfw5QqKzXNAT5t9Rh+pvHfsg10BfthPGOnnuClp GqpPbgB2Egm05pajhl02yknkoFH9Sqv1voZd79IfMo5gen9yCJ5gRoAEyp9zsLKbhIz97YsBEuE 1pu0HAri26zW+MPuMv9AtMb7UZsE+/uLPiT3xm/YBwGG31TYGmVieGxzMZuvAhC7AxF1QQmgJua kYHyoo2iyq1/r9dnqaJPs31DAyXu65JRYbCO9Bd6U= X-Google-Smtp-Source: AGHT+IGjKqDezO1KBHCL63Fd5Bun+kmPXoVm9zHWZ2RG9jOY0E1h5CYd45ublccvIV/u8Cf/dnoRRgMjuHEb5A== X-Received: from lunarfall.svl.corp.google.com ([2620:15c:2d3:204:3aa6:e329:52e1:bd8c]) (user=steadmon job=sendgmr) by 2002:a25:abec:0:b0:dbf:4359:326a with SMTP id v99-20020a25abec000000b00dbf4359326amr264111ybi.1.1705700298371; Fri, 19 Jan 2024 13:38:18 -0800 (PST) Date: Fri, 19 Jan 2024 13:38:13 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: Subject: [PATCH 2/2] ci: build and run minimal fuzzers in GitHub CI From: Josh Steadmon To: git@vger.kernel.org To prevent bitrot, we would like to regularly exercise the fuzz tests in order to make sure they still link & run properly. We already compile the fuzz test objects as part of the default `make` target, but we do not link the executables due to the fuzz tests needing specific compilers and compiler features. This has lead to frequent build breakages for the fuzz tests. To remedy this, we can add a CI step to actually link the fuzz executables, and run them (with finite input rather than the default infinite random input mode) to verify that they execute properly. Since the main use of the fuzz tests is via OSS-Fuzz [1], and OSS-Fuzz only runs tests on Linux [2], we only set up a CI test for the fuzzers on Linux. [1] https://github.com/google/oss-fuzz [2] https://google.github.io/oss-fuzz/further-reading/fuzzer-environment/ Signed-off-by: Josh Steadmon --- .github/workflows/main.yml | 11 +++++++++++ Makefile | 3 +++ ci/run-build-and-minimal-fuzzers.sh | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100755 ci/run-build-and-minimal-fuzzers.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9fdbd54028..4d97da57ec 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -309,6 +309,17 @@ jobs: with: name: failed-tests-${{matrix.vector.jobname}} path: ${{env.FAILED_TEST_ARTIFACTS}} + fuzz-smoke-test: + name: fuzz smoke test + needs: ci-config + if: needs.ci-config.outputs.enabled == 'yes' + env: + CC: clang + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: ci/install-dependencies.sh + - run: ci/run-build-and-minimal-fuzzers.sh dockerized: name: ${{matrix.vector.jobname}} (${{matrix.vector.image}}) needs: ci-config diff --git a/Makefile b/Makefile index 1e9bd6430f..2e94c566e0 100644 --- a/Makefile +++ b/Makefile @@ -752,6 +752,9 @@ SCRIPTS = $(SCRIPT_SH_GEN) \ ETAGS_TARGET = TAGS +# If you add a new fuzzer, please also make sure to run it in +# ci/run-build-and-minimal-fuzzers.sh so that we make sure it still links and +# runs in the future. FUZZ_OBJS += oss-fuzz/dummy-cmd-main.o FUZZ_OBJS += oss-fuzz/fuzz-commit-graph.o FUZZ_OBJS += oss-fuzz/fuzz-date.o diff --git a/ci/run-build-and-minimal-fuzzers.sh b/ci/run-build-and-minimal-fuzzers.sh new file mode 100755 index 0000000000..8ba486f659 --- /dev/null +++ b/ci/run-build-and-minimal-fuzzers.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# +# Build and test Git's fuzzers +# + +. ${0%/*}/lib.sh + +group "Build fuzzers" make \ + CC=clang \ + CXX=clang++ \ + CFLAGS="-fsanitize=fuzzer-no-link,address" \ + LIB_FUZZING_ENGINE="-fsanitize=fuzzer,address" \ + fuzz-all + +for fuzzer in commit-graph date pack-headers pack-idx ; do + begin_group "fuzz-$fuzzer" + ./oss-fuzz/fuzz-$fuzzer -verbosity=0 -runs=1 || exit 1 + end_group "fuzz-$fuzzer" +done