Skip to content

Commit

Permalink
Decorate and identify SNP libraries (microsoft#4569)
Browse files Browse the repository at this point in the history
(cherry picked from commit d88c76a)

# Conflicts:
#	.daily_canary
#	.snpcc_canary
#	tests/infra/remote.py
  • Loading branch information
jumaffre committed Nov 18, 2022
1 parent 7eccd1c commit 6ebcedc
Show file tree
Hide file tree
Showing 39 changed files with 372 additions and 143 deletions.
1 change: 1 addition & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"INCLUDE_DIRS": "*",
"LINK_LIBS_ENCLAVE": "*",
"LINK_LIBS_VIRTUAL": "*",
"LINK_LIBS_SNP": "*",
},
},
"add_client_exe": {
Expand Down
4 changes: 2 additions & 2 deletions .daily_canary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
___ ___
(- *) (O o) | Y
( V ) ( V ) O /
/--x-m- /--m-m---xXx--/----
( V ) < V ) O /
/--x-m- /--m-m---xXx--/
2 changes: 1 addition & 1 deletion .snpcc_canary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

| Y
O /
/-xXx--/----
/-xXx--/-----)
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Upgraded OpenEnclave to 0.18.4.

### Changed

- `enclave.type` configuration entry now only supports `Debug` or `Release`. Trusted Execution Environment platform should be specified via new `enclave.platform` configuration entry (`SGX`, `SNP` or `Virtual`) (#4569).

### Fixed

- Fix issue with large snapshots that may cause node crash on startup (join/recover) if configured stack size was too low (#4566).
Expand Down
54 changes: 28 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,16 @@ if(COMPILE_TARGET STREQUAL "sgx")
)

target_link_libraries(
ccf.enclave PUBLIC quickjs.enclave http_parser.enclave sss.enclave
ccf_endpoints.enclave ccfcrypto.enclave ccf_kv.enclave
ccf.enclave
PUBLIC quickjs.enclave
http_parser.enclave
sss.enclave
ccf_endpoints.enclave
ccfcrypto.enclave
ccf_kv.enclave
nghttp2.enclave
)

target_link_libraries(ccf.enclave PUBLIC nghttp2.enclave)

add_lvi_mitigations(ccf.enclave)

install(
Expand All @@ -141,19 +145,19 @@ if(COMPILE_TARGET STREQUAL "sgx")
# Same as virtual for the time being but will diverge soon
elseif(COMPILE_TARGET STREQUAL "snp")

# virtual version
add_library(ccf.virtual STATIC ${CCF_IMPL_SOURCE})
# SNP version
add_library(ccf.snp STATIC ${CCF_IMPL_SOURCE})

target_compile_definitions(
ccf.virtual PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE
_LIBCPP_HAS_THREAD_API_PTHREAD PLATFORM_SNP
ccf.snp PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE
_LIBCPP_HAS_THREAD_API_PTHREAD PLATFORM_SNP
)

target_compile_options(ccf.virtual PUBLIC ${COMPILE_LIBCXX})
add_warning_checks(ccf.virtual)
target_compile_options(ccf.snp PUBLIC ${COMPILE_LIBCXX})
add_warning_checks(ccf.snp)

target_include_directories(
ccf.virtual SYSTEM
ccf.snp SYSTEM
PUBLIC
$<BUILD_INTERFACE:${CCF_GENERATED_DIR}>
$<INSTALL_INTERFACE:include/ccf/> #< This contains the private headers
Expand All @@ -164,32 +168,31 @@ elseif(COMPILE_TARGET STREQUAL "snp")
)

target_link_libraries(
ccf.virtual
ccf.snp
PUBLIC ${LINK_LIBCXX}
-lgcc
http_parser.host
quickjs.host
sss.host
ccf_endpoints.host
ccfcrypto.host
ccf_kv.host
http_parser.snp
quickjs.snp
sss.snp
ccf_endpoints.snp
ccfcrypto.snp
ccf_kv.snp
nghttp2.snp
${OE_HOST_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
)

target_link_libraries(ccf.virtual PUBLIC nghttp2.host)

set_property(TARGET ccf.virtual PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET ccf.snp PROPERTY POSITION_INDEPENDENT_CODE ON)

add_san(ccf.virtual)
add_san(ccf.snp)

install(
TARGETS ccf.virtual
TARGETS ccf.snp
EXPORT ccf
DESTINATION lib
)

add_dependencies(ccf ccf.virtual)
add_dependencies(ccf ccf.snp)

elseif(COMPILE_TARGET STREQUAL "virtual")

Expand Down Expand Up @@ -225,12 +228,11 @@ elseif(COMPILE_TARGET STREQUAL "virtual")
ccf_endpoints.host
ccfcrypto.host
ccf_kv.host
nghttp2.host
${OE_HOST_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
)

target_link_libraries(ccf.virtual PUBLIC nghttp2.host)

set_property(TARGET ccf.virtual PROPERTY POSITION_INDEPENDENT_CODE ON)

add_san(ccf.virtual)
Expand Down
36 changes: 20 additions & 16 deletions cmake/ccf_app.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ endfunction()
function(add_ccf_app name)

cmake_parse_arguments(
PARSE_ARGV 1 PARSED_ARGS "" ""
"SRCS;INCLUDE_DIRS;LINK_LIBS_ENCLAVE;LINK_LIBS_VIRTUAL;DEPS;INSTALL_LIBS"
PARSE_ARGV
1
PARSED_ARGS
""
""
"SRCS;INCLUDE_DIRS;LINK_LIBS_ENCLAVE;LINK_LIBS_VIRTUAL;LINK_LIBS_SNP;DEPS;INSTALL_LIBS"
)
add_custom_target(${name} ALL)

Expand Down Expand Up @@ -126,42 +130,42 @@ function(add_ccf_app name)
endif()

elseif(COMPILE_TARGET STREQUAL "snp")
# Build a virtual enclave, loaded as a shared library without OE
set(virt_name ${name}.virtual)
# Build an SNP enclave, loaded as a shared library without OE
set(snp_name ${name}.snp)

add_library(${virt_name} SHARED ${PARSED_ARGS_SRCS})
add_library(${snp_name} SHARED ${PARSED_ARGS_SRCS})

target_compile_definitions(${virt_name} PUBLIC PLATFORM_SNP)
target_compile_definitions(${snp_name} PUBLIC PLATFORM_SNP)

target_include_directories(
${virt_name} SYSTEM PRIVATE ${PARSED_ARGS_INCLUDE_DIRS}
${snp_name} SYSTEM PRIVATE ${PARSED_ARGS_INCLUDE_DIRS}
)
add_warning_checks(${virt_name})
add_warning_checks(${snp_name})

target_link_libraries(
${virt_name} PRIVATE ${PARSED_ARGS_LINK_LIBS_VIRTUAL} ccf.virtual
${snp_name} PRIVATE ${PARSED_ARGS_LINK_LIBS_SNP} ccf.snp
)

if(NOT SAN)
target_link_options(${virt_name} PRIVATE LINKER:--no-undefined)
target_link_options(${snp_name} PRIVATE LINKER:--no-undefined)
endif()

target_link_options(
${virt_name} PRIVATE
${snp_name} PRIVATE
LINKER:--undefined=enclave_create_node,--undefined=enclave_run
)

set_property(TARGET ${virt_name} PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET ${snp_name} PROPERTY POSITION_INDEPENDENT_CODE ON)

add_san(${virt_name})
add_san(${snp_name})

add_dependencies(${name} ${virt_name})
add_dependencies(${name} ${snp_name})
if(PARSED_ARGS_DEPS)
add_dependencies(${virt_name} ${PARSED_ARGS_DEPS})
add_dependencies(${snp_name} ${PARSED_ARGS_DEPS})
endif()

if(${PARSED_ARGS_INSTALL_LIBS})
install(TARGETS ${virt_name} DESTINATION lib)
install(TARGETS ${snp_name} DESTINATION lib)
endif()

elseif(COMPILE_TARGET STREQUAL "virtual")
Expand Down
91 changes: 66 additions & 25 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ if(COMPILE_TARGET STREQUAL "sgx")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEFAULT_ENCLAVE_TYPE debug)
endif()
elseif(COMPILE_TARGET STREQUAL "snp")
set(INSTALL_VIRTUAL_LIBRARIES OFF)
else()
set(INSTALL_VIRTUAL_LIBRARIES ON)
set(DEFAULT_ENCLAVE_TYPE virtual)
endif()

set(HTTP_PARSER_SOURCES
Expand Down Expand Up @@ -314,6 +315,14 @@ if(COMPILE_TARGET STREQUAL "sgx")
EXPORT ccf
DESTINATION lib
)
elseif(COMPILE_TARGET STREQUAL "snp")
add_library(http_parser.snp "${HTTP_PARSER_SOURCES}")
set_property(TARGET http_parser.snp PROPERTY POSITION_INDEPENDENT_CODE ON)
install(
TARGETS http_parser.snp
EXPORT ccf
DESTINATION lib
)
endif()

add_library(http_parser.host "${HTTP_PARSER_SOURCES}")
Expand All @@ -339,7 +348,17 @@ if(COMPILE_TARGET STREQUAL "sgx")
EXPORT ccf
DESTINATION lib
)
elseif(COMPILE_TARGET STREQUAL "snp")
add_host_library(ccf_kv.snp "${CCF_KV_SOURCES}")
add_san(ccf_kv.snp)
add_warning_checks(ccf_kv.snp)
install(
TARGETS ccf_kv.snp
EXPORT ccf
DESTINATION lib
)
endif()

add_host_library(ccf_kv.host "${CCF_KV_SOURCES}")
add_san(ccf_kv.host)
add_warning_checks(ccf_kv.host)
Expand All @@ -362,6 +381,17 @@ if(COMPILE_TARGET STREQUAL "sgx")
EXPORT ccf
DESTINATION lib
)
elseif(COMPILE_TARGET STREQUAL "snp")
add_host_library(ccf_endpoints.snp "${CCF_ENDPOINTS_SOURCES}")
target_link_libraries(ccf_endpoints.snp PUBLIC qcbor.snp)
target_link_libraries(ccf_endpoints.snp PUBLIC t_cose.snp)
add_san(ccf_endpoints.snp)
add_warning_checks(ccf_endpoints.snp)
install(
TARGETS ccf_endpoints.snp
EXPORT ccf
DESTINATION lib
)
endif()

