1# Copyright 2021 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# 15################################################################################ 16 17FROM gcr.io/oss-fuzz-base/base-clang 18 19RUN dpkg --add-architecture i386 && \ 20 apt-get update && \ 21 apt-get install -y software-properties-common && \ 22 add-apt-repository ppa:git-core/ppa && \ 23 apt-get update && \ 24 apt-get install -y \ 25 binutils-dev \ 26 build-essential \ 27 curl \ 28 git \ 29 jq \ 30 libc6-dev-i386 \ 31 patchelf \ 32 rsync \ 33 subversion \ 34 zip 35 36# Build and install latest Python 3 (3.8.3). 37ENV PYTHON_VERSION 3.8.3 38RUN export PYTHON_DEPS="\ 39 zlib1g-dev \ 40 libncurses5-dev \ 41 libgdbm-dev \ 42 libnss3-dev \ 43 libssl-dev \ 44 libsqlite3-dev \ 45 libreadline-dev \ 46 libffi-dev \ 47 libbz2-dev \ 48 liblzma-dev" && \ 49 unset CFLAGS CXXFLAGS && \ 50 apt-get install -y $PYTHON_DEPS && \ 51 cd /tmp && \ 52 curl -O https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tar.xz && \ 53 tar -xvf Python-$PYTHON_VERSION.tar.xz && \ 54 cd Python-$PYTHON_VERSION && \ 55 ./configure --enable-optimizations --enable-shared && \ 56 make -j install && \ 57 ldconfig && \ 58 ln -s /usr/bin/python3 /usr/bin/python && \ 59 cd .. && \ 60 rm -r /tmp/Python-$PYTHON_VERSION.tar.xz /tmp/Python-$PYTHON_VERSION && \ 61 rm -rf /usr/local/lib/python3.8/test && \ 62 apt-get remove -y $PYTHON_DEPS # https://github.com/google/oss-fuzz/issues/3888 63 64# Install six for Bazel rules. 65RUN unset CFLAGS CXXFLAGS && pip3 install -v --no-cache-dir \ 66 six==1.15.0 && rm -rf /tmp/* 67 68# Install Bazel through Bazelisk, which automatically fetches the latest Bazel version. 69ENV BAZELISK_VERSION 1.9.0 70RUN curl -L https://github.com/bazelbuild/bazelisk/releases/download/v$BAZELISK_VERSION/bazelisk-linux-amd64 -o /usr/local/bin/bazel && \ 71 chmod +x /usr/local/bin/bazel 72 73# Default build flags for various sanitizers. 74ENV SANITIZER_FLAGS_address "-fsanitize=address -fsanitize-address-use-after-scope" 75 76# Set of '-fsanitize' flags matches '-fno-sanitize-recover' + 'unsigned-integer-overflow'. 77ENV SANITIZER_FLAGS_undefined "-fsanitize=array-bounds,bool,builtin,enum,float-divide-by-zero,function,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unsigned-integer-overflow,unreachable,vla-bound,vptr -fno-sanitize-recover=array-bounds,bool,builtin,enum,float-divide-by-zero,function,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr" 78 79ENV SANITIZER_FLAGS_memory "-fsanitize=memory -fsanitize-memory-track-origins" 80 81ENV SANITIZER_FLAGS_dataflow "-fsanitize=dataflow" 82 83ENV SANITIZER_FLAGS_thread "-fsanitize=thread" 84 85# Do not use any sanitizers in the coverage build. 86ENV SANITIZER_FLAGS_coverage "" 87 88# We use unsigned-integer-overflow as an additional coverage signal and have to 89# suppress error messages. See https://github.com/google/oss-fuzz/issues/910. 90ENV UBSAN_OPTIONS="silence_unsigned_overflow=1" 91 92# To suppress warnings from binaries running during compilation. 93ENV DFSAN_OPTIONS='warn_unimplemented=0' 94 95# Default build flags for coverage feedback. 96ENV COVERAGE_FLAGS="-fsanitize=fuzzer-no-link" 97 98# Use '-Wno-unused-command-line-argument' to suppress "warning: -ldl: 'linker' input unused" 99# messages which are treated as errors by some projects. 100ENV COVERAGE_FLAGS_coverage "-fprofile-instr-generate -fcoverage-mapping -pthread -Wl,--no-as-needed -Wl,-ldl -Wl,-lm -Wno-unused-command-line-argument" 101 102# Coverage isntrumentation flags for dataflow builds. 103ENV COVERAGE_FLAGS_dataflow="-fsanitize-coverage=trace-pc-guard,pc-table,bb,trace-cmp" 104 105# Default sanitizer, fuzzing engine and architecture to use. 106ENV SANITIZER="address" 107ENV FUZZING_ENGINE="libfuzzer" 108ENV ARCHITECTURE="x86_64" 109 110# DEPRECATED - NEW CODE SHOULD NOT USE THIS. OLD CODE SHOULD STOP. Please use 111# LIB_FUZZING_ENGINE instead. 112# Path to fuzzing engine library to support some old users of 113# LIB_FUZZING_ENGINE. 114ENV LIB_FUZZING_ENGINE_DEPRECATED="/usr/lib/libFuzzingEngine.a" 115 116# Argument passed to compiler to link against fuzzing engine. 117# Defaults to the path, but is "-fsanitize=fuzzer" in libFuzzer builds. 118ENV LIB_FUZZING_ENGINE="/usr/lib/libFuzzingEngine.a" 119 120# TODO: remove after tpm2 catchup. 121ENV FUZZER_LDFLAGS "" 122 123WORKDIR $SRC 124 125# TODO: switch to -b stable once we can. 126RUN git clone https://github.com/AFLplusplus/AFLplusplus.git aflplusplus && \ 127 cd aflplusplus && \ 128 git checkout 4fe572b80f76ff0b0e916b639d1e04d5af48b157 129 130RUN cd $SRC && \ 131 curl -L -O https://github.com/google/honggfuzz/archive/oss-fuzz.tar.gz && \ 132 mkdir honggfuzz && \ 133 cd honggfuzz && \ 134 tar -xzv --strip-components=1 -f $SRC/oss-fuzz.tar.gz && \ 135 rm -rf examples $SRC/oss-fuzz.tar.gz 136 137# Do precompiles before copying other scripts for better cache efficiency. 138COPY precompile_afl /usr/local/bin/ 139RUN precompile_afl 140 141COPY precompile_honggfuzz /usr/local/bin/ 142RUN precompile_honggfuzz 143 144COPY cargo compile compile_afl compile_dataflow compile_libfuzzer compile_honggfuzz \ 145 compile_go_fuzzer debug_afl srcmap \ 146 write_labels.py bazel_build_fuzz_tests \ 147 # Go, java, and swift installation scripts. 148 install_go.sh \ 149 install_java.sh \ 150 install_python.sh \ 151 install_rust.sh \ 152 install_swift.sh \ 153 /usr/local/bin/ 154 155COPY llvmsymbol.diff $SRC 156COPY detect_repo.py /opt/cifuzz/ 157 158CMD ["compile"] 159