Skip to content

Commit

Permalink
ta: os_test: do not call TEE_CloseTASession() if session is not opened
Browse files Browse the repository at this point in the history
The Global Platform specification [1] tells us that the session
parameter of TEE_CloseTASession() is:

  An opened session handle

The behaviour is unspecified if the session handle is not opened.

Make sure not to call TEE_CloseTASession() with an invalid session
handle when TEE_OpenTASession() fails by either:

  - doing an early return
  - adding an additional cleanup label

[1] TEE Internal Core API Specification – Public Release v1.3.1,
    §4.9.2 "TEE_CloseTASession"

Signed-off-by: Vincent Mailhol <[email protected]>
Reviewed-by: Etienne Carriere <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
  • Loading branch information
vincent-mailhol committed Nov 20, 2023
1 parent e53eb67 commit a704d90
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions ta/os_test/os_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ static TEE_Result test_mem_access_right(uint32_t param_types,
&sess, &ret_orig);
if (res != TEE_SUCCESS) {
EMSG("TEE_OpenTASession failed\n");
goto cleanup_return;
return res;
}

l_pts = TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT,
Expand All @@ -547,12 +547,9 @@ static TEE_Result test_mem_access_right(uint32_t param_types,
res = TEE_InvokeTACommand(sess, TEE_TIMEOUT_INFINITE,
TA_OS_TEST_CMD_PARAMS_ACCESS,
l_pts, l_params, &ret_orig);
if (res != TEE_SUCCESS) {
if (res != TEE_SUCCESS)
EMSG("TEE_InvokeTACommand failed\n");
goto cleanup_return;
}

cleanup_return:
TEE_CloseTASession(sess);
return res;
}
Expand Down Expand Up @@ -944,7 +941,7 @@ TEE_Result ta_entry_client(uint32_t param_types, TEE_Param params[4])
&sess, &ret_orig);
if (res != TEE_SUCCESS) {
EMSG("TEE_OpenTASession failed\n");
goto cleanup_return;
goto cleanup_free;
}

l_pts = TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT,
Expand All @@ -959,18 +956,19 @@ TEE_Result ta_entry_client(uint32_t param_types, TEE_Param params[4])
&ret_orig);
if (res != TEE_SUCCESS) {
EMSG("TEE_InvokeTACommand failed\n");
goto cleanup_return;
goto cleanup_close_session;
}

if (TEE_MemCompare(sha256_out, out, sizeof(sha256_out)) != 0) {
EMSG("out parameter failed\n");
res = TEE_ERROR_GENERIC;
goto cleanup_return;
goto cleanup_close_session;
}

cleanup_return:
TEE_Free(in);
cleanup_close_session:
TEE_CloseTASession(sess);
cleanup_free:
TEE_Free(in);
return res;
}

Expand Down Expand Up @@ -1106,7 +1104,7 @@ TEE_Result ta_entry_ta2ta_memref(uint32_t param_types, TEE_Param params[4])
&sess, &ret_orig);
if (res != TEE_SUCCESS) {
EMSG("TEE_OpenTASession failed");
goto cleanup_return;
return res;
}

l_pts = TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT,
Expand Down

0 comments on commit a704d90

Please sign in to comment.