Skip to content

Commit 0b26c35

Browse files
committed
Some OE/SGX cleanup, prompted by things noticed in the 5.x branch
1 parent 44904a3 commit 0b26c35

File tree

11 files changed

+8
-278
lines changed

11 files changed

+8
-278
lines changed

CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,10 @@ if(KV_STATE_RB)
107107
endif()
108108

109109
# This option controls whether to link virtual builds against snmalloc rather
110-
# than use the system allocator. In builds using Open Enclave, enclave
111-
# allocation is managed separately and enabling snmalloc is done by linking
112-
# openenclave::oesnmalloc
113-
option(USE_SNMALLOC "Link virtual build against snmalloc" ON)
110+
# than use the system allocator.
111+
option(USE_SNMALLOC "Link against snmalloc" ON)
114112

115-
# Default inherited from Open Enclave usage
113+
# Useful for debugging with libc++ hardening options
116114
option(USE_LIBCXX "Use libc++ instead of libstdc++" OFF)
117115

118116
enable_language(ASM)

include/ccf/ds/ccf_exception.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,6 @@ namespace ccf
3232
std::string result;
3333
};
3434

35-
class ccf_oe_attester_init_error : public ccf_logic_error
36-
{
37-
public:
38-
ccf_oe_attester_init_error(const std::string& what_arg) :
39-
ccf_logic_error(what_arg)
40-
{}
41-
};
42-
43-
class ccf_oe_verifier_init_error : public ccf_logic_error
44-
{
45-
public:
46-
ccf_oe_verifier_init_error(const std::string& what_arg) :
47-
ccf_logic_error(what_arg)
48-
{}
49-
};
50-
5135
class ccf_openssl_rdrand_init_error : public ccf_logic_error
5236
{
5337
public:

include/ccf/pal/attestation.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ namespace ccf::pal
3838
j["report_data"].get<std::vector<uint8_t>>());
3939
}
4040

41-
// Verifying SNP attestation report is available on all platforms as unlike
42-
// SGX, this does not require external dependencies (Open Enclave for SGX).
41+
// Verifying SNP attestation report is available on all platforms
4342
static void verify_snp_attestation_report(
4443
const QuoteInfo& quote_info,
4544
PlatformAttestationMeasurement& measurement,

include/ccf/pal/enclave.h

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/common/enclave_interface_types.h

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,17 @@ enum CreateNodeStatus
2727
/** Enclave initialisation failed */
2828
EnclaveInitFailed = 6,
2929

30-
/** Open Enclave Verifier initialisation failed */
31-
OEVerifierInitFailed = 7,
32-
33-
/** Open Enclave Attester initialisation failed */
34-
OEAttesterInitFailed = 8,
35-
3630
/** OpenSSL RDRAND Init Failed */
37-
OpenSSLRDRANDInitFailed = 9,
31+
OpenSSLRDRANDInitFailed = 7,
3832

3933
/** The reconfiguration method is not supported */
40-
ReconfigurationMethodNotSupported = 10,
34+
ReconfigurationMethodNotSupported = 8,
4135

4236
/** Host and enclave versions must match */
43-
VersionMismatch = 11,
37+
VersionMismatch = 9,
4438

4539
/** When reading from host memory, the source must be 8-byte aligned **/
46-
UnalignedArguments = 12,
40+
UnalignedArguments = 10,
4741
};
4842

