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

Fuzzer Framework #5940

Merged
merged 168 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 158 commits
Commits
Show all changes
168 commits
Select commit Hold shift + click to select a range
0fa075e
first commit fuzzer
nicola-cab Oct 12, 2022
ddd2c1a
fix script
nicola-cab Oct 12, 2022
19027a1
restore parallel fuzzer
nicola-cab Oct 13, 2022
85c999f
code refactory
nicola-cab Oct 13, 2022
1fe1da0
code re-org
nicola-cab Oct 14, 2022
70d7bf4
support input file from cmd line
nicola-cab Oct 14, 2022
7cf6411
comment crashing commands in order to verify them
nicola-cab Oct 14, 2022
73a28f0
Merge branch 'master' of github.com:realm/realm-core into nc/fuzzer
nicola-cab Oct 17, 2022
d111728
code cleanup and logging
nicola-cab Oct 17, 2022
0b16041
added fuzz logger
nicola-cab Oct 18, 2022
d8cc443
added new constructor for libfuzz
nicola-cab Oct 19, 2022
30cb356
ctro for libfuzz
nicola-cab Oct 19, 2022
51b9b3f
add support for libfuzzer
nicola-cab Oct 19, 2022
bbd3cfe
appease format checks
nicola-cab Oct 19, 2022
89c3381
lib fuzzer support and defines
nicola-cab Oct 19, 2022
15a61cf
added support for libfuzzer
nicola-cab Oct 20, 2022
4c569da
Merge branch 'master' of github.com:realm/realm-core into nc/fuzzer
nicola-cab Oct 21, 2022
a574d88
unify how to launch fuzzer
nicola-cab Oct 21, 2022
a5a3e31
fix forgotten file
nicola-cab Oct 21, 2022
22379e1
adding open/close to commands
nicola-cab Oct 21, 2022
dfa6646
Merge branch 'master' of github.com:realm/realm-core into nc/fuzzer
nicola-cab Oct 24, 2022
c978ad2
Fix logging
nicola-cab Oct 24, 2022
a65267e
catch some exceptions during fuzzing
nicola-cab Oct 24, 2022
6763a8a
exception unification catching logic
nicola-cab Oct 24, 2022
a5e49db
Make realm-libfuzz compile on Linux
jedelbo Oct 25, 2022
4ad5408
Merge branch 'je/fuzzer' into nc/fuzzer
nicola-cab Oct 25, 2022
dcf2267
Merge branch 'master' of github.com:realm/realm-core into nc/fuzzer
nicola-cab Oct 25, 2022
9e50175
restore encryption
nicola-cab Oct 25, 2022
48f79c6
fix parent node verification function
nicola-cab Oct 26, 2022
7c6a2b8
fix string cmp
nicola-cab Oct 26, 2022
d6156eb
Merge branch 'master' of github.com:realm/realm-core into nc/fuzzer
nicola-cab Nov 29, 2022
98a7e77
Merge branch 'master' of github.com:realm/realm-core into nc/fuzzer
nicola-cab Dec 13, 2022
aec4c77
Attempt to fix compilation issues for non apple builds
nicola-cab Dec 13, 2022
91e4c2d
attempt to fix compilation
nicola-cab Dec 14, 2022
585e0ea
fix compilation issues
nicola-cab Dec 14, 2022
6fbf9ca
attempt to fix compilation issue
nicola-cab Dec 15, 2022
3a8af67
attempt to fix compilation
nicola-cab Dec 15, 2022
8535fe3
clean up
nicola-cab Dec 15, 2022
97f65b4
cleanup
nicola-cab Dec 15, 2022
3ef6e22
cleanup
nicola-cab Dec 15, 2022
1753b20
attempt to fix compilation
nicola-cab Dec 15, 2022
1efb701
test
nicola-cab Dec 15, 2022
a29f4c3
revert specialityBuilds cmake changes
nicola-cab Dec 15, 2022
b1dea82
Merge branch 'master' of github.com:realm/realm-core into nc/fuzzer
nicola-cab Dec 15, 2022
8082cb2
Add Readme
nicola-cab Dec 15, 2022
8b0f4ed
changelog entry
nicola-cab Dec 15, 2022
3b26962
removed stale testing folder
nicola-cab Dec 15, 2022
b097258
better formatting
nicola-cab Dec 15, 2022
66d6791
better formatting
nicola-cab Dec 15, 2022
bdf1517
restore support for afl++ and fix clang libfuzzer command line
nicola-cab Dec 15, 2022
6de6c68
make linux builders happy
nicola-cab Dec 15, 2022
56b41c3
really testing things
nicola-cab Dec 15, 2022
2caa486
add cstring header
nicola-cab Dec 16, 2022
b468cbb
test building
nicola-cab Dec 16, 2022
f86bf68
fix libuv finding packages
nicola-cab Dec 16, 2022
e8078d8
fix libuv finding cmake
nicola-cab Dec 16, 2022
b0300c2
Update CMakeLists.txt
fealebenpae Dec 16, 2022
1be6f6b
Update CMakeLists.txt
fealebenpae Dec 16, 2022
3e3f757
Update CMakeLists.txt
fealebenpae Dec 16, 2022
d7034e3
pull master and fix conflicts
nicola-cab Dec 19, 2022
908cc1b
fix changelog and readme
nicola-cab Dec 19, 2022
26b1cfb
add evergreen running logic for fuzzer
nicola-cab Dec 19, 2022
58d86fa
attempt to fix evergreen cnf
nicola-cab Dec 19, 2022
dfc76b1
fuzzer cnf
nicola-cab Dec 19, 2022
dfaa03d
attempt to fix evergreen cnf
nicola-cab Dec 19, 2022
88c2405
run fuzzer for macos builder
nicola-cab Dec 19, 2022
f4855a6
test
nicola-cab Dec 19, 2022
cc75925
test
nicola-cab Dec 19, 2022
4a7ccc4
test
nicola-cab Dec 19, 2022
7848dbe
test enable macos-fuzzer
nicola-cab Dec 19, 2022
92c6de2
add fuzzer to evergreen
nicola-cab Dec 19, 2022
45c2d25
removed redundant cmake build mode
nicola-cab Dec 19, 2022
9c65f6b
compile and fuzzer for macos fuzzing build
nicola-cab Dec 19, 2022
417792b
test
nicola-cab Dec 19, 2022
7836c8c
test
nicola-cab Dec 19, 2022
76b3690
test on ubuntu
nicola-cab Dec 19, 2022
c944d82
test
nicola-cab Dec 20, 2022
e6a99e3
test fuzzer
nicola-cab Dec 20, 2022
e7d6c2b
pull master and fix conflicts
nicola-cab Dec 20, 2022
e04aa57
compile and test fuzzer
nicola-cab Dec 20, 2022
4232bca
compile test
nicola-cab Dec 20, 2022
d900dd0
test fuzzer as task
nicola-cab Dec 20, 2022
4558c36
test macos fuzzer
nicola-cab Dec 20, 2022
0c1a355
build fuzzer
nicola-cab Dec 20, 2022
bb8727b
last test before to try things locally
nicola-cab Dec 20, 2022
4d8ad3c
fix param
nicola-cab Dec 20, 2022
e47ccb0
changes to cnf file
nicola-cab Dec 20, 2022
c3cbf06
fix spaces
nicola-cab Dec 20, 2022
1a155ab
pull master and fix conflicts
nicola-cab Dec 21, 2022
5868931
fix after evergreen validate check
nicola-cab Dec 21, 2022
216f42f
re-org a bit fuzzer builder
nicola-cab Dec 21, 2022
695e33d
remove quotes
nicola-cab Dec 21, 2022
ed60633
test
nicola-cab Dec 21, 2022
6f73ae2
remove fuzzer from task-group
nicola-cab Dec 21, 2022
fd9fd42
add fuzzer build
nicola-cab Dec 21, 2022
ee241ae
test compilation and if compile-rt works
nicola-cab Dec 21, 2022
8ca4cdf
fix generator
nicola-cab Dec 21, 2022
0053aa4
xcode generator
nicola-cab Dec 21, 2022
93863ec
test if fixes linking issues
nicola-cab Dec 21, 2022
9832d74
test
nicola-cab Dec 21, 2022
810729c
test
nicola-cab Dec 21, 2022
0dcc548
test building and linking
nicola-cab Dec 21, 2022
71deb5b
fix cnf
nicola-cab Dec 21, 2022
e57c557
test xcode 14.1
nicola-cab Dec 21, 2022
003a536
test
nicola-cab Dec 21, 2022
96d6c03
pull master
nicola-cab Jan 10, 2023
5e47421
test fuzzer
nicola-cab Jan 10, 2023
a6bd9ee
unify include logic
nicola-cab Jan 10, 2023
a773bde
add linking instruction for address sanitizer
nicola-cab Jan 10, 2023
4c42fe6
add linker flags to correct builder
nicola-cab Jan 10, 2023
65d28d5
link fuzzer
nicola-cab Jan 10, 2023
8a52a89
test only fuzzer
nicola-cab Jan 10, 2023
1a6a44b
Merge branch 'master' of github.com:realm/realm-core into nc/fuzzer
nicola-cab Jan 19, 2023
dfd16ae
test running the fuzzer on ubuntu
nicola-cab Jan 19, 2023
3561b15
no extra flags
nicola-cab Jan 19, 2023
4f66ee2
add toolchain file for LLVM via homebrew
fealebenpae Jan 19, 2023
4bc951a
test pre keyword
nicola-cab Jan 19, 2023
40d7218
Merge branch 'nc/fuzzer' of github.com:realm/realm-core into nc/fuzzer
nicola-cab Jan 19, 2023
e090c4a
fix file format
nicola-cab Jan 19, 2023
106ba7c
test pre condition
nicola-cab Jan 19, 2023
0b37563
Revert "add toolchain file for LLVM via homebrew"
nicola-cab Jan 19, 2023
6e943ce
try daily setup
nicola-cab Jan 19, 2023
690ec81
try daily setup
nicola-cab Jan 19, 2023
26e6232
restructure a little bit evergreen file
nicola-cab Jan 20, 2023
fe367ee
Merge branch 'master' of github.com:realm/realm-core into nc/fuzzer
nicola-cab Jan 20, 2023
bc3cf97
added support for upload crash input strings
nicola-cab Jan 20, 2023
0fdd865
added support for publishing to s3 fuzzer crash dumps
nicola-cab Jan 20, 2023
4f2c57b
test crash
nicola-cab Jan 23, 2023
db8cbb0
fix typo
nicola-cab Jan 23, 2023
2f6cdde
test
nicola-cab Jan 23, 2023
200573a
fix running fuzzer exe
nicola-cab Jan 23, 2023
1f03f05
several fixes
nicola-cab Jan 23, 2023
d87484f
better folder naming and fix path
nicola-cab Jan 23, 2023
7461d5a
delete prev folder
nicola-cab Jan 23, 2023
772d825
appease clang format checks
nicola-cab Jan 23, 2023
33b1fbe
test exe path
nicola-cab Jan 23, 2023
6c7ea4f
test launcher
nicola-cab Jan 23, 2023
990acf1
fix path
nicola-cab Jan 23, 2023
cc37f08
fix path in order to generate crash report
nicola-cab Jan 24, 2023
49b978d
test path
nicola-cab Jan 24, 2023
937a36b
remove archive file after upload
nicola-cab Jan 24, 2023
54b3943
test cpack find
nicola-cab Jan 24, 2023
52f1369
remove cpack machinery and test
nicola-cab Jan 24, 2023
d0115c4
test
nicola-cab Jan 24, 2023
34a75a4
revert cnf to prev working
nicola-cab Jan 24, 2023
6d2fae3
debug
nicola-cab Jan 24, 2023
af0ed29
fix crash file detection
nicola-cab Jan 24, 2023
165ba21
run the fuzzer daily
nicola-cab Jan 24, 2023
bdf8e91
remove fake exception + remove support for async tr
nicola-cab Jan 24, 2023
e6223aa
Update test/realm-fuzzer/afl_runner.cpp
nicola-cab Jan 26, 2023
847c8c1
Merge branch 'master' of github.com:realm/realm-core into nc/fuzzer
nicola-cab Jan 26, 2023
e67002e
code review
nicola-cab Jan 26, 2023
a7f9cad
better build folder names
nicola-cab Jan 26, 2023
14bedb6
code review
nicola-cab Jan 26, 2023
a43147a
fix changelog
nicola-cab Jan 26, 2023
5d071e1
pull master and fix conflicts
nicola-cab Jan 27, 2023
d702196
Merge branch 'master' of github.com:realm/realm-core into nc/fuzzer
nicola-cab Jan 27, 2023
27d7d1e
update scripts
nicola-cab Jan 27, 2023
2f05d63
merge master and fix conflicts
nicola-cab Jan 30, 2023
1406fe1
update entry in the changelog
nicola-cab Jan 30, 2023
714677b
Fix compile warnings
jedelbo Jan 31, 2023
d1d292a
fix conflicts with master
nicola-cab Jan 31, 2023
f37edc1
delete .gitignore
nicola-cab Jan 31, 2023
0f86d13
code review
nicola-cab Jan 31, 2023
89f1fa7
test compilation
nicola-cab Feb 1, 2023
86adb58
test
nicola-cab Feb 1, 2023
ce14bb4
restore configuration
nicola-cab Feb 1, 2023
117ea1c
fix configuration file
nicola-cab Feb 2, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* Remove `File::is_removed` ([#6222](https://github.com/realm/realm-core/pull/6222))
* Client reset recovery froze Realms for the callbacks in an invalid way. It is unclear if this resulted in any actual problems.
* Fix default enabled debug output during realm-sync-tests ([#6233](https://github.com/realm/realm-core/issues/6233))
* Create the fuzzer framework project in order to run fuzz testing on evergreen ([PR #5940](https://github.com/realm/realm-core/pull/5940))
* Update ClientImpl::Connection and DefaultWebSocketImpl to use the new WebSocketObserver callbacks ([PR #6219](https://github.com/realm/realm-core/pull/6219))
* Switched client reset tests to using private `force_client_reset` server API ([PR #6216](https://github.com/realm/realm-core/pull/6216))

Expand Down
80 changes: 79 additions & 1 deletion evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ functions:
script: |-
set -o errexit
git submodule update --init --recursive

"compile":
- command: shell.exec
params:
Expand Down Expand Up @@ -81,6 +81,10 @@ functions:
set_cmake_var realm_vars REALM_ENABLE_ALLOC_SET_ZERO BOOL On
fi

if [ -n "${enable_fuzzer|}" ]; then
set_cmake_var realm_vars REALM_LIBFUZZER BOOL On
fi

if [ -z "${disable_sync|}" ]; then
set_cmake_var realm_vars REALM_ENABLE_SYNC BOOL On
fi
Expand Down Expand Up @@ -224,6 +228,35 @@ functions:
content_type: text/text
display_name: install baas output
optional: true

"upload fuzzer results":
- command: shell.exec
params:
working_dir: realm-core/build/test/realm-fuzzer
script: |-
if ls crash-*> /dev/null 2>&1; then
nicola-cab marked this conversation as resolved.
Show resolved Hide resolved
echo "Found crash file"
mv crash-* realm-fuzzer-crash.txt
fi

- command: s3.put
params:
working_dir: realm-core/build/test/realm-fuzzer
aws_key: '${artifacts_aws_access_key}'
aws_secret: '${artifacts_aws_secret_key}'
local_file: 'realm-core/build/test/realm-fuzzer/realm-fuzzer-crash.txt'
remote_file: '${project}/${branch_name}/${task_id}/${execution}/realm-fuzzer-crash.txt'
bucket: mciuploads
permissions: public-read
content_type: text/text
display_name: Fuzzer crash report
optional: true

- command: shell.exec
params:
working_dir: realm-core/build/test/realm-fuzzer
script: |-
rm realm-fuzzer-crash.txt

"run hang analyzer":
- command: shell.exec
Expand Down Expand Up @@ -659,6 +692,17 @@ tasks:
echo $out
exit 1

- name: fuzzer
tags: [ "test_suite"]
commands:
- command: shell.exec
timeout_secs: 3600
nicola-cab marked this conversation as resolved.
Show resolved Hide resolved
params:
working_dir: realm-core/build/test/realm-fuzzer
shell: /bin/bash
script: |-
${cmake_build_type|Debug}/realm-libfuzz

task_groups:
- name: compile_test_and_package
max_hosts: 1
Expand Down Expand Up @@ -730,6 +774,19 @@ task_groups:
tasks:
- long-running-core-tests

- name: fuzzer-tests
setup_group_can_fail_task: true
setup_group:
- func: "fetch source"
- func: "fetch binaries"
- func: "compile"
vars:
target_to_build: realm-libfuzz
teardown_task:
- func: "upload fuzzer results"
tasks:
- fuzzer

buildvariants:
- name: ubuntu2004
display_name: "Ubuntu 20.04 x86_64 (Clang 11)"
Expand Down Expand Up @@ -862,6 +919,27 @@ buildvariants:
distros:
- ubuntu2004-large

- name: ubuntu2004-fuzzer
display_name: "Ubuntu 20.04 x86_64 (Clang 11 Fuzzer)"
run_on: ubuntu2004-small
expansions:
clang_url: "https://s3.amazonaws.com/static.realm.io/evergreen-assets/clang%2Bllvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz"
cmake_url: "https://s3.amazonaws.com/static.realm.io/evergreen-assets/cmake-3.20.3-linux-x86_64.tar.gz"
cmake_bindir: "./cmake_binaries/bin"
fetch_missing_dependencies: On
run_tests_against_baas: On
enable_ubsan: On
c_compiler: "./clang_binaries/bin/clang"
cxx_compiler: "./clang_binaries/bin/clang++"
cmake_build_type: RelWithDebInfo
run_with_encryption: On
enable_fuzzer: On
tasks:
- name: fuzzer-tests
cron: "@daily"
patchable: false


- name: rhel70
display_name: "RHEL 7 x86_64"
run_on: rhel70-small
Expand Down
3 changes: 2 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ add_subdirectory(util)
add_custom_target(benchmarks)
add_subdirectory(object-store)

# AFL not yet supported by Windows
# AFL and LIBFUZZER not yet supported by Windows
if(NOT CMAKE_SYSTEM_NAME MATCHES "^Windows")
add_subdirectory(fuzzy)
add_subdirectory(realm-fuzzer)
endif()

add_subdirectory(benchmark-common-tasks)
Expand Down
6 changes: 0 additions & 6 deletions test/fuzzy/libfuzzer_entry.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#include <realm/db.hpp>
#include <realm/history.hpp>

#include <ctime>
#include <cstdio>
#include <fstream>
#include <iostream>

#include "../fuzz_group.hpp"
#include "../util/test_path.hpp"

Expand Down
41 changes: 14 additions & 27 deletions test/object-store/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,36 +126,23 @@ target_include_directories(ObjectStoreTests PRIVATE
# on Apple platforms we use the built-in CFRunLoop
# everywhere else it's libuv, except UWP where it doesn't build
if(NOT APPLE AND NOT WINDOWS_STORE)
option(REALM_FETCH_MISSING_DEPENDENCIES "Download missing dependencies with CMake's FetchContent where possible" ON)
if(REALM_FETCH_MISSING_DEPENDENCIES)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason behind removing this option?

Copy link
Member Author

@nicola-cab nicola-cab Jan 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We changed the CMake file, dependencies are always fetched if needed. Check the rest of the cmake file. I haven't removed the option. I needed to have libUV exported 'above' object store in order to link it in the fuzzer. The reason why I need this is because right now the fuzzer lives outside the object store folder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not sure why we would need to change this file. I can build without the change and I would prefer not to be forced to download and build libuv.

find_package(LibUV)
else()
find_package(LibUV REQUIRED)
include(FetchContent)
set(libUV_Git_TAG "v1.35.0")
if(MSVC)
set(liUV_Git_TAG "v1.43.0")
endif()
if(LibUV_FOUND)
set(libuv_target LibUV::LibUV)
elseif(REALM_FETCH_MISSING_DEPENDENCIES)
message(STATUS "LibUV not found, building from source with FetchContent")
include(FetchContent)
set(libUV_Git_TAG "v1.35.0")
if(MSVC)
set(liUV_Git_TAG "v1.43.0")
endif()
FetchContent_Declare(
libuv
GIT_REPOSITORY https://github.com/libuv/libuv.git
GIT_TAG ${libUV_Git_TAG}
)
# Don't use FetchContent_MakeAvailable since it wants to build libuv.so as well
FetchContent_Populate(libuv)
add_subdirectory(${libuv_SOURCE_DIR} ${libuv_BINARY_DIR} EXCLUDE_FROM_ALL)
set(libuv_target uv_a)
endif()
target_link_libraries(ObjectStoreTests ${libuv_target})
FetchContent_Declare(
libuv
GIT_REPOSITORY https://github.com/libuv/libuv.git
GIT_TAG ${libUV_Git_TAG}
)
# Don't use FetchContent_MakeAvailable since it wants to build libuv.so as well
FetchContent_Populate(libuv)
add_subdirectory(${libuv_SOURCE_DIR} ${libuv_BINARY_DIR} EXCLUDE_FROM_ALL)
target_link_libraries(ObjectStoreTests uv_a)
# FIXME: ObjectStore itself shouldn't care about this, but we need to refactor scheduler.cpp to make it happen
target_compile_definitions(ObjectStore PUBLIC REALM_HAVE_UV=1)
get_property(libuv_include_dir TARGET ${libuv_target} PROPERTY INCLUDE_DIRECTORIES)
target_include_directories(ObjectStore PRIVATE ${libuv_include_dir})
target_include_directories(ObjectStore PRIVATE $<TARGET_PROPERTY:uv_a,INCLUDE_DIRECTORIES>)
endif()

add_subdirectory(notifications-fuzzer)
Expand Down
5 changes: 5 additions & 0 deletions test/realm-fuzzer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
findings/*
nicola-cab marked this conversation as resolved.
Show resolved Hide resolved
fuzzy-tests*
generate-fuzzy-input*
*.d
*.o
45 changes: 45 additions & 0 deletions test/realm-fuzzer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
set(TEST_AFL_SOURCES
afl_runner.cpp
fuzz_engine.cpp
fuzz_object.cpp
fuzz_configurator.cpp
) # TEST_AFL_SOURCES_OBJECT_STORE

set(TEST_LIBFUZZER_SOURCES
libfuzzer_runner.cpp
fuzz_engine.cpp
fuzz_object.cpp
fuzz_configurator.cpp
) # TEST_LIBFUZZER_SOURCES_OBJECT_STORE

file(GLOB FUZZER_RUN_SCRIPTS
"scripts/start_fuzz_afl.sh"
"scripts/start_lib_fuzzer.sh")

file(COPY ${FUZZER_RUN_SCRIPTS}
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(GLOB AFL_SEEDS "testcases/*")
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/testcases)
file(COPY ${AFL_SEEDS}
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/testcases)

add_executable(realm-afl++ ${TEST_AFL_SOURCES})
target_link_libraries(realm-afl++ TestUtil ObjectStore)

if(REALM_LIBFUZZER)
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
add_executable(realm-libfuzz ${TEST_LIBFUZZER_SOURCES})
target_link_libraries(realm-libfuzz TestUtil ObjectStore)
endif()
endif()

# on Apple platforms we use the built-in CFRunLoop
# everywhere else it's libuv, except UWP where it doesn't build
if(NOT APPLE AND NOT WINDOWS_STORE)
target_link_libraries(realm-afl++ uv_a)
if(REALM_LIBFUZZER)
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
target_link_libraries(realm-libfuzz uv_a)
endif()
endif()
endif()
72 changes: 72 additions & 0 deletions test/realm-fuzzer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# The Fuzz Framework project

This project is an attempt to put together all the small fuzzers we have already scattered around the code.
There are two goals:
1. To be able to run all the fuzzers, collect crashes reports and fix possible bugs that the fuzzer might find.
2. To be able to replace libfuzzer with google fuzz test (https://github.com/google/fuzztest) at some point.

AFL++ support is not dropped yet, but since we want to integrate things inside evergreen and follow the same approach we implement for address/thread sanitazer we prefer to use libfuzzer and clang.
## Prerequisites

In case you want to use AFL++, then you should install the latest version of the American Fuzzy Lop ++ (AFL++).
Please use this quick guide: https://aflplus.plus/building/ it requires llvm >= 9.0.

For using libfuzzer, the only pre-requisite is having a recent version of clang.
## Running
If you don't want to build manually, you can skip this section and jump to the `Scripts` section. \
Run the fuzzer via AFL++:

```
cd <realm-core-src>
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=${build_mode}
-D CMAKE_C_COMPILER=afl-cc
-D CMAKE_CXX_COMPILER=afl-c++
-D REALM_ENABLE_ENCRYPTION=ON
nicola-cab marked this conversation as resolved.
Show resolved Hide resolved
-G Ninja
..
cmake --build . --target realm-afl++
afl-fuzz -t "$time_out"
-m "$memory"
-i "${ROOT_DIR}/test/fuzzy_object_store/testcases"
-o "${FINDINGS_DIR}"
realm-afl++ @@
```

Run the fuzzer via libFuzzer (only with Clang)
```
cd <realm-core-src>
mkdir build
cd build
cmake -D REALM_LIBFUZZER=ON
-D CMAKE_BUILD_TYPE=${build_mode}
-D CMAKE_C_COMPILER=clang
-D CMAKE_CXX_COMPILER=clang++
-D REALM_ENABLE_ENCRYPTION=ON
-G Ninja
..
cmake --build . --target realm-libfuzz
./realm_libfuzz <corpus>
```

## Scripts

`sh start_fuzz_afl.sh`
Builds `realm-core` and `object-store` in `Debug` mode using the afl++ compiler `afl-cc` and starts 1 instance of `afl-fuzz`.
It expects `AFLPlusPlus` to be installed in your system and in general added to your `PATH`.
Optionally, the following arguments can be passed to the script:
1) `<num_fuzzers>` the number of fuzzers to launch (by default 1).
2) `<build_mode>` either `Release` or `Debug`.

`sh start_lib_fuzzer.sh`
Builds `realm-core` and `object-store` in `Debug` mode using the clang compiler and starts `realm-libfuzz`.
Optionally, the following arguments can be passed to the script:
1) `<build_mode>` either `Release` or `Debug`.
2) `<corpus>` essentially initial set of inputs for improving fuzzer efficiency.

## See Also

[AFL++ github](https://github.com/AFLplusplus/AFLplusplus) \
[LibFuzzer](https://github.com/google/fuzzing/blob/master/tutorial/libFuzzerTutorial.md) \
[Google Fuzz Test](https://github.com/google/fuzztest)
36 changes: 36 additions & 0 deletions test/realm-fuzzer/afl_runner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*************************************************************************
*
* Copyright 2022 Realm Inc.
*
* 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.
*
**************************************************************************/

#include "fuzz_engine.hpp"

int main(int argc, const char* argv[])
{
FuzzEngine fuzz_engine;
bool enable_logging = false;
std::string path = "realm-afl.txt";
size_t input_index = 0;
for (size_t i = 0; i < (size_t)argc; ++i) {
if (strcmp(argv[i], "--log") == 0) {
enable_logging = true;
}
else {
input_index = i;
}
}
return fuzz_engine.run_fuzzer(argv[input_index], "realm_afl", enable_logging, path);
}
Loading