Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fox experiment #1957

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions fuzzers/bandfuzz/builder.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ARG parent_image
FROM $parent_image
COPY --from=whexy/bandfuzz:sbft_v1 /fuzzers /tmp/fuzzers
COPY --from=whexy/bandfuzz:sbft_v1 /bf /bf
ENV PATH="/bf/llvm/llvm-12/bin:${PATH}"
RUN echo "/bf/llvm/llvm-12/lib" >> /etc/ld.so.conf.d/bandfuzz.conf && ldconfig
70 changes: 70 additions & 0 deletions fuzzers/bandfuzz/fuzzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# BandFuzz
# Author: Wenxuan ([email protected], shiwx.org)

import os
import shutil
import subprocess

def build():
env = os.environ.copy()
src_folder = env['SRC']
out_folder = os.path.join(env['OUT'], 'target')
build_script = os.path.join(src_folder, 'build.sh')
benchmark = os.getenv('BENCHMARK')
fuzzer = os.getenv('FUZZER')

# Run bf-cc to build the benchmark
print(f'Building benchmark {benchmark} with fuzzer {fuzzer}!')
subprocess.check_call(['chmod', '+x', build_script])
subprocess.check_call(['cp', '/bf/compilers.yaml', "."])
subprocess.check_call(['/bf/bin/bf-cc', '-i', src_folder, '-o', out_folder, build_script], env=env)

# Copy fuzzers to the out folder
subprocess.check_call(['cp', '-r', '/bf/fuzzers', env['OUT']])

# Copy necessary runtime files to the out folder
subprocess.check_call(['mkdir', '-p', os.path.join(env['OUT'], 'llvm')])
subprocess.check_call(['cp', '-r', '/bf/llvm/llvm-12/bin', os.path.join(env['OUT'], 'llvm', 'bin')])
subprocess.check_call(['cp', '-r', '/bf/llvm/llvm-12/lib', os.path.join(env['OUT'], 'llvm', 'lib')])
subprocess.check_call(['cp', '/bf/bin/bf', env['OUT']])
subprocess.check_call(['cp', '/bf/config_gen.py', env['OUT']])

# Copy one target binary to the out folder
# otherwise fuzzbench will complain, because of common/fuzzer_utils.py: get_fuzz_target_binary (line 77)
source_dir = os.path.join(env['OUT'], 'target', 'aflpp')
dest_dir = env['OUT']
for item in os.listdir(source_dir):
s = os.path.join(source_dir, item)
d = os.path.join(dest_dir, item)

if os.path.isdir(s):
shutil.copytree(s, d, dirs_exist_ok=True)
else:
shutil.copy2(s, d)

def fuzz(input_corpus, output_corpus, target_binary):
target_binary_base = os.path.basename(target_binary)
target_folder = os.path.dirname(target_binary)
target_binary_name = os.path.join(target_folder, "target", target_binary_base)

# Generate config file
with open("config.yaml", "w") as file:
config_gen_script = os.path.join(target_folder,'config_gen.py')
subprocess.check_call(['chmod', '+x', config_gen_script])
subprocess.check_call([config_gen_script, '-i', input_corpus, '-o', output_corpus, '--', target_binary_name], env=os.environ.copy(), stdout=file)

# Generate empty seed file if no seed file is provided
if os.listdir(input_corpus):
pass
else:
print('Creating a fake seed file in empty corpus directory.')
default_seed_file = os.path.join(input_corpus, 'default_seed')
with open(default_seed_file, 'w', encoding='utf-8') as file_handle:
file_handle.write('hi')

# add /out/llvm/lib to ldconfig
with open('/etc/ld.so.conf.d/bandfuzz.conf', 'w') as file:
file.write('/out/llvm/lib\n')
subprocess.check_call(['ldconfig'])

subprocess.check_call(['./bf', '--lazy=30'])
7 changes: 7 additions & 0 deletions fuzzers/bandfuzz/runner.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM gcr.io/fuzzbench/base-image