4943
constexpr char const* create_node_result_to_str(CreateNodeStatus result)
@@ -78,14 +72,6 @@ constexpr char const* create_node_result_to_str(CreateNodeStatus result)
7872
{
7973
return "EnclaveInitFailed";
8074
}
81-
case CreateNodeStatus::OEVerifierInitFailed:
82-
{
83-
return "OEVerifierInitFailed";
84-
}
85-
case CreateNodeStatus::OEAttesterInitFailed:
86-
{
87-
return "OEAttesterInitFailed";
88-
}
8975
case CreateNodeStatus::OpenSSLRDRANDInitFailed:
9076
{
9177
return "OpenSSLRDRANDInitFailed";

src/enclave/enclave.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "ccf/js/core/context.h"
77
#include "ccf/node_context.h"
88
#include "ccf/node_subsystem_interface.h"
9-
#include "ccf/pal/enclave.h"
109
#include "ccf/pal/mem.h"
1110
#include "crypto/openssl/hash.h"
1211
#include "ds/oversized.h"
@@ -35,7 +34,6 @@
3534
#include "ringbuffer_logger.h"
3635
#include "rpc_map.h"
3736
#include "rpc_sessions.h"
38-
#include "verify.h"
3937

4038
#include <openssl/engine.h>
4139

@@ -101,14 +99,8 @@ namespace ccf
10199
rpc_map(std::make_shared<RPCMap>()),
102100
rpcsessions(std::make_shared<RPCSessions>(*writer_factory, rpc_map))
103101
{
104-
ccf::pal::initialize_enclave();
105-
ccf::initialize_verifiers();
106102
ccf::crypto::openssl_sha256_init();
107103

108-
// https://github.com/microsoft/CCF/issues/5569
109-
// Open Enclave with OpenSSL 3.x (default for SGX) is built with RDCPU
110-
// (https://github.com/openenclave/openenclave/blob/master/docs/OpenSSLSupport.md#how-to-use-rand-apis)
111-
// and so does not need to make use of the (deprecated) ENGINE_x API.
112104
#if !(defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3)
113105
// From
114106
// https://software.intel.com/content/www/us/en/develop/articles/how-to-use-the-rdrand-engine-in-openssl-for-random-number-generation.html
@@ -217,8 +209,6 @@ namespace ccf
217209
}
218210
#endif
219211
LOG_TRACE_FMT("Shutting down enclave");
220-
ccf::shutdown_verifiers();
221-
ccf::pal::shutdown_enclave();
222212
ccf::crypto::openssl_sha256_shutdown();
223213
}
224214

