blob: 33cfe57e56c5b1dadadffee2b39324df36d85c15 [file] [log] [blame]
Etienne Carriere9b7b70d2020-05-16 10:27:23 +02001// SPDX-License-Identifier: GPL-2.0
Pascal Brandc639ac82015-07-02 08:53:34 +02002/*
Javier Almansa Sobrinocddc0002020-02-10 13:35:37 +00003 * Copyright (c) 2020, ARM Limited. All rights reserved.
Pascal Brandc639ac82015-07-02 08:53:34 +02004 * Copyright (c) 2014, STMicroelectronics International N.V.
Pascal Brandc639ac82015-07-02 08:53:34 +02005 */
6
Aleksandr Anisimov01f6f062021-01-19 11:02:25 +03007#include <errno.h>
Etienne Carrierea4653552017-01-11 10:04:24 +01008#include <limits.h>
9#include <pthread.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020010#include <stdio.h>
Jens Wiklanderec545fb2017-11-24 16:58:07 +010011#include <stdlib.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020012#include <string.h>
David Brownb2865ab2016-08-02 11:44:41 -060013#include <sys/stat.h>
14#include <sys/types.h>
Etienne Carrierea4653552017-01-11 10:04:24 +010015#include <unistd.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020016
17#include "xtest_test.h"
18#include "xtest_helpers.h"
Vesa Jääskeläinen502c5492020-04-05 20:12:02 +030019#include "xtest_uuid_helpers.h"
Jens Wiklander4441fe22015-10-23 16:53:02 +020020#include <signed_hdr.h>
Etienne Carriere92c34422018-02-09 13:11:40 +010021#include <util.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020022
Etienne Carriere726d8bc2017-03-21 15:45:59 +010023#include <pta_invoke_tests.h>
Pascal Brandc639ac82015-07-02 08:53:34 +020024#include <ta_crypt.h>
25#include <ta_os_test.h>
26#include <ta_create_fail_test.h>
27#include <ta_rpc_test.h>
28#include <ta_sims_test.h>
Ovidiu Mihalachi15cecff2019-04-02 16:36:31 +030029#include <ta_miss_test.h>
30#include <ta_sims_keepalive_test.h>
Jens Wiklanderac27ec12015-07-15 15:23:14 +020031#include <ta_concurrent.h>
Javier Almansa Sobrinocddc0002020-02-10 13:35:37 +000032#include <ta_tpm_log_test.h>
Aleksandr Anisimov01f6f062021-01-19 11:02:25 +030033#include <ta_supp_plugin.h>
Etienne Carriere50abf9a2017-03-24 11:33:50 +010034#include <sdp_basic.h>
Jens Wiklanderec545fb2017-11-24 16:58:07 +010035#include <pta_secstor_ta_mgmt.h>
Jens Wiklanderec545fb2017-11-24 16:58:07 +010036
Aleksandr Anisimov01f6f062021-01-19 11:02:25 +030037#include <test_supp_plugin.h>
38
Jens Wiklanderec545fb2017-11-24 16:58:07 +010039#ifndef MIN
40#define MIN(a, b) ((a) < (b) ? (a) : (b))
41#endif
Pascal Brandc639ac82015-07-02 08:53:34 +020042
Pascal Brandc639ac82015-07-02 08:53:34 +020043struct xtest_crypto_session {
44 ADBG_Case_t *c;
45 TEEC_Session *session;
46 uint32_t cmd_id_sha256;
47 uint32_t cmd_id_aes256ecb_encrypt;
48 uint32_t cmd_id_aes256ecb_decrypt;
49};
50
51static void xtest_crypto_test(struct xtest_crypto_session *cs)
52{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +010053 uint32_t ret_orig = 0;
54 uint8_t crypt_out[16] = { };
Pascal Brandc639ac82015-07-02 08:53:34 +020055 uint8_t crypt_in[16] = { 22, 17 };
56
57 crypt_in[15] = 60;
58
59 Do_ADBG_BeginSubCase(cs->c, "AES encrypt");
60 {
61 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
62
63 op.params[0].tmpref.buffer = crypt_in;
64 op.params[0].tmpref.size = sizeof(crypt_in);
65 op.params[1].tmpref.buffer = crypt_out;
66 op.params[1].tmpref.size = sizeof(crypt_out);
67 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
68 TEEC_MEMREF_TEMP_OUTPUT,
69 TEEC_NONE, TEEC_NONE);
70
71 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
72 TEEC_InvokeCommand(cs->session,
73 cs->
74 cmd_id_aes256ecb_encrypt,
75 &op,
76 &ret_orig));
77 }
78 Do_ADBG_EndSubCase(cs->c, "AES encrypt");
79
80 Do_ADBG_BeginSubCase(cs->c, "AES decrypt");
81 {
82 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +010083 uint8_t out[16] = { };
Pascal Brandc639ac82015-07-02 08:53:34 +020084
85 op.params[0].tmpref.buffer = crypt_out;
86 op.params[0].tmpref.size = sizeof(crypt_out);
87 op.params[1].tmpref.buffer = out;
88 op.params[1].tmpref.size = sizeof(out);
89 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
90 TEEC_MEMREF_TEMP_OUTPUT,
91 TEEC_NONE, TEEC_NONE);
92
93 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
94 TEEC_InvokeCommand(cs->session,
95 cs->
96 cmd_id_aes256ecb_decrypt,
97 &op,
98 &ret_orig));
99
100 if (!ADBG_EXPECT(cs->c, 0,
101 memcmp(crypt_in, out, sizeof(crypt_in)))) {
102 Do_ADBG_Log("crypt_in:");
103 Do_ADBG_HexLog(crypt_in, sizeof(crypt_in), 16);
104 Do_ADBG_Log("out:");
105 Do_ADBG_HexLog(out, sizeof(out), 16);
106 }
107 }
108 Do_ADBG_EndSubCase(cs->c, "AES decrypt");
109
110 Do_ADBG_BeginSubCase(cs->c, "SHA-256 test, 3 bytes input");
111 {
112 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
113 static const uint8_t sha256_in[] = { 'a', 'b', 'c' };
114 static const uint8_t sha256_out[] = {
115 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
116 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
117 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
118 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
119 };
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100120 uint8_t out[32] = { };
Pascal Brandc639ac82015-07-02 08:53:34 +0200121
122 op.params[0].tmpref.buffer = (void *)sha256_in;
123 op.params[0].tmpref.size = sizeof(sha256_in);
124 op.params[1].tmpref.buffer = out;
125 op.params[1].tmpref.size = sizeof(out);
126 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
127 TEEC_MEMREF_TEMP_OUTPUT,
128 TEEC_NONE, TEEC_NONE);
129
130 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
131 TEEC_InvokeCommand(cs->session,
132 cs->
133 cmd_id_sha256,
134 &op,
135 &ret_orig));
136
137 if (!ADBG_EXPECT(cs->c, 0, memcmp(sha256_out, out,
138 sizeof(sha256_out)))) {
139 Do_ADBG_Log("sha256_out:");
140 Do_ADBG_HexLog(sha256_out, sizeof(sha256_out), 16);
141 Do_ADBG_Log("out:");
142 Do_ADBG_HexLog(out, sizeof(out), 16);
143 }
144 }
145 Do_ADBG_EndSubCase(cs->c, "SHA-256 test, 3 bytes input");
146
Etienne Carrierea3198522017-10-26 09:48:55 +0200147 Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200148 {
149 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
150 static const uint8_t in[] = {
151 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
152 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
153 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
154 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
155 };
156 static const uint8_t exp_out[] = {
157 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
158 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
159 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
160 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
161 };
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100162 uint8_t out[sizeof(exp_out)] = { };
Pascal Brandc639ac82015-07-02 08:53:34 +0200163
164 op.params[0].tmpref.buffer = (void *)in;
165 op.params[0].tmpref.size = sizeof(in);
166 op.params[1].tmpref.buffer = out;
167 op.params[1].tmpref.size = sizeof(out);
168 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
169 TEEC_MEMREF_TEMP_OUTPUT,
170 TEEC_NONE, TEEC_NONE);
171
172 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
173 TEEC_InvokeCommand(cs->session,
174 cs->
175 cmd_id_aes256ecb_encrypt,
176 &op,
177 &ret_orig));
178
179 if (!ADBG_EXPECT(cs->c, 0,
180 memcmp(exp_out, out, sizeof(exp_out)))) {
181 Do_ADBG_Log("exp_out:");
182 Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16);
183 Do_ADBG_Log("out:");
184 Do_ADBG_HexLog(out, sizeof(out), 16);
185 }
186 }
Etienne Carrierea3198522017-10-26 09:48:55 +0200187 Do_ADBG_EndSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200188
Etienne Carrierea3198522017-10-26 09:48:55 +0200189 Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200190 {
191 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
192 static const uint8_t in[] = {
193 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
194 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
195 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
196 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
197 };
198 static const uint8_t exp_out[] = {
199 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
200 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
201 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
202 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
203 };
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100204 uint8_t out[sizeof(exp_out)] = { };
Pascal Brandc639ac82015-07-02 08:53:34 +0200205
206 op.params[0].tmpref.buffer = (void *)in;
207 op.params[0].tmpref.size = sizeof(in);
208 op.params[1].tmpref.buffer = out;
209 op.params[1].tmpref.size = sizeof(out);
210 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
211 TEEC_MEMREF_TEMP_OUTPUT,
212 TEEC_NONE, TEEC_NONE);
213
214 (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c,
215 TEEC_InvokeCommand(cs->session,
216 cs->
217 cmd_id_aes256ecb_decrypt,
218 &op,
219 &ret_orig));
220
221 if (!ADBG_EXPECT(cs->c, 0,
222 memcmp(exp_out, out, sizeof(exp_out)))) {
223 Do_ADBG_Log("exp_out:");
224 Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16);
225 Do_ADBG_Log("out:");
226 Do_ADBG_HexLog(out, sizeof(out), 16);
227 }
228 }
Etienne Carrierea3198522017-10-26 09:48:55 +0200229 Do_ADBG_EndSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)");
Pascal Brandc639ac82015-07-02 08:53:34 +0200230}
231
232static void xtest_tee_test_1001(ADBG_Case_t *c)
233{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100234 TEEC_Result res = TEEC_ERROR_GENERIC;
235 TEEC_Session session = { };
236 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200237
Etienne Carriere11093162017-10-26 09:49:04 +0200238 /* Pseudo TA is optional: warn and nicely exit if not found */
Etienne Carriere726d8bc2017-03-21 15:45:59 +0100239 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
Jens Wiklandercf16e842016-02-10 09:07:09 +0100240 &ret_orig);
Etienne Carriere11093162017-10-26 09:49:04 +0200241 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
242 Do_ADBG_Log(" - 1001 - skip test, pseudo TA not found");
Jens Wiklandercf16e842016-02-10 09:07:09 +0100243 return;
Etienne Carriere11093162017-10-26 09:49:04 +0200244 }
245 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Pascal Brandc639ac82015-07-02 08:53:34 +0200246
Jens Wiklandercf16e842016-02-10 09:07:09 +0100247 (void)ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(
Etienne Carriere726d8bc2017-03-21 15:45:59 +0100248 &session, PTA_INVOKE_TESTS_CMD_SELF_TESTS, NULL, &ret_orig));
Jens Wiklandercf16e842016-02-10 09:07:09 +0100249 TEEC_CloseSession(&session);
Pascal Brandc639ac82015-07-02 08:53:34 +0200250}
Jens Wiklander14f48872018-06-29 15:30:13 +0200251ADBG_CASE_DEFINE(regression, 1001, xtest_tee_test_1001, "Core self tests");
Pascal Brandc639ac82015-07-02 08:53:34 +0200252
Jens Wiklander1d70a112017-10-16 15:16:39 +0200253static void xtest_tee_test_1002(ADBG_Case_t *c)
254{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100255 TEEC_Result res = TEEC_ERROR_GENERIC;
256 TEEC_Session session = { };
Jens Wiklander1d70a112017-10-16 15:16:39 +0200257 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100258 uint32_t ret_orig = 0;
259 uint8_t buf[16 * 1024] = { };
Jens Wiklander1d70a112017-10-16 15:16:39 +0200260 uint8_t exp_sum = 0;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100261 size_t n = 0;
Jens Wiklander1d70a112017-10-16 15:16:39 +0200262
Etienne Carriere11093162017-10-26 09:49:04 +0200263 /* Pseudo TA is optional: warn and nicely exit if not found */
Jens Wiklander1d70a112017-10-16 15:16:39 +0200264 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
265 &ret_orig);
Etienne Carriere11093162017-10-26 09:49:04 +0200266 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
267 Do_ADBG_Log(" - 1002 - skip test, pseudo TA not found");
Jens Wiklander1d70a112017-10-16 15:16:39 +0200268 return;
Etienne Carriere11093162017-10-26 09:49:04 +0200269 }
270 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Jens Wiklander1d70a112017-10-16 15:16:39 +0200271
272 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE,
273 TEEC_NONE, TEEC_NONE);
274 op.params[0].tmpref.size = sizeof(buf);
275 op.params[0].tmpref.buffer = buf;
276
277 for (n = 0; n < sizeof(buf); n++)
278 buf[n] = n + 1;
279 for (n = 0; n < sizeof(buf); n++)
280 exp_sum += buf[n];
281
282 if (!ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(
283 &session, PTA_INVOKE_TESTS_CMD_PARAMS, &op, &ret_orig)))
284 goto out;
285
286 ADBG_EXPECT_COMPARE_SIGNED(c, exp_sum, ==, buf[0]);
287out:
288 TEEC_CloseSession(&session);
289}
Jens Wiklander14f48872018-06-29 15:30:13 +0200290ADBG_CASE_DEFINE(regression, 1002, xtest_tee_test_1002, "PTA parameters");
Jens Wiklander1d70a112017-10-16 15:16:39 +0200291
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100292struct test_1003_arg {
293 uint32_t test_type;
294 size_t repeat;
295 size_t max_before_lockers;
296 size_t max_during_lockers;
297 size_t before_lockers;
298 size_t during_lockers;
299 TEEC_Result res;
300 uint32_t error_orig;
301};
Jens Wiklander1d70a112017-10-16 15:16:39 +0200302
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100303static void *test_1003_thread(void *arg)
304{
305 struct test_1003_arg *a = arg;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100306 TEEC_Session session = { };
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100307 size_t rounds = 64 * 1024;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100308 size_t n = 0;
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100309
310 a->res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid,
311 NULL, &a->error_orig);
312 if (a->res != TEEC_SUCCESS)
313 return NULL;
314
315 for (n = 0; n < a->repeat; n++) {
316 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
317
318 op.params[0].value.a = a->test_type;
319 op.params[0].value.b = rounds;
320
321 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
322 TEEC_VALUE_OUTPUT,
323 TEEC_NONE, TEEC_NONE);
324 a->res = TEEC_InvokeCommand(&session,
325 PTA_INVOKE_TESTS_CMD_MUTEX,
326 &op, &a->error_orig);
327 if (a->test_type == PTA_MUTEX_TEST_WRITER &&
328 op.params[1].value.b != 1) {
329 Do_ADBG_Log("n %zu %" PRIu32, n, op.params[1].value.b);
330 a->res = TEEC_ERROR_BAD_STATE;
331 a->error_orig = 42;
332 break;
333 }
334
335 if (a->test_type == PTA_MUTEX_TEST_READER) {
336 if (op.params[1].value.a > a->max_before_lockers)
337 a->max_before_lockers = op.params[1].value.a;
338
339 if (op.params[1].value.b > a->max_during_lockers)
340 a->max_during_lockers = op.params[1].value.b;
341
342 a->before_lockers += op.params[1].value.a;
343 a->during_lockers += op.params[1].value.b;
344 }
345 }
346 TEEC_CloseSession(&session);
347
348 return NULL;
349}
350
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100351#define TEST_1003_THREAD_COUNT (3 * 2)
352
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100353static void xtest_tee_test_1003(ADBG_Case_t *c)
354{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100355 TEEC_Result res = TEEC_ERROR_GENERIC;
356 TEEC_Session session = { };
357 uint32_t ret_orig = 0;
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100358 size_t repeat = 20;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100359 struct test_1003_arg arg[TEST_1003_THREAD_COUNT] = { };
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100360 size_t max_read_concurrency = 0;
361 size_t max_read_waiters = 0;
362 size_t num_concurrent_read_lockers = 0;
363 size_t num_concurrent_read_waiters = 0;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100364 size_t n = 0;
365 size_t nt = TEST_1003_THREAD_COUNT;
366 double mean_read_concurrency = 0;
367 double mean_read_waiters = 0;
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100368 size_t num_writers = 0;
369 size_t num_readers = 0;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100370 pthread_t thr[TEST_1003_THREAD_COUNT] = { };
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100371
372 /* Pseudo TA is optional: warn and nicely exit if not found */
373 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
374 &ret_orig);
375 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
376 Do_ADBG_Log(" - 1003 - skip test, pseudo TA not found");
377 return;
378 }
379 ADBG_EXPECT_TEEC_SUCCESS(c, res);
380 TEEC_CloseSession(&session);
381
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100382 for (n = 0; n < nt; n++) {
383 if (n % 3) {
384 arg[n].test_type = PTA_MUTEX_TEST_READER;
385 num_readers++;
386 } else {
387 arg[n].test_type = PTA_MUTEX_TEST_WRITER;
388 num_writers++;
389 }
390 arg[n].repeat = repeat;
391 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
392 test_1003_thread, arg + n)))
393 nt = n; /* break loop and start cleanup */
394 }
395
396 for (n = 0; n < nt; n++) {
397 ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL));
398 if (!ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res))
399 Do_ADBG_Log("error origin %" PRIu32,
400 arg[n].error_orig);
401 if (arg[n].test_type == PTA_MUTEX_TEST_READER) {
402 if (arg[n].max_during_lockers > max_read_concurrency)
403 max_read_concurrency =
404 arg[n].max_during_lockers;
405
406 if (arg[n].max_before_lockers > max_read_waiters)
407 max_read_waiters = arg[n].max_before_lockers;
408
409 num_concurrent_read_lockers += arg[n].during_lockers;
410 num_concurrent_read_waiters += arg[n].before_lockers;
411 }
412 }
413
414 mean_read_concurrency = (double)num_concurrent_read_lockers /
415 (double)(repeat * num_readers);
416 mean_read_waiters = (double)num_concurrent_read_waiters /
417 (double)(repeat * num_readers);
418
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100419 Do_ADBG_Log(" Number of parallel threads: %d (%zu writers and %zu readers)",
420 TEST_1003_THREAD_COUNT, num_writers, num_readers);
Jens Wiklander0c86bc32017-11-13 19:52:03 +0100421 Do_ADBG_Log(" Max read concurrency: %zu", max_read_concurrency);
422 Do_ADBG_Log(" Max read waiters: %zu", max_read_waiters);
423 Do_ADBG_Log(" Mean read concurrency: %g", mean_read_concurrency);
424 Do_ADBG_Log(" Mean read waiting: %g", mean_read_waiters);
425}
Jens Wiklander14f48872018-06-29 15:30:13 +0200426ADBG_CASE_DEFINE(regression, 1003, xtest_tee_test_1003,
427 "Core internal read/write mutex");
Jens Wiklander1d70a112017-10-16 15:16:39 +0200428
Pascal Brandc639ac82015-07-02 08:53:34 +0200429static void xtest_tee_test_1004(ADBG_Case_t *c)
430{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100431 TEEC_Session session = { };
432 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200433 struct xtest_crypto_session cs = { c, &session, TA_CRYPT_CMD_SHA256,
434 TA_CRYPT_CMD_AES256ECB_ENC,
435 TA_CRYPT_CMD_AES256ECB_DEC };
436
437 if (!ADBG_EXPECT_TEEC_SUCCESS(c, xtest_teec_open_session(
438 &session, &crypt_user_ta_uuid,
439 NULL, &ret_orig)))
440 return;
441
442 /* Run the "complete crypto test suite" */
443 xtest_crypto_test(&cs);
444
445 TEEC_CloseSession(&session);
446}
Jens Wiklander14f48872018-06-29 15:30:13 +0200447ADBG_CASE_DEFINE(regression, 1004, xtest_tee_test_1004, "Test User Crypt TA");
Pascal Brandc639ac82015-07-02 08:53:34 +0200448
Etienne Carriere92c34422018-02-09 13:11:40 +0100449static void xtest_tee_test_invalid_mem_access(ADBG_Case_t *c, unsigned int n)
Pascal Brandc639ac82015-07-02 08:53:34 +0200450{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100451 TEEC_Session session = { };
Pascal Brandc639ac82015-07-02 08:53:34 +0200452 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100453 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200454
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300455 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200456 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300457 &ret_orig)))
458 return;
Pascal Brandc639ac82015-07-02 08:53:34 +0200459
460 op.params[0].value.a = n;
461 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE,
462 TEEC_NONE);
463
464 (void)ADBG_EXPECT_TEEC_RESULT(c,
465 TEEC_ERROR_TARGET_DEAD,
466 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op,
467 &ret_orig));
468
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300469 (void)ADBG_EXPECT_TEEC_RESULT(c,
470 TEEC_ERROR_TARGET_DEAD,
471 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op,
Pascal Brandc639ac82015-07-02 08:53:34 +0200472 &ret_orig));
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300473
Pascal Brandc639ac82015-07-02 08:53:34 +0200474 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
475
476 TEEC_CloseSession(&session);
477}
478
Etienne Carriere92c34422018-02-09 13:11:40 +0100479static void xtest_tee_test_invalid_mem_access2(ADBG_Case_t *c, unsigned int n,
480 size_t size)
481{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100482 TEEC_Session session = { };
Etienne Carriere92c34422018-02-09 13:11:40 +0100483 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100484 uint32_t ret_orig = 0;
485 TEEC_SharedMemory shm = { };
Etienne Carriere92c34422018-02-09 13:11:40 +0100486
Etienne Carriere92c34422018-02-09 13:11:40 +0100487 shm.size = size;
488 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
489 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
490 TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm)))
491 return;
492
493 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
494 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
495 &ret_orig)))
Jens Wiklander6987a822019-06-28 12:47:42 +0200496 goto rel_shm;
Etienne Carriere92c34422018-02-09 13:11:40 +0100497
498 op.params[0].value.a = (uint32_t)n;
499 op.params[1].memref.parent = &shm;
500 op.params[1].memref.size = size;
501 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_MEMREF_WHOLE,
502 TEEC_NONE, TEEC_NONE);
503
504 (void)ADBG_EXPECT_TEEC_RESULT(c,
505 TEEC_ERROR_TARGET_DEAD,
506 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op,
507 &ret_orig));
508
509 (void)ADBG_EXPECT_TEEC_RESULT(c,
510 TEEC_ERROR_TARGET_DEAD,
511 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op,
512 &ret_orig));
513
514 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
515
516 TEEC_CloseSession(&session);
Jens Wiklander6987a822019-06-28 12:47:42 +0200517rel_shm:
518 TEEC_ReleaseSharedMemory(&shm);
Etienne Carriere92c34422018-02-09 13:11:40 +0100519}
520
Pascal Brandc639ac82015-07-02 08:53:34 +0200521static void xtest_tee_test_1005(ADBG_Case_t *c)
522{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100523 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200524#define MAX_SESSIONS 3
525 TEEC_Session sessions[MAX_SESSIONS];
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100526 int i = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200527
528 for (i = 0; i < MAX_SESSIONS; i++) {
529 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Jens Wiklandereb6bce72016-09-23 11:37:33 +0200530 xtest_teec_open_session(&sessions[i],
531 &concurrent_ta_uuid,
Pascal Brandc639ac82015-07-02 08:53:34 +0200532 NULL, &ret_orig)))
533 break;
534 }
535
536 for (; --i >= 0; )
537 TEEC_CloseSession(&sessions[i]);
538}
Jens Wiklander14f48872018-06-29 15:30:13 +0200539ADBG_CASE_DEFINE(regression, 1005, xtest_tee_test_1005, "Many sessions");
Pascal Brandc639ac82015-07-02 08:53:34 +0200540
541static void xtest_tee_test_1006(ADBG_Case_t *c)
542{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100543 TEEC_Session session = { };
544 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200545 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100546 uint8_t buf[32] = { };
Pascal Brandc639ac82015-07-02 08:53:34 +0200547
548 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
549 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
550 &ret_orig)))
551 return;
552
553 op.params[0].tmpref.buffer = buf;
554 op.params[0].tmpref.size = sizeof(buf);
555 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE,
556 TEEC_NONE, TEEC_NONE);
557
558 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
559 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BASIC, &op,
560 &ret_orig));
561
562 TEEC_CloseSession(&session);
563}
Jens Wiklander14f48872018-06-29 15:30:13 +0200564ADBG_CASE_DEFINE(regression, 1006, xtest_tee_test_1006,
565 "Test Basic OS features");
Pascal Brandc639ac82015-07-02 08:53:34 +0200566
567static void xtest_tee_test_1007(ADBG_Case_t *c)
568{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100569 TEEC_Session session = { };
570 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200571
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300572 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200573 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300574 &ret_orig)))
575 return;
Pascal Brandc639ac82015-07-02 08:53:34 +0200576
577 (void)ADBG_EXPECT_TEEC_RESULT(c,
578 TEEC_ERROR_TARGET_DEAD,
579 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PANIC, NULL,
580 &ret_orig));
581
582 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
583
584 (void)ADBG_EXPECT_TEEC_RESULT(c,
585 TEEC_ERROR_TARGET_DEAD,
586 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_INIT, NULL,
587 &ret_orig));
588
589 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
590
591 TEEC_CloseSession(&session);
592}
Jens Wiklander14f48872018-06-29 15:30:13 +0200593ADBG_CASE_DEFINE(regression, 1007, xtest_tee_test_1007, "Test Panic");
Pascal Brandc639ac82015-07-02 08:53:34 +0200594
Jerome Forissierf02a2212015-10-29 14:33:35 +0100595#ifndef TA_DIR
Victor Chong3d8798f2017-03-01 18:31:48 +0000596# ifdef __ANDROID__
Yongqin Liu286f1fc2018-06-21 22:09:15 +0800597#define TA_DIR "/vendor/lib/optee_armtz"
Victor Chong3d8798f2017-03-01 18:31:48 +0000598# else
Jerome Forissierf02a2212015-10-29 14:33:35 +0100599#define TA_DIR "/lib/optee_armtz"
Victor Chong3d8798f2017-03-01 18:31:48 +0000600# endif
Jerome Forissierf02a2212015-10-29 14:33:35 +0100601#endif
602
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100603static FILE *open_ta_file(const TEEC_UUID *uuid, const char *mode)
David Brownb2865ab2016-08-02 11:44:41 -0600604{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100605 char buf[PATH_MAX] = { };
David Brownb2865ab2016-08-02 11:44:41 -0600606
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100607 snprintf(buf, sizeof(buf),
Jens Wiklander6203b872016-12-08 19:18:29 +0100608 "%s/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.ta",
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100609 TA_DIR, uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion,
Jens Wiklanderb7940892015-10-23 16:02:40 +0200610 uuid->clockSeqAndNode[0], uuid->clockSeqAndNode[1],
611 uuid->clockSeqAndNode[2], uuid->clockSeqAndNode[3],
612 uuid->clockSeqAndNode[4], uuid->clockSeqAndNode[5],
David Brownb2865ab2016-08-02 11:44:41 -0600613 uuid->clockSeqAndNode[6], uuid->clockSeqAndNode[7]);
Jens Wiklanderb7940892015-10-23 16:02:40 +0200614
Jens Wiklanderb7940892015-10-23 16:02:40 +0200615 return fopen(buf, mode);
616}
617
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100618static bool load_corrupt_ta(ADBG_Case_t *c, size_t offs, uint8_t mask)
Jens Wiklander4441fe22015-10-23 16:53:02 +0200619{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100620 TEEC_Session session = { };
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100621 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
622 TEEC_UUID uuid = PTA_SECSTOR_TA_MGMT_UUID;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100623 TEEC_Result res = TEEC_ERROR_GENERIC;
624 uint32_t ret_orig = 0;
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100625 FILE *f = NULL;
626 bool r = false;
627 uint8_t *buf = NULL;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100628 size_t sz = 0;
629 size_t fread_res = 0;
Jens Wiklander4441fe22015-10-23 16:53:02 +0200630
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100631 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
632 xtest_teec_open_session(&session, &uuid, NULL, &ret_orig)))
633 goto out;
Jens Wiklander4441fe22015-10-23 16:53:02 +0200634
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100635 f = open_ta_file(&create_fail_test_ta_uuid, "rb");
636 if (!ADBG_EXPECT_NOT_NULL(c, f))
637 goto out;
638 if (!ADBG_EXPECT_TRUE(c, !fseek(f, 0, SEEK_END)))
639 goto out;
640 sz = ftell(f);
641 rewind(f);
642
643 buf = malloc(sz);
644 if (!ADBG_EXPECT_NOT_NULL(c, buf))
645 goto out;
646
647 fread_res = fread(buf, 1, sz, f);
648 if (!ADBG_EXPECT_COMPARE_UNSIGNED(c, fread_res, ==, sz))
649 goto out;
650
Jens Wiklander4441fe22015-10-23 16:53:02 +0200651 fclose(f);
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100652 f = NULL;
Jens Wiklander4441fe22015-10-23 16:53:02 +0200653
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100654 buf[MIN(offs, sz)] ^= mask;
Jens Wiklander4441fe22015-10-23 16:53:02 +0200655
Jens Wiklanderec545fb2017-11-24 16:58:07 +0100656 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE,
657 TEEC_NONE, TEEC_NONE);
658 op.params[0].tmpref.buffer = buf;
659 op.params[0].tmpref.size = sz;
660
661 res = TEEC_InvokeCommand(&session, PTA_SECSTOR_TA_MGMT_BOOTSTRAP, &op,
662 &ret_orig);
663 r = ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_SECURITY, res);
664out:
665 free(buf);
666 if (f)
667 fclose(f);
668 TEEC_CloseSession(&session);
Jens Wiklander4441fe22015-10-23 16:53:02 +0200669 return r;
670}
Jens Wiklandere1a201d2020-02-12 18:36:20 +0100671
672static void test_1008_corrupt_ta(ADBG_Case_t *c)
673{
674 TEEC_UUID uuid = PTA_SECSTOR_TA_MGMT_UUID;
675 TEEC_Result res = TEEC_ERROR_GENERIC;
676 TEEC_Session session = { };
677 uint32_t ret_orig = 0;
678
679 res = xtest_teec_open_session(&session, &uuid, NULL, &ret_orig);
680 if (res) {
681 if (ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
682 res))
Joakim Becha1212b62020-04-07 12:06:00 +0200683 Do_ADBG_Log("PTA Secure Storage TA Management not found: skip test");
Jens Wiklandere1a201d2020-02-12 18:36:20 +0100684 return;
685 }
686 TEEC_CloseSession(&session);
687
688 ADBG_EXPECT_TRUE(c,
689 load_corrupt_ta(c, offsetof(struct shdr, magic), 1));
690 ADBG_EXPECT_TRUE(c,
691 load_corrupt_ta(c, offsetof(struct shdr, img_type), 1));
692 ADBG_EXPECT_TRUE(c,
693 load_corrupt_ta(c, offsetof(struct shdr, img_size), 1));
694 ADBG_EXPECT_TRUE(c,
695 load_corrupt_ta(c, offsetof(struct shdr, algo), 1));
696 ADBG_EXPECT_TRUE(c,
697 load_corrupt_ta(c, offsetof(struct shdr, hash_size), 1));
698 ADBG_EXPECT_TRUE(c,
699 load_corrupt_ta(c, offsetof(struct shdr, sig_size), 1));
700 ADBG_EXPECT_TRUE(c,
701 load_corrupt_ta(c, sizeof(struct shdr), 1)); /* hash */
702 ADBG_EXPECT_TRUE(c,
703 load_corrupt_ta(c, sizeof(struct shdr) + 32, 1)); /* sig */
704 ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 3000, 1)); /* payload */
705 ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 8000, 1)); /* payload */
706}
Jens Wiklander4441fe22015-10-23 16:53:02 +0200707
Pascal Brandc639ac82015-07-02 08:53:34 +0200708static void xtest_tee_test_1008(ADBG_Case_t *c)
709{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100710 TEEC_Session session = { };
711 TEEC_Session session_crypt = { };
712 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200713
714 Do_ADBG_BeginSubCase(c, "Invoke command");
715 {
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300716 if (ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200717 xtest_teec_open_session(&session, &os_test_ta_uuid,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300718 NULL, &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200719
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300720 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
721 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CLIENT,
722 NULL, &ret_orig));
723 TEEC_CloseSession(&session);
724 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200725
Pascal Brandc639ac82015-07-02 08:53:34 +0200726 }
727 Do_ADBG_EndSubCase(c, "Invoke command");
728
729 Do_ADBG_BeginSubCase(c, "Invoke command with timeout");
730 {
731 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
732
733 op.params[0].value.a = 2000;
734 op.paramTypes = TEEC_PARAM_TYPES(
735 TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE);
736
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300737 if (ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200738 xtest_teec_open_session(&session,
739 &os_test_ta_uuid,
740 NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300741 &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200742
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300743 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
744 TEEC_InvokeCommand(&session,
745 TA_OS_TEST_CMD_CLIENT_WITH_TIMEOUT,
746 &op, &ret_orig));
747 TEEC_CloseSession(&session);
748 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200749 }
750 Do_ADBG_EndSubCase(c, "Invoke command with timeout");
751
752 Do_ADBG_BeginSubCase(c, "Create session fail");
753 {
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100754 size_t n = 0;
Jens Wiklanderb7940892015-10-23 16:02:40 +0200755
Pascal Brandc639ac82015-07-02 08:53:34 +0200756 for (n = 0; n < 100; n++) {
757 Do_ADBG_Log("n = %zu", n);
758 (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC,
759 xtest_teec_open_session(&session_crypt,
760 &create_fail_test_ta_uuid,
761 NULL, &ret_orig));
Jerome Forissierec7a31f2020-11-20 11:30:06 +0100762 /* level > 0 may be used to detect/debug memory leaks */
763 if (!level)
764 break;
Pascal Brandc639ac82015-07-02 08:53:34 +0200765 }
766 }
767 Do_ADBG_EndSubCase(c, "Create session fail");
Jens Wiklanderb7940892015-10-23 16:02:40 +0200768
Jens Wiklander4441fe22015-10-23 16:53:02 +0200769 Do_ADBG_BeginSubCase(c, "Load corrupt TA");
Jens Wiklandere1a201d2020-02-12 18:36:20 +0100770 test_1008_corrupt_ta(c);
Jens Wiklander4441fe22015-10-23 16:53:02 +0200771 Do_ADBG_EndSubCase(c, "Load corrupt TA");
Pascal Brandc639ac82015-07-02 08:53:34 +0200772}
Jens Wiklander14f48872018-06-29 15:30:13 +0200773ADBG_CASE_DEFINE(regression, 1008, xtest_tee_test_1008,
774 "TEE internal client API");
Pascal Brandc639ac82015-07-02 08:53:34 +0200775
Pascal Brandc639ac82015-07-02 08:53:34 +0200776static void *cancellation_thread(void *arg)
777{
778 /*
779 * Sleep 0.5 seconds before cancellation to make sure that the other
780 * thread is in RPC_WAIT.
781 */
782 (void)usleep(500000);
783 TEEC_RequestCancellation(arg);
784 return NULL;
785}
Pascal Brandc639ac82015-07-02 08:53:34 +0200786
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300787static void xtest_tee_test_1009_subcase(ADBG_Case_t *c, const char *subcase,
788 uint32_t timeout, bool cancel)
Pascal Brandc639ac82015-07-02 08:53:34 +0200789{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100790 TEEC_Session session = { };
791 uint32_t ret_orig = 0;
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300792 pthread_t thr;
Pascal Brandc639ac82015-07-02 08:53:34 +0200793
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100794 memset(&thr, 0, sizeof(thr));
795
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300796 Do_ADBG_BeginSubCase(c, "%s", subcase);
Pascal Brandc639ac82015-07-02 08:53:34 +0200797 {
798 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
799
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300800 if (ADBG_EXPECT_TEEC_SUCCESS(c,
801 xtest_teec_open_session(&session, &os_test_ta_uuid,
802 NULL, &ret_orig))) {
Pascal Brandc639ac82015-07-02 08:53:34 +0200803
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300804 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c,
805 TEEC_ORIGIN_TRUSTED_APP,
806 ret_orig);
Pascal Brandc639ac82015-07-02 08:53:34 +0200807
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300808 op.params[0].value.a = timeout;
809 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
810 TEEC_NONE,
811 TEEC_NONE, TEEC_NONE);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300812 if (cancel) {
813 (void)ADBG_EXPECT(c, 0,
814 pthread_create(&thr, NULL,
815 cancellation_thread, &op));
Pascal Brandc639ac82015-07-02 08:53:34 +0200816
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300817 (void)ADBG_EXPECT_TEEC_RESULT(c,
818 TEEC_ERROR_CANCEL,
819 TEEC_InvokeCommand(&session,
820 TA_OS_TEST_CMD_WAIT,
821 &op,
822 &ret_orig));
823 } else
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300824
825 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
826 TEEC_InvokeCommand(&session,
827 TA_OS_TEST_CMD_WAIT,
828 &op,
829 &ret_orig));
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300830 if (cancel)
831 (void)ADBG_EXPECT(c, 0, pthread_join(thr, NULL));
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300832
833 TEEC_CloseSession(&session);
834 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200835 }
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300836 Do_ADBG_EndSubCase(c, "%s", subcase);
837}
838
839static void xtest_tee_test_1009(ADBG_Case_t *c)
840{
841 xtest_tee_test_1009_subcase(c, "TEE Wait 0.1s", 100, false);
842 xtest_tee_test_1009_subcase(c, "TEE Wait 0.5s", 500, false);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300843 xtest_tee_test_1009_subcase(c, "TEE Wait 2s cancel", 2000, true);
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300844 xtest_tee_test_1009_subcase(c, "TEE Wait 2s", 2000, false);
Pascal Brandc639ac82015-07-02 08:53:34 +0200845}
Jens Wiklander14f48872018-06-29 15:30:13 +0200846ADBG_CASE_DEFINE(regression, 1009, xtest_tee_test_1009, "TEE Wait");
Pascal Brandc639ac82015-07-02 08:53:34 +0200847
848static void xtest_tee_test_1010(ADBG_Case_t *c)
849{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100850 unsigned int n = 0;
851 unsigned int idx = 0;
Etienne Carriere92c34422018-02-09 13:11:40 +0100852 size_t memref_sz[] = { 1024, 65536 };
Pascal Brandc639ac82015-07-02 08:53:34 +0200853
854 for (n = 1; n <= 5; n++) {
855 Do_ADBG_BeginSubCase(c, "Invalid memory access %u", n);
856 xtest_tee_test_invalid_mem_access(c, n);
857 Do_ADBG_EndSubCase(c, "Invalid memory access %u", n);
858 }
Etienne Carriere92c34422018-02-09 13:11:40 +0100859
860 for (idx = 0; idx < ARRAY_SIZE(memref_sz); idx++) {
861 for (n = 1; n <= 5; n++) {
862 Do_ADBG_BeginSubCase(c,
Igor Opaniuke8236ac2018-02-12 12:26:25 +0200863 "Invalid memory access %u with %zu bytes memref",
Etienne Carriere92c34422018-02-09 13:11:40 +0100864 n, memref_sz[idx]);
865 xtest_tee_test_invalid_mem_access2(c, n, memref_sz[idx]);
866 Do_ADBG_EndSubCase(c,
Igor Opaniuke8236ac2018-02-12 12:26:25 +0200867 "Invalid memory access %u with %zu bytes memref",
Etienne Carriere92c34422018-02-09 13:11:40 +0100868 n, memref_sz[idx]);
869 }
870 }
Pascal Brandc639ac82015-07-02 08:53:34 +0200871}
Jens Wiklander14f48872018-06-29 15:30:13 +0200872ADBG_CASE_DEFINE(regression, 1010, xtest_tee_test_1010,
873 "Invalid memory access");
Pascal Brandc639ac82015-07-02 08:53:34 +0200874
875static void xtest_tee_test_1011(ADBG_Case_t *c)
876{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100877 TEEC_Session session = { };
878 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200879 struct xtest_crypto_session cs = {
880 c, &session, TA_RPC_CMD_CRYPT_SHA256,
881 TA_RPC_CMD_CRYPT_AES256ECB_ENC,
882 TA_RPC_CMD_CRYPT_AES256ECB_DEC
883 };
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100884 struct xtest_crypto_session cs_privmem = {
885 c, &session,
886 TA_RPC_CMD_CRYPT_PRIVMEM_SHA256,
887 TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_ENC,
888 TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_DEC
889 };
Pascal Brandc639ac82015-07-02 08:53:34 +0200890 TEEC_UUID uuid = rpc_test_ta_uuid;
891
892 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
893 xtest_teec_open_session(&session, &uuid, NULL, &ret_orig)))
894 return;
895
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100896 Do_ADBG_BeginSubCase(c, "TA-to-TA via non-secure shared memory");
Pascal Brandc639ac82015-07-02 08:53:34 +0200897 /*
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100898 * Run the "complete crypto test suite" using TA-to-TA
899 * communication
Pascal Brandc639ac82015-07-02 08:53:34 +0200900 */
901 xtest_crypto_test(&cs);
Jens Wiklanderf7b9c632017-01-03 17:32:26 +0100902 Do_ADBG_EndSubCase(c, "TA-to-TA via non-secure shared memory");
903
904 Do_ADBG_BeginSubCase(c, "TA-to-TA via TA private memory");
905 /*
906 * Run the "complete crypto test suite" using TA-to-TA
907 * communication via TA private memory.
908 */
909 xtest_crypto_test(&cs_privmem);
910 Do_ADBG_EndSubCase(c, "TA-to-TA via TA private memory");
911
Pascal Brandc639ac82015-07-02 08:53:34 +0200912 TEEC_CloseSession(&session);
913}
Jens Wiklander14f48872018-06-29 15:30:13 +0200914ADBG_CASE_DEFINE(regression, 1011, xtest_tee_test_1011,
915 "Test TA-to-TA features with User Crypt TA");
Pascal Brandc639ac82015-07-02 08:53:34 +0200916
917/*
918 * Note that this test is failing when
919 * - running twice in a raw
920 * - and the user TA is statically linked
921 * This is because the counter is not reseted when opening the first session
922 * in case the TA is statically linked
923 */
924static void xtest_tee_test_1012(ADBG_Case_t *c)
925{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100926 TEEC_Session session1 = { };
927 TEEC_Session session2 = { };
928 uint32_t ret_orig = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200929 TEEC_UUID uuid = sims_test_ta_uuid;
930
931 Do_ADBG_BeginSubCase(c, "Single Instance Multi Session");
932 {
933 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
934 static const uint8_t in[] = {
935 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96,
936 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92,
937 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
938 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
939 };
Etienne Carrieree4ec9e42019-03-28 13:30:21 +0100940 uint8_t out[32] = { };
941 int i = 0;
Pascal Brandc639ac82015-07-02 08:53:34 +0200942
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300943 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200944 xtest_teec_open_session(&session1, &uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300945 &ret_orig)))
946 return;
Pascal Brandc639ac82015-07-02 08:53:34 +0200947
948 op.params[0].value.a = 0;
949 op.params[1].tmpref.buffer = (void *)in;
950 op.params[1].tmpref.size = sizeof(in);
951 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
952 TEEC_MEMREF_TEMP_INPUT,
953 TEEC_NONE, TEEC_NONE);
954
955 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
956 TEEC_InvokeCommand(&session1, TA_SIMS_CMD_WRITE, &op,
957 &ret_orig));
958
Jerome Forissier3cc0a422017-12-14 09:53:24 +0100959 for (i = 1; i < 3; i++) {
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300960 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Pascal Brandc639ac82015-07-02 08:53:34 +0200961 xtest_teec_open_session(&session2, &uuid, NULL,
Volodymyr Babchukae3dcd72016-10-20 16:51:59 +0300962 &ret_orig)))
963 continue;
Pascal Brandc639ac82015-07-02 08:53:34 +0200964
965 op.params[0].value.a = 0;
966 op.params[1].tmpref.buffer = out;
967 op.params[1].tmpref.size = sizeof(out);
968 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
969 TEEC_MEMREF_TEMP_OUTPUT,
970 TEEC_NONE, TEEC_NONE);
971
972 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
973 TEEC_InvokeCommand(&session2, TA_SIMS_CMD_READ,
974 &op, &ret_orig));
975
976 if (!ADBG_EXPECT_BUFFER(c, in, sizeof(in), out,
977 sizeof(out))) {
978 Do_ADBG_Log("in:");
979 Do_ADBG_HexLog(in, sizeof(in), 16);
980 Do_ADBG_Log("out:");
981 Do_ADBG_HexLog(out, sizeof(out), 16);
982 }
983
984 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT,
985 TEEC_NONE, TEEC_NONE,
986 TEEC_NONE);
987
988 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
989 TEEC_InvokeCommand(&session1,
990 TA_SIMS_CMD_GET_COUNTER,
991 &op, &ret_orig));
992
993 (void)ADBG_EXPECT(c, 0, op.params[0].value.a);
994
995 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
996 TEEC_InvokeCommand(&session2,
997 TA_SIMS_CMD_GET_COUNTER, &op,
998 &ret_orig));
999
1000 (void)ADBG_EXPECT(c, i, op.params[0].value.a);
1001 TEEC_CloseSession(&session2);
1002 }
1003
1004 memset(out, 0, sizeof(out));
1005 op.params[0].value.a = 0;
1006 op.params[1].tmpref.buffer = out;
1007 op.params[1].tmpref.size = sizeof(out);
1008 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
1009 TEEC_MEMREF_TEMP_OUTPUT,
1010 TEEC_NONE, TEEC_NONE);
1011
1012 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1013 TEEC_InvokeCommand(&session1, TA_SIMS_CMD_READ, &op,
1014 &ret_orig));
1015
1016 if (!ADBG_EXPECT(c, 0, memcmp(in, out, sizeof(in)))) {
1017 Do_ADBG_Log("in:");
1018 Do_ADBG_HexLog(in, sizeof(in), 16);
1019 Do_ADBG_Log("out:");
1020 Do_ADBG_HexLog(out, sizeof(out), 16);
1021 }
1022
1023 TEEC_CloseSession(&session1);
1024 }
Ovidiu Mihalachi3e6183e2019-04-25 10:23:21 +03001025 Do_ADBG_EndSubCase(c, "Single Instance Multi Session");
Pascal Brandc639ac82015-07-02 08:53:34 +02001026}
Jens Wiklander14f48872018-06-29 15:30:13 +02001027ADBG_CASE_DEFINE(regression, 1012, xtest_tee_test_1012,
1028 "Test Single Instance Multi Session features with SIMS TA");
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001029
1030struct test_1013_thread_arg {
Jens Wiklander70672972016-04-06 00:01:45 +02001031 const TEEC_UUID *uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001032 uint32_t cmd;
1033 uint32_t repeat;
1034 TEEC_SharedMemory *shm;
1035 uint32_t error_orig;
1036 TEEC_Result res;
1037 uint32_t max_concurrency;
1038 const uint8_t *in;
1039 size_t in_len;
1040 uint8_t *out;
1041 size_t out_len;
1042};
1043
1044static void *test_1013_thread(void *arg)
1045{
1046 struct test_1013_thread_arg *a = arg;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001047 TEEC_Session session = { };
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001048 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1049 uint8_t p2 = TEEC_NONE;
1050 uint8_t p3 = TEEC_NONE;
1051
Jens Wiklander70672972016-04-06 00:01:45 +02001052 a->res = xtest_teec_open_session(&session, a->uuid, NULL,
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001053 &a->error_orig);
1054 if (a->res != TEEC_SUCCESS)
1055 return NULL;
1056
1057 op.params[0].memref.parent = a->shm;
1058 op.params[0].memref.size = a->shm->size;
1059 op.params[0].memref.offset = 0;
1060 op.params[1].value.a = a->repeat;
1061 op.params[1].value.b = 0;
1062 op.params[2].tmpref.buffer = (void *)a->in;
1063 op.params[2].tmpref.size = a->in_len;
1064 op.params[3].tmpref.buffer = a->out;
1065 op.params[3].tmpref.size = a->out_len;
1066
1067 if (a->in_len)
1068 p2 = TEEC_MEMREF_TEMP_INPUT;
1069 if (a->out_len)
1070 p3 = TEEC_MEMREF_TEMP_OUTPUT;
1071
1072 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT,
1073 TEEC_VALUE_INOUT, p2, p3);
1074
1075 a->res = TEEC_InvokeCommand(&session, a->cmd, &op, &a->error_orig);
1076 a->max_concurrency = op.params[1].value.b;
1077 a->out_len = op.params[3].tmpref.size;
1078 TEEC_CloseSession(&session);
1079 return NULL;
1080}
1081
Pascal Brand4fa35582015-12-17 10:59:12 +01001082#define NUM_THREADS 3
1083
Jens Wiklander70672972016-04-06 00:01:45 +02001084static void xtest_tee_test_1013_single(ADBG_Case_t *c, double *mean_concurrency,
1085 const TEEC_UUID *uuid)
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001086{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001087 size_t nt = 0;
1088 size_t n = 0;
Jens Wiklander70672972016-04-06 00:01:45 +02001089 size_t repeat = 1000;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001090 TEEC_SharedMemory shm = { };
1091 size_t max_concurrency = 0;
1092 struct test_1013_thread_arg arg[NUM_THREADS] = { };
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001093 static const uint8_t sha256_in[] = { 'a', 'b', 'c' };
1094 static const uint8_t sha256_out[] = {
1095 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
1096 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
1097 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
1098 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
1099 };
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001100 uint8_t out[32] = { };
1101 pthread_t thr[NUM_THREADS] = { };
Jerome Forissierfbdc1752021-06-29 11:25:35 +02001102 bool skip = false;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001103
Jens Wiklander70672972016-04-06 00:01:45 +02001104 Do_ADBG_BeginSubCase(c, "Busy loop repeat %zu", repeat * 10);
Pascal Brand4fa35582015-12-17 10:59:12 +01001105 *mean_concurrency = 0;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001106
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001107 shm.size = sizeof(struct ta_concurrent_shm);
1108 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
1109 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1110 TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm)))
1111 return;
1112
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001113 memset(shm.buffer, 0, shm.size);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001114 max_concurrency = 0;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001115 nt = NUM_THREADS;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001116
1117 for (n = 0; n < nt; n++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001118 arg[n].uuid = uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001119 arg[n].cmd = TA_CONCURRENT_CMD_BUSY_LOOP;
Jens Wiklander70672972016-04-06 00:01:45 +02001120 arg[n].repeat = repeat * 10;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001121 arg[n].shm = &shm;
1122 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
1123 test_1013_thread, arg + n)))
1124 nt = n; /* break loop and start cleanup */
1125 }
1126
1127 for (n = 0; n < nt; n++) {
1128 ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL));
Jerome Forissierfbdc1752021-06-29 11:25:35 +02001129 if (arg[n].res == TEEC_ERROR_OUT_OF_MEMORY &&
1130 !memcmp(uuid, &concurrent_large_ta_uuid, sizeof(*uuid))) {
1131 Do_ADBG_Log("TEEC_ERROR_OUT_OF_MEMORY - ignored");
1132 skip = true;
1133 continue;
1134 }
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001135 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 */
Jerome Forissierfbdc1752021-06-29 11:25:35 +02001146 if (!skip) {
1147 (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, >, 0);
1148 (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, <=,
1149 NUM_THREADS);
1150 *mean_concurrency += max_concurrency;
1151 }
Jens Wiklander70672972016-04-06 00:01:45 +02001152 Do_ADBG_EndSubCase(c, "Busy loop repeat %zu", repeat * 10);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001153
Jens Wiklander70672972016-04-06 00:01:45 +02001154 Do_ADBG_BeginSubCase(c, "SHA-256 loop repeat %zu", repeat);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001155 memset(shm.buffer, 0, shm.size);
1156 memset(arg, 0, sizeof(arg));
1157 max_concurrency = 0;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001158 nt = NUM_THREADS;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001159
1160 for (n = 0; n < nt; n++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001161 arg[n].uuid = uuid;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001162 arg[n].cmd = TA_CONCURRENT_CMD_SHA256;
Jens Wiklander70672972016-04-06 00:01:45 +02001163 arg[n].repeat = repeat;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001164 arg[n].shm = &shm;
1165 arg[n].in = sha256_in;
1166 arg[n].in_len = sizeof(sha256_in);
1167 arg[n].out = out;
1168 arg[n].out_len = sizeof(out);
1169 if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL,
1170 test_1013_thread, arg + n)))
1171 nt = n; /* break loop and start cleanup */
1172 }
1173
1174 for (n = 0; n < nt; n++) {
Jerome Forissierfbdc1752021-06-29 11:25:35 +02001175 ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL));
1176 if (arg[n].res == TEEC_ERROR_OUT_OF_MEMORY &&
1177 !memcmp(uuid, &concurrent_large_ta_uuid, sizeof(*uuid))) {
1178 Do_ADBG_Log("TEEC_ERROR_OUT_OF_MEMORY - ignored");
1179 continue;
1180 }
1181 if (ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res))
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001182 ADBG_EXPECT_BUFFER(c, sha256_out, sizeof(sha256_out),
1183 arg[n].out, arg[n].out_len);
1184 if (arg[n].max_concurrency > max_concurrency)
1185 max_concurrency = arg[n].max_concurrency;
1186 }
Pascal Brand4fa35582015-12-17 10:59:12 +01001187 *mean_concurrency += max_concurrency;
Jens Wiklander70672972016-04-06 00:01:45 +02001188 Do_ADBG_EndSubCase(c, "SHA-256 loop repeat %zu", repeat);
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001189
Pascal Brand4fa35582015-12-17 10:59:12 +01001190 *mean_concurrency /= 2.0;
Jens Wiklanderac27ec12015-07-15 15:23:14 +02001191 TEEC_ReleaseSharedMemory(&shm);
1192}
Pascal Brand4fa35582015-12-17 10:59:12 +01001193
1194static void xtest_tee_test_1013(ADBG_Case_t *c)
1195{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001196 int i = 0;
1197 double mean_concurrency = 0;
1198 double concurrency = 0;
Jens Wiklander70672972016-04-06 00:01:45 +02001199 int nb_loops = 24;
Jens Wiklander6a9d15a2016-02-01 10:29:42 +01001200
1201 if (level == 0)
1202 nb_loops /= 2;
Pascal Brand4fa35582015-12-17 10:59:12 +01001203
Jens Wiklander70672972016-04-06 00:01:45 +02001204 Do_ADBG_BeginSubCase(c, "Using small concurrency TA");
Pascal Brand4fa35582015-12-17 10:59:12 +01001205 mean_concurrency = 0;
1206 for (i = 0; i < nb_loops; i++) {
Jens Wiklander70672972016-04-06 00:01:45 +02001207 xtest_tee_test_1013_single(c, &concurrency,
1208 &concurrent_ta_uuid);
Pascal Brand4fa35582015-12-17 10:59:12 +01001209 mean_concurrency += concurrency;
1210 }
1211 mean_concurrency /= nb_loops;
1212
1213 Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS);
1214 Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency);
Jens Wiklander70672972016-04-06 00:01:45 +02001215 Do_ADBG_EndSubCase(c, "Using small concurrency TA");
Pascal Brand4fa35582015-12-17 10:59:12 +01001216
Jens Wiklander70672972016-04-06 00:01:45 +02001217 Do_ADBG_BeginSubCase(c, "Using large concurrency TA");
1218 mean_concurrency = 0;
1219 for (i = 0; i < nb_loops; i++) {
1220 xtest_tee_test_1013_single(c, &concurrency,
1221 &concurrent_large_ta_uuid);
1222 mean_concurrency += concurrency;
1223 }
1224 mean_concurrency /= nb_loops;
1225
1226 Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS);
1227 Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency);
1228 Do_ADBG_EndSubCase(c, "Using large concurrency TA");
1229}
Jens Wiklander14f48872018-06-29 15:30:13 +02001230ADBG_CASE_DEFINE(regression, 1013, xtest_tee_test_1013,
Joakim Becha1212b62020-04-07 12:06:00 +02001231 "Test concurrency with concurrent TA");
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001232
1233#ifdef CFG_SECURE_DATA_PATH
1234static void xtest_tee_test_1014(ADBG_Case_t *c)
1235{
1236 UNUSED(c);
1237
1238 int size = 17000;
1239 int loop = 10;
1240 int ion_heap = DEFAULT_ION_HEAP_TYPE;
1241 int rnd_offset = 1;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001242 int test = 0;
1243 int ret = 0;
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001244
1245 test = TEST_NS_TO_TA;
1246 Do_ADBG_BeginSubCase(c, "SDP: NonSecure client 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: NonSecure client invokes a SDP TA");
1250
1251 test = TEST_TA_TO_TA;
1252 Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP TA");
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 TA");
1256
1257 test = TEST_TA_TO_PTA;
Igor Opaniuk2e0a6792021-01-09 00:51:19 +02001258 Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a test pTA (invoke_tests.pta)");
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, 0, ret);
Igor Opaniuk2e0a6792021-01-09 00:51:19 +02001261 Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a test pTA (invoke_tests.pta)");
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001262
1263 test = TEST_NS_TO_PTA;
Igor Opaniuk2e0a6792021-01-09 00:51:19 +02001264 Do_ADBG_BeginSubCase(c, "SDP: NSec CA invokes a test pTA (invoke_tests.pta) (should fail)");
Etienne Carriereb9a95822017-04-26 15:03:53 +02001265 ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001266 ADBG_EXPECT(c, 1, ret);
Igor Opaniuk2e0a6792021-01-09 00:51:19 +02001267 Do_ADBG_EndSubCase(c, "SDP: NSec CA invokes a test pTA (invoke_tests.pta) (should fail)");
Etienne Carriered9be3dc2018-04-25 18:30:19 +02001268
1269 Do_ADBG_BeginSubCase(c, "SDP: Invoke TA with out of bounds SDP memref");
1270 ret = sdp_out_of_bounds_memref_test(size, ion_heap, 0);
1271 ADBG_EXPECT(c, 0, ret);
1272 Do_ADBG_EndSubCase(c, NULL);
Etienne Carriere50abf9a2017-03-24 11:33:50 +01001273}
Jens Wiklander14f48872018-06-29 15:30:13 +02001274ADBG_CASE_DEFINE(regression, 1014, xtest_tee_test_1014,
1275 "Test secure data path against SDP TAs and pTAs");
1276#endif /*CFG_SECURE_DATA_PATH*/
Jens Wiklander272d3642017-04-03 13:03:47 +02001277
1278static void xtest_tee_test_1015(ADBG_Case_t *c)
1279{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001280 TEEC_Result res = TEEC_ERROR_GENERIC;
1281 TEEC_Session session = { };
1282 uint32_t ret_orig = 0;
Jens Wiklander272d3642017-04-03 13:03:47 +02001283
Etienne Carriere11093162017-10-26 09:49:04 +02001284 /* Pseudo TA is optional: warn and nicely exit if not found */
Jens Wiklander272d3642017-04-03 13:03:47 +02001285 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
1286 &ret_orig);
Etienne Carriere11093162017-10-26 09:49:04 +02001287 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
1288 Do_ADBG_Log(" - 1015 - skip test, pseudo TA not found");
Jens Wiklander272d3642017-04-03 13:03:47 +02001289 return;
Etienne Carriere11093162017-10-26 09:49:04 +02001290 }
1291 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Jens Wiklander272d3642017-04-03 13:03:47 +02001292
1293 ADBG_EXPECT_TEEC_SUCCESS(c,
1294 TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_FS_HTREE,
1295 NULL, &ret_orig));
1296 TEEC_CloseSession(&session);
1297}
Jens Wiklander14f48872018-06-29 15:30:13 +02001298ADBG_CASE_DEFINE(regression, 1015, xtest_tee_test_1015,
1299 "FS hash-tree corner cases");
Jerome Forissiere916b102017-06-07 17:55:52 +02001300
1301static void xtest_tee_test_1016(ADBG_Case_t *c)
1302{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001303 TEEC_Session session = { };
Jerome Forissiere916b102017-06-07 17:55:52 +02001304 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001305 uint32_t ret_orig = 0;
Jerome Forissiere916b102017-06-07 17:55:52 +02001306
1307 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1308 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
1309 &ret_orig)))
1310 return;
1311
1312 op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE,
1313 TEEC_NONE);
1314
1315 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1316 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TA2TA_MEMREF, &op,
1317 &ret_orig));
1318
1319 TEEC_CloseSession(&session);
1320}
Jens Wiklander14f48872018-06-29 15:30:13 +02001321ADBG_CASE_DEFINE(regression, 1016, xtest_tee_test_1016,
1322 "Test TA to TA transfers (in/out/inout memrefs on the stack)");
Jens Wiklander87e81702018-03-20 12:00:00 +08001323
1324static void xtest_tee_test_1017(ADBG_Case_t *c)
1325{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001326 TEEC_Session session = { };
Jens Wiklander87e81702018-03-20 12:00:00 +08001327 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001328 uint32_t ret_orig = 0;
1329 TEEC_SharedMemory shm = { };
Jens Wiklander87e81702018-03-20 12:00:00 +08001330 size_t page_size = 4096;
1331
Jens Wiklander87e81702018-03-20 12:00:00 +08001332 shm.size = 8 * page_size;
1333 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
1334 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1335 TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm)))
1336 return;
1337
1338 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1339 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
1340 &ret_orig)))
1341 goto out;
1342
1343 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT,
1344 TEEC_MEMREF_PARTIAL_INPUT,
1345 TEEC_MEMREF_PARTIAL_OUTPUT,
1346 TEEC_MEMREF_PARTIAL_OUTPUT);
1347
1348 /*
1349 * The first two memrefs are supposed to be combined into in
1350 * region and the last two memrefs should have one region each
1351 * when the parameters are mapped for the TA.
1352 */
1353 op.params[0].memref.parent = &shm;
1354 op.params[0].memref.size = page_size;
1355 op.params[0].memref.offset = 0;
1356
1357 op.params[1].memref.parent = &shm;
1358 op.params[1].memref.size = page_size;
1359 op.params[1].memref.offset = page_size;
1360
1361 op.params[2].memref.parent = &shm;
1362 op.params[2].memref.size = page_size;
1363 op.params[2].memref.offset = 4 * page_size;
1364
1365 op.params[3].memref.parent = &shm;
1366 op.params[3].memref.size = 2 * page_size;
1367 op.params[3].memref.offset = 6 * page_size;
1368
1369 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1370 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PARAMS, &op,
1371 &ret_orig));
1372
1373 TEEC_CloseSession(&session);
1374out:
1375 TEEC_ReleaseSharedMemory(&shm);
1376}
Jens Wiklander14f48872018-06-29 15:30:13 +02001377ADBG_CASE_DEFINE(regression, 1017, xtest_tee_test_1017,
1378 "Test coalescing memrefs");
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001379
Etienne Carriere84382b32018-04-25 18:30:30 +02001380static void invoke_1byte_out_of_bounds(ADBG_Case_t *c, TEEC_Session *session,
1381 TEEC_SharedMemory *shm)
1382{
1383 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1384 TEEC_Result ret = TEEC_ERROR_GENERIC;
1385 uint32_t ret_orig = 0;
1386
1387 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT,
1388 TEEC_NONE, TEEC_NONE, TEEC_NONE);
1389
1390 op.params[0].memref.parent = shm;
1391 op.params[0].memref.size = shm->size / 2;
1392 op.params[0].memref.offset = shm->size - (shm->size / 2) + 1;
1393
1394 ret = TEEC_InvokeCommand(session, TA_OS_TEST_CMD_PARAMS,
1395 &op, &ret_orig);
1396
Etienne Carriere48fa1b22020-04-08 13:42:01 +02001397 ADBG_EXPECT_COMPARE_UNSIGNED(c, ret_orig, !=, TEEC_ORIGIN_TRUSTED_APP);
Etienne Carriere84382b32018-04-25 18:30:30 +02001398 if (ret != TEEC_ERROR_BAD_PARAMETERS && ret != TEEC_ERROR_GENERIC) {
1399 ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS, ret);
1400 ADBG_EXPECT(c, TEEC_ERROR_GENERIC, ret);
1401 }
1402}
1403
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001404static void xtest_tee_test_1018(ADBG_Case_t *c)
1405{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001406 TEEC_Session session = { };
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001407 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001408 uint32_t ret_orig = 0;
1409 TEEC_SharedMemory shm = { };
Etienne Carriere84382b32018-04-25 18:30:30 +02001410 TEEC_Result ret = TEEC_ERROR_GENERIC;
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001411 size_t page_size = 4096;
Joakim Becha1212b62020-04-07 12:06:00 +02001412 /* Intentionally not 4kB aligned and odd */
Etienne Carriere84382b32018-04-25 18:30:30 +02001413 uint8_t buffer[6001] = { };
1414
1415 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1416 xtest_teec_open_session(&session,
1417 &os_test_ta_uuid,
1418 NULL,
1419 &ret_orig)))
1420 return;
1421
Joakim Becha1212b62020-04-07 12:06:00 +02001422 Do_ADBG_BeginSubCase(c, "Out of bounds > 4kB on allocated shm");
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001423
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001424 shm.size = 8 * page_size;
1425 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
1426 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Etienne Carriere84382b32018-04-25 18:30:30 +02001427 TEEC_AllocateSharedMemory(&xtest_teec_ctx,
1428 &shm)))
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001429 goto out;
1430
1431 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT,
1432 TEEC_MEMREF_PARTIAL_INPUT,
1433 TEEC_MEMREF_PARTIAL_OUTPUT,
1434 TEEC_MEMREF_PARTIAL_OUTPUT);
1435
1436 /*
1437 * The first two memrefs are supposed to be combined into in
1438 * region and the last two memrefs should have one region each
1439 * when the parameters are mapped for the TA.
1440 */
1441 op.params[0].memref.parent = &shm;
1442 op.params[0].memref.size = page_size;
1443 op.params[0].memref.offset = 0;
1444
1445 op.params[1].memref.parent = &shm;
1446 op.params[1].memref.size = page_size;
1447 op.params[1].memref.offset = page_size;
1448
1449 op.params[2].memref.parent = &shm;
1450 op.params[2].memref.size = page_size;
1451 op.params[2].memref.offset = 4 * page_size;
1452
1453 op.params[3].memref.parent = &shm;
1454 op.params[3].memref.size = 3 * page_size;
1455 op.params[3].memref.offset = 6 * page_size;
1456
Etienne Carriere84382b32018-04-25 18:30:30 +02001457 ret = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PARAMS, &op,
1458 &ret_orig);
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001459
Etienne Carriere48fa1b22020-04-08 13:42:01 +02001460 ADBG_EXPECT_COMPARE_UNSIGNED(c, ret_orig, !=, TEEC_ORIGIN_TRUSTED_APP);
Etienne Carriere84382b32018-04-25 18:30:30 +02001461 if (ret != TEEC_ERROR_BAD_PARAMETERS && ret != TEEC_ERROR_GENERIC) {
1462 ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS, ret);
1463 ADBG_EXPECT(c, TEEC_ERROR_GENERIC, ret);
1464 }
1465
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001466 TEEC_ReleaseSharedMemory(&shm);
Etienne Carriere84382b32018-04-25 18:30:30 +02001467 Do_ADBG_EndSubCase(c, NULL);
1468
1469 Do_ADBG_BeginSubCase(c, "Out of bounds by 1 byte on registered shm");
1470
1471 memset(&shm, 0, sizeof(shm));
1472 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
1473 shm.buffer = buffer;
1474 shm.size = sizeof(buffer);
1475
1476 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1477 TEEC_RegisterSharedMemory(&xtest_teec_ctx,
1478 &shm)))
1479 goto out;
1480
1481 invoke_1byte_out_of_bounds(c, &session, &shm);
1482
1483 TEEC_ReleaseSharedMemory(&shm);
1484 Do_ADBG_EndSubCase(c, NULL);
1485
1486 Do_ADBG_BeginSubCase(c, "Out of bounds by 1 byte ref on allocated shm");
1487
1488 memset(&shm, 0, sizeof(shm));
1489 shm.size = sizeof(buffer);
1490 shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
1491 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1492 TEEC_AllocateSharedMemory(&xtest_teec_ctx,
1493 &shm)))
1494 goto out;
1495
1496 invoke_1byte_out_of_bounds(c, &session, &shm);
1497
1498 TEEC_ReleaseSharedMemory(&shm);
1499 Do_ADBG_EndSubCase(c, NULL);
1500
1501out:
1502 TEEC_CloseSession(&session);
Jens Wiklanderbb10bcd2018-03-20 12:50:58 +08001503}
Jens Wiklander14f48872018-06-29 15:30:13 +02001504ADBG_CASE_DEFINE(regression, 1018, xtest_tee_test_1018,
1505 "Test memref out of bounds");
Jerome Forissier53bde722018-05-31 09:14:54 +02001506
Jerome Forissier53bde722018-05-31 09:14:54 +02001507static void xtest_tee_test_1019(ADBG_Case_t *c)
1508{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001509 TEEC_Session session = { };
1510 uint32_t ret_orig = 0;
Jerome Forissier53bde722018-05-31 09:14:54 +02001511
1512 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1513 xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
1514 &ret_orig)))
1515 return;
1516
1517 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1518 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB, NULL,
1519 &ret_orig));
1520
1521 (void)ADBG_EXPECT_TEEC_RESULT(c,
1522 TEEC_ERROR_TARGET_DEAD,
1523 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_PANIC,
1524 NULL, &ret_orig));
1525
1526 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
1527
1528 TEEC_CloseSession(&session);
1529}
Jens Wiklander14f48872018-06-29 15:30:13 +02001530ADBG_CASE_DEFINE(regression, 1019, xtest_tee_test_1019,
1531 "Test dynamically linked TA");
Jerome Forissier3357f872018-10-05 15:13:44 +02001532
1533static void xtest_tee_test_1020(ADBG_Case_t *c)
1534{
Etienne Carrieree4ec9e42019-03-28 13:30:21 +01001535 TEEC_Result res = TEEC_ERROR_GENERIC;
1536 TEEC_Session session = { };
1537 uint32_t ret_orig = 0;
Jerome Forissier3357f872018-10-05 15:13:44 +02001538
1539 /* Pseudo TA is optional: warn and nicely exit if not found */
1540 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
1541 &ret_orig);
1542 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
1543 Do_ADBG_Log(" - 1020 - skip test, pseudo TA not found");
1544 return;
1545 }
1546 ADBG_EXPECT_TEEC_SUCCESS(c, res);
1547
1548 res = TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_LOCKDEP,
1549 NULL, &ret_orig);
1550 if (res != TEEC_SUCCESS) {
1551 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TRUSTED_APP,
1552 ret_orig);
1553 if (res == TEEC_ERROR_NOT_SUPPORTED) {
1554 Do_ADBG_Log(" - 1020 - skip test, feature not "
1555 "implemented");
1556 goto out;
1557 }
1558 /* Error */
1559 (void)ADBG_EXPECT_TEEC_SUCCESS(c, res);
1560 }
1561out:
1562 TEEC_CloseSession(&session);
1563}
1564ADBG_CASE_DEFINE(regression, 1020, xtest_tee_test_1020,
1565 "Test lockdep algorithm");
Ovidiu Mihalachi15cecff2019-04-02 16:36:31 +03001566
1567static TEEC_Result open_sec_session(TEEC_Session *session,
1568 const TEEC_UUID *uuid)
1569{
1570 TEEC_Result res = TEEC_ERROR_GENERIC;
1571 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1572 uint32_t ret_orig = 0;
1573
1574 op.params[0].tmpref.buffer = (void *)uuid;
1575 op.params[0].tmpref.size = sizeof(*uuid);
1576 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
1577 TEEC_NONE, TEEC_NONE, TEEC_NONE);
1578
1579 res = TEEC_InvokeCommand(session, TA_SIMS_OPEN_TA_SESSION,
1580 &op, &ret_orig);
1581 if (res != TEEC_SUCCESS)
1582 return TEEC_ERROR_GENERIC;
1583
1584 return res;
1585}
1586
1587static TEEC_Result sims_get_counter(TEEC_Session *session,
1588 uint32_t *counter)
1589{
1590 TEEC_Result res = TEEC_ERROR_GENERIC;
1591 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1592 uint32_t ret_orig = 0;
1593
1594 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT,
1595 TEEC_NONE, TEEC_NONE, TEEC_NONE);
1596
1597 res = TEEC_InvokeCommand(session, TA_SIMS_CMD_GET_COUNTER,
1598 &op, &ret_orig);
1599 if (res == TEEC_SUCCESS)
1600 *counter = op.params[0].value.a;
1601
1602 return res;
1603}
1604
1605static TEEC_Result trigger_panic(TEEC_Session *session,
1606 const TEEC_UUID *uuid)
1607{
1608 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1609 uint32_t ret_orig = 0;
1610
1611 if (!uuid) {
1612 op.params[0].tmpref.buffer = NULL;
1613 op.params[0].tmpref.size = 0;
1614 } else {
1615 op.params[0].tmpref.buffer = (void *)uuid;
1616 op.params[0].tmpref.size = sizeof(*uuid);
1617 }
1618 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
1619 TEEC_NONE, TEEC_NONE, TEEC_NONE);
1620
1621 return TEEC_InvokeCommand(session, TA_SIMS_CMD_PANIC,
1622 &op, &ret_orig);
1623}
1624
1625static void test_panic_ca_to_ta(ADBG_Case_t *c, const TEEC_UUID *uuid,
1626 bool multi_instance)
1627{
1628 TEEC_Result exp_res = TEEC_ERROR_GENERIC;
1629 uint32_t counter = 0;
1630 uint32_t ret_orig = 0;
1631 uint32_t exp_counter = 0;
1632 TEEC_Session cs[3] = { };
1633
1634 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1635 xtest_teec_open_session(&cs[0], uuid, NULL,
1636 &ret_orig)))
1637 return;
1638
1639 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1640 xtest_teec_open_session(&cs[1], uuid, NULL,
1641 &ret_orig)))
1642 goto bail0;
1643
1644 if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter)))
1645 goto bail1;
1646
1647 if (!ADBG_EXPECT(c, 0, counter))
1648 goto bail1;
1649
1650 if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[1], &counter)))
1651 goto bail1;
1652
1653 exp_counter = multi_instance ? 0 : 1;
Ovidiu Mihalachi110aac42019-09-11 14:08:01 +03001654 if (!ADBG_EXPECT(c, exp_counter, counter))
Ovidiu Mihalachi15cecff2019-04-02 16:36:31 +03001655 goto bail1;
1656
1657 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD,
1658 trigger_panic(&cs[1], NULL)))
1659 goto bail1;
1660
1661 exp_res = multi_instance ? TEEC_SUCCESS : TEEC_ERROR_TARGET_DEAD;
1662 if (!ADBG_EXPECT_TEEC_RESULT(c, exp_res,
1663 sims_get_counter(&cs[0], &counter)))
1664 goto bail1;
1665
1666 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD,
1667 sims_get_counter(&cs[1], &counter)))
1668 goto bail1;
1669
1670 /* Attempt to open a session on panicked context */
Ovidiu Mihalachi110aac42019-09-11 14:08:01 +03001671 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
Ovidiu Mihalachi15cecff2019-04-02 16:36:31 +03001672 xtest_teec_open_session(&cs[1], uuid, NULL,
1673 &ret_orig)))
1674 goto bail1;
1675
1676 /* Sanity check of still valid TA context */
1677 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1678 xtest_teec_open_session(&cs[2], uuid, NULL,
1679 &ret_orig)))
1680 goto bail1;
1681
1682 /* Sanity check of still valid TA context */
1683 if (multi_instance) {
1684 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1685 sims_get_counter(&cs[0], &counter)))
1686 goto bail2;
1687
1688 if (!ADBG_EXPECT(c, 0, counter))
1689 goto bail2;
1690 }
1691
1692 if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[2], &counter)))
1693 goto bail2;
1694
Ovidiu Mihalachi110aac42019-09-11 14:08:01 +03001695 exp_counter = multi_instance ? 0 : 1;
1696 if (!ADBG_EXPECT(c, exp_counter, counter))
Ovidiu Mihalachi15cecff2019-04-02 16:36:31 +03001697 goto bail2;
1698
1699bail2:
1700 TEEC_CloseSession(&cs[2]);
1701bail1:
1702 TEEC_CloseSession(&cs[1]);
1703bail0:
1704 TEEC_CloseSession(&cs[0]);
1705}
1706
1707static void test_panic_ta_to_ta(ADBG_Case_t *c, const TEEC_UUID *uuid1,
1708 const TEEC_UUID *uuid2)
1709{
1710 uint32_t ret_orig = 0;
1711 uint32_t counter = 0;
1712 TEEC_Session cs[3] = { };
1713
1714 /* Test pre-conditions */
1715 /* 2.1 - CA opens a session toward TA1 */
1716 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1717 xtest_teec_open_session(&cs[0], uuid1, NULL,
1718 &ret_orig)))
1719 return;
1720
1721 /* 2.2 - CA opens a session toward TA2 */
1722 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1723 xtest_teec_open_session(&cs[1], uuid2, NULL,
1724 &ret_orig)))
1725 goto bail0;
1726
1727 /* 2.3 - TA1 opens a session toward TA2 */
1728 if (!ADBG_EXPECT_TEEC_SUCCESS(c, open_sec_session(&cs[0], uuid2)))
1729 goto bail1;
1730
1731 /* 2.4 - CA invokes TA2 which panics */
1732 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD,
1733 trigger_panic(&cs[1], NULL)))
1734 goto bail1;
1735
1736 /* Expected results */
1737 /* 2.5 - Expect CA->TA1 session is still alive */
1738 if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter)))
1739 goto bail1;
1740
1741 /* 2.6 - Expect CA->TA2 session is properly released */
1742 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD,
1743 sims_get_counter(&cs[1], &counter)))
1744 goto bail1;
1745
1746bail1:
1747 TEEC_CloseSession(&cs[1]);
1748bail0:
1749 TEEC_CloseSession(&cs[0]);
1750
1751 memset(cs, 0, sizeof(cs));
1752
1753 /* Test pre-conditions */
1754 /* 2.1 - CA opens a session toward TA1 */
1755 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1756 xtest_teec_open_session(&cs[0], uuid1, NULL,
1757 &ret_orig)))
1758 return;
1759
1760 /* 2.2 - CA opens a session toward TA2 */
1761 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1762 xtest_teec_open_session(&cs[1], uuid2, NULL,
1763 &ret_orig)))
1764 goto bail2;
1765
1766 /* 2.3 - TA1 opens a session toward TA2 */
1767 if (!ADBG_EXPECT_TEEC_SUCCESS(c, open_sec_session(&cs[0], uuid2)))
1768 goto bail3;
1769
1770 /* 2.4 - CA invokes TA1 which invokes TA2 which panics */
1771 if (!ADBG_EXPECT_TEEC_SUCCESS(c, trigger_panic(&cs[0], uuid2)))
1772 goto bail3;
1773
1774 /* Expected results */
1775 /* 2.5 - Expect CA->TA1 session is still alive */
1776 if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter)))
1777 goto bail3;
1778
1779 /* 2.6 - Expect CA->TA2 session is properly released */
1780 if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD,
1781 sims_get_counter(&cs[1], &counter)))
1782 goto bail3;
1783
1784bail3:
1785 TEEC_CloseSession(&cs[1]);
1786bail2:
1787 TEEC_CloseSession(&cs[0]);
1788}
1789
1790static void xtest_tee_test_1021(ADBG_Case_t *c)
1791{
1792 Do_ADBG_BeginSubCase(c, "Multiple Instances Single Session");
1793 test_panic_ca_to_ta(c, &miss_test_ta_uuid, true);
1794 Do_ADBG_EndSubCase(c, "Multiple Instances Single Session");
1795
1796 Do_ADBG_BeginSubCase(c, "Single Instance Multi Sessions");
1797 test_panic_ca_to_ta(c, &sims_test_ta_uuid, false);
1798 Do_ADBG_EndSubCase(c, "Single Instance Multi Sessions");
1799
1800 Do_ADBG_BeginSubCase(c, "Single Instance Multi Sessions Keep Alive");
1801 test_panic_ca_to_ta(c, &sims_keepalive_test_ta_uuid, false);
1802 Do_ADBG_EndSubCase(c, "Single Instance Multi Sessions Keep Alive");
1803
1804 Do_ADBG_BeginSubCase(c, "Multi Sessions TA to TA");
1805 test_panic_ta_to_ta(c, &sims_test_ta_uuid,
1806 &sims_keepalive_test_ta_uuid);
1807 Do_ADBG_EndSubCase(c, "Multi Sessions TA to TA");
1808}
1809ADBG_CASE_DEFINE(regression, 1021, xtest_tee_test_1021,
1810 "Test panic context release");
Jerome Forissiera9ab5d02019-03-17 21:14:06 +01001811
1812static void xtest_tee_test_1022(ADBG_Case_t *c)
1813{
1814 TEEC_Session session = { 0 };
1815 uint32_t ret_orig = 0;
1816
1817 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1818 xtest_teec_open_session(&session, &os_test_ta_uuid,
1819 NULL, &ret_orig)))
1820 return;
1821
1822 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1823 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL, NULL,
1824 &ret_orig));
1825
1826 (void)ADBG_EXPECT_TEEC_RESULT(c,
1827 TEEC_ERROR_TARGET_DEAD,
1828 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL_PANIC,
1829 NULL, &ret_orig));
1830
1831 (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig);
1832
1833 TEEC_CloseSession(&session);
1834}
1835ADBG_CASE_DEFINE(regression, 1022, xtest_tee_test_1022,
1836 "Test dlopen()/dlsym()/dlclose() API");
Jerome Forissiere9571e82020-02-18 15:26:20 +01001837
1838/*
1839 * Testing the ELF initialization (.init_array)
1840 *
1841 * - The TA has a global variable which can also be accessed by the two shared
1842 * libraries os_test_lib (linked with the TA) and os_test_lib_dl (loaded via
1843 * dlopen())
1844 * - The TA and both libraries have initialization functions (declared with the
1845 * "constructor" attribute) which perform the following:
1846 * * The TA multiplies by 10 then adds 1
1847 * * os_test_lib multiplies by 10 then adds 2
1848 * * os_test_lib_dl multiplies by 10 then adds 3
1849 * By testing the variable value we make sure the initializations occurred in
1850 * the correct order.
1851 */
1852static void xtest_tee_test_1023(ADBG_Case_t *c)
1853{
1854 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1855 TEEC_Session session = { 0 };
1856 uint32_t ret_orig = 0;
1857
1858 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE,
1859 TEEC_NONE, TEEC_NONE);
1860
1861 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1862 xtest_teec_open_session(&session, &os_test_ta_uuid,
1863 NULL, &ret_orig)))
1864 return;
1865
1866 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1867 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_GET_GLOBAL_VAR, &op,
1868 &ret_orig));
1869
1870 /* Expected: initialization of os_test_lib, then TA */
1871 (void)ADBG_EXPECT_COMPARE_SIGNED(c, op.params[0].value.a, ==, 21);
1872
1873 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1874 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL, NULL,
1875 &ret_orig));
1876
1877 (void)ADBG_EXPECT_TEEC_SUCCESS(c,
1878 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_GET_GLOBAL_VAR, &op,
1879 &ret_orig));
1880
1881 /* Expected: initialization of os_test_lib_dl */
1882 (void)ADBG_EXPECT_COMPARE_SIGNED(c, op.params[0].value.a, ==, 213);
1883
1884 TEEC_CloseSession(&session);
1885}
1886ADBG_CASE_DEFINE(regression, 1023, xtest_tee_test_1023,
1887 "Test ELF initialization (.init_array)");
Javier Almansa Sobrinocddc0002020-02-10 13:35:37 +00001888
1889#ifdef CFG_CORE_TPM_EVENT_LOG
1890static void xtest_tee_test_1024(ADBG_Case_t *c)
1891{
1892 TEEC_Session session = {};
1893 uint32_t ret_orig = 0;
1894
1895 xtest_teec_open_session(&session, &tpm_log_test_ta_uuid,
1896 NULL, &ret_orig);
1897
1898 Do_ADBG_BeginSubCase(c, "TPM test service invocation");
1899 ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(&session,
1900 TA_TPM_TEST_GET_LOG,
1901 NULL, &ret_orig));
1902 Do_ADBG_EndSubCase(c, "TPM test service invocation");
1903
1904 Do_ADBG_BeginSubCase(c, "TPM test passing short buffer");
1905 ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(&session,
1906 TA_TPM_TEST_SHORT_BUF,
1907 NULL, &ret_orig));
1908 Do_ADBG_EndSubCase(c, "TPM test passing short buffer");
1909
1910 TEEC_CloseSession(&session);
1911}
1912
1913ADBG_CASE_DEFINE(regression, 1024, xtest_tee_test_1024,
1914 "Test PTA_SYSTEM_GET_TPM_EVENT_LOG Service");
1915#endif /* CFG_CORE_TPM_EVENT_LOG */
Cedric Neveux9f483bb2019-03-04 08:58:06 +01001916
1917static void xtest_tee_test_1025(ADBG_Case_t *c)
1918{
1919 TEEC_Session session = {};
1920 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
1921 uint32_t ret_orig = 0;
1922 uint8_t *empty_buf = NULL;
Etienne Carriere71383d42020-04-14 12:31:25 +02001923 TEEC_SharedMemory shm = { };
Etienne Carrieredba3f3b2020-04-08 17:08:16 +02001924 TEEC_Result res = TEEC_ERROR_GENERIC;
Etienne Carriere71383d42020-04-14 12:31:25 +02001925
1926 Do_ADBG_BeginSubCase(c, "Invalid NULL buffer memref registration");
1927
1928 memset(&shm, 0, sizeof(shm));
1929 shm.flags = TEEC_MEM_INPUT;
1930 shm.buffer = NULL;
1931 shm.size = 0;
1932
1933 ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS,
1934 TEEC_RegisterSharedMemory(&xtest_teec_ctx, &shm));
1935
1936 memset(&shm, 0, sizeof(shm));
1937 shm.flags = TEEC_MEM_OUTPUT;
1938 shm.buffer = NULL;
1939 shm.size = 0;
1940
1941 ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS,
1942 TEEC_RegisterSharedMemory(&xtest_teec_ctx, &shm));
1943
1944 Do_ADBG_EndSubCase(c, "Invalid NULL buffer memref registration");
Cedric Neveux9f483bb2019-03-04 08:58:06 +01001945
Etienne Carrierec602a522020-04-13 18:53:17 +02001946 if (!xtest_teec_ctx.memref_null) {
Etienne Carriere71383d42020-04-14 12:31:25 +02001947 Do_ADBG_Log("Skip subcases: MEMREF_NULL capability not supported");
Etienne Carrierec602a522020-04-13 18:53:17 +02001948 return;
1949 }
1950
Cedric Neveux9f483bb2019-03-04 08:58:06 +01001951 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
1952 xtest_teec_open_session(&session,
1953 &os_test_ta_uuid,
1954 NULL, &ret_orig)))
1955 return;
1956
1957 empty_buf = malloc(1);
1958 if (!empty_buf) {
1959 (void)ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_ERROR_OUT_OF_MEMORY);
Etienne Carrieredba3f3b2020-04-08 17:08:16 +02001960 goto out_session;
Cedric Neveux9f483bb2019-03-04 08:58:06 +01001961 }
1962
1963 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
1964 TEEC_MEMREF_TEMP_INPUT,
1965 TEEC_MEMREF_TEMP_OUTPUT,
1966 TEEC_MEMREF_TEMP_OUTPUT);
1967
1968 Do_ADBG_BeginSubCase(c,
1969 "Input/Output MEMREF Buffer NULL - Size 0 bytes");
1970
1971 op.params[0].tmpref.buffer = empty_buf;
1972 op.params[0].tmpref.size = 0;
1973
1974 op.params[1].tmpref.buffer = NULL;
1975 op.params[1].tmpref.size = 0;
1976
1977 op.params[2].tmpref.buffer = empty_buf;
1978 op.params[2].tmpref.size = 0;
1979
1980 op.params[3].tmpref.buffer = NULL;
1981 op.params[3].tmpref.size = 0;
1982
1983 ADBG_EXPECT(c, TEE_SUCCESS,
1984 TEEC_InvokeCommand(&session,
1985 TA_OS_TEST_CMD_NULL_MEMREF_PARAMS, &op,
1986 &ret_orig));
1987
1988 Do_ADBG_EndSubCase(c, "Input/Output MEMREF Buffer NULL - Size 0 bytes");
1989
1990 Do_ADBG_BeginSubCase(c, "Input MEMREF Buffer NULL - Size non 0 bytes");
1991
1992 op.params[0].tmpref.buffer = empty_buf;
1993 op.params[0].tmpref.size = 1;
1994
1995 op.params[1].tmpref.buffer = NULL;
1996 op.params[1].tmpref.size = 0;
1997
1998 op.params[2].tmpref.buffer = empty_buf;
1999 op.params[2].tmpref.size = 0;
2000
2001 op.params[3].tmpref.buffer = NULL;
2002 op.params[3].tmpref.size = 0;
2003
2004 ADBG_EXPECT(c, TEE_ERROR_BAD_PARAMETERS,
2005 TEEC_InvokeCommand(&session,
2006 TA_OS_TEST_CMD_NULL_MEMREF_PARAMS, &op,
2007 &ret_orig));
2008
Etienne Carrieredba3f3b2020-04-08 17:08:16 +02002009 TEEC_CloseSession(&session);
2010
Cedric Neveux9f483bb2019-03-04 08:58:06 +01002011 Do_ADBG_EndSubCase(c, "Input MEMREF Buffer NULL - Size non 0 bytes");
2012
Etienne Carrieredba3f3b2020-04-08 17:08:16 +02002013 Do_ADBG_BeginSubCase(c, "Input MEMREF Buffer NULL over PTA invocation");
2014
2015 /* Pseudo TA is optional: warn and nicely exit if not found */
2016 res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
2017 &ret_orig);
2018 if (res == TEEC_ERROR_ITEM_NOT_FOUND) {
2019 Do_ADBG_Log(" - 1025 - skip test, pseudo TA not found");
2020 goto out;
2021 }
2022 if (!ADBG_EXPECT_TEEC_SUCCESS(c, res))
2023 goto out;
2024
2025 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE,
2026 TEEC_NONE, TEEC_NONE);
2027 op.params[0].tmpref.buffer = NULL;
2028 op.params[0].tmpref.size = 0;
2029
2030 ADBG_EXPECT(c, TEE_SUCCESS,
2031 TEEC_InvokeCommand(&session,
2032 PTA_INVOKE_TESTS_CMD_MEMREF_NULL,
2033 &op, &ret_orig));
2034
2035out_session:
Cedric Neveux9f483bb2019-03-04 08:58:06 +01002036 TEEC_CloseSession(&session);
Etienne Carrieredba3f3b2020-04-08 17:08:16 +02002037out:
2038 Do_ADBG_EndSubCase(c, NULL);
Cedric Neveux9f483bb2019-03-04 08:58:06 +01002039 free(empty_buf);
2040}
2041ADBG_CASE_DEFINE(regression, 1025, xtest_tee_test_1025,
2042 "Test memref NULL and/or 0 bytes size");
Vesa Jääskeläinene8c0c8d2020-04-05 20:11:53 +03002043
Vesa Jääskeläinen502c5492020-04-05 20:12:02 +03002044#define TEE_UUID_NS_NAME_SIZE 128
2045
2046/*
2047 * TEE Client UUID name space identifier (UUIDv4)
2048 *
2049 * Value here is random UUID that is allocated as name space identifier for
2050 * forming Client UUID's for TEE environment using UUIDv5 scheme.
2051 */
2052static const char *client_uuid_linux_ns = "58ac9ca0-2086-4683-a1b8-ec4bc08e01b6";
2053
Vesa Jääskeläinene8c0c8d2020-04-05 20:11:53 +03002054/* TEEC_LOGIN_PUBLIC's Client UUID is NIL UUID */
2055static TEEC_UUID client_uuid_public = { };
2056
2057static void xtest_tee_test_1026(ADBG_Case_t *c)
2058{
2059 TEEC_Result result = TEEC_ERROR_GENERIC;
2060 uint32_t ret_orig = 0;
2061 TEEC_Session session = { };
2062 uint32_t login = UINT32_MAX;
2063 TEEC_UUID client_uuid = { };
2064
2065 result = TEEC_OpenSession(&xtest_teec_ctx, &session, &os_test_ta_uuid,
2066 TEEC_LOGIN_PUBLIC, NULL, NULL, &ret_orig);
2067
2068 if (!ADBG_EXPECT_TEEC_SUCCESS(c, result))
2069 return;
2070
2071 result = ta_os_test_cmd_client_identity(&session, &login,
2072 &client_uuid);
2073
2074 if (!ADBG_EXPECT_TEEC_SUCCESS(c, result))
2075 goto out;
2076
2077 ADBG_EXPECT_COMPARE_UNSIGNED(c, login, ==, TEEC_LOGIN_PUBLIC);
2078
2079 ADBG_EXPECT_EQUAL(c, &client_uuid_public, &client_uuid,
2080 sizeof(TEEC_UUID));
2081
2082out:
2083 TEEC_CloseSession(&session);
2084}
2085
2086ADBG_CASE_DEFINE(regression, 1026, xtest_tee_test_1026,
2087 "Session: public login");
Vesa Jääskeläinen502c5492020-04-05 20:12:02 +03002088
Etienne Carrieref461e1d2020-05-19 12:42:08 +02002089/*
2090 * regression_1027
2091 * Depends on OpenSSL
Jerome Forissier81e71a82021-06-16 10:39:12 +02002092 * Depends on kernel commit c5b4312bea5d ("tee: optee: Add support for session
2093 * login client UUID generation")
2094 * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c5b4312bea5d
Etienne Carrieref461e1d2020-05-19 12:42:08 +02002095 *
2096 * xtest skips the test when not built with OpenSSL.
2097 */
Vesa Jääskeläinen502c5492020-04-05 20:12:02 +03002098static void xtest_tee_test_1027(ADBG_Case_t *c)
2099{
Victor Chong8e070bc2020-05-13 09:59:33 +01002100#ifdef OPENSSL_FOUND
Vesa Jääskeläinen502c5492020-04-05 20:12:02 +03002101 TEEC_Result result = TEEC_ERROR_GENERIC;
2102 uint32_t ret_orig = 0;
2103 TEEC_Session session = { };
2104 uint32_t login = UINT32_MAX;
2105 TEEC_UUID client_uuid = { };
2106 TEEC_UUID expected_client_uuid = { };
2107 TEEC_UUID uuid_ns = { };
2108 char uuid_name[TEE_UUID_NS_NAME_SIZE] = { };
2109
2110 result = xtest_uuid_from_str(&uuid_ns, client_uuid_linux_ns);
2111
2112 if (!ADBG_EXPECT_TEEC_SUCCESS(c, result))
2113 return;
2114
2115 sprintf(uuid_name, "uid=%x", geteuid());
2116
2117 result = xtest_uuid_v5(&expected_client_uuid, &uuid_ns, uuid_name,
2118 strlen(uuid_name));
2119 if (!ADBG_EXPECT_TEEC_SUCCESS(c, result))
2120 return;
2121
2122 result = TEEC_OpenSession(&xtest_teec_ctx, &session, &os_test_ta_uuid,
2123 TEEC_LOGIN_USER, NULL, NULL, &ret_orig);
2124
2125 if (!ADBG_EXPECT_TEEC_SUCCESS(c, result))
2126 return;
2127
2128 result = ta_os_test_cmd_client_identity(&session, &login,
2129 &client_uuid);
2130
2131 if (!ADBG_EXPECT_TEEC_SUCCESS(c, result))
2132 goto out;
2133
2134 ADBG_EXPECT_COMPARE_UNSIGNED(c, login, ==, TEEC_LOGIN_USER);
2135
2136 ADBG_EXPECT_EQUAL(c, &expected_client_uuid, &client_uuid,
2137 sizeof(TEEC_UUID));
2138
2139out:
2140 TEEC_CloseSession(&session);
Victor Chong8e070bc2020-05-13 09:59:33 +01002141#else /*!OPENSSL_FOUND*/
2142 UNUSED(c);
Etienne Carriere359b0032020-05-16 05:56:48 +02002143 UNUSED(client_uuid_linux_ns);
Victor Chong8e070bc2020-05-13 09:59:33 +01002144 /* xtest_uuid_v5() depends on OpenSSL */
2145 Do_ADBG_Log("OpenSSL not available, skipping test 1027");
2146#endif
Vesa Jääskeläinen502c5492020-04-05 20:12:02 +03002147}
2148
2149ADBG_CASE_DEFINE(regression, 1027, xtest_tee_test_1027,
2150 "Session: user login for current user");
Vesa Jääskeläinen30dd0872020-04-05 20:12:06 +03002151
Etienne Carrieref461e1d2020-05-19 12:42:08 +02002152/*
2153 * regression_1028
Jerome Forissier81e71a82021-06-16 10:39:12 +02002154 * Depends on kernel commit c5b4312bea5d ("tee: optee: Add support for session
2155 * login client UUID generation")
2156 * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c5b4312bea5d
Etienne Carrieref461e1d2020-05-19 12:42:08 +02002157 *
2158 * xtest skips the test when not built with OpenSSL.
2159 */
Vesa Jääskeläinen30dd0872020-04-05 20:12:06 +03002160static void xtest_tee_test_1028(ADBG_Case_t *c)
2161{
Victor Chong8e070bc2020-05-13 09:59:33 +01002162#ifdef OPENSSL_FOUND
Vesa Jääskeläinen30dd0872020-04-05 20:12:06 +03002163 TEEC_Result result = TEEC_ERROR_GENERIC;
2164 uint32_t ret_orig = 0;
2165 TEEC_Session session = { };
2166 uint32_t login = UINT32_MAX;
2167 TEEC_UUID client_uuid = { };
2168 TEEC_UUID expected_client_uuid = { };
2169 TEEC_UUID uuid_ns = { };
2170 char uuid_name[TEE_UUID_NS_NAME_SIZE] = { };
2171 uint32_t group = 0;
2172
2173 group = getegid();
2174
2175 result = xtest_uuid_from_str(&uuid_ns, client_uuid_linux_ns);
2176
2177 if (!ADBG_EXPECT_TEEC_SUCCESS(c, result))
2178 return;
2179
2180 sprintf(uuid_name, "gid=%x", group);
2181
2182 result = xtest_uuid_v5(&expected_client_uuid, &uuid_ns, uuid_name,
2183 strlen(uuid_name));
2184 if (!ADBG_EXPECT_TEEC_SUCCESS(c, result))
2185 return;
2186
2187 result = TEEC_OpenSession(&xtest_teec_ctx, &session, &os_test_ta_uuid,
2188 TEEC_LOGIN_GROUP, &group, NULL, &ret_orig);
2189
2190 if (!ADBG_EXPECT_TEEC_SUCCESS(c, result))
2191 return;
2192
2193 result = ta_os_test_cmd_client_identity(&session, &login,
2194 &client_uuid);
2195
2196 if (!ADBG_EXPECT_TEEC_SUCCESS(c, result))
2197 goto out;
2198
2199 ADBG_EXPECT_COMPARE_UNSIGNED(c, login, ==, TEEC_LOGIN_GROUP);
2200
2201 ADBG_EXPECT_EQUAL(c, &expected_client_uuid, &client_uuid,
2202 sizeof(TEEC_UUID));
2203
2204out:
2205 TEEC_CloseSession(&session);
Victor Chong8e070bc2020-05-13 09:59:33 +01002206#else /*!OPENSSL_FOUND*/
2207 UNUSED(c);
2208 /* xtest_uuid_v5() depends on OpenSSL */
2209 Do_ADBG_Log("OpenSSL not available, skipping test 1028");
2210#endif
Vesa Jääskeläinen30dd0872020-04-05 20:12:06 +03002211}
2212
2213ADBG_CASE_DEFINE(regression, 1028, xtest_tee_test_1028,
2214 "Session: group login for current user's effective group");
Jerome Forissier9a7101b2020-06-17 17:55:00 +02002215
2216static void xtest_tee_test_1029(ADBG_Case_t *c)
2217{
Jerome Forissier82e87bb2020-08-19 14:00:09 +02002218 TEEC_Result res = TEEC_SUCCESS;
Jerome Forissier9a7101b2020-06-17 17:55:00 +02002219 TEEC_Session session = { 0 };
2220 uint32_t ret_orig = 0;
2221
2222 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
2223 xtest_teec_open_session(&session, &os_test_ta_uuid,
2224 NULL, &ret_orig)))
2225 return;
2226
2227 Do_ADBG_BeginSubCase(c, "TLS variables (main program)");
Jerome Forissier82e87bb2020-08-19 14:00:09 +02002228 res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TLS_TEST_MAIN, NULL,
2229 &ret_orig);
2230 if (res == TEEC_ERROR_NOT_SUPPORTED)
2231 Do_ADBG_Log(" - 1029 - skip test, "
2232 "TA returned TEEC_ERROR_NOT_SUPPORTED");
2233 else
2234 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Jerome Forissier9a7101b2020-06-17 17:55:00 +02002235 Do_ADBG_EndSubCase(c, "TLS variables (main program)");
2236
2237 Do_ADBG_BeginSubCase(c, "TLS variables (shared library)");
Jerome Forissier82e87bb2020-08-19 14:00:09 +02002238 res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TLS_TEST_SHLIB, NULL,
2239 &ret_orig);
2240 if (res == TEEC_ERROR_NOT_SUPPORTED)
2241 Do_ADBG_Log(" - 1029 - skip test, "
2242 "TA returned TEEC_ERROR_NOT_SUPPORTED");
2243 else
2244 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Jerome Forissier9a7101b2020-06-17 17:55:00 +02002245 Do_ADBG_EndSubCase(c, "TLS variables (shared library)");
2246
2247 TEEC_CloseSession(&session);
2248}
2249ADBG_CASE_DEFINE(regression, 1029, xtest_tee_test_1029,
2250 "Test __thread attribute");
Jerome Forissier4565c452020-06-17 17:55:00 +02002251
2252static void xtest_tee_test_1030(ADBG_Case_t *c)
2253{
2254 TEEC_Session session = { 0 };
2255 uint32_t ret_orig = 0;
2256
2257 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
2258 xtest_teec_open_session(&session, &os_test_ta_uuid,
2259 NULL, &ret_orig)))
2260 return;
2261
2262 Do_ADBG_BeginSubCase(c, "Before dlopen()");
2263 ADBG_EXPECT_TEEC_SUCCESS(c,
2264 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_DL_PHDR, NULL,
2265 &ret_orig));
2266 Do_ADBG_EndSubCase(c, "Before dlopen()");
2267
2268 Do_ADBG_BeginSubCase(c, "After dlopen()");
2269 ADBG_EXPECT_TEEC_SUCCESS(c,
2270 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_DL_PHDR_DL, NULL,
2271 &ret_orig));
2272 Do_ADBG_EndSubCase(c, "After dlopen()");
2273
2274 TEEC_CloseSession(&session);
2275}
2276ADBG_CASE_DEFINE(regression, 1030, xtest_tee_test_1030,
2277 "Test dl_iterate_phdr()");
Jerome Forissier1a205ae2020-06-17 17:55:00 +02002278
2279#ifndef __clang__
2280static void xtest_tee_test_1031(ADBG_Case_t *c)
2281{
2282 TEEC_Result ret = TEE_SUCCESS;
2283 TEEC_Session session = { 0 };
2284 uint32_t ret_orig = 0;
2285
2286 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
2287 xtest_teec_open_session(&session, &os_test_ta_uuid,
2288 NULL, &ret_orig)))
2289 return;
2290
2291 Do_ADBG_BeginSubCase(c, "Global object constructor (main program)");
2292 ret = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_CTOR_MAIN, NULL,
2293 &ret_orig);
2294 if (ret == TEEC_ERROR_NOT_SUPPORTED) {
2295 printf("TA not built with C++ support, skipping C++ tests\n");
2296 Do_ADBG_EndSubCase(c, "Global object constructor (main program)");
2297 goto out;
2298
2299 }
2300 ADBG_EXPECT_TEEC_SUCCESS(c, ret);
2301 Do_ADBG_EndSubCase(c, "Global object constructor (main program)");
2302
2303 Do_ADBG_BeginSubCase(c, "Global object constructor (shared library)");
2304 ADBG_EXPECT_TEEC_SUCCESS(c,
2305 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_CTOR_SHLIB,
2306 NULL, &ret_orig));
2307 Do_ADBG_EndSubCase(c, "Global object constructor (shared library)");
2308
2309 Do_ADBG_BeginSubCase(c, "Global object constructor (dlopen()ed lib)");
2310 ADBG_EXPECT_TEEC_SUCCESS(c,
2311 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_CTOR_SHLIB_DL,
2312 NULL, &ret_orig));
2313 Do_ADBG_EndSubCase(c, "Global object constructor (dlopen()ed lib)");
2314
2315 Do_ADBG_BeginSubCase(c, "Exceptions (simple)");
2316 ADBG_EXPECT_TEEC_SUCCESS(c,
2317 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_EXC_MAIN, NULL,
2318 &ret_orig));
2319 Do_ADBG_EndSubCase(c, "Exceptions (simple)");
2320
2321 Do_ADBG_BeginSubCase(c, "Exceptions (mixed C/C++ frames)");
2322 ADBG_EXPECT_TEEC_SUCCESS(c,
2323 TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_EXC_MIXED, NULL,
2324 &ret_orig));
2325 Do_ADBG_EndSubCase(c, "Exceptions (mixed C/C++ frames)");
2326out:
2327 TEEC_CloseSession(&session);
2328}
2329ADBG_CASE_DEFINE(regression, 1031, xtest_tee_test_1031,
2330 "Test C++ features");
2331#endif
Jens Wiklandere16da892020-09-04 09:24:16 +02002332
2333static void xtest_tee_test_1032(ADBG_Case_t *c)
2334{
2335 TEEC_Result res = TEEC_SUCCESS;
2336 TEEC_Context ctx = { };
2337 TEEC_SharedMemory shm1 = {
2338 .buffer = xtest_tee_test_1032,
2339 .size = 32,
2340 .flags = TEEC_MEM_INPUT,
2341 };
2342 static const uint8_t dummy_data[32] = { 1, 2, 3, 4, };
2343 TEEC_SharedMemory shm2 = {
2344 .buffer = (void *)dummy_data,
2345 .size = sizeof(dummy_data),
2346 .flags = TEEC_MEM_INPUT,
2347 };
2348
2349 res = TEEC_InitializeContext(xtest_tee_name, &ctx);
2350 if (!ADBG_EXPECT_TEEC_SUCCESS(c, res))
2351 return;
2352
2353 res = TEEC_RegisterSharedMemory(&ctx, &shm1);
2354 if (ADBG_EXPECT_TEEC_SUCCESS(c, res))
2355 TEEC_ReleaseSharedMemory(&shm1);
2356
2357 res = TEEC_RegisterSharedMemory(&ctx, &shm2);
2358 if (ADBG_EXPECT_TEEC_SUCCESS(c, res))
2359 TEEC_ReleaseSharedMemory(&shm2);
2360
2361 TEEC_FinalizeContext(&ctx);
2362}
2363ADBG_CASE_DEFINE(regression, 1032, xtest_tee_test_1032,
2364 "Register read-only shared memory");
Aleksandr Anisimov01f6f062021-01-19 11:02:25 +03002365
2366static void xtest_tee_test_1033(ADBG_Case_t *c)
2367{
2368 TEEC_Session session = { };
2369 uint32_t ret_orig = 0;
2370
2371 /* TA will ping the test plugin during open session operation */
2372 if (!ADBG_EXPECT_TEEC_SUCCESS(c,
2373 xtest_teec_open_session(&session, &supp_plugin_test_ta_uuid,
2374 NULL, &ret_orig)))
2375 return;
2376
2377 Do_ADBG_BeginSubCase(c, "Pass values to/from a plugin");
2378 {
2379 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
2380
2381 op.params[0].value.a = 20;
2382 op.params[0].value.b = 10;
2383 op.params[1].value.a = '+';
2384 op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT,
2385 TEEC_VALUE_INPUT, TEEC_NONE,
2386 TEEC_NONE);
2387
2388 ADBG_EXPECT_TEEC_SUCCESS(c,
2389 TEEC_InvokeCommand(&session,
2390 TA_SUPP_PLUGIN_CMD_PASS_VALUES, &op,
2391 &ret_orig));
2392 ADBG_EXPECT(c, 30, op.params[0].value.a);
2393
2394 /* reassign, because the values was changed during previous op */
2395 op.params[0].value.a = 20;
2396 op.params[0].value.b = 10;
2397 op.params[1].value.a = '-';
2398 ADBG_EXPECT_TEEC_SUCCESS(c,
2399 TEEC_InvokeCommand(&session,
2400 TA_SUPP_PLUGIN_CMD_PASS_VALUES, &op,
2401 &ret_orig));
2402 ADBG_EXPECT(c, 10, op.params[0].value.a);
2403 }
2404 Do_ADBG_EndSubCase(c, "Pass values to/from a plugin");
2405
2406 Do_ADBG_BeginSubCase(c, "Pass array to a plugin");
2407 {
2408 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
Aleksandr Anisimov80768392021-03-05 19:36:20 +03002409 uint8_t to_plugin[] = { 0, 1, 2, 3, 4, 5 };
Aleksandr Anisimov01f6f062021-01-19 11:02:25 +03002410
2411 op.params[0].tmpref.buffer = to_plugin;
2412 op.params[0].tmpref.size = sizeof(to_plugin);
Aleksandr Anisimov01f6f062021-01-19 11:02:25 +03002413 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT,
Aleksandr Anisimov80768392021-03-05 19:36:20 +03002414 TEEC_VALUE_OUTPUT,
Aleksandr Anisimov01f6f062021-01-19 11:02:25 +03002415 TEEC_NONE, TEEC_NONE);
2416
2417 ADBG_EXPECT_TEEC_SUCCESS(c,
2418 TEEC_InvokeCommand(&session,
2419 TA_SUPP_PLUGIN_CMD_WRITE_ARR,
2420 &op, &ret_orig));
2421
2422 /*
Aleksandr Anisimov80768392021-03-05 19:36:20 +03002423 * The test plugin must calculate a sum of the input elements
2424 * and store it to 'op.params[1].value.a'
Aleksandr Anisimov01f6f062021-01-19 11:02:25 +03002425 */
Aleksandr Anisimov80768392021-03-05 19:36:20 +03002426 ADBG_EXPECT(c, 15, op.params[1].value.a);
Aleksandr Anisimov01f6f062021-01-19 11:02:25 +03002427 }
2428 Do_ADBG_EndSubCase(c, "Pass array to a plugin");
2429
2430 Do_ADBG_BeginSubCase(c, "Get array from a plugin");
2431 {
2432 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
2433 char from_plugin[64] = { };
2434 char expected_arr[] = "Array from plugin";
2435 size_t expectes_size = sizeof(expected_arr);
2436
2437 op.params[0].tmpref.buffer = from_plugin;
2438 op.params[0].tmpref.size = sizeof(from_plugin);
2439 op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT,
2440 TEEC_VALUE_OUTPUT, TEEC_NONE,
2441 TEEC_NONE);
2442 ADBG_EXPECT_TEEC_SUCCESS(c,
2443 TEEC_InvokeCommand(&session,
2444 TA_SUPP_PLUGIN_CMD_GET_ARR, &op,
2445 &ret_orig));
2446 ADBG_EXPECT(c, expectes_size, op.params[1].value.a);
2447 ADBG_EXPECT_EQUAL(c, expected_arr, from_plugin, expectes_size);
2448 }
2449 Do_ADBG_EndSubCase(c, "Get array from a plugin");
2450
2451 Do_ADBG_BeginSubCase(c, "Not allow bad input to a plugin");
2452 {
2453 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
2454
2455 op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE,
2456 TEEC_NONE, TEEC_NONE);
2457 ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_BAD_PARAMETERS,
2458 TEEC_InvokeCommand(&session,
2459 TA_SUPP_PLUGIN_CMD_BAD_UUID, &op,
2460 &ret_orig));
2461 ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_BAD_PARAMETERS,
2462 TEEC_InvokeCommand(&session,
2463 TA_SUPP_PLUGIN_CMD_BAD_IN_DATA, &op,
2464 &ret_orig));
2465 ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_BAD_PARAMETERS,
2466 TEEC_InvokeCommand(&session,
2467 TA_SUPP_PLUGIN_CMD_BAD_IN_LEN, &op,
2468 &ret_orig));
2469 }
2470 Do_ADBG_EndSubCase(c, "Not allow bad input to a plugin");
2471
2472 Do_ADBG_BeginSubCase(c, "Call an unknown plugin");
2473 {
2474 TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
2475
2476 op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE,
2477 TEEC_NONE, TEEC_NONE);
2478 ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND,
2479 TEEC_InvokeCommand(&session,
2480 TA_SUPP_PLUGIN_CMD_UNKNOWN_UUID,
2481 &op, &ret_orig));
2482 }
2483 Do_ADBG_EndSubCase(c, "Call an unknown plugin");
2484
2485 TEEC_CloseSession(&session);
2486}
2487ADBG_CASE_DEFINE(regression, 1033, xtest_tee_test_1033,
2488 "Test the supplicant plugin framework");
Jens Wiklander94fb1582021-05-19 10:14:57 +02002489
2490static void xtest_tee_test_1034(ADBG_Case_t *c)
2491{
2492 TEEC_Result res = TEEC_SUCCESS;
2493 TEEC_Session session = { };
2494 uint32_t ret_orig = 0;
2495
2496 res = xtest_teec_open_session(&session, &large_ta_uuid, NULL,
2497 &ret_orig);
Jerome Forissiere8be5b52021-06-29 16:29:06 +02002498 if (res == TEEC_ERROR_OUT_OF_MEMORY) {
2499 Do_ADBG_Log("TEEC_ERROR_OUT_OF_MEMORY - ignored");
2500 } else {
2501 ADBG_EXPECT_TEEC_SUCCESS(c, res);
Jens Wiklander94fb1582021-05-19 10:14:57 +02002502 TEEC_CloseSession(&session);
Jerome Forissiere8be5b52021-06-29 16:29:06 +02002503 }
Jens Wiklander94fb1582021-05-19 10:14:57 +02002504}
2505ADBG_CASE_DEFINE(regression, 1034, xtest_tee_test_1034,
2506 "Test loading a large TA");