Skip to content

Commit

Permalink
svc: check for allocation overflow in crypto calls part 2
Browse files Browse the repository at this point in the history
Without checking for overflow there is a risk of allocating a buffer
with size smaller than anticipated and as a consequence of that it might
lead to a heap based overflow with attacker controlled data written
outside the boundaries of the buffer.

Fixes: OP-TEE-2018-0011: "Integer overflow in crypto system calls (x2)"

Signed-off-by: Joakim Bech <[email protected]>
Tested-by: Joakim Bech <[email protected]> (QEMU v7, v8)
Reviewed-by: Jens Wiklander <[email protected]>
Reported-by: Riscure <[email protected]>
Reported-by: Alyssa Milburn <[email protected]>
Acked-by: Etienne Carriere <[email protected]>
  • Loading branch information
jbech-linaro authored and jforissier committed Jan 21, 2019
1 parent a637243 commit 70697bf
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/tee/tee_svc_cryp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3274,7 +3274,12 @@ TEE_Result syscall_asymm_operate(unsigned long state,
if (res != TEE_SUCCESS)
return res;

params = malloc(sizeof(TEE_Attribute) * num_params);
size_t alloc_size = 0;

if (MUL_OVERFLOW(sizeof(TEE_Attribute), num_params, &alloc_size))
return TEE_ERROR_OVERFLOW;

params = malloc(alloc_size);
if (!params)
return TEE_ERROR_OUT_OF_MEMORY;
res = copy_in_attrs(utc, usr_params, num_params, params);
Expand Down Expand Up @@ -3436,7 +3441,12 @@ TEE_Result syscall_asymm_verify(unsigned long state,
if (res != TEE_SUCCESS)
return res;

params = malloc(sizeof(TEE_Attribute) * num_params);
size_t alloc_size = 0;

if (MUL_OVERFLOW(sizeof(TEE_Attribute), num_params, &alloc_size))
return TEE_ERROR_OVERFLOW;

params = malloc(alloc_size);
if (!params)
return TEE_ERROR_OUT_OF_MEMORY;
res = copy_in_attrs(utc, usr_params, num_params, params);
Expand Down

0 comments on commit 70697bf

Please sign in to comment.