src/enclave/main.cpp

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "ccf/ds/ccf_exception.h"
44
#include "ccf/ds/json.h"
55
#include "ccf/ds/logger.h"
6-
#include "ccf/pal/enclave.h"
76
#include "ccf/pal/locking.h"
87
#include "ccf/version.h"
98
#include "common/enclave_interface_types.h"
@@ -30,25 +29,6 @@ std::chrono::microseconds ccf::Channel::min_gap_between_initiation_attempts(
3029

3130
extern "C"
3231
{
33-
// Confirming in-enclave behaviour in separate unit tests is tricky, so we
34-
// do final sanity checks on some basic behaviour here, on every enclave
35-
// launch.
36-
void enclave_sanity_checks()
37-
{
38-
{
39-
ccf::pal::Mutex m;
40-
m.lock();
41-
if (m.try_lock())
42-
{
43-
LOG_FATAL_FMT("Able to lock mutex multiple times");
44-
abort();
45-
}
46-
m.unlock();
47-
}
48-
49-
LOG_DEBUG_FMT("All sanity check tests passed");
50-
}
51-
5232
CreateNodeStatus enclave_create_node(
5333
void* enclave_config,
5434
uint8_t* ccf_config,
@@ -77,12 +57,6 @@ extern "C"
7757
return CreateNodeStatus::NodeAlreadyCreated;
7858
}
7959

80-
if (!ccf::pal::is_outside_enclave(enclave_config, sizeof(EnclaveConfig)))
81-
{
82-
LOG_FAIL_FMT("Memory outside enclave: enclave_config");
83-
return CreateNodeStatus::MemoryNotOutsideEnclave;
84-
}
85-
8660
EnclaveConfig ec = *static_cast<EnclaveConfig*>(enclave_config);
8761

8862
// Setup logger to allow enclave logs to reach the host before node is
@@ -101,30 +75,12 @@ extern "C"
10175
auto writer_factory = std::make_unique<oversized::WriterFactory>(
10276
*basic_writer_factory, ec.writer_config);
10377

104-
// Check that ringbuffer memory ranges are entirely outside of the enclave
105-
if (
106-
!ccf::pal::is_outside_enclave(
107-
ec.from_enclave_buffer_start, ec.from_enclave_buffer_size) ||
108-
!ccf::pal::is_outside_enclave(
109-
ec.to_enclave_buffer_start, ec.to_enclave_buffer_size) ||
110-
!ccf::pal::is_outside_enclave(
111-
ec.to_enclave_buffer_offsets, sizeof(ringbuffer::Offsets)) ||
112-
!ccf::pal::is_outside_enclave(
113-
ec.from_enclave_buffer_offsets, sizeof(ringbuffer::Offsets)))
114-
{
115-
return CreateNodeStatus::MemoryNotOutsideEnclave;
116-
}
117-
11878
// Note: because logger uses ringbuffer, logger can only be initialised once
11979
// ringbuffer memory has been verified
12080
auto new_logger = std::make_unique<ccf::RingbufferLogger>(*writer_factory);
12181
auto ringbuffer_logger = new_logger.get();
12282
ccf::logger::config::loggers().push_back(std::move(new_logger));
12383

124-
ccf::pal::redirect_platform_logging();
125-
126-
enclave_sanity_checks();
127-
12884
{
12985
auto ccf_version_string = std::string(ccf::ccf_version);
13086
if (ccf_version_string.size() > enclave_version_size)
@@ -152,33 +108,10 @@ extern "C"
152108
// threads are known
153109
threading::ThreadMessaging::init(num_pending_threads);
154110

155-
// Check that where we expect arguments to be in host-memory, they
156-
// really are. lfence after these checks to prevent speculative
157-
// execution
158-
if (!ccf::pal::is_outside_enclave(
159-
time_location, sizeof(*ccf::enclavetime::host_time_us)))
160-
{
161-
LOG_FAIL_FMT("Memory outside enclave: time_location");
162-
return CreateNodeStatus::MemoryNotOutsideEnclave;
163-
}
164-
165111
ccf::enclavetime::host_time_us =
166112
static_cast<decltype(ccf::enclavetime::host_time_us)>(time_location);
167113
}
168114

169-
if (!ccf::pal::is_outside_enclave(ccf_config, ccf_config_size))
170-
{
171-
LOG_FAIL_FMT("Memory outside enclave: ccf_config");
172-
return CreateNodeStatus::MemoryNotOutsideEnclave;
173-
}
174-
175-
if (!ccf::pal::is_outside_enclave(
176-
startup_snapshot_data, startup_snapshot_size))
177-
{
178-
LOG_FAIL_FMT("Memory outside enclave: startup snapshot");
179-
return CreateNodeStatus::MemoryNotOutsideEnclave;
180-
}
181-
182115
ccf::StartupConfig cc =
183116
nlohmann::json::parse(ccf_config, ccf_config + ccf_config_size);
184117

@@ -228,18 +161,6 @@ extern "C"
228161
cc.node_certificate.curve_id,
229162
work_beacon);
230163
}
231-
catch (const ccf::ccf_oe_attester_init_error& e)
232-
{
233-
LOG_FAIL_FMT(
234-
"ccf_oe_attester_init_error during enclave init: {}", e.what());
235-
return CreateNodeStatus::OEAttesterInitFailed;
236-
}
237-
catch (const ccf::ccf_oe_verifier_init_error& e)
238-
{
239-
LOG_FAIL_FMT(
240-
"ccf_oe_verifier_init_error during enclave init: {}", e.what());
241-
return CreateNodeStatus::OEVerifierInitFailed;
242-
}
243164
catch (const ccf::ccf_openssl_rdrand_init_error& e)
244165
{
245166
LOG_FAIL_FMT(

src/enclave/verify.h

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/enclave/virtual_enclave.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ extern "C"
169169
// Only return OE_OK when the error isn't OE related
170170
switch (*status)
171171
{
172-
case CreateNodeStatus::OEAttesterInitFailed:
173-
case CreateNodeStatus::OEVerifierInitFailed:
174172
case CreateNodeStatus::EnclaveInitFailed:
175173
case CreateNodeStatus::MemoryNotOutsideEnclave:
176174
return OE_FAILURE;

0 commit comments

Comments
 (0)