From b881b6ae0f6fb9af4e398341069cd6dc29f1ad9d Mon Sep 17 00:00:00 2001 From: Max Moroz Date: Wed, 15 Apr 2020 22:38:17 -0700 Subject: [PATCH 1/3] [Go] remove "-lpthread" flag from "compile_fuzzer" and fix comments (#2714). --- .../new-project-guide/go_lang.md | 6 ++--- projects/go-attestation/build.sh | 19 ++++++++------- projects/go-dns/build.sh | 9 ++++--- projects/go-json-iterator/build.sh | 7 +++--- projects/golang/build.sh | 24 +++++++++---------- projects/gonids/build.sh | 10 ++++---- projects/kubernetes/build.sh | 7 +++--- projects/syzkaller/build.sh | 7 +++--- 8 files changed, 44 insertions(+), 45 deletions(-) diff --git a/docs/getting-started/new-project-guide/go_lang.md b/docs/getting-started/new-project-guide/go_lang.md index f58716dfc1b7..be7482c33ba3 100644 --- a/docs/getting-started/new-project-guide/go_lang.md +++ b/docs/getting-started/new-project-guide/go_lang.md @@ -82,11 +82,11 @@ function compile_fuzzer { function=$2 fuzzer=$3 - # Instrument all Go files relevant to this fuzzer + # Compile and instrument all Go files relevant to this fuzz target. go-fuzz -func $function -o $fuzzer.a $path - # Instrumented, compiled Go ($fuzzer.a) + fuzzing engine = fuzzer binary - $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -lpthread -o $OUT/$fuzzer + # Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary. + $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer } compile_fuzzer ./pkg/compiler Fuzz compiler_fuzzer diff --git a/projects/go-attestation/build.sh b/projects/go-attestation/build.sh index 92d6de56c20c..20fef0038ebb 100755 --- a/projects/go-attestation/build.sh +++ b/projects/go-attestation/build.sh @@ -15,20 +15,23 @@ # ################################################################################ -# Based on the function from oss-fuzz/projects/golang/build.sh script. function compile_fuzzer { package=$1 function=$2 fuzzer=$3 - # Instrument all Go files relevant to this fuzzer + # Compile and instrument all Go files relevant to this fuzz target. go-fuzz -func $function -o $fuzzer.a $package - # Instrumented, compiled Go ($fuzzer.a) + fuzzing engine = fuzzer binary - $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -lpthread -o $OUT/$fuzzer + # Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary. + $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer } -compile_fuzzer github.com/google/go-attestation/attest FuzzParseEventLog parse_event_log_fuzzer -compile_fuzzer github.com/google/go-attestation/attest FuzzParseAKPublic12 parse_ak_public12_fuzzer -compile_fuzzer github.com/google/go-attestation/attest FuzzParseAKPublic20 parse_ak_public20_fuzzer -compile_fuzzer github.com/google/go-attestation/attest FuzzParseEKCertificate parse_ek_certificate_fuzzer +compile_fuzzer github.com/google/go-attestation/attest FuzzParseEventLog \ + parse_event_log_fuzzer +compile_fuzzer github.com/google/go-attestation/attest FuzzParseAKPublic12 \ + parse_ak_public12_fuzzer +compile_fuzzer github.com/google/go-attestation/attest FuzzParseAKPublic20 \ + parse_ak_public20_fuzzer +compile_fuzzer github.com/google/go-attestation/attest FuzzParseEKCertificate \ + parse_ek_certificate_fuzzer diff --git a/projects/go-dns/build.sh b/projects/go-dns/build.sh index e2c3f29ffe99..4005309af7c6 100755 --- a/projects/go-dns/build.sh +++ b/projects/go-dns/build.sh @@ -15,19 +15,18 @@ # ################################################################################ -# build target function function compile_fuzzer { path=$1 function=$2 fuzzer=$3 - # Instrument all Go files relevant to this fuzzer + # Compile and instrument all Go files relevant to this fuzz target. go-fuzz -tags fuzz -func $function -o $fuzzer.a $path - # Instrumented, compiled Go ($fuzzer.a) + fuzzing engine = fuzzer binary - $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -lpthread -o $OUT/$fuzzer + # Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary. + $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer } -#same as usual except for added -tags fuzz +# Same as usual except for added -tags fuzz. compile_fuzzer /root/go/src/github.com/miekg/dns/ FuzzNewRR fuzz_newrr compile_fuzzer /root/go/src/github.com/miekg/dns/ Fuzz fuzz_msg_unpack diff --git a/projects/go-json-iterator/build.sh b/projects/go-json-iterator/build.sh index 476de37d828b..1d2bc4728319 100755 --- a/projects/go-json-iterator/build.sh +++ b/projects/go-json-iterator/build.sh @@ -15,17 +15,16 @@ # ################################################################################ -# build target function function compile_fuzzer { path=$1 function=$2 fuzzer=$3 - # Instrument all Go files relevant to this fuzzer + # Compile and instrument all Go files relevant to this fuzz target. go-fuzz -func $function -o $fuzzer.a $path - # Instrumented, compiled Go ($fuzzer.a) + fuzzing engine = fuzzer binary - $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -lpthread -o $OUT/$fuzzer + # Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary. + $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer } compile_fuzzer . Fuzz fuzz_json diff --git a/projects/golang/build.sh b/projects/golang/build.sh index 147192ebdbbe..931e30f67989 100755 --- a/projects/golang/build.sh +++ b/projects/golang/build.sh @@ -13,23 +13,23 @@ # limitations under the License. function compile_fuzzer { - fuzzer=$(basename $1) + fuzzer=$(basename $1) - # Instrument all Go files relevant to this fuzzer, compile and store in $fuzzer.a - go-fuzz -o $fuzzer.a github.com/dvyukov/go-fuzz-corpus/$fuzzer + # Compile and instrument all Go files relevant to this fuzz target. + go-fuzz -o $fuzzer.a github.com/dvyukov/go-fuzz-corpus/$fuzzer - # Instrumented, compiled Go ($fuzzer.a) + libFuzzer = fuzzer binary - $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -lpthread -o fuzzer-$fuzzer + # Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary. + $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o fuzzer-$fuzzer - # Copy the fuzzer binary - cp fuzzer-$fuzzer $OUT + # Copy the fuzzer binary + cp fuzzer-$fuzzer $OUT - # Pack the seed corpus - zip -r fuzzer-${fuzzer}_seed_corpus.zip \ - $GOPATH/src/github.com/dvyukov/go-fuzz-corpus/$fuzzer/corpus + # Pack the seed corpus + zip -r fuzzer-${fuzzer}_seed_corpus.zip \ + $GOPATH/src/github.com/dvyukov/go-fuzz-corpus/$fuzzer/corpus - # Copy the seed corpus - cp fuzzer-${fuzzer}_seed_corpus.zip $OUT + # Copy the seed corpus + cp fuzzer-${fuzzer}_seed_corpus.zip $OUT } export -f compile_fuzzer diff --git a/projects/gonids/build.sh b/projects/gonids/build.sh index 5f241aaff258..ae49734f7643 100755 --- a/projects/gonids/build.sh +++ b/projects/gonids/build.sh @@ -15,20 +15,20 @@ # ################################################################################ -# build target function function compile_fuzzer { path=$1 function=$2 fuzzer=$3 - # Instrument all Go files relevant to this fuzzer + # Compile and instrument all Go files relevant to this fuzz target. go-fuzz -func $function -o $fuzzer.a $path - # Instrumented, compiled Go ($fuzzer.a) + fuzzing engine = fuzzer binary - $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -lpthread -o $OUT/$fuzzer + # Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary. + $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer } -compile_fuzzer /root/go/src/github.com/google/gonids/ FuzzParseRule fuzz_parserule +compile_fuzzer /root/go/src/github.com/google/gonids/ FuzzParseRule \ + fuzz_parserule unzip emerging.rules.zip cd rules diff --git a/projects/kubernetes/build.sh b/projects/kubernetes/build.sh index ff4b0b32877f..802ac6a73ce3 100755 --- a/projects/kubernetes/build.sh +++ b/projects/kubernetes/build.sh @@ -20,17 +20,16 @@ set -o pipefail set -o errexit set -x -# Based on the function from oss-fuzz/projects/golang/build.sh script. function compile_fuzzer { local pkg=$1 local function=$2 local fuzzer="${pkg}_${function}" - # Instrument all Go files relevant to this fuzzer + # Compile and instrument all Go files relevant to this fuzz target. go-fuzz -func "${function}" -o "${fuzzer}.a" "k8s.io/kubernetes/test/fuzz/${pkg}" - # Instrumented, compiled Go ($fuzzer.a) + fuzzing engine = fuzzer binary - $CXX $CXXFLAGS $LIB_FUZZING_ENGINE "${fuzzer}.a" -lpthread -o "${OUT}/${fuzzer}" + # Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary. + $CXX $CXXFLAGS $LIB_FUZZING_ENGINE "${fuzzer}.a" -o "${OUT}/${fuzzer}" } compile_fuzzer "yaml" "FuzzDurationStrict" diff --git a/projects/syzkaller/build.sh b/projects/syzkaller/build.sh index 2977b577af3c..744ae34a0099 100755 --- a/projects/syzkaller/build.sh +++ b/projects/syzkaller/build.sh @@ -15,17 +15,16 @@ # ################################################################################ -# Based on the function from oss-fuzz/projects/golang/build.sh script. function compile_fuzzer { path=$1 function=$2 fuzzer=$3 - # Instrument all Go files relevant to this fuzzer + # Compile and instrument all Go files relevant to this fuzz target. go-fuzz -func $function -o $fuzzer.a $path - # Instrumented, compiled Go ($fuzzer.a) + fuzzing engine = fuzzer binary - $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -lpthread -o $OUT/$fuzzer + # Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary. + $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer } compile_fuzzer ./pkg/compiler Fuzz compiler_fuzzer From 9bb652fd13126f0d675eebf1f6b2979790ed5394 Mon Sep 17 00:00:00 2001 From: Max Moroz Date: Wed, 15 Apr 2020 23:17:39 -0700 Subject: [PATCH 2/3] fix unrelated go-dns and gonids errors --- projects/go-dns/build.sh | 4 ++-- projects/gonids/Dockerfile | 2 +- projects/gonids/build.sh | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/projects/go-dns/build.sh b/projects/go-dns/build.sh index 4005309af7c6..b9309993de7c 100755 --- a/projects/go-dns/build.sh +++ b/projects/go-dns/build.sh @@ -28,5 +28,5 @@ function compile_fuzzer { } # Same as usual except for added -tags fuzz. -compile_fuzzer /root/go/src/github.com/miekg/dns/ FuzzNewRR fuzz_newrr -compile_fuzzer /root/go/src/github.com/miekg/dns/ Fuzz fuzz_msg_unpack +compile_fuzzer github.com/miekg/dns FuzzNewRR fuzz_newrr +compile_fuzzer github.com/miekg/dns Fuzz fuzz_msg_unpack diff --git a/projects/gonids/Dockerfile b/projects/gonids/Dockerfile index 6ca5bd5e8e0f..7d82c0a13e7d 100644 --- a/projects/gonids/Dockerfile +++ b/projects/gonids/Dockerfile @@ -21,4 +21,4 @@ RUN go get github.com/google/gonids ADD https://rules.emergingthreats.net/open/suricata/emerging.rules.zip emerging.rules.zip COPY build.sh $SRC/ -WORKDIR $SRC/ +WORKDIR $SRC diff --git a/projects/gonids/build.sh b/projects/gonids/build.sh index ae49734f7643..277b1c59c128 100755 --- a/projects/gonids/build.sh +++ b/projects/gonids/build.sh @@ -27,8 +27,7 @@ function compile_fuzzer { $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer } -compile_fuzzer /root/go/src/github.com/google/gonids/ FuzzParseRule \ - fuzz_parserule +compile_fuzzer github.com/google/gonids FuzzParseRule fuzz_parserule unzip emerging.rules.zip cd rules From b9d3d8cf94448a2b48cf23145fdefd32d24325d8 Mon Sep 17 00:00:00 2001 From: Max Moroz Date: Thu, 16 Apr 2020 09:33:21 -0700 Subject: [PATCH 3/3] simplify golang/build.sh as per Abhishek's comment --- projects/golang/build.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/projects/golang/build.sh b/projects/golang/build.sh index 931e30f67989..f207a5931577 100755 --- a/projects/golang/build.sh +++ b/projects/golang/build.sh @@ -19,17 +19,11 @@ function compile_fuzzer { go-fuzz -o $fuzzer.a github.com/dvyukov/go-fuzz-corpus/$fuzzer # Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary. - $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o fuzzer-$fuzzer - - # Copy the fuzzer binary - cp fuzzer-$fuzzer $OUT + $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/fuzzer-$fuzzer # Pack the seed corpus - zip -r fuzzer-${fuzzer}_seed_corpus.zip \ + zip -r $OUT/fuzzer-${fuzzer}_seed_corpus.zip \ $GOPATH/src/github.com/dvyukov/go-fuzz-corpus/$fuzzer/corpus - - # Copy the seed corpus - cp fuzzer-${fuzzer}_seed_corpus.zip $OUT } export -f compile_fuzzer