Interface: Change control param to uint32_t preprocessor
Define a uint32_t preprocessor to pack control params.
Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
Change-Id: I0992620af1c39ef6dba182cac88e81cd666be0c6
diff --git a/interface/src/psa/psa_client.c b/interface/src/psa/psa_client.c
index e462063..2d92182 100644
--- a/interface/src/psa/psa_client.c
+++ b/interface/src/psa/psa_client.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -9,6 +9,7 @@
#include "tfm/tfm_core_svc.h"
#include "psa/client.h"
#include "tfm_api.h"
+#include "tfm_psa_call_param.h"
__attribute__((naked))
uint32_t psa_framework_version(void)
@@ -36,8 +37,9 @@
__attribute__((naked))
static psa_status_t psa_call_param_pack(psa_handle_t handle,
- struct tfm_control_parameter_t *ctrl_param,
- const psa_invec *in_vec, psa_outvec *out_vec)
+ uint32_t ctrl_param,
+ const psa_invec *in_vec,
+ psa_outvec *out_vec)
{
__ASM volatile("SVC %0 \n"
"BX LR \n"
@@ -51,12 +53,18 @@
psa_outvec *out_vec,
size_t out_len)
{
- struct tfm_control_parameter_t ctrl_param;
- ctrl_param.type = type;
- ctrl_param.in_len = in_len;
- ctrl_param.out_len = out_len;
+ if ((type > INT16_MAX) ||
+ (type < INT16_MIN) ||
+ (in_len > PSA_MAX_IOVEC) ||
+ (out_len > PSA_MAX_IOVEC) ||
+ ((in_len + out_len) > PSA_MAX_IOVEC)) {
+ return PSA_ERROR_INVALID_ARGUMENT;
+ }
- return psa_call_param_pack(handle, &ctrl_param, in_vec, out_vec);
+ return psa_call_param_pack(handle,
+ PARAM_PACK(type, in_len, out_len),
+ in_vec,
+ out_vec);
}
__attribute__((naked))
diff --git a/interface/src/tfm_psa_ns_api.c b/interface/src/tfm_psa_ns_api.c
index 9a677a2..9d60a11 100644
--- a/interface/src/tfm_psa_ns_api.c
+++ b/interface/src/tfm_psa_ns_api.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -8,6 +8,7 @@
#include "psa/client.h"
#include "tfm_ns_interface.h"
#include "tfm_api.h"
+#include "tfm_psa_call_param.h"
/**** API functions ****/
@@ -47,23 +48,18 @@
psa_outvec *out_vec,
size_t out_len)
{
- /* FixMe: sanity check can be added to offload some NS thread checks from
- * TFM secure API
- */
-
- /* Due to v8M restrictions, TF-M NS API needs to add another layer of
- * serialization in order for NS to pass arguments to S
- */
- const struct tfm_control_parameter_t ctrl_param = {
- .type = type,
- .in_len = in_len,
- .out_len = out_len,
- };
+ if ((type > INT16_MAX) ||
+ (type < INT16_MIN) ||
+ (in_len > PSA_MAX_IOVEC) ||
+ (out_len > PSA_MAX_IOVEC) ||
+ ((in_len + out_len) > PSA_MAX_IOVEC)) {
+ return PSA_ERROR_INVALID_ARGUMENT;
+ }
return tfm_ns_interface_dispatch(
(veneer_fn)tfm_psa_call_veneer,
(uint32_t)handle,
- (uint32_t)&ctrl_param,
+ PARAM_PACK(type, in_len, out_len),
(uint32_t)in_vec,
(uint32_t)out_vec);
}