Closed hunkob closed 1 month ago
The fix for #4 will provide protection for writes on invalid pointers (i.e. NULL pointers and/or insufficient lengths). Protecting reads from invalid pointers adds overhead which is likely not increasing the security of the solution:
It's worth noting that TF-M Threat model does not protect against Denial-of-Service attacks and it is always possible for an NS application to maliciously generate an invalid read or write that will cause DoS, without involving the secure FW at all.
Mitigated through #4
01: Missing check of input/output vector count in crypto partition
Summary
When processing messages to the crypto partition in
tfm_crypto_api_dispatcher
, the number in input and output arguments is neither checked nor passed on to the different crypto interface functions (e.g.tfm_crypto_key_management_interface
). This leads to the access of NULL pointers while writing output values.Technical Description
Message dispatching of the crypto partition is implemented in
secure_fw/partitions/crypto/crypto_init.c
:tfm_crypto_sfn
PSA_IPC_CALL
tfm_crypto_call_srv
tfm_crypto_call_srv
in_vec
andout_vec
:in_len
is at least 1in_vec
from client memory to scratch buffer and allocates buffer forout_vec
tfm_crypto_api_dispatcher
tfm_crypto_api_dispatcher
in_len
andout_len
in_len
andout_len
is not passed to child functionin_len
andout_len
in_vec[1]..in_vec[PSA_MAX_IOVEC]
andout_vec[0]..out_vec[PSA_MAX_IOVEC]
may lead to an NULL pointer dereftfm_crypto_key_management_interface
insecure_fw/partitions/crypto/crypto_key_management.c
out_vec[0].base
:in_vec[1].base
:Proposed fix
Overhaul the argument verification and remove implicit and undocumented assumptions of available arguments:
tfm_crypto_api_dispatcher
should passin_len
andout_len
to all child functions.tfm_crypto_key_management_interface
, should verify the correctin_len
/out_len
prior to usage ofin_vec
/out_vec
and return an error iflen
is insufficient.Reproducer
Most messages with
out_len = 0
will trigger an NULL pointer deref, e.g.:This message leads to a NULL pointer deref:
0x10000848
corresponds tosecure_fw/partitions/crypto/crypto_cipher.c:78
which is an access toout_vec[0].base
.Attachments