1# Copyright 2016 Google Inc. 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 latest atheris for python fuzzing, pyinstaller for fuzzer packaging, 65# six for Bazel rules. 66RUN unset CFLAGS CXXFLAGS && pip3 install -v --no-cache-dir \ 67 atheris pyinstaller==4.1 six==1.15.0 && \ 68 rm -rf /tmp/* 69 70# Download and install the latest stable Go. 71RUN cd /tmp && \ 72 curl -O https://storage.googleapis.com/golang/getgo/installer_linux && \ 73 chmod +x ./installer_linux && \ 74 SHELL="bash" ./installer_linux && \ 75 rm -rf ./installer_linux 76 77# Set up Golang environment variables (copied from /root/.bash_profile). 78ENV GOPATH /root/go 79 80# /root/.go/bin is for the standard Go binaries (i.e. go, gofmt, etc). 81# $GOPATH/bin is for the binaries from the dependencies installed via "go get". 82ENV PATH $PATH:/root/.go/bin:$GOPATH/bin 83 84# Uses golang 1.14+ cmd/compile's native libfuzzer instrumentation. 85RUN go get -u github.com/mdempsky/go114-fuzz-build && \ 86 ln -s $GOPATH/bin/go114-fuzz-build $GOPATH/bin/go-fuzz 87 88# Install Rust and cargo-fuzz for libFuzzer instrumentation. 89ENV CARGO_HOME=/rust 90ENV RUSTUP_HOME=/rust/rustup 91ENV PATH=$PATH:/rust/bin 92RUN curl https://sh.rustup.rs | sh -s -- -y --default-toolchain=nightly --profile=minimal 93RUN cargo install cargo-fuzz && rm -rf /rust/registry 94# Needed to recompile rust std library for MSAN 95RUN rustup component add rust-src --toolchain nightly 96# Set up custom environment variable for source code copy for coverage reports 97ENV OSSFUZZ_RUSTPATH /rust 98 99# Install Bazel through Bazelisk, which automatically fetches the latest Bazel version. 100ENV BAZELISK_VERSION 1.7.4 101RUN curl -L https://github.com/bazelbuild/bazelisk/releases/download/v$BAZELISK_VERSION/bazelisk-linux-amd64 -o /usr/local/bin/bazel && \ 102 chmod +x /usr/local/bin/bazel 103 104# Install OpenJDK 15 and trim its size by removing unused components. 105ENV JAVA_HOME=/usr/lib/jvm/java-15-openjdk-amd64 106ENV JVM_LD_LIBRARY_PATH=$JAVA_HOME/lib/server 107ENV PATH=$PATH:$JAVA_HOME/bin 108RUN cd /tmp && \ 109 curl -L -O https://download.java.net/java/GA/jdk15.0.2/0d1cfde4252546c6931946de8db48ee2/7/GPL/openjdk-15.0.2_linux-x64_bin.tar.gz && \ 110 mkdir -p $JAVA_HOME && \ 111 tar -xzv --strip-components=1 -f openjdk-15.0.2_linux-x64_bin.tar.gz --directory $JAVA_HOME && \ 112 rm -f openjdk-15.0.2_linux-x64_bin.tar.gz && \ 113 rm -rf $JAVA_HOME/jmods $JAVA_HOME/lib/src.zip 114 115# Install the latest Jazzer in $OUT. 116# jazzer_api_deploy.jar is required only at build-time, the agent and the 117# drivers are copied to $OUT as they need to be present on the runners. 118ENV JAZZER_API_PATH "/usr/local/lib/jazzer_api_deploy.jar" 119RUN cd $SRC/ && \ 120 git clone --depth=1 https://github.com/CodeIntelligenceTesting/jazzer && \ 121 cd jazzer && \ 122 bazel build --java_runtime_version=localjdk_15 -c opt --cxxopt="-stdlib=libc++" --linkopt=-lc++ \ 123 //agent:jazzer_agent_deploy.jar //driver:jazzer_driver //driver:jazzer_driver_asan //agent:jazzer_api_deploy.jar && \ 124 cp bazel-bin/agent/jazzer_agent_deploy.jar bazel-bin/driver/jazzer_driver bazel-bin/driver/jazzer_driver_asan /usr/local/bin/ && \ 125 cp bazel-bin/agent/jazzer_api_deploy.jar $JAZZER_API_PATH && \ 126 rm -rf ~/.cache/bazel ~/.cache/bazelisk && \ 127 rm -rf $SRC/jazzer 128 129# Default build flags for various sanitizers. 130ENV SANITIZER_FLAGS_address "-fsanitize=address -fsanitize-address-use-after-scope" 131 132# Set of '-fsanitize' flags matches '-fno-sanitize-recover' + 'unsigned-integer-overflow'. 133ENV 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" 134 135ENV SANITIZER_FLAGS_memory "-fsanitize=memory -fsanitize-memory-track-origins" 136 137ENV SANITIZER_FLAGS_dataflow "-fsanitize=dataflow" 138 139ENV SANITIZER_FLAGS_thread "-fsanitize=thread" 140 141# Do not use any sanitizers in the coverage build. 142ENV SANITIZER_FLAGS_coverage "" 143 144# We use unsigned-integer-overflow as an additional coverage signal and have to 145# suppress error messages. See https://github.com/google/oss-fuzz/issues/910. 146ENV UBSAN_OPTIONS="silence_unsigned_overflow=1" 147 148# To suppress warnings from binaries running during compilation. 149ENV DFSAN_OPTIONS='warn_unimplemented=0' 150 151# Default build flags for coverage feedback. 152ENV COVERAGE_FLAGS="-fsanitize=fuzzer-no-link" 153 154# Use '-Wno-unused-command-line-argument' to suppress "warning: -ldl: 'linker' input unused" 155# messages which are treated as errors by some projects. 156ENV COVERAGE_FLAGS_coverage "-fprofile-instr-generate -fcoverage-mapping -pthread -Wl,--no-as-needed -Wl,-ldl -Wl,-lm -Wno-unused-command-line-argument" 157 158# Coverage isntrumentation flags for dataflow builds. 159ENV COVERAGE_FLAGS_dataflow="-fsanitize-coverage=trace-pc-guard,pc-table,bb,trace-cmp" 160 161# Default sanitizer, fuzzing engine and architecture to use. 162ENV SANITIZER="address" 163ENV FUZZING_ENGINE="libfuzzer" 164ENV ARCHITECTURE="x86_64" 165 166# DEPRECATED - NEW CODE SHOULD NOT USE THIS. OLD CODE SHOULD STOP. Please use 167# LIB_FUZZING_ENGINE instead. 168# Path to fuzzing engine library to support some old users of 169# LIB_FUZZING_ENGINE. 170ENV LIB_FUZZING_ENGINE_DEPRECATED="/usr/lib/libFuzzingEngine.a" 171 172# Argument passed to compiler to link against fuzzing engine. 173# Defaults to the path, but is "-fsanitize=fuzzer" in libFuzzer builds. 174ENV LIB_FUZZING_ENGINE="/usr/lib/libFuzzingEngine.a" 175 176# TODO: remove after tpm2 catchup. 177ENV FUZZER_LDFLAGS "" 178 179WORKDIR $SRC 180 181# TODO: switch to -b stable once we can. 182RUN git clone https://github.com/AFLplusplus/AFLplusplus.git aflplusplus && \ 183 cd aflplusplus && \ 184 git checkout 2102264acf5c271b7560a82771b3af8136af9354 185 186RUN cd $SRC && \ 187 curl -L -O https://github.com/google/honggfuzz/archive/oss-fuzz.tar.gz && \ 188 mkdir honggfuzz && \ 189 cd honggfuzz && \ 190 tar -xzv --strip-components=1 -f $SRC/oss-fuzz.tar.gz && \ 191 rm -rf examples $SRC/oss-fuzz.tar.gz 192 193COPY cargo compile compile_afl compile_dataflow compile_libfuzzer compile_honggfuzz \ 194 compile_go_fuzzer precompile_honggfuzz precompile_afl debug_afl srcmap \ 195 write_labels.py bazel_build_fuzz_tests /usr/local/bin/ 196 197COPY detect_repo.py /opt/cifuzz/ 198COPY ossfuzz_coverage_runner.go $GOPATH 199 200RUN precompile_honggfuzz 201RUN precompile_afl 202 203CMD ["compile"] 204