From ed437b5ea16eb1b6b923755020d9e61292b54a48 Mon Sep 17 00:00:00 2001 From: Sean Christopherson Date: Tue, 20 Sep 2016 10:35:02 -0700 Subject: [PATCH] Set misc_attr for failing _create_enclave flows Set misc_attr in the top level sgx_create_enclave if _create_enclave fails. This provides the user with the platform's capabilities when sgx_create_enclave fails for any reason other than a parameter error. Previously the misc_attr was only set upon failure if build_image failed, which was not helpful when sgx_create_enclave failed due to an attribute error, e.g. misc_select, as the flow aborted before it reached build_image. Signed-off-by: Sean Christopherson --- psw/urts/linux/urts.cpp | 8 ++++++++ psw/urts/loader.cpp | 12 +----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/psw/urts/linux/urts.cpp b/psw/urts/linux/urts.cpp index 4c2af4c365..f82c803c87 100644 --- a/psw/urts/linux/urts.cpp +++ b/psw/urts/linux/urts.cpp @@ -58,6 +58,14 @@ extern "C" sgx_status_t sgx_create_enclave(const char *file_name, const int debu file.name_len = (uint32_t)strlen(resolved_path); ret = _create_enclave(!!debug, fd, file, NULL, launch_token, launch_token_updated, enclave_id, misc_attr); + if(SGX_SUCCESS != ret && misc_attr) + { + sgx_misc_attribute_t plat_cap; + memset(&plat_cap, 0, sizeof(plat_cap)); + get_enclave_creator()->get_plat_cap(&plat_cap); + memcpy_s(misc_attr, sizeof(sgx_misc_attribute_t), &plat_cap, sizeof(sgx_misc_attribute_t)); + } + close(fd); return ret; diff --git a/psw/urts/loader.cpp b/psw/urts/loader.cpp index ba1e2f4f2f..187937131d 100644 --- a/psw/urts/loader.cpp +++ b/psw/urts/loader.cpp @@ -641,7 +641,7 @@ int CLoader::load_enclave(SGXLaunchToken *lc, int debug, const metadata_t *metad } ret = build_image(lc, &sgx_misc_attr.secs_attr, prd_css_file, &sgx_misc_attr); - //return platform capability if fail. Otherwise, return secs.attr. + //Update misc_attr with secs.attr upon success. if(SGX_SUCCESS == ret) { if(misc_attr) @@ -651,16 +651,6 @@ int CLoader::load_enclave(SGXLaunchToken *lc, int debug, const metadata_t *metad misc_attr->secs_attr.flags |= SGX_FLAGS_INITTED; } } - else - { - if(misc_attr) - { - sgx_misc_attribute_t plat_cap; - memset(&plat_cap, 0, sizeof(plat_cap)); - get_enclave_creator()->get_plat_cap(&plat_cap); - memcpy_s(misc_attr, sizeof(sgx_misc_attribute_t), &plat_cap, sizeof(sgx_misc_attribute_t)); - } - } return ret; }