Interface: Fix parameter mismatch between client & service
In RPC implementations of TF-M, the data model of the Client and Service
may be different. So, for C integer types with an implementation-defined
bit width, the type definition in the client library's environment may
not be equivalent to the one in the RoT Service environment.
The IPC protocols used in TF-M generally use fixed-width types to avoid
this kind of issue. However, there are a few PSA APIs that use size_t
parameters, which are then passed in iovecs.
To avoid passing parameters of an unexpected size to the service, this
change makes the definition of size_t in the RoT Service environment
visible to the client and converts parameters as required.
Change-Id: Ieb3577479ee42d4f7c7ea6189ea96d1638cbdf39
Signed-off-by: Jamie Fox <jamie.fox@arm.com>
Signed-off-by: David Vincze <david.vincze@arm.com>
diff --git a/interface/src/tfm_its_api.c b/interface/src/tfm_its_api.c
index adea920..9488bdc 100644
--- a/interface/src/tfm_its_api.c
+++ b/interface/src/tfm_its_api.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -10,6 +10,12 @@
#include "psa_manifest/sid.h"
#include "tfm_its_defs.h"
+struct rot_psa_its_storage_info_t {
+ rot_size_t capacity;
+ rot_size_t size;
+ psa_storage_create_flags_t flags;
+};
+
psa_status_t psa_its_set(psa_storage_uid_t uid,
size_t data_length,
const void *p_data,
@@ -36,16 +42,22 @@
size_t *p_data_length)
{
psa_status_t status;
+ rot_size_t data_offset_param;
psa_invec in_vec[] = {
{ .base = &uid, .len = sizeof(uid) },
- { .base = &data_offset, .len = sizeof(data_offset) }
+ { .base = &data_offset_param, .len = sizeof(data_offset_param) }
};
psa_outvec out_vec[] = {
{ .base = p_data, .len = data_size }
};
+ if (data_offset > ROT_SIZE_MAX) {
+ return PSA_ERROR_INVALID_ARGUMENT;
+ }
+ data_offset_param = (rot_size_t)data_offset;
+
if (p_data_length == NULL) {
return PSA_ERROR_INVALID_ARGUMENT;
}
@@ -62,19 +74,28 @@
struct psa_storage_info_t *p_info)
{
psa_status_t status;
+ struct rot_psa_its_storage_info_t info_param = {0};
psa_invec in_vec[] = {
{ .base = &uid, .len = sizeof(uid) }
};
psa_outvec out_vec[] = {
- { .base = p_info, .len = sizeof(*p_info) }
+ { .base = &info_param, .len = sizeof(info_param) }
};
+ if (p_info == NULL) {
+ return PSA_ERROR_INVALID_ARGUMENT;
+ }
+
status = psa_call(TFM_INTERNAL_TRUSTED_STORAGE_SERVICE_HANDLE,
TFM_ITS_GET_INFO, in_vec, IOVEC_LEN(in_vec), out_vec,
IOVEC_LEN(out_vec));
+ p_info->capacity = info_param.capacity;
+ p_info->size = info_param.size;
+ p_info->flags = info_param.flags;
+
return status;
}