aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMingyang Sun <mingyang.sun@arm.com>2021-03-30 18:34:40 +0800
committerKen Liu <ken.liu@arm.com>2021-04-16 10:56:02 +0200
commite8d380874e87714acca9afef3e6d31ab724c9c0c (patch)
tree9d77ce68da138bb633d975af39da64e83d5458b0
parentc46ee1f4be567c0dbdb9dc74ed746586bdcbcf68 (diff)
downloadtrusted-firmware-m-e8d380874e87714acca9afef3e6d31ab724c9c0c.tar.gz
SPM: Optimize static handle check macro
Sometimes program only needs to check if the handle is static. So, the IS_VALID_STATIC_HANDLE() macro can be split into two different macros: - Check if the handle is static. - Check if the index information in static handle is valid. Change-Id: I8975055bdf30e92056480fed98d2986c826b4077 Signed-off-by: Mingyang Sun <mingyang.sun@arm.com>
-rw-r--r--secure_fw/spm/cmsis_psa/spm_ipc.h14
-rw-r--r--secure_fw/spm/ffm/spm_psa_client_call.c9
2 files changed, 14 insertions, 9 deletions
diff --git a/secure_fw/spm/cmsis_psa/spm_ipc.h b/secure_fw/spm/cmsis_psa/spm_ipc.h
index dc0fd1f0a..d83b7db1e 100644
--- a/secure_fw/spm/cmsis_psa/spm_ipc.h
+++ b/secure_fw/spm/cmsis_psa/spm_ipc.h
@@ -49,14 +49,14 @@
#define GET_VERSION_FROM_STATIC_HANDLE(handle) \
(uint32_t)(((handle) >> STAIC_HANDLE_VER_OFFSET) & STAIC_HANDLE_VER_MASK)
+/* Validate the static handle indicator bit */
#define STAIC_HANDLE_INDICATOR_OFFSET 30
-/*
- * A valid static handle must have indicator bit set, have a positive index,
- * 1 <= index <= STATIC_HANDLE_NUM_LIMIT.
- */
-#define IS_VALID_STATIC_HANDLE(handle) \
- (((handle) & (1UL << STAIC_HANDLE_INDICATOR_OFFSET)) && \
- (GET_INDEX_FROM_STATIC_HANDLE(handle) < STATIC_HANDLE_NUM_LIMIT))
+#define IS_STATIC_HANDLE(handle) \
+ ((handle) & (1UL << STAIC_HANDLE_INDICATOR_OFFSET))
+
+/* Valid index should be [0, STATIC_HANDLE_NUM_LIMIT-1] */
+#define IS_VALID_STATIC_HANDLE_IDX(index) \
+ (((index) >= 0) && ((index) < STATIC_HANDLE_NUM_LIMIT))
#define SPM_INVALID_PARTITION_IDX (~0U)
diff --git a/secure_fw/spm/ffm/spm_psa_client_call.c b/secure_fw/spm/ffm/spm_psa_client_call.c
index 28f5987df..7e186e4a2 100644
--- a/secure_fw/spm/ffm/spm_psa_client_call.c
+++ b/secure_fw/spm/ffm/spm_psa_client_call.c
@@ -151,8 +151,13 @@ psa_status_t tfm_spm_client_psa_call(psa_handle_t handle, int32_t type,
}
/* Allocate space from handle pool for static handle. */
- if (IS_VALID_STATIC_HANDLE(handle)) {
+ if (IS_STATIC_HANDLE(handle)) {
index = GET_INDEX_FROM_STATIC_HANDLE(handle);
+
+ if (!IS_VALID_STATIC_HANDLE_IDX(index)) {
+ TFM_PROGRAMMER_ERROR(ns_caller, PSA_ERROR_PROGRAMMER_ERROR);
+ }
+
service = GET_STATELESS_SERVICE(index);
sid = GET_STATELESS_SID(index);
@@ -312,7 +317,7 @@ void tfm_spm_client_psa_close(psa_handle_t handle, bool ns_caller)
}
/* It is a PROGRAMMER ERROR if called with a stateless handle. */
- if (IS_VALID_STATIC_HANDLE(handle)) {
+ if (IS_STATIC_HANDLE(handle)) {
TFM_PROGRAMMER_ERROR(ns_caller, PROGRAMMER_ERROR_NULL);
}