Skip to content

Commit c066da8

Browse files
committed
arm_tee_psa_ipc: validate in_vec/out_vec base and length before dereferencing in crypto dispatcher
F#3541, F#3542
1 parent 415b956 commit c066da8

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

src/arm_tee_psa_ipc.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ static psa_status_t wolfboot_crypto_dispatch(const psa_invec *in_vec,
389389
if (in_len < 3 || out_vec == NULL || out_len < 1) {
390390
return PSA_ERROR_INVALID_ARGUMENT;
391391
}
392+
if (in_vec[1].base == NULL ||
393+
in_vec[1].len < sizeof(psa_key_attributes_t)) {
394+
return PSA_ERROR_INVALID_ARGUMENT;
395+
}
392396
{
393397
psa_key_attributes_t attr = *(const psa_key_attributes_t *)in_vec[1].base;
394398
/* Fallback to volatile storage if persistent storage is unavailable. */
@@ -405,6 +409,10 @@ static psa_status_t wolfboot_crypto_dispatch(const psa_invec *in_vec,
405409
if (in_len < 2 || out_vec == NULL || out_len < 1) {
406410
return PSA_ERROR_INVALID_ARGUMENT;
407411
}
412+
if (in_vec[1].base == NULL ||
413+
in_vec[1].len < sizeof(psa_key_attributes_t)) {
414+
return PSA_ERROR_INVALID_ARGUMENT;
415+
}
408416
{
409417
psa_key_attributes_t attr = *(const psa_key_attributes_t *)in_vec[1].base;
410418
/* Fallback to volatile storage if persistent storage is unavailable. */
@@ -479,7 +487,9 @@ static psa_status_t wolfboot_crypto_dispatch(const psa_invec *in_vec,
479487
struct wolfboot_hash_slot *slot;
480488
uint32_t handle = 0;
481489
psa_status_t status;
482-
if (out_vec == NULL || out_len < 1) {
490+
if (out_vec == NULL || out_len < 1 ||
491+
out_vec[0].base == NULL ||
492+
out_vec[0].len < sizeof(uint32_t)) {
483493
return PSA_ERROR_INVALID_ARGUMENT;
484494
}
485495
slot = wolfboot_hash_alloc(&handle);
@@ -515,7 +525,9 @@ static psa_status_t wolfboot_crypto_dispatch(const psa_invec *in_vec,
515525
struct wolfboot_hash_slot *dst_slot;
516526
uint32_t handle = 0;
517527
psa_status_t status;
518-
if (out_vec == NULL || out_len < 1) {
528+
if (out_vec == NULL || out_len < 1 ||
529+
out_vec[0].base == NULL ||
530+
out_vec[0].len < sizeof(uint32_t)) {
519531
return PSA_ERROR_INVALID_ARGUMENT;
520532
}
521533
src_slot = wolfboot_hash_find(iov->op_handle);
@@ -540,7 +552,9 @@ static psa_status_t wolfboot_crypto_dispatch(const psa_invec *in_vec,
540552
struct wolfboot_hash_slot *slot;
541553
size_t hash_len = 0;
542554
psa_status_t status;
543-
if (out_vec == NULL || out_len < 2) {
555+
if (out_vec == NULL || out_len < 2 ||
556+
out_vec[0].base == NULL ||
557+
out_vec[0].len < sizeof(uint32_t)) {
544558
return PSA_ERROR_INVALID_ARGUMENT;
545559
}
546560
slot = wolfboot_hash_find(iov->op_handle);
@@ -562,7 +576,9 @@ static psa_status_t wolfboot_crypto_dispatch(const psa_invec *in_vec,
562576

563577
case ARM_TEE_CRYPTO_HASH_ABORT_SID: {
564578
struct wolfboot_hash_slot *slot;
565-
if (out_vec == NULL || out_len < 1) {
579+
if (out_vec == NULL || out_len < 1 ||
580+
out_vec[0].base == NULL ||
581+
out_vec[0].len < sizeof(uint32_t)) {
566582
return PSA_ERROR_INVALID_ARGUMENT;
567583
}
568584
slot = wolfboot_hash_find(iov->op_handle);
@@ -582,7 +598,9 @@ static psa_status_t wolfboot_crypto_dispatch(const psa_invec *in_vec,
582598
struct wolfboot_cipher_slot *slot;
583599
uint32_t handle = 0;
584600
psa_status_t status;
585-
if (out_vec == NULL || out_len < 1) {
601+
if (out_vec == NULL || out_len < 1 ||
602+
out_vec[0].base == NULL ||
603+
out_vec[0].len < sizeof(uint32_t)) {
586604
return PSA_ERROR_INVALID_ARGUMENT;
587605
}
588606
slot = wolfboot_cipher_alloc(&handle);

0 commit comments

Comments
 (0)