Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*.png binary
*.jpg binary

src/crypto/test/cbor_fuzz_corpus/* binary

*.h linguist-language=C++
*.cpp linguist-language=C++

Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/long-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,18 @@ jobs:
cd build
./tests.sh --output-on-failure --timeout 1600 -LE "benchmark"

- name: "Run CBOR fuzz test"
run: |
set -o pipefail
set -ex
mkdir -p build_fuzz
cd build_fuzz
rm -f CMakeCache.txt
cmake -GNinja -DFUZZING=ON -DSAN=ON -DUSE_LIBCXX=ON -DUSE_SNMALLOC=OFF ..
ninja cbor_fuzz_test
mkdir -p /tmp/cbor_fuzz_live
./cbor_fuzz_test /tmp/cbor_fuzz_live ../src/crypto/test/cbor_fuzz_corpus -max_total_time=60
Comment thread
achamayou marked this conversation as resolved.

- name: "Upload logs"
if: success() || failure()
uses: actions/upload-artifact@v7
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,15 @@ if(BUILD_TESTS)
target_include_directories(cbor_test PRIVATE ${CCFCRYPTO_INC})
target_link_libraries(cbor_test PRIVATE ccfcrypto)

if(FUZZING)
add_fuzz_test(
cbor_fuzz_test
${CMAKE_CURRENT_SOURCE_DIR}/src/crypto/cbor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/crypto/test/cbor_fuzz.cpp
)
target_link_libraries(cbor_fuzz_test PRIVATE evercbor)
endif()

add_unit_test(
sharing_test
${CMAKE_CURRENT_SOURCE_DIR}/src/crypto/test/secret_sharing.cpp
Expand Down
17 changes: 17 additions & 0 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ function(add_unit_test name)
add_san_test_properties(${name})
endfunction()

# Fuzz test wrapper (requires -DFUZZING=ON -DUSE_LIBCXX=ON)
function(add_fuzz_test name)
if(NOT USE_LIBCXX)
message(
FATAL_ERROR
"Fuzz targets require USE_LIBCXX=ON to avoid UBSAN false positives from libstdc++ shared_ptr"
)
endif()

add_executable(${name} ${CCF_DIR}/src/enclave/thread_local.cpp ${ARGN})
target_compile_options(${name} PRIVATE ${COMPILE_LIBCXX} -fsanitize=fuzzer)
target_link_options(${name} PRIVATE -fsanitize=fuzzer)
target_include_directories(${name} PRIVATE src ${CCFCRYPTO_INC})
target_link_libraries(${name} PRIVATE ${LINK_LIBCXX} -pthread)
add_san(${name})
endfunction()

# Test binary wrapper
function(add_test_bin name)
add_executable(${name} ${CCF_DIR}/src/enclave/thread_local.cpp ${ARGN})
Expand Down
5 changes: 5 additions & 0 deletions cmake/preproject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
endif()

option(TSAN "Enable Thread Sanitizers" OFF)
option(FUZZING "Enable libFuzzer fuzz testing" OFF)

if(FUZZING AND TSAN)
message(FATAL_ERROR "FUZZING and TSAN cannot be enabled together")
endif()

Comment thread
maxtropets marked this conversation as resolved.
option(COLORED_OUTPUT "Always produce ANSI-colored output." ON)

Expand Down
35 changes: 35 additions & 0 deletions src/crypto/test/cbor_fuzz.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the Apache 2.0 License.

#include "crypto/cbor.h"

#include <cstddef>
#include <cstdint>
#include <span>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
ccf::cbor::Value value;
try
{
value = ccf::cbor::parse({data, size});
}
catch (const ccf::cbor::CBORDecodeError&)
{
return 0;
}

// If parse succeeded, exercise serialization round-trip and string
// rendering. Any failure here is a real bug — let the fuzzer surface it.
std::ignore = ccf::cbor::to_string(value);
auto serialized = ccf::cbor::serialize(value);
auto reparsed = ccf::cbor::parse(serialized);
Comment thread
maxtropets marked this conversation as resolved.
auto reserialized = ccf::cbor::serialize(reparsed);

if (serialized != reserialized)
{
__builtin_trap();
}

return 0;
}
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/array123
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/array_of_maps
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��ax�ay�az
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/array_with_map
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��aa
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/bstr_hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ehello
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/complex_array_map
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
���ecount*elabeleitemsfactive��
Binary file added src/crypto/test/cbor_fuzz_corpus/cose_receipt
Binary file not shown.
Binary file not shown.
Binary file added src/crypto/test/cbor_fuzz_corpus/cose_sign1_flat
Binary file not shown.
Binary file added src/crypto/test/cbor_fuzz_corpus/cose_sign1_nested
Binary file not shown.
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/deeply_nested_array
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
����
Empty file.
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/empty_array
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/empty_bytes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/empty_map
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/empty_string
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/header_map_footer
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�fheader�bid{dnamedtestffooter
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/int64_max
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�������
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/int64_min
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
;�������
Binary file added src/crypto/test/cbor_fuzz_corpus/int64_overflow
Binary file not shown.
Binary file added src/crypto/test/cbor_fuzz_corpus/int_widths
Binary file not shown.
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/map1234
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/map_bool_vals
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�genabled�hdisabled�gunknown�
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/map_multi_arrays
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�aa�ab�ac�
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/map_neg_keys
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
� iminus one)iminus ten
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/map_str_str
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�axaycfoocbar
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/map_with_array
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�eitems�
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/mixed_array
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�ctwoA3��
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/negint1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/nested_arrays
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
����
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/nested_tags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�#2�#<fnested
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/simple_false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/simple_null
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/simple_true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/simple_undefined
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/tagged_array
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�#��
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/tagged_bool
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�#,�
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/tagged_bytes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�#+B��
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/tagged_empty_array
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�$T�
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/tagged_int
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�#)8)
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/tagged_map
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�'�aaab
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/tagged_string
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�#*mtagged string
Comment thread
maxtropets marked this conversation as resolved.
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/tstr_hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ehello
1 change: 1 addition & 0 deletions src/crypto/test/cbor_fuzz_corpus/uint42
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*