1 Star 0 Fork 36

李宁杰/secGear

forked from src-openEuler/secGear 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0039-clean-memory-when-it-come-to-error_handle.patch 3.41 KB
一键复制 编辑 原始数据 按行查看 历史
From 8b70a9d74bcbb07cd8f33664398b1e5a41a46033 Mon Sep 17 00:00:00 2001
From: chenmaodong <chenmaodong@huawei.com>
Date: Thu, 3 Jun 2021 21:01:34 +0800
Subject: [PATCH] clean memory when it come to error_handle delete the rdlock
because we do it in proxy function in *_u.c
Signed-off-by: chenmaodong <chenmaodong@huawei.com>
---
src/host_src/enclave.c | 16 ++++++++++------
src/host_src/sgx/sgx_enclave.c | 2 --
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/host_src/enclave.c b/src/host_src/enclave.c
index 4b75b6e..8d6c8a6 100644
--- a/src/host_src/enclave.c
+++ b/src/host_src/enclave.c
@@ -34,7 +34,7 @@ static void check_dlopen_engine(p_tee_unregistered unregistered_func, cc_enclave
pthread_mutex_unlock(&(g_list_ops.mutex_work));
}
-static void error_handle(cc_enclave_t *l_context, void *handle, p_tee_registered registered_func,
+static void error_handle(cc_enclave_t *enclave, void *handle, p_tee_registered registered_func,
p_tee_unregistered unregistered_func, char* path, bool check)
{
cc_enclave_result_t tmp_res;
@@ -45,19 +45,19 @@ static void error_handle(cc_enclave_t *l_context, void *handle, p_tee_registered
pthread_mutex_unlock(&(g_list_ops.mutex_work));
}
/* in list find engine: handle is null and l_context is not null */
- if (l_context != NULL && l_context->list_ops_node && !handle) {
- tmp_res = find_engine_registered(l_context->list_ops_node->ops_desc->handle, NULL, &unregistered_func);
+ if (enclave != NULL && enclave->list_ops_node && !handle) {
+ tmp_res = find_engine_registered(enclave->list_ops_node->ops_desc->handle, NULL, &unregistered_func);
if (tmp_res != CC_SUCCESS) {
print_error_term("Can not find unregistered in the failed exit phase\n");
} else {
- check_dlopen_engine(unregistered_func, l_context);
+ check_dlopen_engine(unregistered_func, enclave);
}
}
/* handle is not null, means dlopen is ok */
if (handle) {
/* check if registered invoke success */
- if (l_context != NULL && registered_func && unregistered_func && l_context->list_ops_node) {
- check_dlopen_engine(unregistered_func, l_context);
+ if (enclave != NULL && registered_func && unregistered_func && enclave->list_ops_node) {
+ check_dlopen_engine(unregistered_func, enclave);
} else {
/* means registered func invoke fail OR find_engine_registered fail */
dlclose(handle);
@@ -66,6 +66,10 @@ static void error_handle(cc_enclave_t *l_context, void *handle, p_tee_registered
if (path) {
free(path);
}
+
+ if (enclave) {
+ explicit_bzero(enclave, sizeof(cc_enclave_t));
+ }
}
/* Lock to check the number of enclave
diff --git a/src/host_src/sgx/sgx_enclave.c b/src/host_src/sgx/sgx_enclave.c
index aa26957..7b61ba8 100644
--- a/src/host_src/sgx/sgx_enclave.c
+++ b/src/host_src/sgx/sgx_enclave.c
@@ -201,10 +201,8 @@ cc_enclave_result_t cc_enclave_sgx_call_function(
(void)output_buffer_size;
sgx_status_t status;
cc_enclave_result_t cc_status;
- pthread_rwlock_rdlock(&(enclave->rwlock));
status = sgx_ecall(((sgx_context_t *)(enclave->private_data))->edi, (int)function_id, ocall_table, ms);
cc_status = conversion_res_status(status, enclave->type);
- pthread_rwlock_unlock(&(enclave->rwlock));
return cc_status;
}
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/li_ning_jie/secGear.git
git@gitee.com:li_ning_jie/secGear.git
li_ning_jie
secGear
secGear
master

搜索帮助