# ! Breaking change: There's something wrong in Google Cloud SDK apt source, so I have to change it back to ubuntu default source.
RUN rm -rf /etc/apt
COPY --from=ubuntu:20.04 /etc/apt/ /etc/apt/
# ! Before submit anything, please change it back to Google Cloud SDK apt source.
RUN apt-get update -y && apt-get install -y libbfd-dev libunwind-dev
102 changes: 102 additions & 0 deletions fuzzers/fox/builder.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# FROM ubuntu:focal
# ARG DEBIAN_FRONTEND=noninteractive

ARG parent_image
FROM $parent_image

RUN apt-get update && \
apt-get -y install --no-install-suggests --no-install-recommends \
automake \
cmake \
meson \
ninja-build \
bison flex \
build-essential \
git \
binutils \
python3 python3-dev python3-setuptools python-is-python3 \
libtool libtool-bin \
libglib2.0-dev \
wget vim jupp nano bash-completion less \
apt-utils apt-transport-https ca-certificates gnupg dialog \
libpixman-1-dev \
gnuplot-nox \
sudo \
&& rm -rf /var/lib/apt/lists/*

# Add ~/.local/bin and /usr/local/go/bin to the PATH
RUN mkdir -p /home/$USER_NAME/.local/bin
ENV PATH="/home/.local/bin:/usr/local/go/bin:/fox/gllvm_bins:${PATH}"
RUN echo "export PATH=$PATH" >> ~/.bashrc

RUN apt-get update && \
apt-get -y install --no-install-suggests --no-install-recommends \
lsb-release wget software-properties-common gnupg

RUN wget https://apt.llvm.org/llvm.sh
RUN chmod +x llvm.sh
RUN sudo ./llvm.sh 15

RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-15 10 \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-15 \
--slave /usr/bin/opt opt /usr/bin/opt-15
RUN update-alternatives --install /usr/lib/llvm llvm /usr/lib/llvm-15 20 \
--slave /usr/bin/llvm-config llvm-config /usr/bin/llvm-config-15 \
--slave /usr/bin/llvm-link llvm-link /usr/bin/llvm-link-15

ENV LLVM_CONFIG=llvm-config-15

# Import and setup FOX : TODO : add publie repo
RUN git clone https://github.com/adamstorek/FOX.git /fox
RUN git -C /fox checkout sbft24_stable
RUN rm -f /dev/shm/*

RUN git clone https://github.com/adamstorek/FOX.git /fox_cmplog
RUN git -C /fox_cmplog checkout 4.10c_hybrid_mode
RUN rm -f /dev/shm/*

# XXX: Set up vanilla AFL++ as a vanilla option to invoke in case the compilation
# fails (Current known failing targets: harfbuzz, systemd, php)
RUN git clone -b dev https://github.com/AFLplusplus/AFLplusplus /afl_vanilla && \
cd /afl_vanilla && \
git checkout tags/v4.10c || \
true

# Build without Python support as we don't need it.
# Set AFL_NO_X86 to skip flaky tests.
RUN cd /afl_vanilla && \
unset CFLAGS CXXFLAGS && \
export CC=clang-15 AFL_NO_X86=1 && \
PYTHON_INCLUDE=/ make && \
cp utils/aflpp_driver/libAFLDriver.a /

RUN cd /fox && \
unset CFLAGS CXXFLAGS && \
export CC=clang-15 AFL_NO_X86=1 && \
PYTHON_INCLUDE=/ make && \
cp utils/aflpp_driver/libAFLDriver.a /

RUN cd /fox_cmplog && \
unset CFLAGS CXXFLAGS && \
export CC=clang-15 AFL_NO_X86=1 && \
PYTHON_INCLUDE=/ make && \
cp utils/aflpp_driver/libAFLDriver.a /

RUN rm /usr/local/bin/llvm-nm
RUN sudo ln -s /usr/bin/llvm-nm-15 /usr/local/bin/llvm-nm

RUN rm -rf /usr/local/bin/clang*
Loading
Loading