add_host_library(ccf_endpoints.host "${CCF_ENDPOINTS_SOURCES}")
Expand Down Expand Up @@ -408,19 +438,17 @@ if(COMPILE_TARGET STREQUAL "sgx")
DESTINATION lib
)
elseif(COMPILE_TARGET STREQUAL "snp")
add_library(js_openenclave.virtual STATIC ${CCF_DIR}/src/js/openenclave.cpp)
add_san(js_openenclave.virtual)
target_link_libraries(js_openenclave.virtual PUBLIC ccf.virtual)
target_compile_options(js_openenclave.virtual PRIVATE ${COMPILE_LIBCXX})
add_library(js_openenclave.snp STATIC ${CCF_DIR}/src/js/openenclave.cpp)
add_san(js_openenclave.snp)
target_link_libraries(js_openenclave.snp PUBLIC ccf.snp)
target_compile_options(js_openenclave.snp PRIVATE ${COMPILE_LIBCXX})
target_compile_definitions(
js_openenclave.virtual PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE
_LIBCPP_HAS_THREAD_API_PTHREAD PLATFORM_SNP
)
set_property(
TARGET js_openenclave.virtual PROPERTY POSITION_INDEPENDENT_CODE ON
js_openenclave.snp PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE
_LIBCPP_HAS_THREAD_API_PTHREAD PLATFORM_SNP
)
set_property(TARGET js_openenclave.snp PROPERTY POSITION_INDEPENDENT_CODE ON)
install(
TARGETS js_openenclave.virtual
TARGETS js_openenclave.snp
EXPORT ccf
DESTINATION lib
)
Expand Down Expand Up @@ -457,22 +485,20 @@ if(COMPILE_TARGET STREQUAL "sgx")
)
elseif(COMPILE_TARGET STREQUAL "snp")
add_library(
js_generic_base.virtual STATIC
js_generic_base.snp STATIC
${CCF_DIR}/src/apps/js_generic/js_generic_base.cpp
)
add_san(js_generic_base.virtual)
add_warning_checks(js_generic_base.virtual)
target_link_libraries(js_generic_base.virtual PUBLIC ccf.virtual)
target_compile_options(js_generic_base.virtual PRIVATE ${COMPILE_LIBCXX})
add_san(js_generic_base.snp)
add_warning_checks(js_generic_base.snp)
target_link_libraries(js_generic_base.snp PUBLIC ccf.snp)
target_compile_options(js_generic_base.snp PRIVATE ${COMPILE_LIBCXX})
target_compile_definitions(
js_generic_base.virtual PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE
_LIBCPP_HAS_THREAD_API_PTHREAD PLATFORM_SNP
)
set_property(
TARGET js_generic_base.virtual PROPERTY POSITION_INDEPENDENT_CODE ON
js_generic_base.snp PUBLIC INSIDE_ENCLAVE VIRTUAL_ENCLAVE
_LIBCPP_HAS_THREAD_API_PTHREAD PLATFORM_SNP
)
set_property(TARGET js_generic_base.snp PROPERTY POSITION_INDEPENDENT_CODE ON)
install(
TARGETS js_generic_base.virtual
TARGETS js_generic_base.snp
EXPORT ccf
DESTINATION lib
)
Expand Down Expand Up @@ -504,8 +530,8 @@ add_ccf_app(
js_generic
SRCS ${CCF_DIR}/src/apps/js_generic/js_generic.cpp
LINK_LIBS_ENCLAVE js_generic_base.enclave js_openenclave.enclave
LINK_LIBS_VIRTUAL js_generic_base.virtual js_openenclave.virtual INSTALL_LIBS
ON
LINK_LIBS_VIRTUAL js_generic_base.virtual js_openenclave.virtual
LINK_LIBS_SNP js_generic_base.snp js_openenclave.snp INSTALL_LIBS ON
)
sign_app_library(
js_generic.enclave ${CCF_DIR}/src/apps/js_generic/oe_sign.conf
Expand Down Expand Up @@ -639,6 +665,12 @@ function(add_e2e_test)
PROPERTY ENVIRONMENT "DEFAULT_ENCLAVE_TYPE=${DEFAULT_ENCLAVE_TYPE}"
)
endif()

