1 Star 0 Fork 36

yueyuankun/secGear

forked from src-openEuler/secGear 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0056-destroy-enclave-release-remain-shared-memory.patch 4.45 KB
一键复制 编辑 原始数据 按行查看 历史
houmingyong 提交于 2022-12-20 11:17 . fix aysnchronous ecall bug
From b722d85901dbe0906ddb8fed5f5aa9f0646ba9fb Mon Sep 17 00:00:00 2001
From: houmingyong <houmingyong@huawei.com>
Date: Mon, 19 Dec 2022 19:26:22 +0800
Subject: [PATCH] destory enclave release remain shared memory
---
src/host_src/gp/gp_enclave.c | 5 +++
src/host_src/gp/gp_shared_memory.c | 54 ++++++++++++++++++++++++------
src/host_src/gp/gp_shared_memory.h | 2 +-
3 files changed, 50 insertions(+), 11 deletions(-)
diff --git a/src/host_src/gp/gp_enclave.c b/src/host_src/gp/gp_enclave.c
index 521a850..952d584 100644
--- a/src/host_src/gp/gp_enclave.c
+++ b/src/host_src/gp/gp_enclave.c
@@ -520,11 +520,16 @@ cc_enclave_result_t _gp_destroy(cc_enclave_t *context)
{
int res;
TEEC_Result ret;
+ cc_enclave_result_t cc_ret;
if (!context || !context->private_data) {
print_error_term("The input parameters are wrong \n");
return CC_ERROR_BAD_PARAMETERS;
}
+ cc_ret = gp_release_all_shared_memory(context);
+ if (cc_ret != CC_SUCCESS) {
+ print_error_goto("Fail to release all shared memory, errno:%x\n", cc_ret);
+ }
fini_features(context);
diff --git a/src/host_src/gp/gp_shared_memory.c b/src/host_src/gp/gp_shared_memory.c
index 60520a4..b6a958d 100644
--- a/src/host_src/gp/gp_shared_memory.c
+++ b/src/host_src/gp/gp_shared_memory.c
@@ -195,19 +195,10 @@ cc_enclave_result_t gp_register_shared_memory(cc_enclave_t *enclave, void *ptr)
return CC_SUCCESS;
}
-cc_enclave_result_t gp_unregister_shared_memory(cc_enclave_t *enclave, void* ptr)
+cc_enclave_result_t unregister_shared_memory(cc_enclave_t *enclave, gp_shared_memory_t* gp_shared_mem)
{
uint32_t ms = TEE_SECE_AGENT_ID;
- if (!gp_is_shared_mem_start_addr(ptr)) {
- return CC_ERROR_SHARED_MEMORY_START_ADDR_INVALID;
- }
-
- if (GP_SHARED_MEMORY_ENTRY(ptr)->enclave != enclave) {
- return CC_ERROR_INVALID_HANDLE;
- }
-
- gp_shared_memory_t *gp_shared_mem = GP_SHARED_MEMORY_ENTRY(ptr);
if (!__atomic_load_n(&gp_shared_mem->is_registered, __ATOMIC_ACQUIRE)) {
return CC_ERROR_SHARED_MEMORY_NOT_REGISTERED;
}
@@ -236,6 +227,7 @@ cc_enclave_result_t gp_unregister_shared_memory(cc_enclave_t *enclave, void* ptr
char *out_param_buf = param_buf + in_param_buf_size;
/* Copy in_params to in_buf */
+ void *ptr = (char *)gp_shared_mem + sizeof(gp_shared_memory_t);
memcpy(in_param_buf, &args_size, size_to_aligned_size(sizeof(args_size)));
memcpy(in_param_buf + ptr_offset, &ptr, sizeof(void*));
@@ -262,3 +254,45 @@ cc_enclave_result_t gp_unregister_shared_memory(cc_enclave_t *enclave, void* ptr
free(param_buf);
return CC_SUCCESS;
}
+cc_enclave_result_t gp_unregister_shared_memory(cc_enclave_t *enclave, void* ptr)
+{
+
+ if (!gp_is_shared_mem_start_addr(ptr)) {
+ return CC_ERROR_SHARED_MEMORY_START_ADDR_INVALID;
+ }
+
+ if (GP_SHARED_MEMORY_ENTRY(ptr)->enclave != enclave) {
+ return CC_ERROR_INVALID_HANDLE;
+ }
+
+ gp_shared_memory_t *gp_shared_mem = GP_SHARED_MEMORY_ENTRY(ptr);
+ return unregister_shared_memory(enclave, gp_shared_mem);
+}
+
+cc_enclave_result_t gp_release_all_shared_memory(cc_enclave_t *enclave)
+{
+ list_node_t *cur = NULL;
+ list_node_t *tmp = NULL;
+ gp_shared_memory_t *mem = NULL;
+ cc_enclave_result_t step_ret;
+ cc_enclave_result_t ret = CC_SUCCESS;
+
+ CC_RWLOCK_LOCK_RD(&g_shared_mem_list_lock);
+ list_for_each_safe(cur, tmp, &g_shared_mem_list) {
+ mem = list_entry(cur, gp_shared_memory_t, node);
+ if (mem->is_control_buf) {
+ continue;
+ }
+ step_ret = unregister_shared_memory(enclave, mem);
+ if (step_ret != CC_SUCCESS) {
+ ret = step_ret;
+ continue;
+ }
+ list_remove(&mem->node);
+ TEEC_SharedMemory sharedMem = *(TEEC_SharedMemory *)mem;
+ TEEC_ReleaseSharedMemory(&sharedMem);
+ }
+ CC_RWLOCK_UNLOCK(&g_shared_mem_list_lock);
+
+ return ret;
+}
diff --git a/src/host_src/gp/gp_shared_memory.h b/src/host_src/gp/gp_shared_memory.h
index 2ec66a8..6914193 100644
--- a/src/host_src/gp/gp_shared_memory.h
+++ b/src/host_src/gp/gp_shared_memory.h
@@ -59,7 +59,7 @@ cc_enclave_result_t gp_register_shared_memory(cc_enclave_t *enclave, void *ptr);
* Return: CC_SUCCESS, success; others failed.
*/
cc_enclave_result_t gp_unregister_shared_memory(cc_enclave_t *enclave, void *ptr);
-
+cc_enclave_result_t gp_release_all_shared_memory(cc_enclave_t *enclave);
#ifdef __cplusplus
}
#endif
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yue-yuankun/secGear.git
git@gitee.com:yue-yuankun/secGear.git
yue-yuankun
secGear
secGear
master

搜索帮助