Skip to content

Commit

Permalink
libteec: Handle NULL pointer when using TEEC_TempMemoryReference
Browse files Browse the repository at this point in the history
If TEE or TEE driver doesn't support the capability
"TEE_GEN_CAP_MEMREF_NULL", it can't handle NULL pointers.

The cases where NULL pointer is passed with size 0 as
TEEC_TempMemoryReference parameter is a valid use case and should
not return error. In such cases, use TEEC_AllocateSharedMemory()
instead of TEEC_RegisterSharedMemory() to allocate a block of shared
memory.

Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
Signed-off-by: Ruchika Gupta <ruchika.gupta@linaro.org>
  • Loading branch information
ruchi393 authored and jforissier committed Oct 15, 2020
1 parent 2de7f25 commit c0c9253
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions libteec/src/tee_client_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,20 @@ static TEEC_Result teec_pre_process_tmpref(TEEC_Context *ctx,
}
shm->size = tmpref->size;

if (!tmpref->buffer && ctx->memref_null) {
if (!tmpref->buffer) {
if (tmpref->size)
return TEEC_ERROR_BAD_PARAMETERS;

/* Null pointer, indicate no shared memory attached */
MEMREF_SHM_ID(param) = TEE_MEMREF_NULL;
shm->id = -1;
if (ctx->memref_null) {
/* Null pointer, indicate no shared memory attached */
MEMREF_SHM_ID(param) = TEE_MEMREF_NULL;
shm->id = -1;
} else {
res = TEEC_AllocateSharedMemory(ctx, shm);
if (res != TEEC_SUCCESS)
return res;
MEMREF_SHM_ID(param) = shm->id;
}
} else {
shm->buffer = tmpref->buffer;
res = TEEC_RegisterSharedMemory(ctx, shm);
Expand Down

0 comments on commit c0c9253

Please sign in to comment.