set_property(
TEST ${PARSED_ARGS_NAME}
APPEND
PROPERTY ENVIRONMENT "DEFAULT_ENCLAVE_PLATFORM=${COMPILE_TARGET}"
)
endif()
endfunction()

Expand Down Expand Up @@ -666,6 +698,7 @@ function(add_perf_test)

set(TESTS_SUFFIX "")
set(ENCLAVE_TYPE "")
set(ENCLAVE_PLATFORM "${COMPILE_TARGET}")
if("sgx" STREQUAL COMPILE_TARGET)
set(TESTS_SUFFIX "${TESTS_SUFFIX}_sgx")
set(ENCLAVE_TYPE "release")
Expand All @@ -692,7 +725,7 @@ function(add_perf_test)
${CCF_NETWORK_TEST_ARGS} --consensus ${CONSENSUS}
${PARSED_ARGS_CONSTITUTION} --write-tx-times ${VERIFICATION_ARG} --label
${LABEL_ARG} --snapshot-tx-interval 10000 ${PARSED_ARGS_ADDITIONAL_ARGS}
-e ${ENCLAVE_TYPE} ${NODES}
-e ${ENCLAVE_TYPE} -t ${ENCLAVE_PLATFORM} ${NODES}
)

# Make python test client framework importable
Expand All @@ -708,6 +741,14 @@ function(add_perf_test)
PROPERTY ENVIRONMENT "DEFAULT_ENCLAVE_TYPE=${DEFAULT_ENCLAVE_TYPE}"
)
endif()
if(DEFINED DEFAULT_ENCLAVE_PLATFORM)
set_property(
TEST ${TEST_NAME}
APPEND
PROPERTY ENVIRONMENT
"DEFAULT_ENCLAVE_PLATFORM=${DEFAULT_ENCLAVE_PLATFORM}"
)
endif()
set_property(
TEST ${TEST_NAME}
APPEND
Expand Down
Loading

0 comments on commit 6ebcedc

Please sign in to comment.