blob: 38ccc931ceca2a2bc76223a3480a3cb42f9a58bf [file] [log] [blame]
Pascal Brandc639ac82015-07-02 08:53:34 +02001/*
Javier Almansa Sobrinocddc0002020-02-10 13:35:37 +00002 * Copyright (c) 2020, ARM Limited. All rights reserved.
Pascal Brandc639ac82015-07-02 08:53:34 +02003 * Copyright (c) 2014, STMicroelectronics International N.V.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License Version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
Etienne Carrierea4653552017-01-11 10:04:24 +010015#include <limits.h>
16#include <pthread.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020017#include <stdio.h>
Jens Wiklanderec545fb2017-11-24 16:58:07 +010018#include <stdlib.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020019#include <string.h>
David Brownb2865ab2016-08-02 11:44:41 -060020#include <sys/stat.h>
21#include <sys/types.h>
Etienne Carrierea4653552017-01-11 10:04:24 +010022#include <unistd.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020023
24#include "xtest_test.h"
25#include "xtest_helpers.h"
Jens Wiklander4441fe22015-10-23 16:53:02 +020026#include <signed_hdr.h>
Etienne Carriere92c34422018-02-09 13:11:40 +010027#include <util.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020028
Etienne Carriere726d8bc2017-03-21 15:45:59 +010029#include <pta_invoke_tests.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020030#include <ta_crypt.h>
31#include <ta_os_test.h>
32#include <ta_create_fail_test.h>
33#include <ta_rpc_test.h>
34#include <ta_sims_test.h>
Ovidiu Mihalachi15cecff2019-04-02 16:36:31 +030035#include <ta_miss_test.h>
36#include <ta_sims_keepalive_test.h>
Jens Wiklanderac27ec12015-07-15 15:23:14 +020037#include <ta_concurrent.h>
Javier Almansa Sobrinocddc0002020-02-10 13:35:37 +000038#include <ta_tpm_log_test.h>
Etienne Carriere50abf9a2017-03-24 11:33:50 +010039#include <sdp_basic.h>
Jens Wiklanderec545fb2017-11-24 16:58:07 +010040#include <pta_secstor_ta_mgmt.h>
Jens Wiklanderec545fb2017-11-24 16:58:07 +010041
42#ifndef MIN
43#define MIN(a, b) ((a) < (b) ? (a) : (b))
44#endif
Pascal Brandc639ac82015-07-02 08:53:34 +020045
Pascal Brandc639ac82015-07-02 08:53:34 +020046struct xtest_crypto_session {
47 ADBG_Case_t *c;
48 TEEC_Session *session;
49 uint32_t cmd_id_sha256;
50 uint32_t cmd_id_aes256ecb_encrypt;
51 uint32_t cmd_id_aes256ecb_decrypt;
52};
53
54static void xtest_crypto_test(struct xtest_crypto_session *cs)
55{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +010056 uint32_t ret_orig = 0;
57 uint8_t crypt_out[16] = { };
Pascal Brandc639ac82015-07-02 08:53:34 +020058 uint8_t crypt_in[16] = { 22, 17 };
59
60 crypt_in[15] = 60;
61
62 Do_ADBG_BeginSubCase(cs->c, "AES encrypt");
63 {
64 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
65
66 op.params[0].tmpref.buffer = crypt_in;
67 op.params[0].tmpref.size = sizeof(crypt_in);
68 op.params[1].tmpref.buffer = crypt_out;
69 op.params[1].tmpref.size = sizeof(crypt_out);
70 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
71 TEEC_MEMREF_TEMP_OUTPUT,
72 TEEC_NONE, TEEC_NONE);
73
74 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
75 TEEC_InvokeCommand(cs->session,
76 cs->
77 cmd_id_aes256ecb_encrypt,
78 &op,
79 &ret_orig));
80 }
81 Do_ADBG_EndSubCase(cs->c, "AES encrypt");
82
83 Do_ADBG_BeginSubCase(cs->c, "AES decrypt");
84 {
85 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +010086 uint8_t out[16] = { };
Pascal Brandc639ac82015-07-02 08:53:34 +020087
88 op.params[0].tmpref.buffer = crypt_out;
89 op.params[0].tmpref.size = sizeof(crypt_out);
90 op.params[1].tmpref.buffer = out;
91 op.params[1].tmpref.size = sizeof(out);
92 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
93 TEEC_MEMREF_TEMP_OUTPUT,
94 TEEC_NONE, TEEC_NONE);
95
96 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
97 TEEC_InvokeCommand(cs->session,
98 cs->
99 cmd_id_aes256ecb_decrypt,
100 &op,
101 &ret_orig));
102
103 if (!ADBG_EXPECT(cs->c, 0,
104 memcmp(crypt_in, out, sizeof(crypt_in)))) {
105 Do_ADBG_Log("crypt_in:");
106 Do_ADBG_HexLog(crypt_in, sizeof(crypt_in), 16);
107 Do_ADBG_Log("out:");
108 Do_ADBG_HexLog(out, sizeof(out), 16);
109 }
110 }
111 Do_ADBG_EndSubCase(cs->c, "AES decrypt");
112
113 Do_ADBG_BeginSubCase(cs->c, "SHA-256 test, 3 bytes input");
114 {
115 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
116 static const uint8_t sha256_in[] = { 'a', 'b', 'c' };
117 static const uint8_t sha256_out[] = {
118 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
119 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
120 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
121 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
122 };
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100123 uint8_t out[32] = { };
Pascal Brandc639ac82015-07-02 08:53:34 +0200124
125 op.params[0].tmpref.buffer = (void *)sha256_in;
126 op.params[0].tmpref.size = sizeof(sha256_in);
127 op.params[1].tmpref.buffer = out;
128 op.params[1].tmpref.size = sizeof(out);
129 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
130 TEEC_MEMREF_TEMP_OUTPUT,
131 TEEC_NONE, TEEC_NONE);
132
133 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
134 TEEC_InvokeCommand(cs->session,
135 cs->
136 cmd_id_sha256,
137 &op,
138 &ret_orig));
139
140 if (!ADBG_EXPECT(cs->c, 0, memcmp(sha256_out, out,
141 sizeof(sha256_out)))) {
142 Do_ADBG_Log("sha256_out:");
143 Do_ADBG_HexLog(sha256_out, sizeof(sha256_out), 16);
144 Do_ADBG_Log("out:");
145 Do_ADBG_HexLog(out, sizeof(out), 16);
146 }
147 }
148 Do_ADBG_EndSubCase(cs->c, "SHA-256 test, 3 bytes input");
149
Etienne Carrierea3198522017-10-26 09:48:55 +0200150 Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200151 {
152 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
153 static const uint8_t in[] = {
154 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
155 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
156 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
157 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
158 };
159 static const uint8_t exp_out[] = {
160 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
161 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
162 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
163 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
164 };
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100165 uint8_t out[sizeof(exp_out)] = { };
Pascal Brandc639ac82015-07-02 08:53:34 +0200166
167 op.params[0].tmpref.buffer = (void *)in;
168 op.params[0].tmpref.size = sizeof(in);
169 op.params[1].tmpref.buffer = out;
170 op.params[1].tmpref.size = sizeof(out);
171 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
172 TEEC_MEMREF_TEMP_OUTPUT,
173 TEEC_NONE, TEEC_NONE);
174
175 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
176 TEEC_InvokeCommand(cs->session,
177 cs->
178 cmd_id_aes256ecb_encrypt,
179 &op,
180 &ret_orig));
181
182 if (!ADBG_EXPECT(cs->c, 0,
183 memcmp(exp_out, out, sizeof(exp_out)))) {
184 Do_ADBG_Log("exp_out:");
185 Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16);
186 Do_ADBG_Log("out:");
187 Do_ADBG_HexLog(out, sizeof(out), 16);
188 }
189 }
Etienne Carrierea3198522017-10-26 09:48:55 +0200190 Do_ADBG_EndSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200191
Etienne Carrierea3198522017-10-26 09:48:55 +0200192 Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200193 {
194 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
195 static const uint8_t in[] = {
196 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
197 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
198 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
199 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
200 };
201 static const uint8_t exp_out[] = {
202 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
203 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
204 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
205 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
206 };
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100207 uint8_t out[sizeof(exp_out)] = { };
Pascal Brandc639ac82015-07-02 08:53:34 +0200208
209 op.params[0].tmpref.buffer = (void *)in;
210 op.params[0].tmpref.size = sizeof(in);
211 op.params[1].tmpref.buffer = out;
212 op.params[1].tmpref.size = sizeof(out);
213 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
214 TEEC_MEMREF_TEMP_OUTPUT,
215 TEEC_NONE, TEEC_NONE);
216
217 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
218 TEEC_InvokeCommand(cs->session,
219 cs->
220 cmd_id_aes256ecb_decrypt,
221 &op,
222 &ret_orig));
223
224 if (!ADBG_EXPECT(cs->c, 0,
225 memcmp(exp_out, out, sizeof(exp_out)))) {
226 Do_ADBG_Log("exp_out:");
227 Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16);
228 Do_ADBG_Log("out:");
229 Do_ADBG_HexLog(out, sizeof(out), 16);
230 }
231 }
Etienne Carrierea3198522017-10-26 09:48:55 +0200232 Do_ADBG_EndSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200233}
234
235static void xtest_tee_test_1001(ADBG_Case_t *c)
236{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100237 TEEC_Result res = TEEC_ERROR_GENERIC;
238 TEEC_Session session = { };
239 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200240
Etienne Carriere11093162017-10-26 09:49:04 +0200241 /* Pseudo TA is optional: warn and nicely exit if not found */
Etienne Carriere726d8bc2017-03-21 15:45:59 +0100242 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
Jens Wiklandercf16e842016-02-10 09:07:09 +0100243 &ret_orig);
Etienne Carriere11093162017-10-26 09:49:04 +0200244 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
245 Do_ADBG_Log(" - 1001 - skip test, pseudo TA not found");
Jens Wiklandercf16e842016-02-10 09:07:09 +0100246 return;
Etienne Carriere11093162017-10-26 09:49:04 +0200247 }
248 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Pascal Brandc639ac82015-07-02 08:53:34 +0200249
Jens Wiklandercf16e842016-02-10 09:07:09 +0100250 (void)ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(
Etienne Carriere726d8bc2017-03-21 15:45:59 +0100251 &session, PTA_INVOKE_TESTS_CMD_SELF_TESTS, NULL, &ret_orig));
Jens Wiklandercf16e842016-02-10 09:07:09 +0100252 TEEC_CloseSession(&session);
Pascal Brandc639ac82015-07-02 08:53:34 +0200253}
Jens Wiklander14f48872018-06-29 15:30:13 +0200254ADBG_CASE_DEFINE(regression, 1001, xtest_tee_test_1001, "Core self tests");
Pascal Brandc639ac82015-07-02 08:53:34 +0200255
Jens Wiklander1d70a112017-10-16 15:16:39 +0200256static void xtest_tee_test_1002(ADBG_Case_t *c)
257{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100258 TEEC_Result res = TEEC_ERROR_GENERIC;
259 TEEC_Session session = { };
Jens Wiklander1d70a112017-10-16 15:16:39 +0200260 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100261 uint32_t ret_orig = 0;
262 uint8_t buf[16 * 1024] = { };
Jens Wiklander1d70a112017-10-16 15:16:39 +0200263 uint8_t exp_sum = 0;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100264 size_t n = 0;
Jens Wiklander1d70a112017-10-16 15:16:39 +0200265
Etienne Carriere11093162017-10-26 09:49:04 +0200266 /* Pseudo TA is optional: warn and nicely exit if not found */
Jens Wiklander1d70a112017-10-16 15:16:39 +0200267 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
268 &ret_orig);
Etienne Carriere11093162017-10-26 09:49:04 +0200269 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
270 Do_ADBG_Log(" - 1002 - skip test, pseudo TA not found");
Jens Wiklander1d70a112017-10-16 15:16:39 +0200271 return;
Etienne Carriere11093162017-10-26 09:49:04 +0200272 }
273 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Jens Wiklander1d70a112017-10-16 15:16:39 +0200274
275 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE,
276 TEEC_NONE, TEEC_NONE);
277 op.params[0].tmpref.size = sizeof(buf);
278 op.params[0].tmpref.buffer = buf;
279
280 for (n = 0; n < sizeof(buf); n++)
281 buf[n] = n + 1;
282 for (n = 0; n < sizeof(buf); n++)
283 exp_sum += buf[n];
284
285 if (!ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(
286 &session, PTA_INVOKE_TESTS_CMD_PARAMS, &op, &ret_orig)))
287 goto out;
288
289 ADBG_EXPECT_COMPARE_SIGNED(c, exp_sum, ==, buf[0]);
290out:
291 TEEC_CloseSession(&session);
292}
Jens Wiklander14f48872018-06-29 15:30:13 +0200293ADBG_CASE_DEFINE(regression, 1002, xtest_tee_test_1002, "PTA parameters");
Jens Wiklander1d70a112017-10-16 15:16:39 +0200294
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100295struct test_1003_arg {
296 uint32_t test_type;
297 size_t repeat;
298 size_t max_before_lockers;
299 size_t max_during_lockers;
300 size_t before_lockers;
301 size_t during_lockers;
302 TEEC_Result res;
303 uint32_t error_orig;
304};
Jens Wiklander1d70a112017-10-16 15:16:39 +0200305
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100306static void *test_1003_thread(void *arg)
307{
308 struct test_1003_arg *a = arg;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100309 TEEC_Session session = { };
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100310 size_t rounds = 64 * 1024;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100311 size_t n = 0;
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100312
313 a->res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid,
314 NULL, &a->error_orig);
315 if (a->res != TEEC_SUCCESS)
316 return NULL;
317
318 for (n = 0; n < a->repeat; n++) {
319 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
320
321 op.params[0].value.a = a->test_type;
322 op.params[0].value.b = rounds;
323
324 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
325 TEEC_VALUE_OUTPUT,
326 TEEC_NONE, TEEC_NONE);
327 a->res = TEEC_InvokeCommand(&session,
328 PTA_INVOKE_TESTS_CMD_MUTEX,
329 &op, &a->error_orig);
330 if (a->test_type == PTA_MUTEX_TEST_WRITER &&
331 op.params[1].value.b != 1) {
332 Do_ADBG_Log("n %zu %" PRIu32, n, op.params[1].value.b);
333 a->res = TEEC_ERROR_BAD_STATE;
334 a->error_orig = 42;
335 break;
336 }
337
338 if (a->test_type == PTA_MUTEX_TEST_READER) {
339 if (op.params[1].value.a > a->max_before_lockers)
340 a->max_before_lockers = op.params[1].value.a;
341
342 if (op.params[1].value.b > a->max_during_lockers)
343 a->max_during_lockers = op.params[1].value.b;
344
345 a->before_lockers += op.params[1].value.a;
346 a->during_lockers += op.params[1].value.b;
347 }
348 }
349 TEEC_CloseSession(&session);
350
351 return NULL;
352}
353
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100354#define TEST_1003_THREAD_COUNT (3 * 2)
355
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100356static void xtest_tee_test_1003(ADBG_Case_t *c)
357{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100358 TEEC_Result res = TEEC_ERROR_GENERIC;
359 TEEC_Session session = { };
360 uint32_t ret_orig = 0;
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100361 size_t repeat = 20;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100362 struct test_1003_arg arg[TEST_1003_THREAD_COUNT] = { };
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100363 size_t max_read_concurrency = 0;
364 size_t max_read_waiters = 0;
365 size_t num_concurrent_read_lockers = 0;
366 size_t num_concurrent_read_waiters = 0;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100367 size_t n = 0;
368 size_t nt = TEST_1003_THREAD_COUNT;
369 double mean_read_concurrency = 0;
370 double mean_read_waiters = 0;
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100371 size_t num_writers = 0;
372 size_t num_readers = 0;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100373 pthread_t thr[TEST_1003_THREAD_COUNT] = { };
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100374
375 /* Pseudo TA is optional: warn and nicely exit if not found */
376 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
377 &ret_orig);
378 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
379 Do_ADBG_Log(" - 1003 - skip test, pseudo TA not found");
380 return;
381 }
382 ADBG_EXPECT_TEEC_SUCCESS(c, res);
383 TEEC_CloseSession(&session);
384
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100385 for (n = 0; n < nt; n++) {
386 if (n % 3) {
387 arg[n].test_type = PTA_MUTEX_TEST_READER;
388 num_readers++;
389 } else {
390 arg[n].test_type = PTA_MUTEX_TEST_WRITER;
391 num_writers++;
392 }
393 arg[n].repeat = repeat;
394 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
395 test_1003_thread, arg + n)))
396 nt = n; /* break loop and start cleanup */
397 }
398
399 for (n = 0; n < nt; n++) {
400 ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL));
401 if (!ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res))
402 Do_ADBG_Log("error origin %" PRIu32,
403 arg[n].error_orig);
404 if (arg[n].test_type == PTA_MUTEX_TEST_READER) {
405 if (arg[n].max_during_lockers > max_read_concurrency)
406 max_read_concurrency =
407 arg[n].max_during_lockers;
408
409 if (arg[n].max_before_lockers > max_read_waiters)
410 max_read_waiters = arg[n].max_before_lockers;
411
412 num_concurrent_read_lockers += arg[n].during_lockers;
413 num_concurrent_read_waiters += arg[n].before_lockers;
414 }
415 }
416
417 mean_read_concurrency = (double)num_concurrent_read_lockers /
418 (double)(repeat * num_readers);
419 mean_read_waiters = (double)num_concurrent_read_waiters /
420 (double)(repeat * num_readers);
421
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100422 Do_ADBG_Log(" Number of parallel threads: %d (%zu writers and %zu readers)",
423 TEST_1003_THREAD_COUNT, num_writers, num_readers);
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100424 Do_ADBG_Log(" Max read concurrency: %zu", max_read_concurrency);
425 Do_ADBG_Log(" Max read waiters: %zu", max_read_waiters);
426 Do_ADBG_Log(" Mean read concurrency: %g", mean_read_concurrency);
427 Do_ADBG_Log(" Mean read waiting: %g", mean_read_waiters);
428}
Jens Wiklander14f48872018-06-29 15:30:13 +0200429ADBG_CASE_DEFINE(regression, 1003, xtest_tee_test_1003,
430 "Core internal read/write mutex");
Jens Wiklander1d70a112017-10-16 15:16:39 +0200431
Pascal Brandc639ac82015-07-02 08:53:34 +0200432static void xtest_tee_test_1004(ADBG_Case_t *c)
433{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100434 TEEC_Session session = { };
435 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200436 struct xtest_crypto_session cs = { c, &session, TA_CRYPT_CMD_SHA256,
437 TA_CRYPT_CMD_AES256ECB_ENC,
438 TA_CRYPT_CMD_AES256ECB_DEC };
439
440 if (!ADBG_EXPECT_TEEC_SUCCESS(c, xtest_teec_open_session(
441 &session, &crypt_user_ta_uuid,
442 NULL, &ret_orig)))
443 return;
444
445 /* Run the "complete crypto test suite" */
446 xtest_crypto_test(&cs);
447
448 TEEC_CloseSession(&session);
449}
Jens Wiklander14f48872018-06-29 15:30:13 +0200450ADBG_CASE_DEFINE(regression, 1004, xtest_tee_test_1004, "Test User Crypt TA");
Pascal Brandc639ac82015-07-02 08:53:34 +0200451
Etienne Carriere92c34422018-02-09 13:11:40 +0100452static void xtest_tee_test_invalid_mem_access(ADBG_Case_t *c, unsigned int n)
Pascal Brandc639ac82015-07-02 08:53:34 +0200453{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100454 TEEC_Session session = { };
Pascal Brandc639ac82015-07-02 08:53:34 +0200455 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100456 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200457
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300458 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200459 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300460 &ret_orig)))
461 return;
Pascal Brandc639ac82015-07-02 08:53:34 +0200462
463 op.params[0].value.a = n;
464 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE,
465 TEEC_NONE);
466
467 (void)ADBG_EXPECT_TEEC_RESULT(c,
468 TEEC_ERROR_TARGET_DEAD,
469 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op,
470 &ret_orig));
471
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300472 (void)ADBG_EXPECT_TEEC_RESULT(c,
473 TEEC_ERROR_TARGET_DEAD,
474 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op,
Pascal Brandc639ac82015-07-02 08:53:34 +0200475 &ret_orig));
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300476
Pascal Brandc639ac82015-07-02 08:53:34 +0200477 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
478
479 TEEC_CloseSession(&session);
480}
481
Etienne Carriere92c34422018-02-09 13:11:40 +0100482static void xtest_tee_test_invalid_mem_access2(ADBG_Case_t *c, unsigned int n,
483 size_t size)
484{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100485 TEEC_Session session = { };
Etienne Carriere92c34422018-02-09 13:11:40 +0100486 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100487 uint32_t ret_orig = 0;
488 TEEC_SharedMemory shm = { };
Etienne Carriere92c34422018-02-09 13:11:40 +0100489
Etienne Carriere92c34422018-02-09 13:11:40 +0100490 shm.size = size;
491 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
492 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
493 TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm)))
494 return;
495
496 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
497 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
498 &ret_orig)))
Jens Wiklander6987a822019-06-28 12:47:42 +0200499 goto rel_shm;
Etienne Carriere92c34422018-02-09 13:11:40 +0100500
501 op.params[0].value.a = (uint32_t)n;
502 op.params[1].memref.parent = &shm;
503 op.params[1].memref.size = size;
504 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_MEMREF_WHOLE,
505 TEEC_NONE, TEEC_NONE);
506
507 (void)ADBG_EXPECT_TEEC_RESULT(c,
508 TEEC_ERROR_TARGET_DEAD,
509 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op,
510 &ret_orig));
511
512 (void)ADBG_EXPECT_TEEC_RESULT(c,
513 TEEC_ERROR_TARGET_DEAD,
514 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op,
515 &ret_orig));
516
517 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
518
519 TEEC_CloseSession(&session);
Jens Wiklander6987a822019-06-28 12:47:42 +0200520rel_shm:
521 TEEC_ReleaseSharedMemory(&shm);
Etienne Carriere92c34422018-02-09 13:11:40 +0100522}
523
Pascal Brandc639ac82015-07-02 08:53:34 +0200524static void xtest_tee_test_1005(ADBG_Case_t *c)
525{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100526 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200527#define MAX_SESSIONS 3
528 TEEC_Session sessions[MAX_SESSIONS];
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100529 int i = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200530
531 for (i = 0; i < MAX_SESSIONS; i++) {
532 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Jens Wiklandereb6bce72016-09-23 11:37:33 +0200533 xtest_teec_open_session(&sessions[i],
534 &concurrent_ta_uuid,
Pascal Brandc639ac82015-07-02 08:53:34 +0200535 NULL, &ret_orig)))
536 break;
537 }
538
539 for (; --i >= 0; )
540 TEEC_CloseSession(&sessions[i]);
541}
Jens Wiklander14f48872018-06-29 15:30:13 +0200542ADBG_CASE_DEFINE(regression, 1005, xtest_tee_test_1005, "Many sessions");
Pascal Brandc639ac82015-07-02 08:53:34 +0200543
544static void xtest_tee_test_1006(ADBG_Case_t *c)
545{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100546 TEEC_Session session = { };
547 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200548 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100549 uint8_t buf[32] = { };
Pascal Brandc639ac82015-07-02 08:53:34 +0200550
551 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
552 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
553 &ret_orig)))
554 return;
555
556 op.params[0].tmpref.buffer = buf;
557 op.params[0].tmpref.size = sizeof(buf);
558 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE,
559 TEEC_NONE, TEEC_NONE);
560
561 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
562 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BASIC, &op,
563 &ret_orig));
564
565 TEEC_CloseSession(&session);
566}
Jens Wiklander14f48872018-06-29 15:30:13 +0200567ADBG_CASE_DEFINE(regression, 1006, xtest_tee_test_1006,
568 "Test Basic OS features");
Pascal Brandc639ac82015-07-02 08:53:34 +0200569
570static void xtest_tee_test_1007(ADBG_Case_t *c)
571{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100572 TEEC_Session session = { };
573 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200574
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300575 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200576 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300577 &ret_orig)))
578 return;
Pascal Brandc639ac82015-07-02 08:53:34 +0200579
580 (void)ADBG_EXPECT_TEEC_RESULT(c,
581 TEEC_ERROR_TARGET_DEAD,
582 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PANIC, NULL,
583 &ret_orig));
584
585 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
586
587 (void)ADBG_EXPECT_TEEC_RESULT(c,
588 TEEC_ERROR_TARGET_DEAD,
589 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_INIT, NULL,
590 &ret_orig));
591
592 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
593
594 TEEC_CloseSession(&session);
595}
Jens Wiklander14f48872018-06-29 15:30:13 +0200596ADBG_CASE_DEFINE(regression, 1007, xtest_tee_test_1007, "Test Panic");
Pascal Brandc639ac82015-07-02 08:53:34 +0200597
Jerome Forissierf02a2212015-10-29 14:33:35 +0100598#ifndef TA_DIR
Victor Chong3d8798f2017-03-01 18:31:48 +0000599# ifdef __ANDROID__
Yongqin Liu286f1fc2018-06-21 22:09:15 +0800600#define TA_DIR "/vendor/lib/optee_armtz"
Victor Chong3d8798f2017-03-01 18:31:48 +0000601# else
Jerome Forissierf02a2212015-10-29 14:33:35 +0100602#define TA_DIR "/lib/optee_armtz"
Victor Chong3d8798f2017-03-01 18:31:48 +0000603# endif
Jerome Forissierf02a2212015-10-29 14:33:35 +0100604#endif
605
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100606static FILE *open_ta_file(const TEEC_UUID *uuid, const char *mode)
David Brownb2865ab2016-08-02 11:44:41 -0600607{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100608 char buf[PATH_MAX] = { };
David Brownb2865ab2016-08-02 11:44:41 -0600609
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100610 snprintf(buf, sizeof(buf),
Jens Wiklander6203b872016-12-08 19:18:29 +0100611 "%s/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.ta",
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100612 TA_DIR, uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion,
Jens Wiklanderb7940892015-10-23 16:02:40 +0200613 uuid->clockSeqAndNode[0], uuid->clockSeqAndNode[1],
614 uuid->clockSeqAndNode[2], uuid->clockSeqAndNode[3],
615 uuid->clockSeqAndNode[4], uuid->clockSeqAndNode[5],
David Brownb2865ab2016-08-02 11:44:41 -0600616 uuid->clockSeqAndNode[6], uuid->clockSeqAndNode[7]);
Jens Wiklanderb7940892015-10-23 16:02:40 +0200617
Jens Wiklanderb7940892015-10-23 16:02:40 +0200618 return fopen(buf, mode);
619}
620
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100621static bool load_corrupt_ta(ADBG_Case_t *c, size_t offs, uint8_t mask)
Jens Wiklander4441fe22015-10-23 16:53:02 +0200622{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100623 TEEC_Session session = { };
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100624 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
625 TEEC_UUID uuid = PTA_SECSTOR_TA_MGMT_UUID;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100626 TEEC_Result res = TEEC_ERROR_GENERIC;
627 uint32_t ret_orig = 0;
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100628 FILE *f = NULL;
629 bool r = false;
630 uint8_t *buf = NULL;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100631 size_t sz = 0;
632 size_t fread_res = 0;
Jens Wiklander4441fe22015-10-23 16:53:02 +0200633
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100634 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
635 xtest_teec_open_session(&session, &uuid, NULL, &ret_orig)))
636 goto out;
Jens Wiklander4441fe22015-10-23 16:53:02 +0200637
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100638 f = open_ta_file(&create_fail_test_ta_uuid, "rb");
639 if (!ADBG_EXPECT_NOT_NULL(c, f))
640 goto out;
641 if (!ADBG_EXPECT_TRUE(c, !fseek(f, 0, SEEK_END)))
642 goto out;
643 sz = ftell(f);
644 rewind(f);
645
646 buf = malloc(sz);
647 if (!ADBG_EXPECT_NOT_NULL(c, buf))
648 goto out;
649
650 fread_res = fread(buf, 1, sz, f);
651 if (!ADBG_EXPECT_COMPARE_UNSIGNED(c, fread_res, ==, sz))
652 goto out;
653
Jens Wiklander4441fe22015-10-23 16:53:02 +0200654 fclose(f);
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100655 f = NULL;
Jens Wiklander4441fe22015-10-23 16:53:02 +0200656
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100657 buf[MIN(offs, sz)] ^= mask;
Jens Wiklander4441fe22015-10-23 16:53:02 +0200658
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100659 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE,
660 TEEC_NONE, TEEC_NONE);
661 op.params[0].tmpref.buffer = buf;
662 op.params[0].tmpref.size = sz;
663
664 res = TEEC_InvokeCommand(&session, PTA_SECSTOR_TA_MGMT_BOOTSTRAP, &op,
665 &ret_orig);
666 r = ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_SECURITY, res);
667out:
668 free(buf);
669 if (f)
670 fclose(f);
671 TEEC_CloseSession(&session);
Jens Wiklander4441fe22015-10-23 16:53:02 +0200672 return r;
673}
Jens Wiklandere1a201d2020-02-12 18:36:20 +0100674
675static void test_1008_corrupt_ta(ADBG_Case_t *c)
676{
677 TEEC_UUID uuid = PTA_SECSTOR_TA_MGMT_UUID;
678 TEEC_Result res = TEEC_ERROR_GENERIC;
679 TEEC_Session session = { };
680 uint32_t ret_orig = 0;
681
682 res = xtest_teec_open_session(&session, &uuid, NULL, &ret_orig);
683 if (res) {
684 if (ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
685 res))
Joakim Becha1212b62020-04-07 12:06:00 +0200686 Do_ADBG_Log("PTA Secure Storage TA Management not found: skip test");
Jens Wiklandere1a201d2020-02-12 18:36:20 +0100687 return;
688 }
689 TEEC_CloseSession(&session);
690
691 ADBG_EXPECT_TRUE(c,
692 load_corrupt_ta(c, offsetof(struct shdr, magic), 1));
693 ADBG_EXPECT_TRUE(c,
694 load_corrupt_ta(c, offsetof(struct shdr, img_type), 1));
695 ADBG_EXPECT_TRUE(c,
696 load_corrupt_ta(c, offsetof(struct shdr, img_size), 1));
697 ADBG_EXPECT_TRUE(c,
698 load_corrupt_ta(c, offsetof(struct shdr, algo), 1));
699 ADBG_EXPECT_TRUE(c,
700 load_corrupt_ta(c, offsetof(struct shdr, hash_size), 1));
701 ADBG_EXPECT_TRUE(c,
702 load_corrupt_ta(c, offsetof(struct shdr, sig_size), 1));
703 ADBG_EXPECT_TRUE(c,
704 load_corrupt_ta(c, sizeof(struct shdr), 1)); /* hash */
705 ADBG_EXPECT_TRUE(c,
706 load_corrupt_ta(c, sizeof(struct shdr) + 32, 1)); /* sig */
707 ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 3000, 1)); /* payload */
708 ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 8000, 1)); /* payload */
709}
Jens Wiklander4441fe22015-10-23 16:53:02 +0200710
Pascal Brandc639ac82015-07-02 08:53:34 +0200711static void xtest_tee_test_1008(ADBG_Case_t *c)
712{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100713 TEEC_Session session = { };
714 TEEC_Session session_crypt = { };
715 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200716
717 Do_ADBG_BeginSubCase(c, "Invoke command");
718 {
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300719 if (ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200720 xtest_teec_open_session(&session, &os_test_ta_uuid,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300721 NULL, &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200722
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300723 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
724 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CLIENT,
725 NULL, &ret_orig));
726 TEEC_CloseSession(&session);
727 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200728
Pascal Brandc639ac82015-07-02 08:53:34 +0200729 }
730 Do_ADBG_EndSubCase(c, "Invoke command");
731
732 Do_ADBG_BeginSubCase(c, "Invoke command with timeout");
733 {
734 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
735
736 op.params[0].value.a = 2000;
737 op.paramTypes = TEEC_PARAM_TYPES(
738 TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
739
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300740 if (ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200741 xtest_teec_open_session(&session,
742 &os_test_ta_uuid,
743 NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300744 &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200745
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300746 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
747 TEEC_InvokeCommand(&session,
748 TA_OS_TEST_CMD_CLIENT_WITH_TIMEOUT,
749 &op, &ret_orig));
750 TEEC_CloseSession(&session);
751 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200752 }
753 Do_ADBG_EndSubCase(c, "Invoke command with timeout");
754
755 Do_ADBG_BeginSubCase(c, "Create session fail");
756 {
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100757 size_t n = 0;
Jens Wiklanderb7940892015-10-23 16:02:40 +0200758
Pascal Brandc639ac82015-07-02 08:53:34 +0200759 (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC,
760 xtest_teec_open_session(&session_crypt,
761 &create_fail_test_ta_uuid, NULL,
762 &ret_orig));
Pascal Brandc639ac82015-07-02 08:53:34 +0200763 /*
764 * Run this several times to see that there's no memory leakage.
765 */
766 for (n = 0; n < 100; n++) {
767 Do_ADBG_Log("n = %zu", n);
768 (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC,
769 xtest_teec_open_session(&session_crypt,
770 &create_fail_test_ta_uuid,
771 NULL, &ret_orig));
772 }
773 }
774 Do_ADBG_EndSubCase(c, "Create session fail");
Jens Wiklanderb7940892015-10-23 16:02:40 +0200775
Jens Wiklander4441fe22015-10-23 16:53:02 +0200776 Do_ADBG_BeginSubCase(c, "Load corrupt TA");
Jens Wiklandere1a201d2020-02-12 18:36:20 +0100777 test_1008_corrupt_ta(c);
Jens Wiklander4441fe22015-10-23 16:53:02 +0200778 Do_ADBG_EndSubCase(c, "Load corrupt TA");
Pascal Brandc639ac82015-07-02 08:53:34 +0200779}
Jens Wiklander14f48872018-06-29 15:30:13 +0200780ADBG_CASE_DEFINE(regression, 1008, xtest_tee_test_1008,
781 "TEE internal client API");
Pascal Brandc639ac82015-07-02 08:53:34 +0200782
Pascal Brandc639ac82015-07-02 08:53:34 +0200783static void *cancellation_thread(void *arg)
784{
785 /*
786 * Sleep 0.5 seconds before cancellation to make sure that the other
787 * thread is in RPC_WAIT.
788 */
789 (void)usleep(500000);
790 TEEC_RequestCancellation(arg);
791 return NULL;
792}
Pascal Brandc639ac82015-07-02 08:53:34 +0200793
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300794static void xtest_tee_test_1009_subcase(ADBG_Case_t *c, const char *subcase,
795 uint32_t timeout, bool cancel)
Pascal Brandc639ac82015-07-02 08:53:34 +0200796{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100797 TEEC_Session session = { };
798 uint32_t ret_orig = 0;
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300799 pthread_t thr;
Pascal Brandc639ac82015-07-02 08:53:34 +0200800
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100801 memset(&thr, 0, sizeof(thr));
802
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300803 Do_ADBG_BeginSubCase(c, "%s", subcase);
Pascal Brandc639ac82015-07-02 08:53:34 +0200804 {
805 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
806
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300807 if (ADBG_EXPECT_TEEC_SUCCESS(c,
808 xtest_teec_open_session(&session, &os_test_ta_uuid,
809 NULL, &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200810
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300811 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c,
812 TEEC_ORIGIN_TRUSTED_APP,
813 ret_orig);
Pascal Brandc639ac82015-07-02 08:53:34 +0200814
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300815 op.params[0].value.a = timeout;
816 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
817 TEEC_NONE,
818 TEEC_NONE, TEEC_NONE);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300819 if (cancel) {
820 (void)ADBG_EXPECT(c, 0,
821 pthread_create(&thr, NULL,
822 cancellation_thread, &op));
Pascal Brandc639ac82015-07-02 08:53:34 +0200823
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300824 (void)ADBG_EXPECT_TEEC_RESULT(c,
825 TEEC_ERROR_CANCEL,
826 TEEC_InvokeCommand(&session,
827 TA_OS_TEST_CMD_WAIT,
828 &op,
829 &ret_orig));
830 } else
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300831
832 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
833 TEEC_InvokeCommand(&session,
834 TA_OS_TEST_CMD_WAIT,
835 &op,
836 &ret_orig));
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300837 if (cancel)
838 (void)ADBG_EXPECT(c, 0, pthread_join(thr, NULL));
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300839
840 TEEC_CloseSession(&session);
841 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200842 }
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300843 Do_ADBG_EndSubCase(c, "%s", subcase);
844}
845
846static void xtest_tee_test_1009(ADBG_Case_t *c)
847{
848 xtest_tee_test_1009_subcase(c, "TEE Wait 0.1s", 100, false);
849 xtest_tee_test_1009_subcase(c, "TEE Wait 0.5s", 500, false);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300850 xtest_tee_test_1009_subcase(c, "TEE Wait 2s cancel", 2000, true);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300851 xtest_tee_test_1009_subcase(c, "TEE Wait 2s", 2000, false);
Pascal Brandc639ac82015-07-02 08:53:34 +0200852}
Jens Wiklander14f48872018-06-29 15:30:13 +0200853ADBG_CASE_DEFINE(regression, 1009, xtest_tee_test_1009, "TEE Wait");
Pascal Brandc639ac82015-07-02 08:53:34 +0200854
855static void xtest_tee_test_1010(ADBG_Case_t *c)
856{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100857 unsigned int n = 0;
858 unsigned int idx = 0;
Etienne Carriere92c34422018-02-09 13:11:40 +0100859 size_t memref_sz[] = { 1024, 65536 };
Pascal Brandc639ac82015-07-02 08:53:34 +0200860
861 for (n = 1; n <= 5; n++) {
862 Do_ADBG_BeginSubCase(c, "Invalid memory access %u", n);
863 xtest_tee_test_invalid_mem_access(c, n);
864 Do_ADBG_EndSubCase(c, "Invalid memory access %u", n);
865 }
Etienne Carriere92c34422018-02-09 13:11:40 +0100866
867 for (idx = 0; idx < ARRAY_SIZE(memref_sz); idx++) {
868 for (n = 1; n <= 5; n++) {
869 Do_ADBG_BeginSubCase(c,
Igor Opaniuke8236ac2018-02-12 12:26:25 +0200870 "Invalid memory access %u with %zu bytes memref",
Etienne Carriere92c34422018-02-09 13:11:40 +0100871 n, memref_sz[idx]);
872 xtest_tee_test_invalid_mem_access2(c, n, memref_sz[idx]);
873 Do_ADBG_EndSubCase(c,
Igor Opaniuke8236ac2018-02-12 12:26:25 +0200874 "Invalid memory access %u with %zu bytes memref",
Etienne Carriere92c34422018-02-09 13:11:40 +0100875 n, memref_sz[idx]);
876 }
877 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200878}
Jens Wiklander14f48872018-06-29 15:30:13 +0200879ADBG_CASE_DEFINE(regression, 1010, xtest_tee_test_1010,
880 "Invalid memory access");
Pascal Brandc639ac82015-07-02 08:53:34 +0200881
882static void xtest_tee_test_1011(ADBG_Case_t *c)
883{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100884 TEEC_Session session = { };
885 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200886 struct xtest_crypto_session cs = {
887 c, &session, TA_RPC_CMD_CRYPT_SHA256,
888 TA_RPC_CMD_CRYPT_AES256ECB_ENC,
889 TA_RPC_CMD_CRYPT_AES256ECB_DEC
890 };
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100891 struct xtest_crypto_session cs_privmem = {
892 c, &session,
893 TA_RPC_CMD_CRYPT_PRIVMEM_SHA256,
894 TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_ENC,
895 TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_DEC
896 };
Pascal Brandc639ac82015-07-02 08:53:34 +0200897 TEEC_UUID uuid = rpc_test_ta_uuid;
898
899 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
900 xtest_teec_open_session(&session, &uuid, NULL, &ret_orig)))
901 return;
902
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100903 Do_ADBG_BeginSubCase(c, "TA-to-TA via non-secure shared memory");
Pascal Brandc639ac82015-07-02 08:53:34 +0200904 /*
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100905 * Run the "complete crypto test suite" using TA-to-TA
906 * communication
Pascal Brandc639ac82015-07-02 08:53:34 +0200907 */
908 xtest_crypto_test(&cs);
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100909 Do_ADBG_EndSubCase(c, "TA-to-TA via non-secure shared memory");
910
911 Do_ADBG_BeginSubCase(c, "TA-to-TA via TA private memory");
912 /*
913 * Run the "complete crypto test suite" using TA-to-TA
914 * communication via TA private memory.
915 */
916 xtest_crypto_test(&cs_privmem);
917 Do_ADBG_EndSubCase(c, "TA-to-TA via TA private memory");
918
Pascal Brandc639ac82015-07-02 08:53:34 +0200919 TEEC_CloseSession(&session);
920}
Jens Wiklander14f48872018-06-29 15:30:13 +0200921ADBG_CASE_DEFINE(regression, 1011, xtest_tee_test_1011,
922 "Test TA-to-TA features with User Crypt TA");
Pascal Brandc639ac82015-07-02 08:53:34 +0200923
924/*
925 * Note that this test is failing when
926 * - running twice in a raw
927 * - and the user TA is statically linked
928 * This is because the counter is not reseted when opening the first session
929 * in case the TA is statically linked
930 */
931static void xtest_tee_test_1012(ADBG_Case_t *c)
932{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100933 TEEC_Session session1 = { };
934 TEEC_Session session2 = { };
935 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200936 TEEC_UUID uuid = sims_test_ta_uuid;
937
938 Do_ADBG_BeginSubCase(c, "Single Instance Multi Session");
939 {
940 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
941 static const uint8_t in[] = {
942 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
943 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
944 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
945 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
946 };
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100947 uint8_t out[32] = { };
948 int i = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200949
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300950 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200951 xtest_teec_open_session(&session1, &uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300952 &ret_orig)))
953 return;
Pascal Brandc639ac82015-07-02 08:53:34 +0200954
955 op.params[0].value.a = 0;
956 op.params[1].tmpref.buffer = (void *)in;
957 op.params[1].tmpref.size = sizeof(in);
958 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
959 TEEC_MEMREF_TEMP_INPUT,
960 TEEC_NONE, TEEC_NONE);
961
962 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
963 TEEC_InvokeCommand(&session1, TA_SIMS_CMD_WRITE, &op,
964 &ret_orig));
965
Jerome Forissier3cc0a422017-12-14 09:53:24 +0100966 for (i = 1; i < 3; i++) {
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300967 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200968 xtest_teec_open_session(&session2, &uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300969 &ret_orig)))
970 continue;
Pascal Brandc639ac82015-07-02 08:53:34 +0200971
972 op.params[0].value.a = 0;
973 op.params[1].tmpref.buffer = out;
974 op.params[1].tmpref.size = sizeof(out);
975 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
976 TEEC_MEMREF_TEMP_OUTPUT,
977 TEEC_NONE, TEEC_NONE);
978
979 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
980 TEEC_InvokeCommand(&session2, TA_SIMS_CMD_READ,
981 &op, &ret_orig));
982
983 if (!ADBG_EXPECT_BUFFER(c, in, sizeof(in), out,
984 sizeof(out))) {
985 Do_ADBG_Log("in:");
986 Do_ADBG_HexLog(in, sizeof(in), 16);
987 Do_ADBG_Log("out:");
988 Do_ADBG_HexLog(out, sizeof(out), 16);
989 }
990
991 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT,
992 TEEC_NONE, TEEC_NONE,
993 TEEC_NONE);
994
995 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
996 TEEC_InvokeCommand(&session1,
997 TA_SIMS_CMD_GET_COUNTER,
998 &op, &ret_orig));
999
1000 (void)ADBG_EXPECT(c, 0, op.params[0].value.a);
1001
1002 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1003 TEEC_InvokeCommand(&session2,
1004 TA_SIMS_CMD_GET_COUNTER, &op,
1005 &ret_orig));
1006
1007 (void)ADBG_EXPECT(c, i, op.params[0].value.a);
1008 TEEC_CloseSession(&session2);
1009 }
1010
1011 memset(out, 0, sizeof(out));
1012 op.params[0].value.a = 0;
1013 op.params[1].tmpref.buffer = out;
1014 op.params[1].tmpref.size = sizeof(out);
1015 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
1016 TEEC_MEMREF_TEMP_OUTPUT,
1017 TEEC_NONE, TEEC_NONE);
1018
1019 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1020 TEEC_InvokeCommand(&session1, TA_SIMS_CMD_READ, &op,
1021 &ret_orig));
1022
1023 if (!ADBG_EXPECT(c, 0, memcmp(in, out, sizeof(in)))) {
1024 Do_ADBG_Log("in:");
1025 Do_ADBG_HexLog(in, sizeof(in), 16);
1026 Do_ADBG_Log("out:");
1027 Do_ADBG_HexLog(out, sizeof(out), 16);
1028 }
1029
1030 TEEC_CloseSession(&session1);
1031 }
Ovidiu Mihalachi3e6183e2019-04-25 10:23:21 +03001032 Do_ADBG_EndSubCase(c, "Single Instance Multi Session");
Pascal Brandc639ac82015-07-02 08:53:34 +02001033}
Jens Wiklander14f48872018-06-29 15:30:13 +02001034ADBG_CASE_DEFINE(regression, 1012, xtest_tee_test_1012,
1035 "Test Single Instance Multi Session features with SIMS TA");
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001036
1037struct test_1013_thread_arg {
Jens Wiklander70672972016-04-06 00:01:45 +02001038 const TEEC_UUID *uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001039 uint32_t cmd;
1040 uint32_t repeat;
1041 TEEC_SharedMemory *shm;
1042 uint32_t error_orig;
1043 TEEC_Result res;
1044 uint32_t max_concurrency;
1045 const uint8_t *in;
1046 size_t in_len;
1047 uint8_t *out;
1048 size_t out_len;
1049};
1050
1051static void *test_1013_thread(void *arg)
1052{
1053 struct test_1013_thread_arg *a = arg;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001054 TEEC_Session session = { };
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001055 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1056 uint8_t p2 = TEEC_NONE;
1057 uint8_t p3 = TEEC_NONE;
1058
Jens Wiklander70672972016-04-06 00:01:45 +02001059 a->res = xtest_teec_open_session(&session, a->uuid, NULL,
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001060 &a->error_orig);
1061 if (a->res != TEEC_SUCCESS)
1062 return NULL;
1063
1064 op.params[0].memref.parent = a->shm;
1065 op.params[0].memref.size = a->shm->size;
1066 op.params[0].memref.offset = 0;
1067 op.params[1].value.a = a->repeat;
1068 op.params[1].value.b = 0;
1069 op.params[2].tmpref.buffer = (void *)a->in;
1070 op.params[2].tmpref.size = a->in_len;
1071 op.params[3].tmpref.buffer = a->out;
1072 op.params[3].tmpref.size = a->out_len;
1073
1074 if (a->in_len)
1075 p2 = TEEC_MEMREF_TEMP_INPUT;
1076 if (a->out_len)
1077 p3 = TEEC_MEMREF_TEMP_OUTPUT;
1078
1079 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT,
1080 TEEC_VALUE_INOUT, p2, p3);
1081
1082 a->res = TEEC_InvokeCommand(&session, a->cmd, &op, &a->error_orig);
1083 a->max_concurrency = op.params[1].value.b;
1084 a->out_len = op.params[3].tmpref.size;
1085 TEEC_CloseSession(&session);
1086 return NULL;
1087}
1088
Pascal Brand4fa35582015-12-17 10:59:12 +01001089#define NUM_THREADS 3
1090
Jens Wiklander70672972016-04-06 00:01:45 +02001091static void xtest_tee_test_1013_single(ADBG_Case_t *c, double *mean_concurrency,
1092 const TEEC_UUID *uuid)
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001093{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001094 size_t nt = 0;
1095 size_t n = 0;
Jens Wiklander70672972016-04-06 00:01:45 +02001096 size_t repeat = 1000;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001097 TEEC_SharedMemory shm = { };
1098 size_t max_concurrency = 0;
1099 struct test_1013_thread_arg arg[NUM_THREADS] = { };
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001100 static const uint8_t sha256_in[] = { 'a', 'b', 'c' };
1101 static const uint8_t sha256_out[] = {
1102 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
1103 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
1104 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
1105 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
1106 };
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001107 uint8_t out[32] = { };
1108 pthread_t thr[NUM_THREADS] = { };
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001109
Jens Wiklander70672972016-04-06 00:01:45 +02001110 Do_ADBG_BeginSubCase(c, "Busy loop repeat %zu", repeat * 10);
Pascal Brand4fa35582015-12-17 10:59:12 +01001111 *mean_concurrency = 0;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001112
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001113 shm.size = sizeof(struct ta_concurrent_shm);
1114 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
1115 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1116 TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm)))
1117 return;
1118
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001119 memset(shm.buffer, 0, shm.size);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001120 max_concurrency = 0;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001121 nt = NUM_THREADS;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001122
1123 for (n = 0; n < nt; n++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001124 arg[n].uuid = uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001125 arg[n].cmd = TA_CONCURRENT_CMD_BUSY_LOOP;
Jens Wiklander70672972016-04-06 00:01:45 +02001126 arg[n].repeat = repeat * 10;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001127 arg[n].shm = &shm;
1128 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
1129 test_1013_thread, arg + n)))
1130 nt = n; /* break loop and start cleanup */
1131 }
1132
1133 for (n = 0; n < nt; n++) {
1134 ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL));
1135 ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res);
1136 if (arg[n].max_concurrency > max_concurrency)
1137 max_concurrency = arg[n].max_concurrency;
1138 }
1139
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001140 /*
1141 * Concurrency can be limited by several factors, for instance in a
Joakim Becha1212b62020-04-07 12:06:00 +02001142 * single CPU system it's dependent on the Preemption Model used by
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001143 * the kernel (Preemptible Kernel (Low-Latency Desktop) gives the
1144 * best result there).
1145 */
1146 (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, >, 0);
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001147 (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, <=, NUM_THREADS);
Pascal Brand4fa35582015-12-17 10:59:12 +01001148 *mean_concurrency += max_concurrency;
Jens Wiklander70672972016-04-06 00:01:45 +02001149 Do_ADBG_EndSubCase(c, "Busy loop repeat %zu", repeat * 10);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001150
Jens Wiklander70672972016-04-06 00:01:45 +02001151 Do_ADBG_BeginSubCase(c, "SHA-256 loop repeat %zu", repeat);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001152 memset(shm.buffer, 0, shm.size);
1153 memset(arg, 0, sizeof(arg));
1154 max_concurrency = 0;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001155 nt = NUM_THREADS;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001156
1157 for (n = 0; n < nt; n++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001158 arg[n].uuid = uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001159 arg[n].cmd = TA_CONCURRENT_CMD_SHA256;
Jens Wiklander70672972016-04-06 00:01:45 +02001160 arg[n].repeat = repeat;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001161 arg[n].shm = &shm;
1162 arg[n].in = sha256_in;
1163 arg[n].in_len = sizeof(sha256_in);
1164 arg[n].out = out;
1165 arg[n].out_len = sizeof(out);
1166 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
1167 test_1013_thread, arg + n)))
1168 nt = n; /* break loop and start cleanup */
1169 }
1170
1171 for (n = 0; n < nt; n++) {
1172 if (ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)) &&
1173 ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res))
1174 ADBG_EXPECT_BUFFER(c, sha256_out, sizeof(sha256_out),
1175 arg[n].out, arg[n].out_len);
1176 if (arg[n].max_concurrency > max_concurrency)
1177 max_concurrency = arg[n].max_concurrency;
1178 }
Pascal Brand4fa35582015-12-17 10:59:12 +01001179 *mean_concurrency += max_concurrency;
Jens Wiklander70672972016-04-06 00:01:45 +02001180 Do_ADBG_EndSubCase(c, "SHA-256 loop repeat %zu", repeat);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001181
Pascal Brand4fa35582015-12-17 10:59:12 +01001182 *mean_concurrency /= 2.0;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001183 TEEC_ReleaseSharedMemory(&shm);
1184}
Pascal Brand4fa35582015-12-17 10:59:12 +01001185
1186static void xtest_tee_test_1013(ADBG_Case_t *c)
1187{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001188 int i = 0;
1189 double mean_concurrency = 0;
1190 double concurrency = 0;
Jens Wiklander70672972016-04-06 00:01:45 +02001191 int nb_loops = 24;
Jens Wiklander6a9d15a2016-02-01 10:29:42 +01001192
1193 if (level == 0)
1194 nb_loops /= 2;
Pascal Brand4fa35582015-12-17 10:59:12 +01001195
Jens Wiklander70672972016-04-06 00:01:45 +02001196 Do_ADBG_BeginSubCase(c, "Using small concurrency TA");
Pascal Brand4fa35582015-12-17 10:59:12 +01001197 mean_concurrency = 0;
1198 for (i = 0; i < nb_loops; i++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001199 xtest_tee_test_1013_single(c, &concurrency,
1200 &concurrent_ta_uuid);
Pascal Brand4fa35582015-12-17 10:59:12 +01001201 mean_concurrency += concurrency;
1202 }
1203 mean_concurrency /= nb_loops;
1204
1205 Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS);
1206 Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency);
Jens Wiklander70672972016-04-06 00:01:45 +02001207 Do_ADBG_EndSubCase(c, "Using small concurrency TA");
Pascal Brand4fa35582015-12-17 10:59:12 +01001208
Jens Wiklanderc9d7b242016-06-28 18:35:08 +02001209#ifndef CFG_PAGED_USER_TA
Jens Wiklander70672972016-04-06 00:01:45 +02001210 Do_ADBG_BeginSubCase(c, "Using large concurrency TA");
1211 mean_concurrency = 0;
1212 for (i = 0; i < nb_loops; i++) {
1213 xtest_tee_test_1013_single(c, &concurrency,
1214 &concurrent_large_ta_uuid);
1215 mean_concurrency += concurrency;
1216 }
1217 mean_concurrency /= nb_loops;
1218
1219 Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS);
1220 Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency);
1221 Do_ADBG_EndSubCase(c, "Using large concurrency TA");
Jens Wiklanderc9d7b242016-06-28 18:35:08 +02001222#endif
Jens Wiklander70672972016-04-06 00:01:45 +02001223}
Jens Wiklander14f48872018-06-29 15:30:13 +02001224ADBG_CASE_DEFINE(regression, 1013, xtest_tee_test_1013,
Joakim Becha1212b62020-04-07 12:06:00 +02001225 "Test concurrency with concurrent TA");
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001226
1227#ifdef CFG_SECURE_DATA_PATH
1228static void xtest_tee_test_1014(ADBG_Case_t *c)
1229{
1230 UNUSED(c);
1231
1232 int size = 17000;
1233 int loop = 10;
1234 int ion_heap = DEFAULT_ION_HEAP_TYPE;
1235 int rnd_offset = 1;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001236 int test = 0;
1237 int ret = 0;
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001238
1239 test = TEST_NS_TO_TA;
1240 Do_ADBG_BeginSubCase(c, "SDP: NonSecure client invokes a SDP TA");
Etienne Carriereb9a95822017-04-26 15:03:53 +02001241 ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001242 ADBG_EXPECT(c, 0, ret);
1243 Do_ADBG_EndSubCase(c, "SDP: NonSecure client invokes a SDP TA");
1244
1245 test = TEST_TA_TO_TA;
1246 Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP TA");
Etienne Carriereb9a95822017-04-26 15:03:53 +02001247 ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001248 ADBG_EXPECT(c, 0, ret);
1249 Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP TA");
1250
1251 test = TEST_TA_TO_PTA;
1252 Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP pTA");
Etienne Carriereb9a95822017-04-26 15:03:53 +02001253 ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001254 ADBG_EXPECT(c, 0, ret);
1255 Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP pTA");
1256
1257 test = TEST_NS_TO_PTA;
Etienne Carrierea3198522017-10-26 09:48:55 +02001258 Do_ADBG_BeginSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)");
Etienne Carriereb9a95822017-04-26 15:03:53 +02001259 ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001260 ADBG_EXPECT(c, 1, ret);
Etienne Carrierea3198522017-10-26 09:48:55 +02001261 Do_ADBG_EndSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)");
Etienne Carriered9be3dc2018-04-25 18:30:19 +02001262
1263 Do_ADBG_BeginSubCase(c, "SDP: Invoke TA with out of bounds SDP memref");
1264 ret = sdp_out_of_bounds_memref_test(size, ion_heap, 0);
1265 ADBG_EXPECT(c, 0, ret);
1266 Do_ADBG_EndSubCase(c, NULL);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001267}
Jens Wiklander14f48872018-06-29 15:30:13 +02001268ADBG_CASE_DEFINE(regression, 1014, xtest_tee_test_1014,
1269 "Test secure data path against SDP TAs and pTAs");
1270#endif /*CFG_SECURE_DATA_PATH*/
Jens Wiklander272d3642017-04-03 13:03:47 +02001271
1272static void xtest_tee_test_1015(ADBG_Case_t *c)
1273{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001274 TEEC_Result res = TEEC_ERROR_GENERIC;
1275 TEEC_Session session = { };
1276 uint32_t ret_orig = 0;
Jens Wiklander272d3642017-04-03 13:03:47 +02001277
Etienne Carriere11093162017-10-26 09:49:04 +02001278 /* Pseudo TA is optional: warn and nicely exit if not found */
Jens Wiklander272d3642017-04-03 13:03:47 +02001279 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
1280 &ret_orig);
Etienne Carriere11093162017-10-26 09:49:04 +02001281 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
1282 Do_ADBG_Log(" - 1015 - skip test, pseudo TA not found");
Jens Wiklander272d3642017-04-03 13:03:47 +02001283 return;
Etienne Carriere11093162017-10-26 09:49:04 +02001284 }
1285 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Jens Wiklander272d3642017-04-03 13:03:47 +02001286
1287 ADBG_EXPECT_TEEC_SUCCESS(c,
1288 TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_FS_HTREE,
1289 NULL, &ret_orig));
1290 TEEC_CloseSession(&session);
1291}
Jens Wiklander14f48872018-06-29 15:30:13 +02001292ADBG_CASE_DEFINE(regression, 1015, xtest_tee_test_1015,
1293 "FS hash-tree corner cases");
Jerome Forissiere916b102017-06-07 17:55:52 +02001294
1295static void xtest_tee_test_1016(ADBG_Case_t *c)
1296{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001297 TEEC_Session session = { };
Jerome Forissiere916b102017-06-07 17:55:52 +02001298 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001299 uint32_t ret_orig = 0;
Jerome Forissiere916b102017-06-07 17:55:52 +02001300
1301 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1302 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
1303 &ret_orig)))
1304 return;
1305
1306 op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE,
1307 TEEC_NONE);
1308
1309 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1310 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TA2TA_MEMREF, &op,
1311 &ret_orig));
1312
1313 TEEC_CloseSession(&session);
1314}
Jens Wiklander14f48872018-06-29 15:30:13 +02001315ADBG_CASE_DEFINE(regression, 1016, xtest_tee_test_1016,
1316 "Test TA to TA transfers (in/out/inout memrefs on the stack)");
Jens Wiklander87e81702018-03-20 12:00:00 +08001317
1318static void xtest_tee_test_1017(ADBG_Case_t *c)
1319{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001320 TEEC_Session session = { };
Jens Wiklander87e81702018-03-20 12:00:00 +08001321 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001322 uint32_t ret_orig = 0;
1323 TEEC_SharedMemory shm = { };
Jens Wiklander87e81702018-03-20 12:00:00 +08001324 size_t page_size = 4096;
1325
Jens Wiklander87e81702018-03-20 12:00:00 +08001326 shm.size = 8 * page_size;
1327 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
1328 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1329 TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm)))
1330 return;
1331
1332 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1333 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
1334 &ret_orig)))
1335 goto out;
1336
1337 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT,
1338 TEEC_MEMREF_PARTIAL_INPUT,
1339 TEEC_MEMREF_PARTIAL_OUTPUT,
1340 TEEC_MEMREF_PARTIAL_OUTPUT);
1341
1342 /*
1343 * The first two memrefs are supposed to be combined into in
1344 * region and the last two memrefs should have one region each
1345 * when the parameters are mapped for the TA.
1346 */
1347 op.params[0].memref.parent = &shm;
1348 op.params[0].memref.size = page_size;
1349 op.params[0].memref.offset = 0;
1350
1351 op.params[1].memref.parent = &shm;
1352 op.params[1].memref.size = page_size;
1353 op.params[1].memref.offset = page_size;
1354
1355 op.params[2].memref.parent = &shm;
1356 op.params[2].memref.size = page_size;
1357 op.params[2].memref.offset = 4 * page_size;
1358
1359 op.params[3].memref.parent = &shm;
1360 op.params[3].memref.size = 2 * page_size;
1361 op.params[3].memref.offset = 6 * page_size;
1362
1363 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1364 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PARAMS, &op,
1365 &ret_orig));
1366
1367 TEEC_CloseSession(&session);
1368out:
1369 TEEC_ReleaseSharedMemory(&shm);
1370}
Jens Wiklander14f48872018-06-29 15:30:13 +02001371ADBG_CASE_DEFINE(regression, 1017, xtest_tee_test_1017,
1372 "Test coalescing memrefs");
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001373
Etienne Carriere84382b32018-04-25 18:30:30 +02001374static void invoke_1byte_out_of_bounds(ADBG_Case_t *c, TEEC_Session *session,
1375 TEEC_SharedMemory *shm)
1376{
1377 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1378 TEEC_Result ret = TEEC_ERROR_GENERIC;
1379 uint32_t ret_orig = 0;
1380
1381 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT,
1382 TEEC_NONE, TEEC_NONE, TEEC_NONE);
1383
1384 op.params[0].memref.parent = shm;
1385 op.params[0].memref.size = shm->size / 2;
1386 op.params[0].memref.offset = shm->size - (shm->size / 2) + 1;
1387
1388 ret = TEEC_InvokeCommand(session, TA_OS_TEST_CMD_PARAMS,
1389 &op, &ret_orig);
1390
Etienne Carriere48fa1b22020-04-08 13:42:01 +02001391 ADBG_EXPECT_COMPARE_UNSIGNED(c, ret_orig, !=, TEEC_ORIGIN_TRUSTED_APP);
Etienne Carriere84382b32018-04-25 18:30:30 +02001392 if (ret != TEEC_ERROR_BAD_PARAMETERS && ret != TEEC_ERROR_GENERIC) {
1393 ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS, ret);
1394 ADBG_EXPECT(c, TEEC_ERROR_GENERIC, ret);
1395 }
1396}
1397
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001398static void xtest_tee_test_1018(ADBG_Case_t *c)
1399{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001400 TEEC_Session session = { };
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001401 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001402 uint32_t ret_orig = 0;
1403 TEEC_SharedMemory shm = { };
Etienne Carriere84382b32018-04-25 18:30:30 +02001404 TEEC_Result ret = TEEC_ERROR_GENERIC;
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001405 size_t page_size = 4096;
Joakim Becha1212b62020-04-07 12:06:00 +02001406 /* Intentionally not 4kB aligned and odd */
Etienne Carriere84382b32018-04-25 18:30:30 +02001407 uint8_t buffer[6001] = { };
1408
1409 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1410 xtest_teec_open_session(&session,
1411 &os_test_ta_uuid,
1412 NULL,
1413 &ret_orig)))
1414 return;
1415
Joakim Becha1212b62020-04-07 12:06:00 +02001416 Do_ADBG_BeginSubCase(c, "Out of bounds > 4kB on allocated shm");
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001417
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001418 shm.size = 8 * page_size;
1419 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
1420 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Etienne Carriere84382b32018-04-25 18:30:30 +02001421 TEEC_AllocateSharedMemory(&xtest_teec_ctx,
1422 &shm)))
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001423 goto out;
1424
1425 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT,
1426 TEEC_MEMREF_PARTIAL_INPUT,
1427 TEEC_MEMREF_PARTIAL_OUTPUT,
1428 TEEC_MEMREF_PARTIAL_OUTPUT);
1429
1430 /*
1431 * The first two memrefs are supposed to be combined into in
1432 * region and the last two memrefs should have one region each
1433 * when the parameters are mapped for the TA.
1434 */
1435 op.params[0].memref.parent = &shm;
1436 op.params[0].memref.size = page_size;
1437 op.params[0].memref.offset = 0;
1438
1439 op.params[1].memref.parent = &shm;
1440 op.params[1].memref.size = page_size;
1441 op.params[1].memref.offset = page_size;
1442
1443 op.params[2].memref.parent = &shm;
1444 op.params[2].memref.size = page_size;
1445 op.params[2].memref.offset = 4 * page_size;
1446
1447 op.params[3].memref.parent = &shm;
1448 op.params[3].memref.size = 3 * page_size;
1449 op.params[3].memref.offset = 6 * page_size;
1450
Etienne Carriere84382b32018-04-25 18:30:30 +02001451 ret = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PARAMS, &op,
1452 &ret_orig);
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001453
Etienne Carriere48fa1b22020-04-08 13:42:01 +02001454 ADBG_EXPECT_COMPARE_UNSIGNED(c, ret_orig, !=, TEEC_ORIGIN_TRUSTED_APP);
Etienne Carriere84382b32018-04-25 18:30:30 +02001455 if (ret != TEEC_ERROR_BAD_PARAMETERS && ret != TEEC_ERROR_GENERIC) {
1456 ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS, ret);
1457 ADBG_EXPECT(c, TEEC_ERROR_GENERIC, ret);
1458 }
1459
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001460 TEEC_ReleaseSharedMemory(&shm);
Etienne Carriere84382b32018-04-25 18:30:30 +02001461 Do_ADBG_EndSubCase(c, NULL);
1462
1463 Do_ADBG_BeginSubCase(c, "Out of bounds by 1 byte on registered shm");
1464
1465 memset(&shm, 0, sizeof(shm));
1466 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
1467 shm.buffer = buffer;
1468 shm.size = sizeof(buffer);
1469
1470 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1471 TEEC_RegisterSharedMemory(&xtest_teec_ctx,
1472 &shm)))
1473 goto out;
1474
1475 invoke_1byte_out_of_bounds(c, &session, &shm);
1476
1477 TEEC_ReleaseSharedMemory(&shm);
1478 Do_ADBG_EndSubCase(c, NULL);
1479
1480 Do_ADBG_BeginSubCase(c, "Out of bounds by 1 byte ref on allocated shm");
1481
1482 memset(&shm, 0, sizeof(shm));
1483 shm.size = sizeof(buffer);
1484 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
1485 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1486 TEEC_AllocateSharedMemory(&xtest_teec_ctx,
1487 &shm)))
1488 goto out;
1489
1490 invoke_1byte_out_of_bounds(c, &session, &shm);
1491
1492 TEEC_ReleaseSharedMemory(&shm);
1493 Do_ADBG_EndSubCase(c, NULL);
1494
1495out:
1496 TEEC_CloseSession(&session);
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001497}
Jens Wiklander14f48872018-06-29 15:30:13 +02001498ADBG_CASE_DEFINE(regression, 1018, xtest_tee_test_1018,
1499 "Test memref out of bounds");
Jerome Forissier53bde722018-05-31 09:14:54 +02001500
Victor Chong3ff36f52018-06-07 04:37:00 +01001501#if defined(CFG_TA_DYNLINK)
Jerome Forissier53bde722018-05-31 09:14:54 +02001502static void xtest_tee_test_1019(ADBG_Case_t *c)
1503{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001504 TEEC_Session session = { };
1505 uint32_t ret_orig = 0;
Jerome Forissier53bde722018-05-31 09:14:54 +02001506
1507 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1508 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
1509 &ret_orig)))
1510 return;
1511
1512 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1513 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB, NULL,
1514 &ret_orig));
1515
1516 (void)ADBG_EXPECT_TEEC_RESULT(c,
1517 TEEC_ERROR_TARGET_DEAD,
1518 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_PANIC,
1519 NULL, &ret_orig));
1520
1521 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
1522
1523 TEEC_CloseSession(&session);
1524}
Jens Wiklander14f48872018-06-29 15:30:13 +02001525ADBG_CASE_DEFINE(regression, 1019, xtest_tee_test_1019,
1526 "Test dynamically linked TA");
1527#endif /*CFG_TA_DYNLINK*/
Jerome Forissier3357f872018-10-05 15:13:44 +02001528
1529static void xtest_tee_test_1020(ADBG_Case_t *c)
1530{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001531 TEEC_Result res = TEEC_ERROR_GENERIC;
1532 TEEC_Session session = { };
1533 uint32_t ret_orig = 0;
Jerome Forissier3357f872018-10-05 15:13:44 +02001534
1535 /* Pseudo TA is optional: warn and nicely exit if not found */
1536 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
1537 &ret_orig);
1538 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
1539 Do_ADBG_Log(" - 1020 - skip test, pseudo TA not found");
1540 return;
1541 }
1542 ADBG_EXPECT_TEEC_SUCCESS(c, res);
1543
1544 res = TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_LOCKDEP,
1545 NULL, &ret_orig);
1546 if (res != TEEC_SUCCESS) {
1547 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TRUSTED_APP,
1548 ret_orig);
1549 if (res == TEEC_ERROR_NOT_SUPPORTED) {
1550 Do_ADBG_Log(" - 1020 - skip test, feature not "
1551 "implemented");
1552 goto out;
1553 }
1554 /* Error */
1555 (void)ADBG_EXPECT_TEEC_SUCCESS(c, res);
1556 }
1557out:
1558 TEEC_CloseSession(&session);
1559}
1560ADBG_CASE_DEFINE(regression, 1020, xtest_tee_test_1020,
1561 "Test lockdep algorithm");
Ovidiu Mihalachi15cecff2019-04-02 16:36:31 +03001562
1563static TEEC_Result open_sec_session(TEEC_Session *session,
1564 const TEEC_UUID *uuid)
1565{
1566 TEEC_Result res = TEEC_ERROR_GENERIC;
1567 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1568 uint32_t ret_orig = 0;
1569
1570 op.params[0].tmpref.buffer = (void *)uuid;
1571 op.params[0].tmpref.size = sizeof(*uuid);
1572 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
1573 TEEC_NONE, TEEC_NONE, TEEC_NONE);
1574
1575 res = TEEC_InvokeCommand(session, TA_SIMS_OPEN_TA_SESSION,
1576 &op, &ret_orig);
1577 if (res != TEEC_SUCCESS)
1578 return TEEC_ERROR_GENERIC;
1579
1580 return res;
1581}
1582
1583static TEEC_Result sims_get_counter(TEEC_Session *session,
1584 uint32_t *counter)
1585{
1586 TEEC_Result res = TEEC_ERROR_GENERIC;
1587 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1588 uint32_t ret_orig = 0;
1589
1590 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT,
1591 TEEC_NONE, TEEC_NONE, TEEC_NONE);
1592
1593 res = TEEC_InvokeCommand(session, TA_SIMS_CMD_GET_COUNTER,
1594 &op, &ret_orig);
1595 if (res == TEEC_SUCCESS)
1596 *counter = op.params[0].value.a;
1597
1598 return res;
1599}
1600
1601static TEEC_Result trigger_panic(TEEC_Session *session,
1602 const TEEC_UUID *uuid)
1603{
1604 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1605 uint32_t ret_orig = 0;
1606
1607 if (!uuid) {
1608 op.params[0].tmpref.buffer = NULL;
1609 op.params[0].tmpref.size = 0;
1610 } else {
1611 op.params[0].tmpref.buffer = (void *)uuid;
1612 op.params[0].tmpref.size = sizeof(*uuid);
1613 }
1614 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
1615 TEEC_NONE, TEEC_NONE, TEEC_NONE);
1616
1617 return TEEC_InvokeCommand(session, TA_SIMS_CMD_PANIC,
1618 &op, &ret_orig);
1619}
1620
1621static void test_panic_ca_to_ta(ADBG_Case_t *c, const TEEC_UUID *uuid,
1622 bool multi_instance)
1623{
1624 TEEC_Result exp_res = TEEC_ERROR_GENERIC;
1625 uint32_t counter = 0;
1626 uint32_t ret_orig = 0;
1627 uint32_t exp_counter = 0;
1628 TEEC_Session cs[3] = { };
1629
1630 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1631 xtest_teec_open_session(&cs[0], uuid, NULL,
1632 &ret_orig)))
1633 return;
1634
1635 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1636 xtest_teec_open_session(&cs[1], uuid, NULL,
1637 &ret_orig)))
1638 goto bail0;
1639
1640 if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter)))
1641 goto bail1;
1642
1643 if (!ADBG_EXPECT(c, 0, counter))
1644 goto bail1;
1645
1646 if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[1], &counter)))
1647 goto bail1;
1648
1649 exp_counter = multi_instance ? 0 : 1;
Ovidiu Mihalachi110aac42019-09-11 14:08:01 +03001650 if (!ADBG_EXPECT(c, exp_counter, counter))
Ovidiu Mihalachi15cecff2019-04-02 16:36:31 +03001651 goto bail1;
1652
1653 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD,
1654 trigger_panic(&cs[1], NULL)))
1655 goto bail1;
1656
1657 exp_res = multi_instance ? TEEC_SUCCESS : TEEC_ERROR_TARGET_DEAD;
1658 if (!ADBG_EXPECT_TEEC_RESULT(c, exp_res,
1659 sims_get_counter(&cs[0], &counter)))
1660 goto bail1;
1661
1662 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD,
1663 sims_get_counter(&cs[1], &counter)))
1664 goto bail1;
1665
1666 /* Attempt to open a session on panicked context */
Ovidiu Mihalachi110aac42019-09-11 14:08:01 +03001667 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Ovidiu Mihalachi15cecff2019-04-02 16:36:31 +03001668 xtest_teec_open_session(&cs[1], uuid, NULL,
1669 &ret_orig)))
1670 goto bail1;
1671
1672 /* Sanity check of still valid TA context */
1673 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1674 xtest_teec_open_session(&cs[2], uuid, NULL,
1675 &ret_orig)))
1676 goto bail1;
1677
1678 /* Sanity check of still valid TA context */
1679 if (multi_instance) {
1680 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1681 sims_get_counter(&cs[0], &counter)))
1682 goto bail2;
1683
1684 if (!ADBG_EXPECT(c, 0, counter))
1685 goto bail2;
1686 }
1687
1688 if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[2], &counter)))
1689 goto bail2;
1690
Ovidiu Mihalachi110aac42019-09-11 14:08:01 +03001691 exp_counter = multi_instance ? 0 : 1;
1692 if (!ADBG_EXPECT(c, exp_counter, counter))
Ovidiu Mihalachi15cecff2019-04-02 16:36:31 +03001693 goto bail2;
1694
1695bail2:
1696 TEEC_CloseSession(&cs[2]);
1697bail1:
1698 TEEC_CloseSession(&cs[1]);
1699bail0:
1700 TEEC_CloseSession(&cs[0]);
1701}
1702
1703static void test_panic_ta_to_ta(ADBG_Case_t *c, const TEEC_UUID *uuid1,
1704 const TEEC_UUID *uuid2)
1705{
1706 uint32_t ret_orig = 0;
1707 uint32_t counter = 0;
1708 TEEC_Session cs[3] = { };
1709
1710 /* Test pre-conditions */
1711 /* 2.1 - CA opens a session toward TA1 */
1712 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1713 xtest_teec_open_session(&cs[0], uuid1, NULL,
1714 &ret_orig)))
1715 return;
1716
1717 /* 2.2 - CA opens a session toward TA2 */
1718 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1719 xtest_teec_open_session(&cs[1], uuid2, NULL,
1720 &ret_orig)))
1721 goto bail0;
1722
1723 /* 2.3 - TA1 opens a session toward TA2 */
1724 if (!ADBG_EXPECT_TEEC_SUCCESS(c, open_sec_session(&cs[0], uuid2)))
1725 goto bail1;
1726
1727 /* 2.4 - CA invokes TA2 which panics */
1728 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD,
1729 trigger_panic(&cs[1], NULL)))
1730 goto bail1;
1731
1732 /* Expected results */
1733 /* 2.5 - Expect CA->TA1 session is still alive */
1734 if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter)))
1735 goto bail1;
1736
1737 /* 2.6 - Expect CA->TA2 session is properly released */
1738 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD,
1739 sims_get_counter(&cs[1], &counter)))
1740 goto bail1;
1741
1742bail1:
1743 TEEC_CloseSession(&cs[1]);
1744bail0:
1745 TEEC_CloseSession(&cs[0]);
1746
1747 memset(cs, 0, sizeof(cs));
1748
1749 /* Test pre-conditions */
1750 /* 2.1 - CA opens a session toward TA1 */
1751 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1752 xtest_teec_open_session(&cs[0], uuid1, NULL,
1753 &ret_orig)))
1754 return;
1755
1756 /* 2.2 - CA opens a session toward TA2 */
1757 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1758 xtest_teec_open_session(&cs[1], uuid2, NULL,
1759 &ret_orig)))
1760 goto bail2;
1761
1762 /* 2.3 - TA1 opens a session toward TA2 */
1763 if (!ADBG_EXPECT_TEEC_SUCCESS(c, open_sec_session(&cs[0], uuid2)))
1764 goto bail3;
1765
1766 /* 2.4 - CA invokes TA1 which invokes TA2 which panics */
1767 if (!ADBG_EXPECT_TEEC_SUCCESS(c, trigger_panic(&cs[0], uuid2)))
1768 goto bail3;
1769
1770 /* Expected results */
1771 /* 2.5 - Expect CA->TA1 session is still alive */
1772 if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter)))
1773 goto bail3;
1774
1775 /* 2.6 - Expect CA->TA2 session is properly released */
1776 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD,
1777 sims_get_counter(&cs[1], &counter)))
1778 goto bail3;
1779
1780bail3:
1781 TEEC_CloseSession(&cs[1]);
1782bail2:
1783 TEEC_CloseSession(&cs[0]);
1784}
1785
1786static void xtest_tee_test_1021(ADBG_Case_t *c)
1787{
1788 Do_ADBG_BeginSubCase(c, "Multiple Instances Single Session");
1789 test_panic_ca_to_ta(c, &miss_test_ta_uuid, true);
1790 Do_ADBG_EndSubCase(c, "Multiple Instances Single Session");
1791
1792 Do_ADBG_BeginSubCase(c, "Single Instance Multi Sessions");
1793 test_panic_ca_to_ta(c, &sims_test_ta_uuid, false);
1794 Do_ADBG_EndSubCase(c, "Single Instance Multi Sessions");
1795
1796 Do_ADBG_BeginSubCase(c, "Single Instance Multi Sessions Keep Alive");
1797 test_panic_ca_to_ta(c, &sims_keepalive_test_ta_uuid, false);
1798 Do_ADBG_EndSubCase(c, "Single Instance Multi Sessions Keep Alive");
1799
1800 Do_ADBG_BeginSubCase(c, "Multi Sessions TA to TA");
1801 test_panic_ta_to_ta(c, &sims_test_ta_uuid,
1802 &sims_keepalive_test_ta_uuid);
1803 Do_ADBG_EndSubCase(c, "Multi Sessions TA to TA");
1804}
1805ADBG_CASE_DEFINE(regression, 1021, xtest_tee_test_1021,
1806 "Test panic context release");
Jerome Forissiera9ab5d02019-03-17 21:14:06 +01001807
1808static void xtest_tee_test_1022(ADBG_Case_t *c)
1809{
1810 TEEC_Session session = { 0 };
1811 uint32_t ret_orig = 0;
1812
1813 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1814 xtest_teec_open_session(&session, &os_test_ta_uuid,
1815 NULL, &ret_orig)))
1816 return;
1817
1818 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1819 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL, NULL,
1820 &ret_orig));
1821
1822 (void)ADBG_EXPECT_TEEC_RESULT(c,
1823 TEEC_ERROR_TARGET_DEAD,
1824 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL_PANIC,
1825 NULL, &ret_orig));
1826
1827 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
1828
1829 TEEC_CloseSession(&session);
1830}
1831ADBG_CASE_DEFINE(regression, 1022, xtest_tee_test_1022,
1832 "Test dlopen()/dlsym()/dlclose() API");
Jerome Forissiere9571e82020-02-18 15:26:20 +01001833
1834/*
1835 * Testing the ELF initialization (.init_array)
1836 *
1837 * - The TA has a global variable which can also be accessed by the two shared
1838 * libraries os_test_lib (linked with the TA) and os_test_lib_dl (loaded via
1839 * dlopen())
1840 * - The TA and both libraries have initialization functions (declared with the
1841 * "constructor" attribute) which perform the following:
1842 * * The TA multiplies by 10 then adds 1
1843 * * os_test_lib multiplies by 10 then adds 2
1844 * * os_test_lib_dl multiplies by 10 then adds 3
1845 * By testing the variable value we make sure the initializations occurred in
1846 * the correct order.
1847 */
1848static void xtest_tee_test_1023(ADBG_Case_t *c)
1849{
1850 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1851 TEEC_Session session = { 0 };
1852 uint32_t ret_orig = 0;
1853
1854 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE,
1855 TEEC_NONE, TEEC_NONE);
1856
1857 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1858 xtest_teec_open_session(&session, &os_test_ta_uuid,
1859 NULL, &ret_orig)))
1860 return;
1861
1862 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1863 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_GET_GLOBAL_VAR, &op,
1864 &ret_orig));
1865
1866 /* Expected: initialization of os_test_lib, then TA */
1867 (void)ADBG_EXPECT_COMPARE_SIGNED(c, op.params[0].value.a, ==, 21);
1868
1869 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1870 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL, NULL,
1871 &ret_orig));
1872
1873 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1874 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_GET_GLOBAL_VAR, &op,
1875 &ret_orig));
1876
1877 /* Expected: initialization of os_test_lib_dl */
1878 (void)ADBG_EXPECT_COMPARE_SIGNED(c, op.params[0].value.a, ==, 213);
1879
1880 TEEC_CloseSession(&session);
1881}
1882ADBG_CASE_DEFINE(regression, 1023, xtest_tee_test_1023,
1883 "Test ELF initialization (.init_array)");
Javier Almansa Sobrinocddc0002020-02-10 13:35:37 +00001884
1885#ifdef CFG_CORE_TPM_EVENT_LOG
1886static void xtest_tee_test_1024(ADBG_Case_t *c)
1887{
1888 TEEC_Session session = {};
1889 uint32_t ret_orig = 0;
1890
1891 xtest_teec_open_session(&session, &tpm_log_test_ta_uuid,
1892 NULL, &ret_orig);
1893
1894 Do_ADBG_BeginSubCase(c, "TPM test service invocation");
1895 ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(&session,
1896 TA_TPM_TEST_GET_LOG,
1897 NULL, &ret_orig));
1898 Do_ADBG_EndSubCase(c, "TPM test service invocation");
1899
1900 Do_ADBG_BeginSubCase(c, "TPM test passing short buffer");
1901 ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(&session,
1902 TA_TPM_TEST_SHORT_BUF,
1903 NULL, &ret_orig));
1904 Do_ADBG_EndSubCase(c, "TPM test passing short buffer");
1905
1906 TEEC_CloseSession(&session);
1907}
1908
1909ADBG_CASE_DEFINE(regression, 1024, xtest_tee_test_1024,
1910 "Test PTA_SYSTEM_GET_TPM_EVENT_LOG Service");
1911#endif /* CFG_CORE_TPM_EVENT_LOG */
Cedric Neveux9f483bb2019-03-04 08:58:06 +01001912
1913static void xtest_tee_test_1025(ADBG_Case_t *c)
1914{
1915 TEEC_Session session = {};
1916 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1917 uint32_t ret_orig = 0;
1918 uint8_t *empty_buf = NULL;
Etienne Carriere71383d42020-04-14 12:31:25 +02001919 TEEC_SharedMemory shm = { };
Etienne Carrieredba3f3b2020-04-08 17:08:16 +02001920 TEEC_Result res = TEEC_ERROR_GENERIC;
Etienne Carriere71383d42020-04-14 12:31:25 +02001921
1922 Do_ADBG_BeginSubCase(c, "Invalid NULL buffer memref registration");
1923
1924 memset(&shm, 0, sizeof(shm));
1925 shm.flags = TEEC_MEM_INPUT;
1926 shm.buffer = NULL;
1927 shm.size = 0;
1928
1929 ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS,
1930 TEEC_RegisterSharedMemory(&xtest_teec_ctx, &shm));
1931
1932 memset(&shm, 0, sizeof(shm));
1933 shm.flags = TEEC_MEM_OUTPUT;
1934 shm.buffer = NULL;
1935 shm.size = 0;
1936
1937 ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS,
1938 TEEC_RegisterSharedMemory(&xtest_teec_ctx, &shm));
1939
1940 Do_ADBG_EndSubCase(c, "Invalid NULL buffer memref registration");
Cedric Neveux9f483bb2019-03-04 08:58:06 +01001941
Etienne Carrierec602a522020-04-13 18:53:17 +02001942 if (!xtest_teec_ctx.memref_null) {
Etienne Carriere71383d42020-04-14 12:31:25 +02001943 Do_ADBG_Log("Skip subcases: MEMREF_NULL capability not supported");
Etienne Carrierec602a522020-04-13 18:53:17 +02001944 return;
1945 }
1946
Cedric Neveux9f483bb2019-03-04 08:58:06 +01001947 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1948 xtest_teec_open_session(&session,
1949 &os_test_ta_uuid,
1950 NULL, &ret_orig)))
1951 return;
1952
1953 empty_buf = malloc(1);
1954 if (!empty_buf) {
1955 (void)ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_ERROR_OUT_OF_MEMORY);
Etienne Carrieredba3f3b2020-04-08 17:08:16 +02001956 goto out_session;
Cedric Neveux9f483bb2019-03-04 08:58:06 +01001957 }
1958
1959 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
1960 TEEC_MEMREF_TEMP_INPUT,
1961 TEEC_MEMREF_TEMP_OUTPUT,
1962 TEEC_MEMREF_TEMP_OUTPUT);
1963
1964 Do_ADBG_BeginSubCase(c,
1965 "Input/Output MEMREF Buffer NULL - Size 0 bytes");
1966
1967 op.params[0].tmpref.buffer = empty_buf;
1968 op.params[0].tmpref.size = 0;
1969
1970 op.params[1].tmpref.buffer = NULL;
1971 op.params[1].tmpref.size = 0;
1972
1973 op.params[2].tmpref.buffer = empty_buf;
1974 op.params[2].tmpref.size = 0;
1975
1976 op.params[3].tmpref.buffer = NULL;
1977 op.params[3].tmpref.size = 0;
1978
1979 ADBG_EXPECT(c, TEE_SUCCESS,
1980 TEEC_InvokeCommand(&session,
1981 TA_OS_TEST_CMD_NULL_MEMREF_PARAMS, &op,
1982 &ret_orig));
1983
1984 Do_ADBG_EndSubCase(c, "Input/Output MEMREF Buffer NULL - Size 0 bytes");
1985
1986 Do_ADBG_BeginSubCase(c, "Input MEMREF Buffer NULL - Size non 0 bytes");
1987
1988 op.params[0].tmpref.buffer = empty_buf;
1989 op.params[0].tmpref.size = 1;
1990
1991 op.params[1].tmpref.buffer = NULL;
1992 op.params[1].tmpref.size = 0;
1993
1994 op.params[2].tmpref.buffer = empty_buf;
1995 op.params[2].tmpref.size = 0;
1996
1997 op.params[3].tmpref.buffer = NULL;
1998 op.params[3].tmpref.size = 0;
1999
2000 ADBG_EXPECT(c, TEE_ERROR_BAD_PARAMETERS,
2001 TEEC_InvokeCommand(&session,
2002 TA_OS_TEST_CMD_NULL_MEMREF_PARAMS, &op,
2003 &ret_orig));
2004
Etienne Carrieredba3f3b2020-04-08 17:08:16 +02002005 TEEC_CloseSession(&session);
2006
Cedric Neveux9f483bb2019-03-04 08:58:06 +01002007 Do_ADBG_EndSubCase(c, "Input MEMREF Buffer NULL - Size non 0 bytes");
2008
Etienne Carrieredba3f3b2020-04-08 17:08:16 +02002009 Do_ADBG_BeginSubCase(c, "Input MEMREF Buffer NULL over PTA invocation");
2010
2011 /* Pseudo TA is optional: warn and nicely exit if not found */
2012 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
2013 &ret_orig);
2014 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
2015 Do_ADBG_Log(" - 1025 - skip test, pseudo TA not found");
2016 goto out;
2017 }
2018 if (!ADBG_EXPECT_TEEC_SUCCESS(c, res))
2019 goto out;
2020
2021 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE,
2022 TEEC_NONE, TEEC_NONE);
2023 op.params[0].tmpref.buffer = NULL;
2024 op.params[0].tmpref.size = 0;
2025
2026 ADBG_EXPECT(c, TEE_SUCCESS,
2027 TEEC_InvokeCommand(&session,
2028 PTA_INVOKE_TESTS_CMD_MEMREF_NULL,
2029 &op, &ret_orig));
2030
2031out_session:
Cedric Neveux9f483bb2019-03-04 08:58:06 +01002032 TEEC_CloseSession(&session);
Etienne Carrieredba3f3b2020-04-08 17:08:16 +02002033out:
2034 Do_ADBG_EndSubCase(c, NULL);
Cedric Neveux9f483bb2019-03-04 08:58:06 +01002035 free(empty_buf);
2036}
2037ADBG_CASE_DEFINE(regression, 1025, xtest_tee_test_1025,
2038 "Test memref NULL and/or 0 bytes size");