TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
psa_its_s_interface_testsuite.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include "its_s_tests.h"
10 #include "test_framework_helpers.h"
12 #include "../its_tests_common.h"
13 #include "tfm_memory_utils.h"
14 
15 /* UID to test partition access control */
16 #define TEST_UID_ACCESS_CONTROL 42U
17 
18 /* List of tests */
19 static void tfm_its_test_2020(struct test_result_t *ret);
20 static void tfm_its_test_2021(struct test_result_t *ret);
21 static void tfm_its_test_2022(struct test_result_t *ret);
22 static void tfm_its_test_2023(struct test_result_t *ret);
23 
24 static struct test_t psa_its_s_tests[] = {
25  {&tfm_its_test_common_001, "TFM_ITS_TEST_2001",
26  "Set interface"},
27  {&tfm_its_test_common_002, "TFM_ITS_TEST_2002",
28  "Set interface with create flags"},
29  {&tfm_its_test_common_003, "TFM_ITS_TEST_2003",
30  "Set interface with NULL data pointer"},
31  {&tfm_its_test_common_004, "TFM_ITS_TEST_2004",
32  "Set interface with write once UID"},
33  {&tfm_its_test_common_005, "TFM_ITS_TEST_2005",
34  "Get interface with valid data"},
35  {&tfm_its_test_common_006, "TFM_ITS_TEST_2006",
36  "Get interface with zero data length"},
37  {&tfm_its_test_common_007, "TFM_ITS_TEST_2007",
38  "Get interface with invalid UIDs"},
39  {&tfm_its_test_common_008, "TFM_ITS_TEST_2008",
40  "Get interface with data lengths and offsets greater than UID length"},
41  {&tfm_its_test_common_009, "TFM_ITS_TEST_2009",
42  "Get interface with NULL data pointer"},
43  {&tfm_its_test_common_010, "TFM_ITS_TEST_2010",
44  "Get info interface with write once UID"},
45  {&tfm_its_test_common_011, "TFM_ITS_TEST_2011",
46  "Get info interface with valid UID"},
47  {&tfm_its_test_common_012, "TFM_ITS_TEST_2012",
48  "Get info interface with invalid UIDs"},
49  {&tfm_its_test_common_013, "TFM_ITS_TEST_2013",
50  "Remove interface with valid UID"},
51  {&tfm_its_test_common_014, "TFM_ITS_TEST_2014",
52  "Remove interface with write once UID"},
53  {&tfm_its_test_common_015, "TFM_ITS_TEST_2015",
54  "Remove interface with invalid UID"},
55  {&tfm_its_test_common_016, "TFM_ITS_TEST_2016",
56  "Block compaction after remove"},
57  {&tfm_its_test_common_017, "TFM_ITS_TEST_2017",
58  "Multiple partial gets"},
59  {&tfm_its_test_common_018, "TFM_ITS_TEST_2018",
60  "Multiple sets to same UID from same thread"},
61  {&tfm_its_test_common_019, "TFM_ITS_TEST_2019",
62  "Set, get and remove interface with different asset sizes"},
63  {&tfm_its_test_2020, "TFM_ITS_TEST_2020",
64  "Set interface with invalid data length"},
65  {&tfm_its_test_2021, "TFM_ITS_TEST_2021",
66  "Get interface with invalid data lengths and offsets"},
67  {&tfm_its_test_2022, "TFM_ITS_TEST_2022",
68  "Get info interface with NULL info pointer"},
69  {&tfm_its_test_2023, "TFM_ITS_TEST_2023",
70  "Attempt to get a UID set by a different partition"},
71 };
72 
74 {
75  uint32_t list_size;
76 
77  list_size = (sizeof(psa_its_s_tests) / sizeof(psa_its_s_tests[0]));
78 
79  set_testsuite("PSA internal trusted storage S interface tests "
80  "(TFM_ITS_TEST_2XXX)",
81  psa_its_s_tests, list_size, p_test_suite);
82 }
83 
90 static void tfm_its_test_2020(struct test_result_t *ret)
91 {
92 #ifndef TFM_PSA_API
93  psa_status_t status;
94  const psa_storage_uid_t uid = TEST_UID_1;
96  const size_t data_len = INVALID_DATA_LEN;
97  const uint8_t write_data[] = WRITE_DATA;
98 
99  /* A parameter with a buffer pointer where its data length is longer than
100  * maximum permitted, it is treated as a secure violation.
101  * TF-M framework rejects the request with a proper error code.
102  * The ITS secure PSA implementation returns
103  * PSA_ERROR_INVALID_ARGUMENT in that case.
104  */
105 
106  /* Set with data length longer than the maximum supported */
107  status = psa_its_set(uid, data_len, write_data, flags);
108  if (status != PSA_ERROR_INVALID_ARGUMENT) {
109  TEST_FAIL("Set should not succeed with invalid data length");
110  return;
111  }
112 
113 #endif
114  ret->val = TEST_PASSED;
115 }
116 
124 static void tfm_its_test_2021(struct test_result_t *ret)
125 {
126 #ifndef TFM_PSA_API
127  psa_status_t status;
128  const psa_storage_uid_t uid = TEST_UID_2;
130  const size_t write_len = WRITE_DATA_SIZE;
131  size_t read_len;
132  size_t offset;
133  const uint8_t write_data[] = WRITE_DATA;
134  uint8_t read_data[] = READ_DATA;
135  size_t read_data_length = 0;
136 
137  status = psa_its_set(uid, write_len, write_data, flags);
138  if (status != PSA_SUCCESS) {
139  TEST_FAIL("Set should not fail");
140  return;
141  }
142 
143  /* Get with data length and offset set to invalid values */
144  read_len = INVALID_DATA_LEN;
145  offset = INVALID_OFFSET;
146 
147  /* A parameter with a buffer pointer where its data length is longer than
148  * maximum permitted, it is treated as a secure violation.
149  * TF-M framework rejects the request with a proper error code.
150  * The ITS secure PSA implementation returns
151  * PSA_ERROR_INVALID_ARGUMENT in that case.
152  */
153 
154  status = psa_its_get(uid, offset, read_len, read_data + HALF_PADDING_SIZE,
155  &read_data_length);
156  if (status != PSA_ERROR_INVALID_ARGUMENT) {
157  TEST_FAIL("Get should not succeed with invalid arguments");
158  return;
159  }
160 
161  /* Check that the read data is unchanged */
162  if (tfm_memcmp(read_data, READ_DATA, sizeof(read_data)) != 0) {
163  TEST_FAIL("Read data should be equal to original read data");
164  return;
165  }
166 
167  read_len = 1;
168  offset = 0;
169 
170  status = psa_its_get(uid, offset, read_len, read_data + HALF_PADDING_SIZE,
171  NULL);
172  if (status != PSA_ERROR_INVALID_ARGUMENT) {
173  TEST_FAIL("Get should not succeed with invalid arguments");
174  return;
175  }
176 
177  /* Check that the read data is unchanged */
178  if (tfm_memcmp(read_data, READ_DATA, sizeof(read_data)) != 0) {
179  TEST_FAIL("Read data should be equal to original read data");
180  return;
181  }
182 
183  /* Call remove to clean up storage for the next test */
184  status = psa_its_remove(uid);
185  if (status != PSA_SUCCESS) {
186  TEST_FAIL("Remove should not fail with valid UID");
187  return;
188  }
189 
190 #endif
191  ret->val = TEST_PASSED;
192 }
193 
200 static void tfm_its_test_2022(struct test_result_t *ret)
201 {
202  psa_status_t status;
203  const psa_storage_uid_t uid = TEST_UID_3;
205  const size_t data_len = WRITE_DATA_SIZE;
206  const uint8_t write_data[] = WRITE_DATA;
207 
208  status = psa_its_set(uid, data_len, write_data, flags);
209  if (status != PSA_SUCCESS) {
210  TEST_FAIL("Set should not fail");
211  return;
212  }
213 
214  /* A parameter with a null pointer is treated as a secure violation.
215  * TF-M framework rejects the request with a proper error code.
216  * The secure PSA ITS implementation returns
217  * PSA_ERROR_INVALID_ARGUMENT in that case.
218  */
219 
220  /* Get info with NULL info pointer */
221 #ifndef TFM_PSA_API
222  status = psa_its_get_info(uid, NULL);
223  if (status != PSA_ERROR_INVALID_ARGUMENT) {
224  TEST_FAIL("Get info should not succeed with NULL info pointer");
225  return;
226  }
227 #endif
228 
229  /* Call remove to clean up storage for the next test */
230  status = psa_its_remove(uid);
231  if (status != PSA_SUCCESS) {
232  TEST_FAIL("Remove should not fail with valid UID");
233  return;
234  }
235 
236  ret->val = TEST_PASSED;
237 }
238 
244 static void tfm_its_test_2023(struct test_result_t *ret)
245 {
246  psa_status_t status;
248 
249  /* Set the UID from this partition's context */
250  status = psa_its_set(uid, WRITE_DATA_SIZE, WRITE_DATA,
252  if (status != PSA_SUCCESS) {
253  TEST_FAIL("Set should not fail");
254  return;
255  }
256 
257  /* Attempt to get the UID from the Secure Client 2 partition */
260  &uid, sizeof(uid));
261  if (status != PSA_ERROR_DOES_NOT_EXIST) {
262  TEST_FAIL("Get should not succeed from a different partition");
263  return;
264  }
265 
266  /* Call remove to clean up storage for the next test */
267  status = psa_its_remove(uid);
268  if (status != PSA_SUCCESS) {
269  TEST_FAIL("Remove should not fail with valid UID");
270  return;
271  }
272 
273  ret->val = TEST_PASSED;
274 }
void tfm_its_test_common_019(struct test_result_t *ret)
Tests set, get_info, get and remove function with:
#define INVALID_OFFSET
#define TEST_UID_2
psa_status_t tfm_secure_client_2_call_test(int32_t id, const void *arg, size_t arg_len)
Calls the test function with the supplied ID within the execution context of the Secure Client 2 part...
#define PSA_SUCCESS
Definition: crypto_values.h:35
#define TEST_FAIL(info_msg)
#define TEST_UID_3
void tfm_its_test_common_016(struct test_result_t *ret)
Tests data block compact feature. Set UID 1 to locate it at the beginning of the block. Then set UID 2 to be located after UID 1 and remove UID 1. UID 2 will be compacted to the beginning of the block. This test verifies that the compaction works correctly by reading back UID 2.
void tfm_its_test_common_007(struct test_result_t *ret)
Tests get function with:
void tfm_its_test_common_012(struct test_result_t *ret)
Tests get info function with:
void tfm_its_test_common_010(struct test_result_t *ret)
Tests get info function with:
enum test_suite_err_t set_testsuite(const char *name, struct test_t *test_list, uint32_t size, struct test_suite_t *p_ts)
Sets test suite parameters.
void tfm_its_test_common_002(struct test_result_t *ret)
Tests set function with:
void tfm_its_test_common_017(struct test_result_t *ret)
Tests set and multiple partial gets.
psa_status_t psa_its_get_info(psa_storage_uid_t uid, struct psa_storage_info_t *p_info)
Retrieve the metadata about the provided uid.
void tfm_its_test_common_011(struct test_result_t *ret)
Tests get info function with:
void register_testsuite_s_psa_its_interface(struct test_suite_t *p_test_suite)
Register testsuite for the PSA internal trusted storage S interface tests.
#define READ_DATA
psa_status_t psa_its_get(psa_storage_uid_t uid, size_t data_offset, size_t data_size, void *p_data, size_t *p_data_length)
Retrieve data associated with a provided UID.
void tfm_its_test_common_008(struct test_result_t *ret)
Tests get function with:
psa_status_t psa_its_remove(psa_storage_uid_t uid)
Remove the provided uid and its associated data from the storage.
void tfm_its_test_common_005(struct test_result_t *ret)
Tests get function with:
void tfm_its_test_common_004(struct test_result_t *ret)
Tests set function with:
#define PSA_ERROR_INVALID_ARGUMENT
#define WRITE_DATA
psa_status_t psa_its_set(psa_storage_uid_t uid, size_t data_length, const void *p_data, psa_storage_create_flags_t create_flags)
Create a new, or modify an existing, uid/value pair.
#define INVALID_DATA_LEN
struct test_result_t ret
void tfm_its_test_common_001(struct test_result_t *ret)
Tests set function with:
#define HALF_PADDING_SIZE
void tfm_its_test_common_015(struct test_result_t *ret)
Tests remove function with:
uint64_t psa_storage_uid_t
void tfm_its_test_common_003(struct test_result_t *ret)
Tests set function with:
enum test_status_t val
void tfm_its_test_common_013(struct test_result_t *ret)
Tests remove function with:
__STATIC_INLINE int tfm_memcmp(const void *ptr1, const void *ptr2, size_t num)
#define PSA_STORAGE_FLAG_NONE
#define WRITE_DATA_SIZE
void tfm_its_test_common_018(struct test_result_t *ret)
Tests multiple sets to the same UID.
#define PSA_ERROR_DOES_NOT_EXIST
Definition: crypto_values.h:89
uint32_t psa_storage_create_flags_t
#define TEST_UID_ACCESS_CONTROL
void tfm_its_test_common_009(struct test_result_t *ret)
Tests get function with:
#define TFM_SECURE_CLIENT_2_ID_ITS_ACCESS_CTRL
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:43
void tfm_its_test_common_014(struct test_result_t *ret)
Tests remove function with:
#define TEST_UID_1
void tfm_its_test_common_006(struct test_result_t *ret)
Tests get function with: