no message

Match-id-e705d95e4831343d4371bcaab51fbb6fddd89dfb
This commit is contained in:
xxx
2023-03-18 16:49:32 +08:00
committed by xxx
parent b17fc91c51
commit e150db9039
25 changed files with 177 additions and 120 deletions
@@ -50,6 +50,10 @@ static elf_load_context_t g_load_context;
TEE_Result rename_tmp_file(const char *new_name, uint32_t len)
{
elf_image_info *img_info_ptr = get_img_info_ptr();
if (img_info_ptr == NULL) {
tloge("the ptr is null\n");
return TEE_ERROR_GENERIC;
}
if (len == 0 || len > MAX_TAFS_NAME_LEN || new_name == NULL) {
tloge("new file name error\n");
return TEE_ERROR_BAD_PARAMETERS;
@@ -70,6 +74,10 @@ TEE_Result rename_tmp_file(const char *new_name, uint32_t len)
static void unlink_file(void)
{
elf_image_info *img_info_ptr = get_img_info_ptr();
if (img_info_ptr == NULL) {
tloge("the ptr is null\n");
return;
}
if (img_info_ptr->tmp_file_exist == false)
return;
@@ -82,6 +90,10 @@ static void unlink_file(void)
static TEE_Result close_tmp_file(void)
{
elf_image_info *img_info_ptr = get_img_info_ptr();
if (img_info_ptr == NULL) {
tloge("the ptr is null\n");
return TEE_ERROR_GENERIC;
}
if (img_info_ptr->img_fp < 0)
return TEE_SUCCESS;
@@ -153,7 +165,7 @@ TEE_Result need_load_app(const smc_cmd_t *cmd)
*(int32_t *)(params->memref.buffer) = need_load;
if (need_load)
if (need_load != 0)
tlogd("need_load flag is %x ==================\n", need_load);
return TEE_SUCCESS;
@@ -195,7 +207,7 @@ static TEE_Result tee_secure_img_get_version(const uint8_t *share_buf, uint32_t
teec_image_identity img_identity = {0};
img_identity = *(teec_image_identity *)share_buf;
/* decide the TA verison */
/* decide the TA version */
bool temp_check = (img_identity.magic_num1 == TA_HEAD_MAGIC1) && (img_identity.magic_num2 == TA_HEAD_MAGIC2) &&
(img_identity.version_num > 1);
if (temp_check) {
@@ -218,6 +230,7 @@ static TEE_Result create_empty_file(elf_image_info *img_info_ptr)
tloge("generate tmp file name failed\n");
return TEE_ERROR_BAD_PARAMETERS;
}
/* the value of file_tmp_number has no meaning, just change it to distinguish tmp file */
file_tmp_number++;
img_info_ptr->img_fp = open(img_info_ptr->tmp_file_name, O_CREAT | O_RDWR, RWRIGHT, (uint64_t)0);
if (img_info_ptr->img_fp < 0) {
@@ -239,9 +252,13 @@ static TEE_Result get_img_load_buf(uint32_t size)
if (size == 0 || size > PAGE_ALIGN_UP(size + ADDITIONAL_BUF_SIZE)) {
tloge("invalid img size %u\n", size);
return TEE_ERROR_BAD_PARAMETERS;
}
}
elf_image_info *img_info_ptr = get_img_info_ptr();
if (img_info_ptr == NULL) {
tloge("the ptr is null\n");
return TEE_ERROR_GENERIC;
}
img_info_ptr->aligned_img_size = PAGE_ALIGN_UP(size + ADDITIONAL_BUF_SIZE); /* get a redundance */
if (create_empty_file(img_info_ptr) != TEE_SUCCESS)
@@ -260,7 +277,7 @@ static TEE_Result get_img_load_buf(uint32_t size)
return TEE_SUCCESS;
}
TEE_Result handle_img_alloc_img_buff(uint32_t img_version, uint8_t *share_buf, uint32_t buf_len)
static TEE_Result handle_img_alloc_img_buff(uint32_t img_version, uint8_t *share_buf, uint32_t buf_len)
{
TEE_Result ret;
uint32_t img_size = 0;
@@ -283,8 +300,12 @@ static TEE_Result tee_secure_image_recieve(uint8_t *share_buf, uint32_t buf_len)
{
uint32_t img_version = 0;
errno_t eret;
elf_image_info *img_info_ptr = get_img_info_ptr();
elf_image_info *img_info_ptr = get_img_info_ptr();
if (img_info_ptr == NULL) {
tloge("the ptr is null\n");
return TEE_ERROR_GENERIC;
}
/* The first time of TA image transfer, it may needs several time to complete */
if (img_info_ptr->img_buf == NULL) {
/* Get TA image version number */
@@ -318,11 +339,16 @@ static TEE_Result recv_img_info_from_tzdriver(const smc_cmd_t *cmd, TEE_Param **
int32_t keep_loading;
uint8_t *share_buf = NULL;
uint32_t buf_len;
elf_image_info *img_info_ptr = get_img_info_ptr();
if (cmd == NULL || params == NULL)
return TEE_ERROR_BAD_PARAMETERS;
elf_image_info *img_info_ptr = get_img_info_ptr();
if (img_info_ptr == NULL) {
tloge("the ptr is null\n");
return TEE_ERROR_GENERIC;
}
/* Get params for cmd, and check the param_type */
ret = tee_cmd_params_parse(cmd, params);
if (ret != TEE_SUCCESS) {
+5 -1
View File
@@ -277,7 +277,11 @@ int32_t handle_unlink_dynamic_drv(uint32_t cmd_id, uint32_t task_id, const uint8
* from lib_list, to denied teecd was killed.
*/
(void)memset_s(&msg, sizeof(msg), 0, sizeof(msg));
(void)memcpy_s(msg.lib_name, sizeof(msg.lib_name) - 1, msg_buf, sizeof(msg.lib_name) - 1);
errno_t rc = memcpy_s(msg.lib_name, sizeof(msg.lib_name) - 1, msg_buf, sizeof(msg.lib_name) - 1);
if (rc != EOK) {
tloge("[error]memcpy_s failed, rc=%d, line:%d.\n", rc, __LINE__);
return GT_ERR_END_CMD;
}
msg.lib_name[LIB_NAME_MAX - 1] = '\0';
msg.is_drvlib = true;
@@ -80,7 +80,7 @@ TEE_Result map_rdr_mem(const smc_cmd_t *cmd)
char chip_type[CHIP_TYPE_LEN_MAX] = {0};
if (tee_get_chip_type(chip_type, CHIP_TYPE_LEN_MAX) != 0) {
tee_push_rdr_update_addr(rdr_mem_addr, (uint32_t)rdr_mem_size,
is_cache_mem, "chip type not set", strlen("chip type not set") + 1);
is_cache_mem, "chip type not set", (uint32_t)strlen("chip type not set") + 1);
} else {
tee_push_rdr_update_addr(rdr_mem_addr, (uint32_t)rdr_mem_size, is_cache_mem, chip_type, CHIP_TYPE_LEN_MAX);
}
@@ -106,7 +106,7 @@ static TEE_Result process_get_reeinfo(uint32_t task_id, struct session_struct *s
buffer_msg.cmd_id = TEE_GET_REEINFO_SUCCESS;
uint32_t ret = ipc_msg_snd(0x0, task_id, &buffer_msg, sizeof(buffer_msg));
if (ret) {
if (ret != 0) {
tloge("get reeinof msg send to ta failed:0x%x\n", ret);
return TEE_ERROR_GENERIC;
}
@@ -12,6 +12,10 @@
#ifndef GTASK_EXT_INTERFACE_H
#define GTASK_EXT_INTERFACE_H
#include <stdint.h>
#include "ta_framework.h"
#include "tee_defines.h"
TEE_Result map_rdr_mem(const smc_cmd_t *cmd);
int32_t handle_info_query(uint32_t cmd_id, uint32_t task_id,
const uint8_t *msg_buf, uint32_t msg_size);
+10 -7
View File
@@ -65,7 +65,7 @@ static nwd_cmd_t *g_nwd_cmd = NULL;
* in g_nwd_cmd is right. */
static DECLEAR_BITMAP(cmd_doing_bitmap, MAX_SMC_CMD);
static uint32_t g_systime_set_flag = 0;
static bool g_systime_set_flag = false;
static void acquire_smc_buf_lock(uint32_t *lock)
{
@@ -262,7 +262,7 @@ int put_last_out_cmd(const smc_cmd_t *cmd)
acquire_smc_buf_lock(&g_nwd_cmd->smc_lock);
rc = memcpy_s(&g_nwd_cmd->out[cmd->event_nr], sizeof(smc_cmd_t), cmd, sizeof(smc_cmd_t));
if (rc) {
if (rc != EOK) {
release_smc_buf_lock(&g_nwd_cmd->smc_lock);
tloge("memcpy out cmd failed\n");
return GT_ERR_END_CMD;
@@ -283,7 +283,7 @@ void ns_cmd_response(smc_cmd_t *cmd)
if (cmd->ret_val != TEE_PENDING) {
TEE_Result ret = copy_pam_to_src(cmd->cmd_id, false);
if (ret)
if (ret != TEE_SUCCESS)
cmd->ret_val = ret;
ret = unmap_ns_operation(cmd);
@@ -316,8 +316,11 @@ TEE_Result handle_time_adjust(const smc_cmd_t *cmd)
return TEE_ERROR_BAD_PARAMETERS;
}
time.seconds = params->value.a;
time.millis = params->value.b;
if (params == NULL)
return TEE_ERROR_BAD_PARAMETERS;
time.seconds = (int32_t)params->value.a;
time.millis = (int32_t)params->value.b;
if ((uint32_t)time.seconds <= SYSTIME_SET_MAX) {
#ifdef CONFIG_OFF_DRV_TIMER
ret = teecall_cap_time_sync(time.seconds, time.millis);
@@ -327,7 +330,7 @@ TEE_Result handle_time_adjust(const smc_cmd_t *cmd)
if (ret != TEE_SUCCESS)
return ret;
g_systime_set_flag = 1;
g_systime_set_flag = true;
} else {
tloge("time adjust failed\n");
ret = TEE_ERROR_GENERIC;
@@ -481,7 +484,7 @@ error:
return GT_ERR_END_CMD;
}
static int handle_ns_cmd()
static int handle_ns_cmd(void)
{
int gt_err_ret;
smc_cmd_t cmd;
+2 -2
View File
@@ -69,11 +69,11 @@ static uint32_t ta_to_global_msg_len(bool ta_is_64)
static int convert_ta2gtask_msg_handle(const uint8_t *msg_buf, bool ta_is_64, ta_to_global_msg *msg)
{
struct ta_to_global_msg_32 *msg_32 = NULL;
const struct ta_to_global_msg_32 *msg_32 = NULL;
if (!ta_is_64) {
/* TA is 32 bit */
msg_32 = (struct ta_to_global_msg_32 *)msg_buf;
msg_32 = (const struct ta_to_global_msg_32 *)(uintptr_t)msg_buf;
msg->ret = msg_32->ret;
msg->agent_id = msg_32->agent_id;
msg->session_context = (uint64_t)(msg_32->session_context);
@@ -13,6 +13,7 @@
#ifndef TEE_NS_CMD_DISPATCH_H
#define TEE_NS_CMD_DISPATCH_H
#include <stdint.h>
#include "ta_framework.h"
typedef TEE_Result (*sync_func)(const smc_cmd_t *cmd);
@@ -34,10 +34,10 @@ static void s_cmd_response(smc_cmd_t *cmd, uint32_t ret_task_id)
ret_msg.ret = cmd->ret_val;
TEE_Result ret = copy_pam_to_src(cmd->cmd_id, true);
if (ret)
if (ret != TEE_SUCCESS)
ret_msg.ret = ret;
if (memcpy_s(&ret_msg.cmd, sizeof(ret_msg.cmd), cmd, sizeof(*cmd))) {
if (memcpy_s(&ret_msg.cmd, sizeof(ret_msg.cmd), cmd, sizeof(*cmd)) != EOK) {
tloge("memcpy ta2ta back cmd failed\n");
ret_msg.ret = TEE_ERROR_GENERIC;
}
+17 -15
View File
@@ -70,13 +70,12 @@ static TEE_Result ta_name_to_path(const struct service_struct *service,
break;
if (strncmp(service->name, builtin_task_info->name, strlen(builtin_task_info->name) + 1) == 0) {
if (strncpy_s(path_name, len, builtin_task_info->path, strlen(builtin_task_info->path)) == 0) {
if (strncpy_s(path_name, len, builtin_task_info->path, strlen(builtin_task_info->path)) == EOK) {
/* set priority for buitlin task */
*p_priority = builtin_task_info->priority;
return TEE_SUCCESS;
} else {
return TEE_ERROR_GENERIC;
}
return TEE_ERROR_GENERIC;
}
}
@@ -177,8 +176,10 @@ static int gt_create_thread(pid_t *pid)
tloge("CALL_TA_CRTEATE_THREAD msg send failed:0x%" PRIx32 "\n", rc);
return NORMAL_FAIL_RET;
}
// wait at Q#1 for ACK message from "worker_thread" created by service thread,
// drop messages from other sources.
/*
* wait at Q#1 for ACK message from "worker_thread" created by service thread,
* drop messages from other sources.
*/
timer_event *event = start_timeout();
do {
if (ipc_msg_q_recv(&msg_id, &sender_pid, 1, TASK_TIMEOUT) != 0) {
@@ -245,7 +246,7 @@ static int gt_recycle_thread(uint32_t task_id, uint32_t session_id)
} while (pid != get_cur_service()->service_thread);
stop_timeout(event);
// "invalid tid" is the the only case for this
/* "invalid tid" is the the only case for this */
if (msg_id != 0) {
tloge("recycle failed, ret=%" PRIu32 "\n", msg_id);
return NORMAL_FAIL_RET;
@@ -389,22 +390,23 @@ static int tee_spawn_with_attr(int *ptask_id, const char *elf_path, char *argv[]
static int32_t get_elf_path(int32_t bin_type, char *loader_path, uint32_t loader_path_size)
{
/* only tarunner.elf support 64bit TA
/*
* only tarunner.elf support 64bit TA
* taloader.elf cannot suuport 64bit TA
* because it cannot handle relocate code
*/
if (get_cur_service()->ta_64bit == true) {
if (memcpy_s(loader_path, loader_path_size, "/tarunner.elf", sizeof("/tarunner.elf")) != 0) {
if (memcpy_s(loader_path, loader_path_size, "/tarunner.elf", sizeof("/tarunner.elf")) != EOK) {
tloge("set loader tarunner fail\n");
return -1;
}
} else if (bin_type == ELF_TARUNNER) {
if (memcpy_s(loader_path, loader_path_size, "/tarunner_a32.elf", sizeof("/tarunner_a32.elf")) != 0) {
if (memcpy_s(loader_path, loader_path_size, "/tarunner_a32.elf", sizeof("/tarunner_a32.elf")) != EOK) {
tloge("set loader tarunner a32 fail\n");
return -1;
}
} else {
if (memcpy_s(loader_path, loader_path_size, "/taloader.elf", sizeof("/taloader.elf")) != 0) {
if (memcpy_s(loader_path, loader_path_size, "/taloader.elf", sizeof("/taloader.elf")) != EOK) {
tloge("set loader tarunner a32 fail\n");
return -1;
}
@@ -483,9 +485,9 @@ static int set_argv_for_tsk(struct argv_base_buffer *argv, char *loader_path, ui
/* tasks load by taloader and tarunner */
if (strncpy_s(argv->task_name, sizeof(argv->task_name), get_cur_service()->name,
sizeof(get_cur_service()->name) - 1) != 0)
sizeof(get_cur_service()->name) - 1) != EOK)
return -EINVAL;
if (strncpy_s(argv->task_path, sizeof(argv->task_path), path_name, path_name_size - 1) != 0)
if (strncpy_s(argv->task_path, sizeof(argv->task_path), path_name, path_name_size - 1) != EOK)
return -EINVAL;
/*
@@ -499,12 +501,12 @@ static int set_argv_for_tsk(struct argv_base_buffer *argv, char *loader_path, ui
tlogd("no dyn client exists\n");
} else {
/* hm-native tasks, just hm_tee_test now! */
if (memcpy_s(loader_path, loader_path_size, path_name, path_name_size) != 0) {
if (memcpy_s(loader_path, loader_path_size, path_name, path_name_size) != EOK) {
tloge("native set loader path fail\n");
return -EINVAL;
}
if (strncpy_s(argv->task_name, sizeof(argv->task_name), path_name, path_name_size) != 0)
if (strncpy_s(argv->task_name, sizeof(argv->task_name), path_name, path_name_size) != EOK)
return -EINVAL;
}
return 0;
@@ -571,7 +573,7 @@ static int gt_create_proc(const struct tsk_init_param *init_param, uint32_t *tas
if (init_spawn_argv_env(init_param, sbuffer, loader_path, sizeof(loader_path)) != 0)
return -1;
if (memmove_s(&uuid.uuid, sizeof(uuid.uuid), &(init_param->uuid), sizeof(init_param->uuid)) != 0) {
if (memmove_s(&uuid.uuid, sizeof(uuid.uuid), &(init_param->uuid), sizeof(init_param->uuid)) != EOK) {
tloge("memmove uuid failed\n");
return -EINVAL;
}
+1
View File
@@ -11,6 +11,7 @@
*/
#ifndef GTASK_TEE_TAK_H
#define GTASK_TEE_TAK_H
#include <stdint.h>
#include "ta_framework.h"
#define NORMAL_FAIL_RET (-1)
@@ -42,7 +42,7 @@ static void response_to_ta(const smc_cmd_t *cmd, uint32_t father_task_id)
struct ta2ta_ret_msg ret_msg = { 0 };
ret_msg.ret = cmd->ret_val;
if (memcpy_s(&ret_msg.cmd, sizeof(ret_msg.cmd), cmd, sizeof(*cmd))) {
if (memcpy_s(&ret_msg.cmd, sizeof(ret_msg.cmd), cmd, sizeof(*cmd)) != EOK) {
tloge("memcpy ta2ta back cmd failed\n");
ret_msg.ret = TEE_ERROR_GENERIC;
}
@@ -254,14 +254,14 @@ void ta_exception_handle_buildin_agent_ack(uint32_t task_id)
TEE_Result ta_exception_handle_agent_ack(const smc_cmd_t *cmd)
{
TEE_UUID *uuid = NULL;
const TEE_UUID *uuid = NULL;
struct service_struct *srv = NULL;
struct session_struct *sess = NULL;
if (cmd == NULL)
return TEE_ERROR_BAD_PARAMETERS;
uuid = (TEE_UUID *)cmd->uuid;
uuid = (const TEE_UUID *)(uintptr_t)cmd->uuid;
srv = find_service_dead(uuid, service_index_of_context(cmd->context));
if (srv == NULL) {
tloge("dead service not found uuid = %x-%x\n", uuid->timeLow, uuid->timeMid);
@@ -349,14 +349,18 @@ static TEE_Result process_kill_task(struct service_struct *srv, const struct ses
int32_t handle_kill_task(const smc_cmd_t *cmd)
{
int32_t service_index;
struct service_struct *srv = NULL;
struct session_struct *sess = NULL;
if (cmd == NULL) {
tloge("handle kill task error, invalid param\n");
return GT_ERR_END_CMD;
}
tlogi("receive kill task msg\n");
TEE_UUID *uuid = (TEE_UUID *)cmd->uuid;
if ((service_index = find_service(uuid, service_index_of_context(cmd->context), &srv)) == -1) {
const TEE_UUID *uuid = (const TEE_UUID *)(uintptr_t)cmd->uuid;
if (find_service(uuid, service_index_of_context(cmd->context), &srv) == -1) {
tloge("find normal service failed, try to find dead service, uuid = %x-%x\n", uuid->timeLow, uuid->timeMid);
/* in case of multi ta have exception at the same time */
srv = find_service_dead(uuid, service_index_of_context(cmd->context));
@@ -394,7 +398,7 @@ int32_t process_task_crash(uint32_t cmd_id, uint32_t task_id, const uint8_t *msg
return GT_ERR_END_CMD;
}
crash_task_id = *(uint32_t *)msg_buf;
crash_task_id = *(const uint32_t *)(uintptr_t)msg_buf;
/* check service exist & valid */
struct service_struct *crash_srv = find_service_by_task_id(crash_task_id);
@@ -13,6 +13,7 @@
#ifndef TEE_TASK_EXCEPTION_H
#define TEE_TASK_EXCEPTION_H
#include <stdint.h>
#include <stddef.h>
#include "tee_defines.h"
#include "gtask_core.h"
+1 -1
View File
@@ -16,6 +16,6 @@
#include "gtask_core.h"
int uuid_to_fname(const TEE_UUID *uuid, char *name, int namelen);
int uuid_to_libname(const TEE_UUID *uuid, char *name, int namelen, char *lib_name, tee_img_type_t type);
int uuid_to_libname(const TEE_UUID *uuid, char *name, int namelen, const char *lib_name, tee_img_type_t type);
#endif
+2 -2
View File
@@ -20,12 +20,12 @@ int get_ta_info(uint32_t task_id, bool *ta_64bit, TEE_UUID *uuid);
int convert_ta2gtask_msg(const uint8_t *msg_buf, uint32_t msg_size, uint32_t taskid, ta_to_global_msg *msg);
/* struct global_to_ta_msg */
TEE_Result send_global2ta_msg(const global_to_ta_msg *msg, uint32_t cmd, uint32_t taskid, const bool *type);
TEE_Result send_global2ta_msg(const global_to_ta_msg *msg, uint32_t cmd, uint32_t taskid, const bool *ta_64bit);
uint32_t get_tee_param_len(bool ta_is_64);
TEE_Result alloc_tee_param_for_ta(uint32_t taskid, struct pam_node *node);
TEE_Result send_ta_init_msg(const ta_init_msg *msg, bool ta_type, uint32_t cmd, uint32_t taskid);
TEE_Result send_ta_init_msg(const ta_init_msg *msg, bool ta_is_64, uint32_t cmd, uint32_t taskid);
#endif
+1
View File
@@ -19,6 +19,7 @@
#define MAX_STACK_SIZE (8 * 1024 * 1024)
#define MAX_TA2TA_LEVEL 1
#define UINT32_BIT_NUM 32
#define get_index_by_uint32(n) ((n) / (UINT32_BIT_NUM))
+1 -1
View File
@@ -16,7 +16,7 @@
#include <ipclib.h>
#include "mem_page_ops.h" /* paddr_t */
#include "ta_framework.h"
#include "sys_timer.h" // timer_private_data_kernel
#include "sys_timer.h"
#include <drv.h>
#define GT_ERR_OK 0
+2 -2
View File
@@ -57,7 +57,7 @@ static int32_t set_proc_mem_size(const struct proc_mem_info *info, posix_spawnat
}
static int run_init_task(char *name, char *envp[], const struct proc_mem_info *info,
struct tee_uuid *uuid, uint32_t *pid_ptr)
const struct tee_uuid *uuid, uint32_t *pid_ptr)
{
char *subargv[] = { name, NULL };
pid_t pid = 0;
@@ -190,7 +190,7 @@ int init_main(void)
return ret;
ret = run_drv_frame_tasks();
if (ret)
if (ret != 0)
return ret;
return 0;
+10 -10
View File
@@ -41,7 +41,8 @@ extern struct session_struct *g_cur_session;
static struct dlist_node g_agent_head;
static uint32_t g_agent_cnt;
/* service thread is a kthread 'CA' in tzdriver, it can be used
/*
* service thread is a kthread 'CA' in tzdriver, it can be used
* to handle build-in agent(ssa) request while there's
* no source CA for agent request.
* cases as list:
@@ -226,7 +227,7 @@ struct agent_control *find_agent(uint32_t agent_id)
break;
}
}
if (!find_flag) {
if (find_flag == 0) {
tlogd("Failed to find the agent 0x%x\n", agent_id);
return NULL;
}
@@ -339,7 +340,7 @@ TEE_Result unregister_agent(const smc_cmd_t *cmd)
uint32_t param_type = 0;
TEE_Param *param = NULL;
if (g_agent_cnt <= 0) {
if (g_agent_cnt == 0) {
tloge("Failed to unregister agent, no more agent exists!\n");
return TEE_ERROR_GENERIC;
}
@@ -358,9 +359,8 @@ TEE_Result unregister_agent(const smc_cmd_t *cmd)
control = find_agent(agent_id);
if (control != NULL) {
if (control->locked) {
tlogd("agent already had lock set!\n");
/* Remove agent from session locked agents */
dlist_delete(&control->session_list);
tloge("agent already had lock set, cannot be unregistered!\n");
return TEE_ERROR_GENERIC;
}
/* If we have waiting sessions then unlock them */
while (!dlist_empty(&control->waiting_sessions)) {
@@ -540,7 +540,7 @@ TEE_Result agent_late_init(const smc_cmd_t *cmd)
if (cmd == NULL)
return TEE_ERROR_BAD_PARAMETERS;
if (cmd_global_ns_get_params(cmd, &param_type, &param))
if (cmd_global_ns_get_params(cmd, &param_type, &param) != 0)
return TEE_ERROR_GENERIC;
/* check params types */
@@ -564,7 +564,7 @@ TEE_Result set_service_thread_cmd(const smc_cmd_t *cmd, bool *async)
if (cmd == NULL || async == NULL)
return TEE_ERROR_BAD_PARAMETERS;
if (memcpy_s(&g_svc_thread_ctrl.cmd, sizeof(smc_cmd_t), cmd, sizeof(smc_cmd_t))) {
if (memcpy_s(&g_svc_thread_ctrl.cmd, sizeof(smc_cmd_t), cmd, sizeof(smc_cmd_t)) != EOK) {
tloge("memcpy cmd failed\n");
return TEE_ERROR_GENERIC;
}
@@ -617,7 +617,7 @@ bool service_thread_request_dequeue(const smc_cmd_t *in, smc_cmd_t *out)
return false;
}
if (memcpy_s(out, sizeof(smc_cmd_t), &g_svc_thread_ctrl.cmd, sizeof(smc_cmd_t))) {
if (memcpy_s(out, sizeof(smc_cmd_t), &g_svc_thread_ctrl.cmd, sizeof(smc_cmd_t)) != EOK) {
tloge("memcpy_s failed\n");
return false;
}
@@ -738,7 +738,7 @@ int32_t handle_service_agent_back_cmd(const smc_cmd_t *cmd)
}
ret = ipc_msg_snd(TEE_TASK_AGENT_SMC_ACK, agent_task_id, NULL, 0);
if (ret)
if (ret != 0)
tloge("send msg to agent:%u fail:%u\n", agent_task_id, ret);
smc_cmd_t cmd_out;
+15 -14
View File
@@ -264,7 +264,7 @@ void release_pam_node(struct pam_node *node)
case TEE_PARAM_TYPE_RESMEM_INPUT:
case TEE_PARAM_TYPE_RESMEM_OUTPUT:
case TEE_PARAM_TYPE_RESMEM_INOUT:
set_res_mem_prop(RESERVED_MEM_NONSECURE, node, i);
(void)set_res_mem_prop(RESERVED_MEM_NONSECURE, node, i);
break;
default:
break;
@@ -432,7 +432,7 @@ void mem_manager_init(void)
TEE_Result store_s_cmd(const smc_cmd_t *cmd)
{
if (g_cur_session != NULL && cmd != NULL) {
if (memcpy_s(&g_cur_session->cmd_in, sizeof(smc_cmd_t), cmd, sizeof(smc_cmd_t))) {
if (memcpy_s(&g_cur_session->cmd_in, sizeof(smc_cmd_t), cmd, sizeof(smc_cmd_t)) != EOK) {
tloge("memcpy_s cmd_in failed\n");
return TEE_ERROR_GENERIC;
}
@@ -445,7 +445,8 @@ TEE_Result store_s_cmd(const smc_cmd_t *cmd)
return TEE_SUCCESS;
}
/* task_id=0, params are copy to gtask -- 32 bit
/*
* task_id=0, params are copy to gtask -- 32 bit
* no need to change
*/
TEE_Result cmd_global_ns_get_params(const smc_cmd_t *cmd, uint32_t *param_type, TEE_Param **params)
@@ -708,14 +709,14 @@ static TEE_Result operation_map_for_gt(uint32_t task_id, const smc_cmd_t *cmd, u
/* copy the ns shared mem into tee */
ret = copy_pam_from_src(operation, operation_size, &pam_node);
if (ret) {
if (ret != 0) {
tloge("copy pam from ree failed.\n");
return ret;
}
if (!ta2ta) {
ret = check_operation_params_in_mailbox_range(&(pam_node->op));
if (ret) {
if (ret != 0) {
tloge("operation buffer is not in mailbox\n");
release_pam_node(pam_node);
return ret;
@@ -723,7 +724,7 @@ static TEE_Result operation_map_for_gt(uint32_t task_id, const smc_cmd_t *cmd, u
}
ret = params_map_for_ta(task_id, cmd, pam_node, ta2ta);
if (ret) {
if (ret != 0) {
tloge("operation map for ta failed:%x\n", ret);
release_pam_node(pam_node);
return ret;
@@ -765,7 +766,7 @@ TEE_Result cmd_ns_get_params(uint32_t task_id, const smc_cmd_t *cmd, uint32_t *p
*param_type = 0;
if (tmp_operation_addr != 0) {
ret = operation_map_for_gt(task_id, cmd, param_type, params, false);
if (ret) {
if (ret != 0) {
tloge("operation ns map for gt failed:%x\n", ret);
return ret;
}
@@ -790,7 +791,7 @@ TEE_Result cmd_secure_get_params(uint32_t task_id, const smc_cmd_t *cmd, uint32_
*params = 0;
if (tmp_operation_addr != 0) {
ret = operation_map_for_gt(task_id, cmd, param_type, params, true);
if (ret) {
if (ret != 0) {
tloge("operation ns map for gt failed:%x\n", ret);
return ret;
}
@@ -868,7 +869,7 @@ TEE_Result map_secure_operation(uint64_t tacmd, smc_cmd_t *out_cmd, uint32_t tas
cmd = (smc_cmd_t *)(uintptr_t)tmp_cmd;
cmd->uid = task_id;
if (memcpy_s(out_cmd, sizeof(*out_cmd), cmd, sizeof(*cmd))) {
if (memcpy_s(out_cmd, sizeof(*out_cmd), cmd, sizeof(*cmd)) != EOK) {
tloge("copy ta2ta out cmd failed\n");
ret = TEE_ERROR_GENERIC;
}
@@ -940,7 +941,7 @@ TEE_Result unmap_ns_operation(smc_cmd_t *cmd)
cmd->operation_phys = 0x0;
cmd->operation_h_phys = 0x0;
if (error_flag)
if (error_flag != 0)
return TEE_ERROR_GENERIC;
return TEE_SUCCESS;
@@ -1083,7 +1084,7 @@ static TEE_Result check_operation_params_in_mailbox_range(const tee_operation_gt
case TEE_PARAM_TYPE_RESMEM_INOUT:
buffer_addr = (paddr_t)((uint32_t)operation->p[i].memref.buffer |
((paddr_t)operation->p_h_addr[i] << SHIFT_OFFSET));
if (buffer_addr && !in_res_mem_range(buffer_addr, operation->p[i].memref.size))
if (buffer_addr != 0 && !in_res_mem_range(buffer_addr, operation->p[i].memref.size))
ret = TEE_ERROR_BAD_PARAMETERS;
break;
default:
@@ -1108,14 +1109,14 @@ TEE_Result check_cmd_in_mailbox_range(const smc_cmd_t *cmd)
return TEE_SUCCESS;
operation_addr = (paddr_t)(cmd->operation_phys | ((paddr_t)cmd->operation_h_phys << SHIFT_OFFSET));
if (operation_addr &&
if (operation_addr != 0 &&
!in_mailbox_range(operation_addr, sizeof(uint32_t) * PARAM_CNT + TEE_PARAM_NUM * sizeof(TEE_Param))) {
tloge("operation is not in mailbox\n");
return TEE_ERROR_BAD_PARAMETERS;
}
login_data_addr = (paddr_t)(cmd->login_data_phy | ((paddr_t)cmd->login_data_h_phy << SHIFT_OFFSET));
if (login_data_addr && !in_mailbox_range(login_data_addr, cmd->login_data_len)) {
if (login_data_addr != 0 && !in_mailbox_range(login_data_addr, cmd->login_data_len)) {
tloge("login data is not in mailbox\n");
return TEE_ERROR_BAD_PARAMETERS;
}
@@ -1169,7 +1170,7 @@ TEE_Result dump_statmeminfo(const smc_cmd_t *cmd)
return ret;
}
print_history = tee_param[1].value.b;
print_history = (int32_t)tee_param[1].value.b;
if (tee_param[1].value.a == 0) {
struct stat_mem_info *meminfo = (struct stat_mem_info *)tee_param[0].memref.buffer;
dump_stat = dump_mem_info(meminfo, print_history);
+1 -1
View File
@@ -12,7 +12,7 @@
#ifndef GTASK_NOTIFY_MANAGER_H
#define GTASK_NOTIFY_MANAGER_H
#include "sys_timer.h" // timer_private_data_kernel
#include "sys_timer.h" /* timer_private_data_kernel */
#define NOTIFY_MEM_SIZE (4 * 1024)
+16 -16
View File
@@ -43,11 +43,10 @@
#define SERVICE_AGED_TIME_LIMIT 2000U /* unit: millis */
// defined in trustedcore/TEE_ext/tee_config.c
/* defined in trustedcore/TEE_ext/tee_config.c */
extern struct service_struct *g_cur_service;
extern struct session_struct *g_cur_session;
#define SERVICE_INDEX_MAX 2048
#define INDEX_MAP_LEN (SERVICE_INDEX_MAX / 8)
#define FIRST_INDEX 1
static uint32_t g_cur_index = FIRST_INDEX;
@@ -55,7 +54,7 @@ static uint8_t g_service_index_map[INDEX_MAP_LEN] = {0};
/* service list head */
struct dlist_node g_service_head;
bool find_task(uint32_t task_id, struct service_struct **entry, struct session_struct **session);
bool find_task(uint32_t task_id, struct service_struct **service, struct session_struct **session);
struct dlist_node *get_service_head_ptr(void)
{
@@ -66,7 +65,7 @@ bool is_gtask_by_uuid(const TEE_UUID *task_uuid)
{
TEE_UUID uuid = TEE_SERVICE_GLOBAL;
if (!TEE_MemCompare(&uuid, task_uuid, sizeof(TEE_UUID)))
if (TEE_MemCompare(&uuid, task_uuid, sizeof(TEE_UUID)) == 0)
return true;
return false;
@@ -82,11 +81,11 @@ int32_t find_service(const TEE_UUID *uuid, uint32_t service_index, struct servic
dlist_for_each_entry(service_entry, &g_service_head, struct service_struct, service_list) {
tlogd("iterate service %s \n", service_entry->name);
if (!TEE_MemCompare(&service_entry->property.uuid, uuid, sizeof(TEE_UUID)) &&
if ((TEE_MemCompare(&service_entry->property.uuid, uuid, sizeof(TEE_UUID)) == 0) &&
!service_entry->is_service_dead) {
tlogd("call service : %s\n", service_entry->name);
if (service_index == 0 || service_index == service_entry->index) {
index = service_entry->index;
index = (int32_t)service_entry->index;
*entry = service_entry;
break;
} else {
@@ -146,7 +145,7 @@ bool dynamic_service_exist(const TEE_UUID *uuid, bool build_in)
return false;
}
static int32_t get_service_index()
static int32_t get_service_index(void)
{
int32_t cnt = 0;
@@ -164,7 +163,7 @@ static int32_t get_service_index()
g_cur_index++;
cnt++;
}
return g_cur_index++;
return (int32_t)(g_cur_index++);
}
static TEE_Result add_to_service_list(struct service_struct *service, const char *name, const TEE_UUID *uuid)
@@ -177,12 +176,13 @@ static TEE_Result add_to_service_list(struct service_struct *service, const char
service->index = (uint32_t)index;
service->init_build = 0;
if (strlen(name) < SERVICE_NAME_MAX) {
if (memmove_s(service->name, sizeof(service->name), (void *)name, strlen(name)) != TEE_SUCCESS) {
if (memmove_s(service->name, sizeof(service->name), (const void *)name, strlen(name)) != TEE_SUCCESS) {
tloge("memmove service name failed\n");
return TEE_ERROR_GENERIC;
}
} else {
if (memmove_s(service->name, sizeof(service->name), (void *)name, sizeof(service->name) - 1) != TEE_SUCCESS) {
if (memmove_s(service->name, sizeof(service->name),
(const void *)name, sizeof(service->name) - 1) != TEE_SUCCESS) {
tloge("memmove service name failed\n");
return TEE_ERROR_GENERIC;
}
@@ -206,11 +206,11 @@ TEE_Result register_service(const char *name, const TEE_UUID *uuid, bool dyn_con
return TEE_ERROR_BAD_PARAMETERS;
tlogd("register_service : %s\n", name);
// build in service can't be register after boot
/* build in service can't be register after boot */
if (!service_attr->build_in && is_build_in_service(uuid))
return TEE_ERROR_REGISTER_EXIST_SERVICE;
// have registered service but elf have been deleted, only need load elf
/* have registered service but elf have been deleted, only need load elf */
if (find_service(uuid, 0, &tmp_service) != INVALID_SERVICE_INDEX) {
tmp_service->elf_state = ELF_EXIST;
return TEE_SUCCESS;
@@ -265,7 +265,7 @@ TEE_Result ta_framework_init(void)
{
TEE_Result ret;
ret = service_manager_init();
if (ret) {
if (ret != 0) {
tloge("service manager init failed:%u\n", ret);
return ret;
}
@@ -383,7 +383,7 @@ static void incr_ref_cnt(struct service_struct *service)
if (service == NULL)
return;
// in case of overflow
/* in case of overflow */
if ((service->ref_cnt + 1) < 0) {
tloge("invalid ref cnt when incr\n");
return;
@@ -397,7 +397,7 @@ void decr_ref_cnt(struct service_struct *service)
if (service == NULL)
return;
// in case of overflow
/* in case of overflow */
if (service->ref_cnt <= 0) {
tloge("invalid ref cnt when decr\n");
return;
@@ -616,7 +616,7 @@ TEE_Result start_internal_task(const TEE_UUID *uuid, uint16_t task_prio, const c
task_param.task_name = task_name;
task_param.que_num = DEFAULT_MSG_QUEUE_NUM;
if (memcpy_s(&task_param.uuid, sizeof(task_param.uuid), &(g_cur_service->property.uuid), sizeof(TEE_UUID)) != 0) {
if (memcpy_s(&task_param.uuid, sizeof(task_param.uuid), &(g_cur_service->property.uuid), sizeof(TEE_UUID)) != EOK) {
tloge("copy uuid failed\n");
ret = TEE_ERROR_GENERIC;
goto create_task_fail;
@@ -16,6 +16,7 @@
#include <ipclib.h>
#define INVALID_SERVICE_INDEX (-1)
#define SERVICE_INDEX_MAX 2048
bool dynamic_service_exist(const TEE_UUID *uuid, bool build_in);
TEE_Result register_service(const char *name, const TEE_UUID *uuid, bool dyn_conf_registed,
+34 -30
View File
@@ -37,7 +37,7 @@
struct service_struct *g_cur_service = (struct service_struct *)NULL;
struct session_struct *g_cur_session = (struct session_struct *)NULL;
// static funs declare
/* static funs declare */
int32_t find_service(const TEE_UUID *uuid, uint32_t service_index, struct service_struct **entry);
void set_session_context(smc_cmd_t *cmd, uint32_t service_index, uint32_t session_id);
TEE_Result process_close_session_entry(struct service_struct **service, struct session_struct **session);
@@ -53,10 +53,11 @@ struct service_struct *get_cur_service(void)
return g_cur_service;
}
static TEE_Result call_ta_invoke_close_session(const smc_cmd_t *cmd, uint32_t cmd_type, uint32_t cmd_id,
global_to_ta_msg *entry_msg)
{
TEE_Result ret;
if (cmd->ret_val == TEE_PENDING2 || cmd->ret_val == TEE_PENDING)
return TEE_SUCCESS;
@@ -71,21 +72,22 @@ static TEE_Result call_ta_invoke_close_session(const smc_cmd_t *cmd, uint32_t cm
entry_msg->last_session = 1;
}
if (cmd_type == CMD_TYPE_NS_TO_SECURE) {
if (cmd_ns_get_params(g_cur_session->task_id, cmd, &entry_msg->param_type, &entry_msg->params) != TEE_SUCCESS) {
ret = cmd_ns_get_params(g_cur_session->task_id, cmd, &entry_msg->param_type, &entry_msg->params);
if (ret != TEE_SUCCESS) {
tloge("map ns params error\n");
return TEE_ERROR_GENERIC;
return ret;
}
entry_msg->session_type = SESSION_FROM_CA;
} else {
if (cmd_secure_get_params(g_cur_session->task_id, cmd, &entry_msg->param_type, &entry_msg->params) !=
TEE_SUCCESS) {
ret = cmd_secure_get_params(g_cur_session->task_id, cmd, &entry_msg->param_type, &entry_msg->params);
if (ret != TEE_SUCCESS) {
tloge("map secure params error\n");
return TEE_ERROR_GENERIC;
return ret;
}
entry_msg->session_type = SESSION_FROM_TA;
}
return TEE_SUCCESS;
return ret;
}
static void set_init_msg_prop(const struct ta_property *in, ta_property_t_64 *out)
@@ -234,10 +236,10 @@ void set_tee_return(smc_cmd_t *cmd, TEE_Result ret_val)
static TEE_Result init_ta_service_session(const smc_cmd_t *cmd)
{
TEE_UUID *uuid = NULL;
const TEE_UUID *uuid = NULL;
int32_t service_index;
uuid = (TEE_UUID *)cmd->uuid;
uuid = (const TEE_UUID *)(uintptr_t)cmd->uuid;
if ((service_index = find_service(uuid, service_index_of_context(cmd->context), &g_cur_service)) == -1) {
tloge("service not found uuid = %x-%x\n", uuid->timeLow, uuid->timeMid);
@@ -259,7 +261,7 @@ TEE_Result init_ta_context(const smc_cmd_t *cmd)
return TEE_ERROR_BAD_PARAMETERS;
TEE_Result ret = init_ta_service_session(cmd);
if (ret) {
if (ret != 0) {
tloge("init ta service session error:%x\n", ret);
return ret;
}
@@ -323,9 +325,9 @@ static TEE_Result check_ta2ta_context(uint32_t task_id)
static TEE_Result init_ta2ta_service(const smc_cmd_t *cmd)
{
TEE_UUID *uuid = NULL;
const TEE_UUID *uuid = NULL;
uuid = (TEE_UUID *)cmd->uuid;
uuid = (const TEE_UUID *)(uintptr_t)cmd->uuid;
if (find_service(uuid, service_index_of_context(cmd->context), &g_cur_service) == -1) {
tloge("find second service fail\n");
return TEE_ERROR_SERVICE_NOT_EXIST;
@@ -469,12 +471,12 @@ void set_session_context(smc_cmd_t *cmd, uint32_t service_index, uint32_t sessio
int32_t get_session_id(void)
{
int32_t id = -1;
int32_t id = ERROR_SESSION_ID;
uint32_t i;
for (i = 0; i < MAX_SESSION_ID; i++) {
if (!(g_cur_service->session_bitmap[get_index_by_uint32(i)] & (uint32_t)(0x1 << get_bit_by_uint32(i)))) {
id = i + 1;
if ((g_cur_service->session_bitmap[get_index_by_uint32(i)] & (uint32_t)(0x1 << get_bit_by_uint32(i))) == 0) {
id = (int32_t)(i + 1);
break;
}
}
@@ -552,7 +554,7 @@ static int get_ta2ta_level(uint32_t cmd_type, uint32_t task_id, uint32_t *level)
return -1;
}
if (sess->ta2ta_level >= 1) {
if (sess->ta2ta_level >= MAX_TA2TA_LEVEL) {
tloge("get caller ta2ta_level:%u, cannot open other ta\n", sess->ta2ta_level);
return -1;
}
@@ -667,7 +669,7 @@ TEE_Result add_new_session_into_list(struct session_struct **session, uint32_t *
(*session)->ta2ta_level = ta2ta_level;
(*session)->session_id = *session_id;
if (join_session_task_name(g_cur_service->name, *session)) {
if (join_session_task_name(g_cur_service->name, *session) != 0) {
tloge("join session task name failed\n");
if (*session != NULL) {
TEE_Free(*session);
@@ -774,7 +776,7 @@ static void check_and_release_ta_elf(void)
static void do_resc_release_work(bool handle_ref_cnt)
{
// after session is created, elf and ref_cnt can be released.
/* after session is created, elf and ref_cnt can be released. */
if (handle_ref_cnt) {
decr_ref_cnt(g_cur_service);
tlogd("service: %s, session count is %d ref_cnt-- is %d\n", g_cur_service->name, g_cur_service->session_count,
@@ -854,7 +856,7 @@ int32_t release_session(struct service_struct *service, struct session_struct *s
struct session_struct *backup_session = NULL;
if (service == NULL || session == NULL)
return TEE_ERROR_BAD_PARAMETERS;
return (int32_t)TEE_ERROR_BAD_PARAMETERS;
task_adapt_unregister_ta(&service->property.uuid, session->task_id);
service->session_count--;
@@ -885,8 +887,10 @@ int32_t release_session(struct service_struct *service, struct session_struct *s
if (session->waiting_agent.next != NULL)
dlist_delete(&session->waiting_agent);
/* We are the last one to go, next
* open session will need to reinit */
/*
* We are the last one to go, next
* open session will need to reinit
*/
TEE_Free(session);
return sre_ret;
@@ -962,7 +966,8 @@ static bool do_target_session_close(struct session_struct *sess_context, struct
if (sess->ta2ta_from_taskid == from_taskid) {
tlogd("ta2ta targert call session : %u\n", sess->session_id);
if (level < 1) {
/* if level == MAX_TA2TA_LEVEL, it is the last level session */
if (level < MAX_TA2TA_LEVEL) {
tlogi("close next TA session level:%u\n", level);
process_close_ta2ta_target_sessions(sess->task_id, (level + 1));
}
@@ -1114,9 +1119,9 @@ void process_open_session_error(void)
return;
}
// release dynamic loaded TA's resource
/* release dynamic loaded TA's resource */
if (g_cur_service->session_count == 0 && g_cur_service->ref_cnt == 0) {
// for non-keepalive TA, we release service node and service thread;
/* for non-keepalive TA, we release service node and service thread; */
if (!is_build_in_service(&(g_cur_service->property.uuid))) {
bool need_release_service = (!g_cur_service->property.keep_alive ||
(g_cur_service->property.keep_alive && g_cur_service->first_open));
@@ -1147,7 +1152,7 @@ bool process_init_session(void)
tlogd("Have non-standard property!");
uint32_t ret = ipc_msg_snd(CALL_TA_OPEN_SESSION_PROP, g_cur_session->task_id,
g_cur_service->property.other_buff, (uint16_t)g_cur_service->property.other_len);
if (ret) {
if (ret != 0) {
tloge("CALL_TA_OPEN_SESSION_PROP msg send to ta failed:0x%x\n", ret);
return false;
}
@@ -1160,9 +1165,8 @@ bool process_init_session(void)
TEE_Result close_session(const smc_cmd_t *cmd, uint32_t cmd_type, bool *sync)
{
TEE_Result ret;
bool check_stat = (cmd == NULL || sync == NULL || g_cur_service == NULL);
if (check_stat)
if (cmd == NULL || sync == NULL || g_cur_service == NULL)
return TEE_ERROR_BAD_PARAMETERS;
*sync = false;
@@ -1173,8 +1177,8 @@ TEE_Result close_session(const smc_cmd_t *cmd, uint32_t cmd_type, bool *sync)
return TEE_SUCCESS;
}
check_stat = (g_cur_session == NULL || g_cur_session->session_id == 0 ||
g_cur_session->session_id > MAX_SESSION_ID);
bool check_stat = (g_cur_session == NULL || g_cur_session->session_id == 0 ||
g_cur_session->session_id > MAX_SESSION_ID);
if (check_stat) {
tloge("close session not exist\n");
return TEE_ERROR_SESSION_NOT_EXIST;
@@ -32,7 +32,7 @@ TEE_Result close_session(const smc_cmd_t *cmd, uint32_t cmd_type, bool *sync);
TEE_Result async_call_ta_entry(const smc_cmd_t *cmd, uint32_t cmd_type, uint32_t cmd_id);
TEE_Result process_open_session(const smc_cmd_t *cmd, uint32_t cmd_type);
void process_open_session_error(void);
TEE_Result process_close_session();
TEE_Result process_close_session(void);
void session_set_cancelable(bool cancelable);
bool process_init_session(void);
void set_session_context(smc_cmd_t *cmd, uint32_t service_index, uint32_t session_id);
@@ -500,6 +500,10 @@ bool check_system_agent_permission(uint32_t task_id, uint32_t agent_id)
return true;
}
/*
* gtask will send agent buffer to ssa when receive register ssa agent msg.
* so only ssa need this interface
*/
void task_adapt_register_agent(uint32_t agent_id)
{
struct dlist_node *pos = NULL;