Etienne Carriere | 9b7b70d | 2020-05-16 10:27:23 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 2 | /* |
Javier Almansa Sobrino | cddc000 | 2020-02-10 13:35:37 +0000 | [diff] [blame] | 3 | * Copyright (c) 2020, ARM Limited. All rights reserved. |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 4 | * Copyright (c) 2014, STMicroelectronics International N.V. |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 7 | #include <errno.h> |
Etienne Carriere | a465355 | 2017-01-11 10:04:24 +0100 | [diff] [blame] | 8 | #include <limits.h> |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 9 | #ifdef OPENSSL_FOUND |
| 10 | #include <openssl/bn.h> |
| 11 | #include <openssl/err.h> |
| 12 | #include <openssl/evp.h> |
| 13 | #include <openssl/rsa.h> |
| 14 | #include <openssl/sha.h> |
| 15 | #endif |
| 16 | #include <pta_attestation.h> |
| 17 | #include <pta_invoke_tests.h> |
| 18 | #include <pta_secstor_ta_mgmt.h> |
Etienne Carriere | a465355 | 2017-01-11 10:04:24 +0100 | [diff] [blame] | 19 | #include <pthread.h> |
Jerome Forissier | 03aa279 | 2023-02-07 14:22:24 +0100 | [diff] [blame] | 20 | #ifdef CFG_SECURE_DATA_PATH |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 21 | #include <sdp_basic.h> |
Jerome Forissier | 03aa279 | 2023-02-07 14:22:24 +0100 | [diff] [blame] | 22 | #endif |
Clément Faure | a15be9e | 2025-05-07 13:54:36 +0000 | [diff] [blame] | 23 | #include <sys/stat.h> |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 24 | #include <signed_hdr.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 25 | #include <stdio.h> |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 26 | #include <stdlib.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 27 | #include <string.h> |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 28 | #include <sys/types.h> |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 29 | #include <ta_arm_bti.h> |
| 30 | #include <ta_concurrent.h> |
| 31 | #include <ta_create_fail_test.h> |
| 32 | #include <ta_crypt.h> |
| 33 | #include <ta_miss_test.h> |
| 34 | #include <ta_os_test.h> |
| 35 | #include <ta_rpc_test.h> |
| 36 | #include <ta_sims_keepalive_test.h> |
| 37 | #include <ta_sims_test.h> |
| 38 | #include <ta_supp_plugin.h> |
| 39 | #include <ta_tpm_log_test.h> |
| 40 | #include <test_supp_plugin.h> |
Etienne Carriere | a465355 | 2017-01-11 10:04:24 +0100 | [diff] [blame] | 41 | #include <unistd.h> |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 42 | #include <utee_defines.h> |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 43 | #include <util.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 44 | |
Jens Wiklander | 6b5d9a3 | 2024-12-10 17:43:47 +0100 | [diff] [blame] | 45 | #include "ftpm_ta.h" |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 46 | #include "xtest_helpers.h" |
| 47 | #include "xtest_test.h" |
| 48 | #include "xtest_uuid_helpers.h" |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 49 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 50 | #ifndef MIN |
| 51 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 52 | #endif |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 53 | |
Etienne Carriere | c0a6172 | 2023-03-07 17:47:42 +0100 | [diff] [blame] | 54 | #define STATS_UUID \ |
| 55 | { 0xd96a5b40, 0xe2c7, 0xb1af, \ |
| 56 | { 0x87, 0x94, 0x10, 0x02, 0xa5, 0xd5, 0xc6, 0x1b } } |
| 57 | |
| 58 | #define STATS_CMD_PAGER_STATS 0 |
| 59 | |
| 60 | #define PAGER_PAGE_COUNT_THRESHOLD ((128 * 1024) / 4096) |
| 61 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 62 | struct xtest_crypto_session { |
| 63 | ADBG_Case_t *c; |
| 64 | TEEC_Session *session; |
| 65 | uint32_t cmd_id_sha256; |
| 66 | uint32_t cmd_id_aes256ecb_encrypt; |
| 67 | uint32_t cmd_id_aes256ecb_decrypt; |
| 68 | }; |
| 69 | |
Etienne Carriere | c0a6172 | 2023-03-07 17:47:42 +0100 | [diff] [blame] | 70 | static bool optee_pager_with_small_pool(void) |
| 71 | { |
| 72 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 73 | TEEC_UUID uuid = STATS_UUID; |
| 74 | TEEC_Context ctx = { }; |
| 75 | TEEC_Session sess = { }; |
| 76 | TEEC_Operation op = { }; |
| 77 | uint32_t eo = 0; |
| 78 | bool rc = false; |
| 79 | |
| 80 | res = TEEC_InitializeContext(NULL, &ctx); |
| 81 | if (res) |
| 82 | return false; |
| 83 | |
| 84 | res = TEEC_OpenSession(&ctx, &sess, &uuid, TEEC_LOGIN_PUBLIC, NULL, |
| 85 | NULL, &eo); |
| 86 | if (res) |
| 87 | goto out_ctx; |
| 88 | |
| 89 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_VALUE_OUTPUT, |
| 90 | TEEC_VALUE_OUTPUT, TEEC_NONE); |
| 91 | res = TEEC_InvokeCommand(&sess, STATS_CMD_PAGER_STATS, &op, &eo); |
| 92 | if (res) |
| 93 | goto out_sess; |
| 94 | |
| 95 | if (op.params[0].value.b && |
| 96 | op.params[0].value.b <= PAGER_PAGE_COUNT_THRESHOLD) |
| 97 | rc = true; |
| 98 | |
| 99 | out_sess: |
| 100 | TEEC_CloseSession(&sess); |
| 101 | out_ctx: |
| 102 | TEEC_FinalizeContext(&ctx); |
| 103 | |
| 104 | return rc; |
| 105 | } |
| 106 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 107 | static void xtest_crypto_test(struct xtest_crypto_session *cs) |
| 108 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 109 | uint32_t ret_orig = 0; |
| 110 | uint8_t crypt_out[16] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 111 | uint8_t crypt_in[16] = { 22, 17 }; |
| 112 | |
| 113 | crypt_in[15] = 60; |
| 114 | |
| 115 | Do_ADBG_BeginSubCase(cs->c, "AES encrypt"); |
| 116 | { |
| 117 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 118 | |
| 119 | op.params[0].tmpref.buffer = crypt_in; |
| 120 | op.params[0].tmpref.size = sizeof(crypt_in); |
| 121 | op.params[1].tmpref.buffer = crypt_out; |
| 122 | op.params[1].tmpref.size = sizeof(crypt_out); |
| 123 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 124 | TEEC_MEMREF_TEMP_OUTPUT, |
| 125 | TEEC_NONE, TEEC_NONE); |
| 126 | |
| 127 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 128 | TEEC_InvokeCommand(cs->session, |
| 129 | cs-> |
| 130 | cmd_id_aes256ecb_encrypt, |
| 131 | &op, |
| 132 | &ret_orig)); |
| 133 | } |
| 134 | Do_ADBG_EndSubCase(cs->c, "AES encrypt"); |
| 135 | |
| 136 | Do_ADBG_BeginSubCase(cs->c, "AES decrypt"); |
| 137 | { |
| 138 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 139 | uint8_t out[16] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 140 | |
| 141 | op.params[0].tmpref.buffer = crypt_out; |
| 142 | op.params[0].tmpref.size = sizeof(crypt_out); |
| 143 | op.params[1].tmpref.buffer = out; |
| 144 | op.params[1].tmpref.size = sizeof(out); |
| 145 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 146 | TEEC_MEMREF_TEMP_OUTPUT, |
| 147 | TEEC_NONE, TEEC_NONE); |
| 148 | |
| 149 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 150 | TEEC_InvokeCommand(cs->session, |
| 151 | cs-> |
| 152 | cmd_id_aes256ecb_decrypt, |
| 153 | &op, |
| 154 | &ret_orig)); |
| 155 | |
| 156 | if (!ADBG_EXPECT(cs->c, 0, |
| 157 | memcmp(crypt_in, out, sizeof(crypt_in)))) { |
| 158 | Do_ADBG_Log("crypt_in:"); |
| 159 | Do_ADBG_HexLog(crypt_in, sizeof(crypt_in), 16); |
| 160 | Do_ADBG_Log("out:"); |
| 161 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 162 | } |
| 163 | } |
| 164 | Do_ADBG_EndSubCase(cs->c, "AES decrypt"); |
| 165 | |
| 166 | Do_ADBG_BeginSubCase(cs->c, "SHA-256 test, 3 bytes input"); |
| 167 | { |
| 168 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 169 | static const uint8_t sha256_in[] = { 'a', 'b', 'c' }; |
| 170 | static const uint8_t sha256_out[] = { |
| 171 | 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, |
| 172 | 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, |
| 173 | 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, |
| 174 | 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad |
| 175 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 176 | uint8_t out[32] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 177 | |
| 178 | op.params[0].tmpref.buffer = (void *)sha256_in; |
| 179 | op.params[0].tmpref.size = sizeof(sha256_in); |
| 180 | op.params[1].tmpref.buffer = out; |
| 181 | op.params[1].tmpref.size = sizeof(out); |
| 182 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 183 | TEEC_MEMREF_TEMP_OUTPUT, |
| 184 | TEEC_NONE, TEEC_NONE); |
| 185 | |
| 186 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 187 | TEEC_InvokeCommand(cs->session, |
| 188 | cs-> |
| 189 | cmd_id_sha256, |
| 190 | &op, |
| 191 | &ret_orig)); |
| 192 | |
| 193 | if (!ADBG_EXPECT(cs->c, 0, memcmp(sha256_out, out, |
| 194 | sizeof(sha256_out)))) { |
| 195 | Do_ADBG_Log("sha256_out:"); |
| 196 | Do_ADBG_HexLog(sha256_out, sizeof(sha256_out), 16); |
| 197 | Do_ADBG_Log("out:"); |
| 198 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 199 | } |
| 200 | } |
| 201 | Do_ADBG_EndSubCase(cs->c, "SHA-256 test, 3 bytes input"); |
| 202 | |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 203 | Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 204 | { |
| 205 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 206 | static const uint8_t in[] = { |
| 207 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 208 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 209 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 210 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f |
| 211 | }; |
| 212 | static const uint8_t exp_out[] = { |
| 213 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 214 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 215 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 216 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 217 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 218 | uint8_t out[sizeof(exp_out)] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 219 | |
| 220 | op.params[0].tmpref.buffer = (void *)in; |
| 221 | op.params[0].tmpref.size = sizeof(in); |
| 222 | op.params[1].tmpref.buffer = out; |
| 223 | op.params[1].tmpref.size = sizeof(out); |
| 224 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 225 | TEEC_MEMREF_TEMP_OUTPUT, |
| 226 | TEEC_NONE, TEEC_NONE); |
| 227 | |
| 228 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 229 | TEEC_InvokeCommand(cs->session, |
| 230 | cs-> |
| 231 | cmd_id_aes256ecb_encrypt, |
| 232 | &op, |
| 233 | &ret_orig)); |
| 234 | |
| 235 | if (!ADBG_EXPECT(cs->c, 0, |
| 236 | memcmp(exp_out, out, sizeof(exp_out)))) { |
| 237 | Do_ADBG_Log("exp_out:"); |
| 238 | Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16); |
| 239 | Do_ADBG_Log("out:"); |
| 240 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 241 | } |
| 242 | } |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 243 | Do_ADBG_EndSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 244 | |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 245 | Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 246 | { |
| 247 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 248 | static const uint8_t in[] = { |
| 249 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 250 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 251 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 252 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 253 | }; |
| 254 | static const uint8_t exp_out[] = { |
| 255 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 256 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 257 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 258 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f |
| 259 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 260 | uint8_t out[sizeof(exp_out)] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 261 | |
| 262 | op.params[0].tmpref.buffer = (void *)in; |
| 263 | op.params[0].tmpref.size = sizeof(in); |
| 264 | op.params[1].tmpref.buffer = out; |
| 265 | op.params[1].tmpref.size = sizeof(out); |
| 266 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 267 | TEEC_MEMREF_TEMP_OUTPUT, |
| 268 | TEEC_NONE, TEEC_NONE); |
| 269 | |
| 270 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 271 | TEEC_InvokeCommand(cs->session, |
| 272 | cs-> |
| 273 | cmd_id_aes256ecb_decrypt, |
| 274 | &op, |
| 275 | &ret_orig)); |
| 276 | |
| 277 | if (!ADBG_EXPECT(cs->c, 0, |
| 278 | memcmp(exp_out, out, sizeof(exp_out)))) { |
| 279 | Do_ADBG_Log("exp_out:"); |
| 280 | Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16); |
| 281 | Do_ADBG_Log("out:"); |
| 282 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 283 | } |
| 284 | } |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 285 | Do_ADBG_EndSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | static void xtest_tee_test_1001(ADBG_Case_t *c) |
| 289 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 290 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 291 | TEEC_Session session = { }; |
| 292 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 293 | |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 294 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Etienne Carriere | 726d8bc | 2017-03-21 15:45:59 +0100 | [diff] [blame] | 295 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 296 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 297 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 298 | Do_ADBG_Log(" - 1001 - skip test, pseudo TA not found"); |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 299 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 300 | } |
Etienne Carriere | 3ea9672 | 2022-03-11 09:16:40 +0100 | [diff] [blame] | 301 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 302 | return; |
| 303 | |
| 304 | Do_ADBG_BeginSubCase(c, "Core self tests"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 305 | |
Raymond Mao | 658859f | 2025-03-25 09:59:47 -0700 | [diff] [blame] | 306 | res = TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_SELF_TESTS, |
| 307 | NULL, &ret_orig); |
| 308 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Etienne Carriere | 3ea9672 | 2022-03-11 09:16:40 +0100 | [diff] [blame] | 309 | |
| 310 | Do_ADBG_EndSubCase(c, "Core self tests"); |
| 311 | |
| 312 | Do_ADBG_BeginSubCase(c, "Core dt_driver self tests"); |
| 313 | |
Raymond Mao | 658859f | 2025-03-25 09:59:47 -0700 | [diff] [blame] | 314 | res = TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_DT_DRIVER_TESTS, |
| 315 | NULL, &ret_orig); |
| 316 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Etienne Carriere | 3ea9672 | 2022-03-11 09:16:40 +0100 | [diff] [blame] | 317 | |
| 318 | Do_ADBG_EndSubCase(c, "Core dt_driver self tests"); |
| 319 | |
Raymond Mao | 658859f | 2025-03-25 09:59:47 -0700 | [diff] [blame] | 320 | Do_ADBG_BeginSubCase(c, "Core transfer list self tests"); |
| 321 | |
| 322 | res = TEEC_InvokeCommand(&session, |
| 323 | PTA_INVOKE_TESTS_CMD_TRANSFER_LIST_TESTS, NULL, |
| 324 | &ret_orig); |
| 325 | if (res == TEE_ERROR_NOT_SUPPORTED) |
| 326 | Do_ADBG_Log("Transfer List tests not supported, skipping"); |
| 327 | else |
| 328 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 329 | |
| 330 | Do_ADBG_EndSubCase(c, "Core transfer list self tests"); |
| 331 | |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 332 | TEEC_CloseSession(&session); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 333 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 334 | ADBG_CASE_DEFINE(regression, 1001, xtest_tee_test_1001, "Core self tests"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 335 | |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 336 | static void xtest_tee_test_1002(ADBG_Case_t *c) |
| 337 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 338 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 339 | TEEC_Session session = { }; |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 340 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 341 | uint32_t ret_orig = 0; |
| 342 | uint8_t buf[16 * 1024] = { }; |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 343 | uint8_t exp_sum = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 344 | size_t n = 0; |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 345 | |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 346 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 347 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 348 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 349 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 350 | Do_ADBG_Log(" - 1002 - skip test, pseudo TA not found"); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 351 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 352 | } |
| 353 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 354 | |
| 355 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, |
| 356 | TEEC_NONE, TEEC_NONE); |
| 357 | op.params[0].tmpref.size = sizeof(buf); |
| 358 | op.params[0].tmpref.buffer = buf; |
| 359 | |
| 360 | for (n = 0; n < sizeof(buf); n++) |
| 361 | buf[n] = n + 1; |
| 362 | for (n = 0; n < sizeof(buf); n++) |
| 363 | exp_sum += buf[n]; |
| 364 | |
| 365 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand( |
| 366 | &session, PTA_INVOKE_TESTS_CMD_PARAMS, &op, &ret_orig))) |
| 367 | goto out; |
| 368 | |
| 369 | ADBG_EXPECT_COMPARE_SIGNED(c, exp_sum, ==, buf[0]); |
| 370 | out: |
| 371 | TEEC_CloseSession(&session); |
| 372 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 373 | ADBG_CASE_DEFINE(regression, 1002, xtest_tee_test_1002, "PTA parameters"); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 374 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 375 | struct test_1003_arg { |
| 376 | uint32_t test_type; |
| 377 | size_t repeat; |
| 378 | size_t max_before_lockers; |
| 379 | size_t max_during_lockers; |
| 380 | size_t before_lockers; |
| 381 | size_t during_lockers; |
| 382 | TEEC_Result res; |
| 383 | uint32_t error_orig; |
| 384 | }; |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 385 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 386 | static void *test_1003_thread(void *arg) |
| 387 | { |
| 388 | struct test_1003_arg *a = arg; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 389 | TEEC_Session session = { }; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 390 | size_t rounds = 64 * 1024; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 391 | size_t n = 0; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 392 | |
| 393 | a->res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, |
| 394 | NULL, &a->error_orig); |
| 395 | if (a->res != TEEC_SUCCESS) |
| 396 | return NULL; |
| 397 | |
| 398 | for (n = 0; n < a->repeat; n++) { |
| 399 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 400 | |
| 401 | op.params[0].value.a = a->test_type; |
| 402 | op.params[0].value.b = rounds; |
| 403 | |
| 404 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 405 | TEEC_VALUE_OUTPUT, |
| 406 | TEEC_NONE, TEEC_NONE); |
| 407 | a->res = TEEC_InvokeCommand(&session, |
| 408 | PTA_INVOKE_TESTS_CMD_MUTEX, |
| 409 | &op, &a->error_orig); |
| 410 | if (a->test_type == PTA_MUTEX_TEST_WRITER && |
| 411 | op.params[1].value.b != 1) { |
| 412 | Do_ADBG_Log("n %zu %" PRIu32, n, op.params[1].value.b); |
| 413 | a->res = TEEC_ERROR_BAD_STATE; |
| 414 | a->error_orig = 42; |
| 415 | break; |
| 416 | } |
| 417 | |
| 418 | if (a->test_type == PTA_MUTEX_TEST_READER) { |
| 419 | if (op.params[1].value.a > a->max_before_lockers) |
| 420 | a->max_before_lockers = op.params[1].value.a; |
| 421 | |
| 422 | if (op.params[1].value.b > a->max_during_lockers) |
| 423 | a->max_during_lockers = op.params[1].value.b; |
| 424 | |
| 425 | a->before_lockers += op.params[1].value.a; |
| 426 | a->during_lockers += op.params[1].value.b; |
| 427 | } |
| 428 | } |
| 429 | TEEC_CloseSession(&session); |
| 430 | |
| 431 | return NULL; |
| 432 | } |
| 433 | |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 434 | #define TEST_1003_THREAD_COUNT (3 * 2) |
| 435 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 436 | static void xtest_tee_test_1003(ADBG_Case_t *c) |
| 437 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 438 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 439 | TEEC_Session session = { }; |
| 440 | uint32_t ret_orig = 0; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 441 | size_t repeat = 20; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 442 | struct test_1003_arg arg[TEST_1003_THREAD_COUNT] = { }; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 443 | size_t max_read_concurrency = 0; |
| 444 | size_t max_read_waiters = 0; |
| 445 | size_t num_concurrent_read_lockers = 0; |
| 446 | size_t num_concurrent_read_waiters = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 447 | size_t n = 0; |
| 448 | size_t nt = TEST_1003_THREAD_COUNT; |
| 449 | double mean_read_concurrency = 0; |
| 450 | double mean_read_waiters = 0; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 451 | size_t num_writers = 0; |
| 452 | size_t num_readers = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 453 | pthread_t thr[TEST_1003_THREAD_COUNT] = { }; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 454 | |
| 455 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
| 456 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 457 | &ret_orig); |
| 458 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 459 | Do_ADBG_Log(" - 1003 - skip test, pseudo TA not found"); |
| 460 | return; |
| 461 | } |
| 462 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 463 | TEEC_CloseSession(&session); |
| 464 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 465 | for (n = 0; n < nt; n++) { |
| 466 | if (n % 3) { |
| 467 | arg[n].test_type = PTA_MUTEX_TEST_READER; |
| 468 | num_readers++; |
| 469 | } else { |
| 470 | arg[n].test_type = PTA_MUTEX_TEST_WRITER; |
| 471 | num_writers++; |
| 472 | } |
| 473 | arg[n].repeat = repeat; |
| 474 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 475 | test_1003_thread, arg + n))) |
| 476 | nt = n; /* break loop and start cleanup */ |
| 477 | } |
| 478 | |
| 479 | for (n = 0; n < nt; n++) { |
| 480 | ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)); |
| 481 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res)) |
| 482 | Do_ADBG_Log("error origin %" PRIu32, |
| 483 | arg[n].error_orig); |
| 484 | if (arg[n].test_type == PTA_MUTEX_TEST_READER) { |
| 485 | if (arg[n].max_during_lockers > max_read_concurrency) |
| 486 | max_read_concurrency = |
| 487 | arg[n].max_during_lockers; |
| 488 | |
| 489 | if (arg[n].max_before_lockers > max_read_waiters) |
| 490 | max_read_waiters = arg[n].max_before_lockers; |
| 491 | |
| 492 | num_concurrent_read_lockers += arg[n].during_lockers; |
| 493 | num_concurrent_read_waiters += arg[n].before_lockers; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | mean_read_concurrency = (double)num_concurrent_read_lockers / |
| 498 | (double)(repeat * num_readers); |
| 499 | mean_read_waiters = (double)num_concurrent_read_waiters / |
| 500 | (double)(repeat * num_readers); |
| 501 | |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 502 | Do_ADBG_Log(" Number of parallel threads: %d (%zu writers and %zu readers)", |
| 503 | TEST_1003_THREAD_COUNT, num_writers, num_readers); |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 504 | Do_ADBG_Log(" Max read concurrency: %zu", max_read_concurrency); |
| 505 | Do_ADBG_Log(" Max read waiters: %zu", max_read_waiters); |
| 506 | Do_ADBG_Log(" Mean read concurrency: %g", mean_read_concurrency); |
| 507 | Do_ADBG_Log(" Mean read waiting: %g", mean_read_waiters); |
| 508 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 509 | ADBG_CASE_DEFINE(regression, 1003, xtest_tee_test_1003, |
| 510 | "Core internal read/write mutex"); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 511 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 512 | static void xtest_tee_test_1004(ADBG_Case_t *c) |
| 513 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 514 | TEEC_Session session = { }; |
| 515 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 516 | struct xtest_crypto_session cs = { c, &session, TA_CRYPT_CMD_SHA256, |
| 517 | TA_CRYPT_CMD_AES256ECB_ENC, |
| 518 | TA_CRYPT_CMD_AES256ECB_DEC }; |
| 519 | |
| 520 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, xtest_teec_open_session( |
| 521 | &session, &crypt_user_ta_uuid, |
| 522 | NULL, &ret_orig))) |
| 523 | return; |
| 524 | |
| 525 | /* Run the "complete crypto test suite" */ |
| 526 | xtest_crypto_test(&cs); |
| 527 | |
| 528 | TEEC_CloseSession(&session); |
| 529 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 530 | ADBG_CASE_DEFINE(regression, 1004, xtest_tee_test_1004, "Test User Crypt TA"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 531 | |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 532 | static void xtest_tee_test_invalid_mem_access(ADBG_Case_t *c, unsigned int n) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 533 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 534 | TEEC_Session session = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 535 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 536 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 537 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 538 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 539 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 540 | &ret_orig))) |
| 541 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 542 | |
| 543 | op.params[0].value.a = n; |
| 544 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, |
| 545 | TEEC_NONE); |
| 546 | |
| 547 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 548 | TEEC_ERROR_TARGET_DEAD, |
| 549 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
| 550 | &ret_orig)); |
| 551 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 552 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 553 | TEEC_ERROR_TARGET_DEAD, |
| 554 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 555 | &ret_orig)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 556 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 557 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 558 | |
| 559 | TEEC_CloseSession(&session); |
| 560 | } |
| 561 | |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 562 | static void xtest_tee_test_invalid_mem_access2(ADBG_Case_t *c, unsigned int n, |
| 563 | size_t size) |
| 564 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 565 | TEEC_Session session = { }; |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 566 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 567 | uint32_t ret_orig = 0; |
| 568 | TEEC_SharedMemory shm = { }; |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 569 | |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 570 | shm.size = size; |
| 571 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 572 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 573 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 574 | return; |
| 575 | |
| 576 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 577 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 578 | &ret_orig))) |
Jens Wiklander | 6987a82 | 2019-06-28 12:47:42 +0200 | [diff] [blame] | 579 | goto rel_shm; |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 580 | |
| 581 | op.params[0].value.a = (uint32_t)n; |
| 582 | op.params[1].memref.parent = &shm; |
| 583 | op.params[1].memref.size = size; |
| 584 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_MEMREF_WHOLE, |
| 585 | TEEC_NONE, TEEC_NONE); |
| 586 | |
| 587 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 588 | TEEC_ERROR_TARGET_DEAD, |
| 589 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
| 590 | &ret_orig)); |
| 591 | |
| 592 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 593 | TEEC_ERROR_TARGET_DEAD, |
| 594 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
| 595 | &ret_orig)); |
| 596 | |
| 597 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 598 | |
| 599 | TEEC_CloseSession(&session); |
Jens Wiklander | 6987a82 | 2019-06-28 12:47:42 +0200 | [diff] [blame] | 600 | rel_shm: |
| 601 | TEEC_ReleaseSharedMemory(&shm); |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 602 | } |
| 603 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 604 | static void xtest_tee_test_1005(ADBG_Case_t *c) |
| 605 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 606 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 607 | #define MAX_SESSIONS 3 |
| 608 | TEEC_Session sessions[MAX_SESSIONS]; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 609 | int i = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 610 | |
| 611 | for (i = 0; i < MAX_SESSIONS; i++) { |
| 612 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Jens Wiklander | eb6bce7 | 2016-09-23 11:37:33 +0200 | [diff] [blame] | 613 | xtest_teec_open_session(&sessions[i], |
| 614 | &concurrent_ta_uuid, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 615 | NULL, &ret_orig))) |
| 616 | break; |
| 617 | } |
| 618 | |
| 619 | for (; --i >= 0; ) |
| 620 | TEEC_CloseSession(&sessions[i]); |
| 621 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 622 | ADBG_CASE_DEFINE(regression, 1005, xtest_tee_test_1005, "Many sessions"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 623 | |
| 624 | static void xtest_tee_test_1006(ADBG_Case_t *c) |
| 625 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 626 | TEEC_Session session = { }; |
| 627 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 628 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 629 | uint8_t buf[32] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 630 | |
| 631 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 632 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 633 | &ret_orig))) |
| 634 | return; |
| 635 | |
| 636 | op.params[0].tmpref.buffer = buf; |
| 637 | op.params[0].tmpref.size = sizeof(buf); |
| 638 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, |
| 639 | TEEC_NONE, TEEC_NONE); |
| 640 | |
| 641 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 642 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BASIC, &op, |
| 643 | &ret_orig)); |
| 644 | |
| 645 | TEEC_CloseSession(&session); |
| 646 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 647 | ADBG_CASE_DEFINE(regression, 1006, xtest_tee_test_1006, |
| 648 | "Test Basic OS features"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 649 | |
| 650 | static void xtest_tee_test_1007(ADBG_Case_t *c) |
| 651 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 652 | TEEC_Session session = { }; |
| 653 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 654 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 655 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 656 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 657 | &ret_orig))) |
| 658 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 659 | |
| 660 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 661 | TEEC_ERROR_TARGET_DEAD, |
| 662 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PANIC, NULL, |
| 663 | &ret_orig)); |
| 664 | |
| 665 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 666 | |
| 667 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 668 | TEEC_ERROR_TARGET_DEAD, |
| 669 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_INIT, NULL, |
| 670 | &ret_orig)); |
| 671 | |
| 672 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 673 | |
| 674 | TEEC_CloseSession(&session); |
| 675 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 676 | ADBG_CASE_DEFINE(regression, 1007, xtest_tee_test_1007, "Test Panic"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 677 | |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 678 | #ifndef TA_DIR |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 679 | # ifdef __ANDROID__ |
Yongqin Liu | 286f1fc | 2018-06-21 22:09:15 +0800 | [diff] [blame] | 680 | #define TA_DIR "/vendor/lib/optee_armtz" |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 681 | # else |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 682 | #define TA_DIR "/lib/optee_armtz" |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 683 | # endif |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 684 | #endif |
| 685 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 686 | static FILE *open_ta_file(const TEEC_UUID *uuid, const char *mode) |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 687 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 688 | char buf[PATH_MAX] = { }; |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 689 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 690 | snprintf(buf, sizeof(buf), |
Jens Wiklander | 6203b87 | 2016-12-08 19:18:29 +0100 | [diff] [blame] | 691 | "%s/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.ta", |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 692 | TA_DIR, uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion, |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 693 | uuid->clockSeqAndNode[0], uuid->clockSeqAndNode[1], |
| 694 | uuid->clockSeqAndNode[2], uuid->clockSeqAndNode[3], |
| 695 | uuid->clockSeqAndNode[4], uuid->clockSeqAndNode[5], |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 696 | uuid->clockSeqAndNode[6], uuid->clockSeqAndNode[7]); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 697 | |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 698 | return fopen(buf, mode); |
| 699 | } |
| 700 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 701 | static bool load_corrupt_ta(ADBG_Case_t *c, size_t offs, uint8_t mask) |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 702 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 703 | TEEC_Session session = { }; |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 704 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 705 | TEEC_UUID uuid = PTA_SECSTOR_TA_MGMT_UUID; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 706 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 707 | uint32_t ret_orig = 0; |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 708 | FILE *f = NULL; |
| 709 | bool r = false; |
| 710 | uint8_t *buf = NULL; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 711 | size_t sz = 0; |
| 712 | size_t fread_res = 0; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 713 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 714 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 715 | xtest_teec_open_session(&session, &uuid, NULL, &ret_orig))) |
| 716 | goto out; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 717 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 718 | f = open_ta_file(&create_fail_test_ta_uuid, "rb"); |
| 719 | if (!ADBG_EXPECT_NOT_NULL(c, f)) |
| 720 | goto out; |
| 721 | if (!ADBG_EXPECT_TRUE(c, !fseek(f, 0, SEEK_END))) |
| 722 | goto out; |
| 723 | sz = ftell(f); |
| 724 | rewind(f); |
| 725 | |
| 726 | buf = malloc(sz); |
| 727 | if (!ADBG_EXPECT_NOT_NULL(c, buf)) |
| 728 | goto out; |
| 729 | |
| 730 | fread_res = fread(buf, 1, sz, f); |
| 731 | if (!ADBG_EXPECT_COMPARE_UNSIGNED(c, fread_res, ==, sz)) |
| 732 | goto out; |
| 733 | |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 734 | fclose(f); |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 735 | f = NULL; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 736 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 737 | buf[MIN(offs, sz)] ^= mask; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 738 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 739 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, |
| 740 | TEEC_NONE, TEEC_NONE); |
| 741 | op.params[0].tmpref.buffer = buf; |
| 742 | op.params[0].tmpref.size = sz; |
| 743 | |
| 744 | res = TEEC_InvokeCommand(&session, PTA_SECSTOR_TA_MGMT_BOOTSTRAP, &op, |
| 745 | &ret_orig); |
| 746 | r = ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_SECURITY, res); |
| 747 | out: |
| 748 | free(buf); |
| 749 | if (f) |
| 750 | fclose(f); |
| 751 | TEEC_CloseSession(&session); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 752 | return r; |
| 753 | } |
Jens Wiklander | e1a201d | 2020-02-12 18:36:20 +0100 | [diff] [blame] | 754 | |
| 755 | static void test_1008_corrupt_ta(ADBG_Case_t *c) |
| 756 | { |
| 757 | TEEC_UUID uuid = PTA_SECSTOR_TA_MGMT_UUID; |
| 758 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 759 | TEEC_Session session = { }; |
| 760 | uint32_t ret_orig = 0; |
| 761 | |
| 762 | res = xtest_teec_open_session(&session, &uuid, NULL, &ret_orig); |
| 763 | if (res) { |
| 764 | if (ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND, |
| 765 | res)) |
Joakim Bech | a1212b6 | 2020-04-07 12:06:00 +0200 | [diff] [blame] | 766 | Do_ADBG_Log("PTA Secure Storage TA Management not found: skip test"); |
Jens Wiklander | e1a201d | 2020-02-12 18:36:20 +0100 | [diff] [blame] | 767 | return; |
| 768 | } |
| 769 | TEEC_CloseSession(&session); |
| 770 | |
| 771 | ADBG_EXPECT_TRUE(c, |
| 772 | load_corrupt_ta(c, offsetof(struct shdr, magic), 1)); |
| 773 | ADBG_EXPECT_TRUE(c, |
| 774 | load_corrupt_ta(c, offsetof(struct shdr, img_type), 1)); |
| 775 | ADBG_EXPECT_TRUE(c, |
| 776 | load_corrupt_ta(c, offsetof(struct shdr, img_size), 1)); |
| 777 | ADBG_EXPECT_TRUE(c, |
| 778 | load_corrupt_ta(c, offsetof(struct shdr, algo), 1)); |
| 779 | ADBG_EXPECT_TRUE(c, |
| 780 | load_corrupt_ta(c, offsetof(struct shdr, hash_size), 1)); |
| 781 | ADBG_EXPECT_TRUE(c, |
| 782 | load_corrupt_ta(c, offsetof(struct shdr, sig_size), 1)); |
| 783 | ADBG_EXPECT_TRUE(c, |
| 784 | load_corrupt_ta(c, sizeof(struct shdr), 1)); /* hash */ |
| 785 | ADBG_EXPECT_TRUE(c, |
| 786 | load_corrupt_ta(c, sizeof(struct shdr) + 32, 1)); /* sig */ |
| 787 | ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 3000, 1)); /* payload */ |
| 788 | ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 8000, 1)); /* payload */ |
| 789 | } |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 790 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 791 | static void xtest_tee_test_1008(ADBG_Case_t *c) |
| 792 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 793 | TEEC_Session session = { }; |
| 794 | TEEC_Session session_crypt = { }; |
| 795 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 796 | |
| 797 | Do_ADBG_BeginSubCase(c, "Invoke command"); |
| 798 | { |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 799 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 800 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 801 | NULL, &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 802 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 803 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 804 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CLIENT, |
| 805 | NULL, &ret_orig)); |
| 806 | TEEC_CloseSession(&session); |
| 807 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 808 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 809 | } |
| 810 | Do_ADBG_EndSubCase(c, "Invoke command"); |
| 811 | |
| 812 | Do_ADBG_BeginSubCase(c, "Invoke command with timeout"); |
| 813 | { |
| 814 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 815 | |
| 816 | op.params[0].value.a = 2000; |
| 817 | op.paramTypes = TEEC_PARAM_TYPES( |
| 818 | TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 819 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 820 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 821 | xtest_teec_open_session(&session, |
| 822 | &os_test_ta_uuid, |
| 823 | NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 824 | &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 825 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 826 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 827 | TEEC_InvokeCommand(&session, |
| 828 | TA_OS_TEST_CMD_CLIENT_WITH_TIMEOUT, |
| 829 | &op, &ret_orig)); |
| 830 | TEEC_CloseSession(&session); |
| 831 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 832 | } |
| 833 | Do_ADBG_EndSubCase(c, "Invoke command with timeout"); |
| 834 | |
| 835 | Do_ADBG_BeginSubCase(c, "Create session fail"); |
| 836 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 837 | size_t n = 0; |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 838 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 839 | for (n = 0; n < 100; n++) { |
| 840 | Do_ADBG_Log("n = %zu", n); |
| 841 | (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC, |
| 842 | xtest_teec_open_session(&session_crypt, |
| 843 | &create_fail_test_ta_uuid, |
| 844 | NULL, &ret_orig)); |
Jerome Forissier | ec7a31f | 2020-11-20 11:30:06 +0100 | [diff] [blame] | 845 | /* level > 0 may be used to detect/debug memory leaks */ |
| 846 | if (!level) |
| 847 | break; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 848 | } |
| 849 | } |
| 850 | Do_ADBG_EndSubCase(c, "Create session fail"); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 851 | |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 852 | Do_ADBG_BeginSubCase(c, "Load corrupt TA"); |
Jens Wiklander | e1a201d | 2020-02-12 18:36:20 +0100 | [diff] [blame] | 853 | test_1008_corrupt_ta(c); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 854 | Do_ADBG_EndSubCase(c, "Load corrupt TA"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 855 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 856 | ADBG_CASE_DEFINE(regression, 1008, xtest_tee_test_1008, |
| 857 | "TEE internal client API"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 858 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 859 | static void *cancellation_thread(void *arg) |
| 860 | { |
| 861 | /* |
| 862 | * Sleep 0.5 seconds before cancellation to make sure that the other |
| 863 | * thread is in RPC_WAIT. |
| 864 | */ |
| 865 | (void)usleep(500000); |
| 866 | TEEC_RequestCancellation(arg); |
| 867 | return NULL; |
| 868 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 869 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 870 | static void xtest_tee_test_1009_subcase(ADBG_Case_t *c, const char *subcase, |
| 871 | uint32_t timeout, bool cancel) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 872 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 873 | TEEC_Session session = { }; |
| 874 | uint32_t ret_orig = 0; |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 875 | pthread_t thr; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 876 | |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 877 | memset(&thr, 0, sizeof(thr)); |
| 878 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 879 | Do_ADBG_BeginSubCase(c, "%s", subcase); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 880 | { |
| 881 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 882 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 883 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
| 884 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 885 | NULL, &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 886 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 887 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, |
| 888 | TEEC_ORIGIN_TRUSTED_APP, |
| 889 | ret_orig); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 890 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 891 | op.params[0].value.a = timeout; |
| 892 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 893 | TEEC_NONE, |
| 894 | TEEC_NONE, TEEC_NONE); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 895 | if (cancel) { |
| 896 | (void)ADBG_EXPECT(c, 0, |
| 897 | pthread_create(&thr, NULL, |
| 898 | cancellation_thread, &op)); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 899 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 900 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 901 | TEEC_ERROR_CANCEL, |
| 902 | TEEC_InvokeCommand(&session, |
| 903 | TA_OS_TEST_CMD_WAIT, |
| 904 | &op, |
| 905 | &ret_orig)); |
| 906 | } else |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 907 | |
| 908 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 909 | TEEC_InvokeCommand(&session, |
| 910 | TA_OS_TEST_CMD_WAIT, |
| 911 | &op, |
| 912 | &ret_orig)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 913 | if (cancel) |
| 914 | (void)ADBG_EXPECT(c, 0, pthread_join(thr, NULL)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 915 | |
| 916 | TEEC_CloseSession(&session); |
| 917 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 918 | } |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 919 | Do_ADBG_EndSubCase(c, "%s", subcase); |
| 920 | } |
| 921 | |
| 922 | static void xtest_tee_test_1009(ADBG_Case_t *c) |
| 923 | { |
| 924 | xtest_tee_test_1009_subcase(c, "TEE Wait 0.1s", 100, false); |
| 925 | xtest_tee_test_1009_subcase(c, "TEE Wait 0.5s", 500, false); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 926 | xtest_tee_test_1009_subcase(c, "TEE Wait 2s cancel", 2000, true); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 927 | xtest_tee_test_1009_subcase(c, "TEE Wait 2s", 2000, false); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 928 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 929 | ADBG_CASE_DEFINE(regression, 1009, xtest_tee_test_1009, "TEE Wait"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 930 | |
| 931 | static void xtest_tee_test_1010(ADBG_Case_t *c) |
| 932 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 933 | unsigned int n = 0; |
| 934 | unsigned int idx = 0; |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 935 | size_t memref_sz[] = { 1024, 65536 }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 936 | |
Jerome Forissier | e4c33f4 | 2021-09-21 11:26:17 +0200 | [diff] [blame] | 937 | for (n = 1; n <= 7; n++) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 938 | Do_ADBG_BeginSubCase(c, "Invalid memory access %u", n); |
| 939 | xtest_tee_test_invalid_mem_access(c, n); |
| 940 | Do_ADBG_EndSubCase(c, "Invalid memory access %u", n); |
| 941 | } |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 942 | |
| 943 | for (idx = 0; idx < ARRAY_SIZE(memref_sz); idx++) { |
| 944 | for (n = 1; n <= 5; n++) { |
| 945 | Do_ADBG_BeginSubCase(c, |
Igor Opaniuk | e8236ac | 2018-02-12 12:26:25 +0200 | [diff] [blame] | 946 | "Invalid memory access %u with %zu bytes memref", |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 947 | n, memref_sz[idx]); |
| 948 | xtest_tee_test_invalid_mem_access2(c, n, memref_sz[idx]); |
| 949 | Do_ADBG_EndSubCase(c, |
Igor Opaniuk | e8236ac | 2018-02-12 12:26:25 +0200 | [diff] [blame] | 950 | "Invalid memory access %u with %zu bytes memref", |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 951 | n, memref_sz[idx]); |
| 952 | } |
| 953 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 954 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 955 | ADBG_CASE_DEFINE(regression, 1010, xtest_tee_test_1010, |
| 956 | "Invalid memory access"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 957 | |
| 958 | static void xtest_tee_test_1011(ADBG_Case_t *c) |
| 959 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 960 | TEEC_Session session = { }; |
| 961 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 962 | struct xtest_crypto_session cs = { |
| 963 | c, &session, TA_RPC_CMD_CRYPT_SHA256, |
| 964 | TA_RPC_CMD_CRYPT_AES256ECB_ENC, |
| 965 | TA_RPC_CMD_CRYPT_AES256ECB_DEC |
| 966 | }; |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 967 | struct xtest_crypto_session cs_privmem = { |
| 968 | c, &session, |
| 969 | TA_RPC_CMD_CRYPT_PRIVMEM_SHA256, |
| 970 | TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_ENC, |
| 971 | TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_DEC |
| 972 | }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 973 | TEEC_UUID uuid = rpc_test_ta_uuid; |
| 974 | |
| 975 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 976 | xtest_teec_open_session(&session, &uuid, NULL, &ret_orig))) |
| 977 | return; |
| 978 | |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 979 | Do_ADBG_BeginSubCase(c, "TA-to-TA via non-secure shared memory"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 980 | /* |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 981 | * Run the "complete crypto test suite" using TA-to-TA |
| 982 | * communication |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 983 | */ |
| 984 | xtest_crypto_test(&cs); |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 985 | Do_ADBG_EndSubCase(c, "TA-to-TA via non-secure shared memory"); |
| 986 | |
| 987 | Do_ADBG_BeginSubCase(c, "TA-to-TA via TA private memory"); |
| 988 | /* |
| 989 | * Run the "complete crypto test suite" using TA-to-TA |
| 990 | * communication via TA private memory. |
| 991 | */ |
| 992 | xtest_crypto_test(&cs_privmem); |
| 993 | Do_ADBG_EndSubCase(c, "TA-to-TA via TA private memory"); |
| 994 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 995 | TEEC_CloseSession(&session); |
| 996 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 997 | ADBG_CASE_DEFINE(regression, 1011, xtest_tee_test_1011, |
| 998 | "Test TA-to-TA features with User Crypt TA"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 999 | |
| 1000 | /* |
| 1001 | * Note that this test is failing when |
| 1002 | * - running twice in a raw |
| 1003 | * - and the user TA is statically linked |
| 1004 | * This is because the counter is not reseted when opening the first session |
| 1005 | * in case the TA is statically linked |
| 1006 | */ |
| 1007 | static void xtest_tee_test_1012(ADBG_Case_t *c) |
| 1008 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1009 | TEEC_Session session1 = { }; |
| 1010 | TEEC_Session session2 = { }; |
| 1011 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1012 | TEEC_UUID uuid = sims_test_ta_uuid; |
| 1013 | |
| 1014 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Session"); |
| 1015 | { |
| 1016 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1017 | static const uint8_t in[] = { |
| 1018 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 1019 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 1020 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 1021 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 1022 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1023 | uint8_t out[32] = { }; |
| 1024 | int i = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1025 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 1026 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1027 | xtest_teec_open_session(&session1, &uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 1028 | &ret_orig))) |
| 1029 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1030 | |
| 1031 | op.params[0].value.a = 0; |
| 1032 | op.params[1].tmpref.buffer = (void *)in; |
| 1033 | op.params[1].tmpref.size = sizeof(in); |
| 1034 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 1035 | TEEC_MEMREF_TEMP_INPUT, |
| 1036 | TEEC_NONE, TEEC_NONE); |
| 1037 | |
| 1038 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1039 | TEEC_InvokeCommand(&session1, TA_SIMS_CMD_WRITE, &op, |
| 1040 | &ret_orig)); |
| 1041 | |
Jerome Forissier | 3cc0a42 | 2017-12-14 09:53:24 +0100 | [diff] [blame] | 1042 | for (i = 1; i < 3; i++) { |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 1043 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1044 | xtest_teec_open_session(&session2, &uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 1045 | &ret_orig))) |
| 1046 | continue; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1047 | |
| 1048 | op.params[0].value.a = 0; |
| 1049 | op.params[1].tmpref.buffer = out; |
| 1050 | op.params[1].tmpref.size = sizeof(out); |
| 1051 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 1052 | TEEC_MEMREF_TEMP_OUTPUT, |
| 1053 | TEEC_NONE, TEEC_NONE); |
| 1054 | |
| 1055 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1056 | TEEC_InvokeCommand(&session2, TA_SIMS_CMD_READ, |
| 1057 | &op, &ret_orig)); |
| 1058 | |
| 1059 | if (!ADBG_EXPECT_BUFFER(c, in, sizeof(in), out, |
| 1060 | sizeof(out))) { |
| 1061 | Do_ADBG_Log("in:"); |
| 1062 | Do_ADBG_HexLog(in, sizeof(in), 16); |
| 1063 | Do_ADBG_Log("out:"); |
| 1064 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 1065 | } |
| 1066 | |
| 1067 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, |
| 1068 | TEEC_NONE, TEEC_NONE, |
| 1069 | TEEC_NONE); |
| 1070 | |
| 1071 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1072 | TEEC_InvokeCommand(&session1, |
| 1073 | TA_SIMS_CMD_GET_COUNTER, |
| 1074 | &op, &ret_orig)); |
| 1075 | |
| 1076 | (void)ADBG_EXPECT(c, 0, op.params[0].value.a); |
| 1077 | |
| 1078 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1079 | TEEC_InvokeCommand(&session2, |
| 1080 | TA_SIMS_CMD_GET_COUNTER, &op, |
| 1081 | &ret_orig)); |
| 1082 | |
| 1083 | (void)ADBG_EXPECT(c, i, op.params[0].value.a); |
| 1084 | TEEC_CloseSession(&session2); |
| 1085 | } |
| 1086 | |
| 1087 | memset(out, 0, sizeof(out)); |
| 1088 | op.params[0].value.a = 0; |
| 1089 | op.params[1].tmpref.buffer = out; |
| 1090 | op.params[1].tmpref.size = sizeof(out); |
| 1091 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 1092 | TEEC_MEMREF_TEMP_OUTPUT, |
| 1093 | TEEC_NONE, TEEC_NONE); |
| 1094 | |
| 1095 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1096 | TEEC_InvokeCommand(&session1, TA_SIMS_CMD_READ, &op, |
| 1097 | &ret_orig)); |
| 1098 | |
| 1099 | if (!ADBG_EXPECT(c, 0, memcmp(in, out, sizeof(in)))) { |
| 1100 | Do_ADBG_Log("in:"); |
| 1101 | Do_ADBG_HexLog(in, sizeof(in), 16); |
| 1102 | Do_ADBG_Log("out:"); |
| 1103 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 1104 | } |
| 1105 | |
| 1106 | TEEC_CloseSession(&session1); |
| 1107 | } |
Ovidiu Mihalachi | 3e6183e | 2019-04-25 10:23:21 +0300 | [diff] [blame] | 1108 | Do_ADBG_EndSubCase(c, "Single Instance Multi Session"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1109 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1110 | ADBG_CASE_DEFINE(regression, 1012, xtest_tee_test_1012, |
| 1111 | "Test Single Instance Multi Session features with SIMS TA"); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1112 | |
| 1113 | struct test_1013_thread_arg { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1114 | const TEEC_UUID *uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1115 | uint32_t cmd; |
| 1116 | uint32_t repeat; |
| 1117 | TEEC_SharedMemory *shm; |
| 1118 | uint32_t error_orig; |
| 1119 | TEEC_Result res; |
| 1120 | uint32_t max_concurrency; |
| 1121 | const uint8_t *in; |
| 1122 | size_t in_len; |
| 1123 | uint8_t *out; |
| 1124 | size_t out_len; |
| 1125 | }; |
| 1126 | |
| 1127 | static void *test_1013_thread(void *arg) |
| 1128 | { |
| 1129 | struct test_1013_thread_arg *a = arg; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1130 | TEEC_Session session = { }; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1131 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1132 | uint8_t p2 = TEEC_NONE; |
| 1133 | uint8_t p3 = TEEC_NONE; |
| 1134 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1135 | a->res = xtest_teec_open_session(&session, a->uuid, NULL, |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1136 | &a->error_orig); |
| 1137 | if (a->res != TEEC_SUCCESS) |
| 1138 | return NULL; |
| 1139 | |
| 1140 | op.params[0].memref.parent = a->shm; |
| 1141 | op.params[0].memref.size = a->shm->size; |
| 1142 | op.params[0].memref.offset = 0; |
| 1143 | op.params[1].value.a = a->repeat; |
| 1144 | op.params[1].value.b = 0; |
| 1145 | op.params[2].tmpref.buffer = (void *)a->in; |
| 1146 | op.params[2].tmpref.size = a->in_len; |
| 1147 | op.params[3].tmpref.buffer = a->out; |
| 1148 | op.params[3].tmpref.size = a->out_len; |
| 1149 | |
| 1150 | if (a->in_len) |
| 1151 | p2 = TEEC_MEMREF_TEMP_INPUT; |
| 1152 | if (a->out_len) |
| 1153 | p3 = TEEC_MEMREF_TEMP_OUTPUT; |
| 1154 | |
| 1155 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, |
| 1156 | TEEC_VALUE_INOUT, p2, p3); |
| 1157 | |
| 1158 | a->res = TEEC_InvokeCommand(&session, a->cmd, &op, &a->error_orig); |
| 1159 | a->max_concurrency = op.params[1].value.b; |
| 1160 | a->out_len = op.params[3].tmpref.size; |
| 1161 | TEEC_CloseSession(&session); |
| 1162 | return NULL; |
| 1163 | } |
| 1164 | |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1165 | #define NUM_THREADS 3 |
| 1166 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1167 | static void xtest_tee_test_1013_single(ADBG_Case_t *c, double *mean_concurrency, |
| 1168 | const TEEC_UUID *uuid) |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1169 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1170 | size_t nt = 0; |
| 1171 | size_t n = 0; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1172 | size_t repeat = 1000; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1173 | TEEC_SharedMemory shm = { }; |
| 1174 | size_t max_concurrency = 0; |
| 1175 | struct test_1013_thread_arg arg[NUM_THREADS] = { }; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1176 | static const uint8_t sha256_in[] = { 'a', 'b', 'c' }; |
| 1177 | static const uint8_t sha256_out[] = { |
| 1178 | 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, |
| 1179 | 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, |
| 1180 | 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, |
| 1181 | 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad |
| 1182 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1183 | uint8_t out[32] = { }; |
| 1184 | pthread_t thr[NUM_THREADS] = { }; |
Jerome Forissier | fbdc175 | 2021-06-29 11:25:35 +0200 | [diff] [blame] | 1185 | bool skip = false; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1186 | |
Etienne Carriere | c0a6172 | 2023-03-07 17:47:42 +0100 | [diff] [blame] | 1187 | /* Decrease number of loops when pager has a small page pool */ |
| 1188 | if (level == 0 && optee_pager_with_small_pool()) |
| 1189 | repeat = 250; |
| 1190 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1191 | Do_ADBG_BeginSubCase(c, "Busy loop repeat %zu", repeat * 10); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1192 | *mean_concurrency = 0; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1193 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1194 | shm.size = sizeof(struct ta_concurrent_shm); |
| 1195 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1196 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1197 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 1198 | return; |
| 1199 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1200 | memset(shm.buffer, 0, shm.size); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1201 | max_concurrency = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1202 | nt = NUM_THREADS; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1203 | |
| 1204 | for (n = 0; n < nt; n++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1205 | arg[n].uuid = uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1206 | arg[n].cmd = TA_CONCURRENT_CMD_BUSY_LOOP; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1207 | arg[n].repeat = repeat * 10; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1208 | arg[n].shm = &shm; |
| 1209 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 1210 | test_1013_thread, arg + n))) |
| 1211 | nt = n; /* break loop and start cleanup */ |
| 1212 | } |
| 1213 | |
| 1214 | for (n = 0; n < nt; n++) { |
| 1215 | ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)); |
Jerome Forissier | fbdc175 | 2021-06-29 11:25:35 +0200 | [diff] [blame] | 1216 | if (arg[n].res == TEEC_ERROR_OUT_OF_MEMORY && |
| 1217 | !memcmp(uuid, &concurrent_large_ta_uuid, sizeof(*uuid))) { |
| 1218 | Do_ADBG_Log("TEEC_ERROR_OUT_OF_MEMORY - ignored"); |
| 1219 | skip = true; |
| 1220 | continue; |
| 1221 | } |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1222 | ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res); |
| 1223 | if (arg[n].max_concurrency > max_concurrency) |
| 1224 | max_concurrency = arg[n].max_concurrency; |
| 1225 | } |
| 1226 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1227 | /* |
| 1228 | * Concurrency can be limited by several factors, for instance in a |
Joakim Bech | a1212b6 | 2020-04-07 12:06:00 +0200 | [diff] [blame] | 1229 | * single CPU system it's dependent on the Preemption Model used by |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1230 | * the kernel (Preemptible Kernel (Low-Latency Desktop) gives the |
| 1231 | * best result there). |
| 1232 | */ |
Jerome Forissier | fbdc175 | 2021-06-29 11:25:35 +0200 | [diff] [blame] | 1233 | if (!skip) { |
| 1234 | (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, >, 0); |
| 1235 | (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, <=, |
| 1236 | NUM_THREADS); |
| 1237 | *mean_concurrency += max_concurrency; |
| 1238 | } |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1239 | Do_ADBG_EndSubCase(c, "Busy loop repeat %zu", repeat * 10); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1240 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1241 | Do_ADBG_BeginSubCase(c, "SHA-256 loop repeat %zu", repeat); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1242 | memset(shm.buffer, 0, shm.size); |
| 1243 | memset(arg, 0, sizeof(arg)); |
| 1244 | max_concurrency = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1245 | nt = NUM_THREADS; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1246 | |
| 1247 | for (n = 0; n < nt; n++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1248 | arg[n].uuid = uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1249 | arg[n].cmd = TA_CONCURRENT_CMD_SHA256; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1250 | arg[n].repeat = repeat; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1251 | arg[n].shm = &shm; |
| 1252 | arg[n].in = sha256_in; |
| 1253 | arg[n].in_len = sizeof(sha256_in); |
| 1254 | arg[n].out = out; |
| 1255 | arg[n].out_len = sizeof(out); |
| 1256 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 1257 | test_1013_thread, arg + n))) |
| 1258 | nt = n; /* break loop and start cleanup */ |
| 1259 | } |
| 1260 | |
| 1261 | for (n = 0; n < nt; n++) { |
Jerome Forissier | fbdc175 | 2021-06-29 11:25:35 +0200 | [diff] [blame] | 1262 | ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)); |
| 1263 | if (arg[n].res == TEEC_ERROR_OUT_OF_MEMORY && |
| 1264 | !memcmp(uuid, &concurrent_large_ta_uuid, sizeof(*uuid))) { |
| 1265 | Do_ADBG_Log("TEEC_ERROR_OUT_OF_MEMORY - ignored"); |
| 1266 | continue; |
| 1267 | } |
| 1268 | if (ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res)) |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1269 | ADBG_EXPECT_BUFFER(c, sha256_out, sizeof(sha256_out), |
| 1270 | arg[n].out, arg[n].out_len); |
| 1271 | if (arg[n].max_concurrency > max_concurrency) |
| 1272 | max_concurrency = arg[n].max_concurrency; |
| 1273 | } |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1274 | *mean_concurrency += max_concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1275 | Do_ADBG_EndSubCase(c, "SHA-256 loop repeat %zu", repeat); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1276 | |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1277 | *mean_concurrency /= 2.0; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1278 | TEEC_ReleaseSharedMemory(&shm); |
| 1279 | } |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1280 | |
| 1281 | static void xtest_tee_test_1013(ADBG_Case_t *c) |
| 1282 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1283 | int i = 0; |
| 1284 | double mean_concurrency = 0; |
| 1285 | double concurrency = 0; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1286 | int nb_loops = 24; |
Jens Wiklander | 6a9d15a | 2016-02-01 10:29:42 +0100 | [diff] [blame] | 1287 | |
| 1288 | if (level == 0) |
| 1289 | nb_loops /= 2; |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1290 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1291 | Do_ADBG_BeginSubCase(c, "Using small concurrency TA"); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1292 | mean_concurrency = 0; |
| 1293 | for (i = 0; i < nb_loops; i++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1294 | xtest_tee_test_1013_single(c, &concurrency, |
| 1295 | &concurrent_ta_uuid); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1296 | mean_concurrency += concurrency; |
| 1297 | } |
| 1298 | mean_concurrency /= nb_loops; |
| 1299 | |
| 1300 | Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS); |
| 1301 | Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency); |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1302 | Do_ADBG_EndSubCase(c, "Using small concurrency TA"); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1303 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1304 | Do_ADBG_BeginSubCase(c, "Using large concurrency TA"); |
| 1305 | mean_concurrency = 0; |
| 1306 | for (i = 0; i < nb_loops; i++) { |
| 1307 | xtest_tee_test_1013_single(c, &concurrency, |
| 1308 | &concurrent_large_ta_uuid); |
| 1309 | mean_concurrency += concurrency; |
| 1310 | } |
| 1311 | mean_concurrency /= nb_loops; |
| 1312 | |
| 1313 | Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS); |
| 1314 | Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency); |
| 1315 | Do_ADBG_EndSubCase(c, "Using large concurrency TA"); |
| 1316 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1317 | ADBG_CASE_DEFINE(regression, 1013, xtest_tee_test_1013, |
Joakim Bech | a1212b6 | 2020-04-07 12:06:00 +0200 | [diff] [blame] | 1318 | "Test concurrency with concurrent TA"); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1319 | |
| 1320 | #ifdef CFG_SECURE_DATA_PATH |
| 1321 | static void xtest_tee_test_1014(ADBG_Case_t *c) |
| 1322 | { |
| 1323 | UNUSED(c); |
| 1324 | |
| 1325 | int size = 17000; |
| 1326 | int loop = 10; |
Olivier Masse | da5282a | 2022-04-07 11:24:08 +0200 | [diff] [blame] | 1327 | const char *heap_name = DEFAULT_HEAP_NAME; |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1328 | int rnd_offset = 1; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1329 | int test = 0; |
| 1330 | int ret = 0; |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1331 | |
| 1332 | test = TEST_NS_TO_TA; |
| 1333 | Do_ADBG_BeginSubCase(c, "SDP: NonSecure client invokes a SDP TA"); |
Jerome Forissier | 03aa279 | 2023-02-07 14:22:24 +0100 | [diff] [blame] | 1334 | ret = sdp_basic_test(test, size, loop, heap_name, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1335 | ADBG_EXPECT(c, 0, ret); |
| 1336 | Do_ADBG_EndSubCase(c, "SDP: NonSecure client invokes a SDP TA"); |
| 1337 | |
| 1338 | test = TEST_TA_TO_TA; |
| 1339 | Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP TA"); |
Jerome Forissier | 03aa279 | 2023-02-07 14:22:24 +0100 | [diff] [blame] | 1340 | ret = sdp_basic_test(test, size, loop, heap_name, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1341 | ADBG_EXPECT(c, 0, ret); |
| 1342 | Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP TA"); |
| 1343 | |
| 1344 | test = TEST_TA_TO_PTA; |
Igor Opaniuk | 2e0a679 | 2021-01-09 00:51:19 +0200 | [diff] [blame] | 1345 | Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a test pTA (invoke_tests.pta)"); |
Jerome Forissier | 03aa279 | 2023-02-07 14:22:24 +0100 | [diff] [blame] | 1346 | ret = sdp_basic_test(test, size, loop, heap_name, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1347 | ADBG_EXPECT(c, 0, ret); |
Igor Opaniuk | 2e0a679 | 2021-01-09 00:51:19 +0200 | [diff] [blame] | 1348 | Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a test pTA (invoke_tests.pta)"); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1349 | |
| 1350 | test = TEST_NS_TO_PTA; |
Igor Opaniuk | 2e0a679 | 2021-01-09 00:51:19 +0200 | [diff] [blame] | 1351 | Do_ADBG_BeginSubCase(c, "SDP: NSec CA invokes a test pTA (invoke_tests.pta) (should fail)"); |
Jerome Forissier | 03aa279 | 2023-02-07 14:22:24 +0100 | [diff] [blame] | 1352 | ret = sdp_basic_test(test, size, loop, heap_name, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1353 | ADBG_EXPECT(c, 1, ret); |
Igor Opaniuk | 2e0a679 | 2021-01-09 00:51:19 +0200 | [diff] [blame] | 1354 | Do_ADBG_EndSubCase(c, "SDP: NSec CA invokes a test pTA (invoke_tests.pta) (should fail)"); |
Etienne Carriere | d9be3dc | 2018-04-25 18:30:19 +0200 | [diff] [blame] | 1355 | |
| 1356 | Do_ADBG_BeginSubCase(c, "SDP: Invoke TA with out of bounds SDP memref"); |
Jerome Forissier | 03aa279 | 2023-02-07 14:22:24 +0100 | [diff] [blame] | 1357 | ret = sdp_out_of_bounds_memref_test(size, heap_name, 0); |
Etienne Carriere | d9be3dc | 2018-04-25 18:30:19 +0200 | [diff] [blame] | 1358 | ADBG_EXPECT(c, 0, ret); |
| 1359 | Do_ADBG_EndSubCase(c, NULL); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1360 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1361 | ADBG_CASE_DEFINE(regression, 1014, xtest_tee_test_1014, |
| 1362 | "Test secure data path against SDP TAs and pTAs"); |
| 1363 | #endif /*CFG_SECURE_DATA_PATH*/ |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1364 | |
Jerome Forissier | f425994 | 2022-01-11 14:27:05 +0100 | [diff] [blame] | 1365 | #ifdef CFG_REE_FS |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1366 | static void xtest_tee_test_1015(ADBG_Case_t *c) |
| 1367 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1368 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1369 | TEEC_Session session = { }; |
| 1370 | uint32_t ret_orig = 0; |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1371 | |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1372 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1373 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 1374 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1375 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 1376 | Do_ADBG_Log(" - 1015 - skip test, pseudo TA not found"); |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1377 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1378 | } |
| 1379 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1380 | |
| 1381 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1382 | TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_FS_HTREE, |
| 1383 | NULL, &ret_orig)); |
| 1384 | TEEC_CloseSession(&session); |
| 1385 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1386 | ADBG_CASE_DEFINE(regression, 1015, xtest_tee_test_1015, |
| 1387 | "FS hash-tree corner cases"); |
Jerome Forissier | f425994 | 2022-01-11 14:27:05 +0100 | [diff] [blame] | 1388 | #endif /*CFG_REE_FS*/ |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1389 | |
| 1390 | static void xtest_tee_test_1016(ADBG_Case_t *c) |
| 1391 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1392 | TEEC_Session session = { }; |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1393 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1394 | uint32_t ret_orig = 0; |
Vincent Mailhol | da741cd | 2023-11-16 20:20:54 +0900 | [diff] [blame] | 1395 | int dummy = 0; |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1396 | |
| 1397 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1398 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1399 | &ret_orig))) |
| 1400 | return; |
| 1401 | |
| 1402 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, |
| 1403 | TEEC_NONE); |
| 1404 | |
| 1405 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1406 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TA2TA_MEMREF, &op, |
| 1407 | &ret_orig)); |
| 1408 | |
Vincent Mailhol | da741cd | 2023-11-16 20:20:54 +0900 | [diff] [blame] | 1409 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 1410 | TEEC_MEMREF_TEMP_INOUT, |
| 1411 | TEEC_MEMREF_TEMP_OUTPUT, |
| 1412 | TEEC_NONE); |
| 1413 | |
| 1414 | op.params[0].tmpref.buffer = &dummy; |
| 1415 | op.params[0].tmpref.size = 0; |
| 1416 | |
| 1417 | op.params[1].tmpref.buffer = &dummy; |
| 1418 | op.params[1].tmpref.size = 0; |
| 1419 | |
| 1420 | op.params[2].tmpref.buffer = &dummy; |
| 1421 | op.params[2].tmpref.size = 0; |
| 1422 | |
| 1423 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1424 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TA2TA_MEMREF_SIZE0, |
| 1425 | &op, &ret_orig)); |
| 1426 | |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1427 | TEEC_CloseSession(&session); |
| 1428 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1429 | ADBG_CASE_DEFINE(regression, 1016, xtest_tee_test_1016, |
| 1430 | "Test TA to TA transfers (in/out/inout memrefs on the stack)"); |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1431 | |
| 1432 | static void xtest_tee_test_1017(ADBG_Case_t *c) |
| 1433 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1434 | TEEC_Session session = { }; |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1435 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1436 | uint32_t ret_orig = 0; |
| 1437 | TEEC_SharedMemory shm = { }; |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1438 | size_t page_size = 4096; |
| 1439 | |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1440 | shm.size = 8 * page_size; |
| 1441 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1442 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1443 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 1444 | return; |
| 1445 | |
| 1446 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1447 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1448 | &ret_orig))) |
| 1449 | goto out; |
| 1450 | |
| 1451 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, |
| 1452 | TEEC_MEMREF_PARTIAL_INPUT, |
| 1453 | TEEC_MEMREF_PARTIAL_OUTPUT, |
| 1454 | TEEC_MEMREF_PARTIAL_OUTPUT); |
| 1455 | |
| 1456 | /* |
| 1457 | * The first two memrefs are supposed to be combined into in |
| 1458 | * region and the last two memrefs should have one region each |
| 1459 | * when the parameters are mapped for the TA. |
| 1460 | */ |
| 1461 | op.params[0].memref.parent = &shm; |
| 1462 | op.params[0].memref.size = page_size; |
| 1463 | op.params[0].memref.offset = 0; |
| 1464 | |
| 1465 | op.params[1].memref.parent = &shm; |
| 1466 | op.params[1].memref.size = page_size; |
| 1467 | op.params[1].memref.offset = page_size; |
| 1468 | |
| 1469 | op.params[2].memref.parent = &shm; |
| 1470 | op.params[2].memref.size = page_size; |
| 1471 | op.params[2].memref.offset = 4 * page_size; |
| 1472 | |
| 1473 | op.params[3].memref.parent = &shm; |
| 1474 | op.params[3].memref.size = 2 * page_size; |
| 1475 | op.params[3].memref.offset = 6 * page_size; |
| 1476 | |
| 1477 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1478 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PARAMS, &op, |
| 1479 | &ret_orig)); |
| 1480 | |
| 1481 | TEEC_CloseSession(&session); |
| 1482 | out: |
| 1483 | TEEC_ReleaseSharedMemory(&shm); |
| 1484 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1485 | ADBG_CASE_DEFINE(regression, 1017, xtest_tee_test_1017, |
| 1486 | "Test coalescing memrefs"); |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1487 | |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1488 | static void invoke_1byte_out_of_bounds(ADBG_Case_t *c, TEEC_Session *session, |
| 1489 | TEEC_SharedMemory *shm) |
| 1490 | { |
| 1491 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1492 | TEEC_Result ret = TEEC_ERROR_GENERIC; |
| 1493 | uint32_t ret_orig = 0; |
| 1494 | |
| 1495 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, |
| 1496 | TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 1497 | |
| 1498 | op.params[0].memref.parent = shm; |
| 1499 | op.params[0].memref.size = shm->size / 2; |
| 1500 | op.params[0].memref.offset = shm->size - (shm->size / 2) + 1; |
| 1501 | |
| 1502 | ret = TEEC_InvokeCommand(session, TA_OS_TEST_CMD_PARAMS, |
| 1503 | &op, &ret_orig); |
| 1504 | |
Etienne Carriere | 48fa1b2 | 2020-04-08 13:42:01 +0200 | [diff] [blame] | 1505 | ADBG_EXPECT_COMPARE_UNSIGNED(c, ret_orig, !=, TEEC_ORIGIN_TRUSTED_APP); |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1506 | if (ret != TEEC_ERROR_BAD_PARAMETERS && ret != TEEC_ERROR_GENERIC) { |
| 1507 | ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS, ret); |
| 1508 | ADBG_EXPECT(c, TEEC_ERROR_GENERIC, ret); |
| 1509 | } |
| 1510 | } |
| 1511 | |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1512 | static void xtest_tee_test_1018(ADBG_Case_t *c) |
| 1513 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1514 | TEEC_Session session = { }; |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1515 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1516 | uint32_t ret_orig = 0; |
| 1517 | TEEC_SharedMemory shm = { }; |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1518 | TEEC_Result ret = TEEC_ERROR_GENERIC; |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1519 | size_t page_size = 4096; |
Joakim Bech | a1212b6 | 2020-04-07 12:06:00 +0200 | [diff] [blame] | 1520 | /* Intentionally not 4kB aligned and odd */ |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1521 | uint8_t buffer[6001] = { }; |
| 1522 | |
| 1523 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1524 | xtest_teec_open_session(&session, |
| 1525 | &os_test_ta_uuid, |
| 1526 | NULL, |
| 1527 | &ret_orig))) |
| 1528 | return; |
| 1529 | |
Joakim Bech | a1212b6 | 2020-04-07 12:06:00 +0200 | [diff] [blame] | 1530 | Do_ADBG_BeginSubCase(c, "Out of bounds > 4kB on allocated shm"); |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1531 | |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1532 | shm.size = 8 * page_size; |
| 1533 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1534 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1535 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, |
| 1536 | &shm))) |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1537 | goto out; |
| 1538 | |
| 1539 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, |
| 1540 | TEEC_MEMREF_PARTIAL_INPUT, |
| 1541 | TEEC_MEMREF_PARTIAL_OUTPUT, |
| 1542 | TEEC_MEMREF_PARTIAL_OUTPUT); |
| 1543 | |
| 1544 | /* |
| 1545 | * The first two memrefs are supposed to be combined into in |
| 1546 | * region and the last two memrefs should have one region each |
| 1547 | * when the parameters are mapped for the TA. |
| 1548 | */ |
| 1549 | op.params[0].memref.parent = &shm; |
| 1550 | op.params[0].memref.size = page_size; |
| 1551 | op.params[0].memref.offset = 0; |
| 1552 | |
| 1553 | op.params[1].memref.parent = &shm; |
| 1554 | op.params[1].memref.size = page_size; |
| 1555 | op.params[1].memref.offset = page_size; |
| 1556 | |
| 1557 | op.params[2].memref.parent = &shm; |
| 1558 | op.params[2].memref.size = page_size; |
| 1559 | op.params[2].memref.offset = 4 * page_size; |
| 1560 | |
| 1561 | op.params[3].memref.parent = &shm; |
| 1562 | op.params[3].memref.size = 3 * page_size; |
| 1563 | op.params[3].memref.offset = 6 * page_size; |
| 1564 | |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1565 | ret = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PARAMS, &op, |
| 1566 | &ret_orig); |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1567 | |
Etienne Carriere | 48fa1b2 | 2020-04-08 13:42:01 +0200 | [diff] [blame] | 1568 | ADBG_EXPECT_COMPARE_UNSIGNED(c, ret_orig, !=, TEEC_ORIGIN_TRUSTED_APP); |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1569 | if (ret != TEEC_ERROR_BAD_PARAMETERS && ret != TEEC_ERROR_GENERIC) { |
| 1570 | ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS, ret); |
| 1571 | ADBG_EXPECT(c, TEEC_ERROR_GENERIC, ret); |
| 1572 | } |
| 1573 | |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1574 | TEEC_ReleaseSharedMemory(&shm); |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1575 | Do_ADBG_EndSubCase(c, NULL); |
| 1576 | |
| 1577 | Do_ADBG_BeginSubCase(c, "Out of bounds by 1 byte on registered shm"); |
| 1578 | |
| 1579 | memset(&shm, 0, sizeof(shm)); |
| 1580 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1581 | shm.buffer = buffer; |
| 1582 | shm.size = sizeof(buffer); |
| 1583 | |
| 1584 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1585 | TEEC_RegisterSharedMemory(&xtest_teec_ctx, |
| 1586 | &shm))) |
| 1587 | goto out; |
| 1588 | |
| 1589 | invoke_1byte_out_of_bounds(c, &session, &shm); |
| 1590 | |
| 1591 | TEEC_ReleaseSharedMemory(&shm); |
| 1592 | Do_ADBG_EndSubCase(c, NULL); |
| 1593 | |
| 1594 | Do_ADBG_BeginSubCase(c, "Out of bounds by 1 byte ref on allocated shm"); |
| 1595 | |
| 1596 | memset(&shm, 0, sizeof(shm)); |
| 1597 | shm.size = sizeof(buffer); |
| 1598 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1599 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1600 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, |
| 1601 | &shm))) |
| 1602 | goto out; |
| 1603 | |
| 1604 | invoke_1byte_out_of_bounds(c, &session, &shm); |
| 1605 | |
| 1606 | TEEC_ReleaseSharedMemory(&shm); |
| 1607 | Do_ADBG_EndSubCase(c, NULL); |
| 1608 | |
| 1609 | out: |
| 1610 | TEEC_CloseSession(&session); |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1611 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1612 | ADBG_CASE_DEFINE(regression, 1018, xtest_tee_test_1018, |
| 1613 | "Test memref out of bounds"); |
Jerome Forissier | 53bde72 | 2018-05-31 09:14:54 +0200 | [diff] [blame] | 1614 | |
Jerome Forissier | 53bde72 | 2018-05-31 09:14:54 +0200 | [diff] [blame] | 1615 | static void xtest_tee_test_1019(ADBG_Case_t *c) |
| 1616 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1617 | TEEC_Session session = { }; |
| 1618 | uint32_t ret_orig = 0; |
Jerome Forissier | 53bde72 | 2018-05-31 09:14:54 +0200 | [diff] [blame] | 1619 | |
| 1620 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1621 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1622 | &ret_orig))) |
| 1623 | return; |
| 1624 | |
| 1625 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1626 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB, NULL, |
| 1627 | &ret_orig)); |
| 1628 | |
| 1629 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 1630 | TEEC_ERROR_TARGET_DEAD, |
| 1631 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_PANIC, |
| 1632 | NULL, &ret_orig)); |
| 1633 | |
| 1634 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 1635 | |
| 1636 | TEEC_CloseSession(&session); |
| 1637 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1638 | ADBG_CASE_DEFINE(regression, 1019, xtest_tee_test_1019, |
| 1639 | "Test dynamically linked TA"); |
Jerome Forissier | 3357f87 | 2018-10-05 15:13:44 +0200 | [diff] [blame] | 1640 | |
| 1641 | static void xtest_tee_test_1020(ADBG_Case_t *c) |
| 1642 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1643 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1644 | TEEC_Session session = { }; |
| 1645 | uint32_t ret_orig = 0; |
Jerome Forissier | 3357f87 | 2018-10-05 15:13:44 +0200 | [diff] [blame] | 1646 | |
| 1647 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
| 1648 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 1649 | &ret_orig); |
| 1650 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 1651 | Do_ADBG_Log(" - 1020 - skip test, pseudo TA not found"); |
| 1652 | return; |
| 1653 | } |
| 1654 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 1655 | |
| 1656 | res = TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_LOCKDEP, |
| 1657 | NULL, &ret_orig); |
| 1658 | if (res != TEEC_SUCCESS) { |
| 1659 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TRUSTED_APP, |
| 1660 | ret_orig); |
| 1661 | if (res == TEEC_ERROR_NOT_SUPPORTED) { |
| 1662 | Do_ADBG_Log(" - 1020 - skip test, feature not " |
| 1663 | "implemented"); |
| 1664 | goto out; |
| 1665 | } |
| 1666 | /* Error */ |
| 1667 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 1668 | } |
| 1669 | out: |
| 1670 | TEEC_CloseSession(&session); |
| 1671 | } |
| 1672 | ADBG_CASE_DEFINE(regression, 1020, xtest_tee_test_1020, |
| 1673 | "Test lockdep algorithm"); |
Ovidiu Mihalachi | 15cecff | 2019-04-02 16:36:31 +0300 | [diff] [blame] | 1674 | |
| 1675 | static TEEC_Result open_sec_session(TEEC_Session *session, |
| 1676 | const TEEC_UUID *uuid) |
| 1677 | { |
| 1678 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1679 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1680 | uint32_t ret_orig = 0; |
| 1681 | |
| 1682 | op.params[0].tmpref.buffer = (void *)uuid; |
| 1683 | op.params[0].tmpref.size = sizeof(*uuid); |
| 1684 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 1685 | TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 1686 | |
| 1687 | res = TEEC_InvokeCommand(session, TA_SIMS_OPEN_TA_SESSION, |
| 1688 | &op, &ret_orig); |
| 1689 | if (res != TEEC_SUCCESS) |
| 1690 | return TEEC_ERROR_GENERIC; |
| 1691 | |
| 1692 | return res; |
| 1693 | } |
| 1694 | |
| 1695 | static TEEC_Result sims_get_counter(TEEC_Session *session, |
| 1696 | uint32_t *counter) |
| 1697 | { |
| 1698 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1699 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1700 | uint32_t ret_orig = 0; |
| 1701 | |
| 1702 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, |
| 1703 | TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 1704 | |
| 1705 | res = TEEC_InvokeCommand(session, TA_SIMS_CMD_GET_COUNTER, |
| 1706 | &op, &ret_orig); |
| 1707 | if (res == TEEC_SUCCESS) |
| 1708 | *counter = op.params[0].value.a; |
| 1709 | |
| 1710 | return res; |
| 1711 | } |
| 1712 | |
| 1713 | static TEEC_Result trigger_panic(TEEC_Session *session, |
| 1714 | const TEEC_UUID *uuid) |
| 1715 | { |
| 1716 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1717 | uint32_t ret_orig = 0; |
| 1718 | |
| 1719 | if (!uuid) { |
| 1720 | op.params[0].tmpref.buffer = NULL; |
| 1721 | op.params[0].tmpref.size = 0; |
| 1722 | } else { |
| 1723 | op.params[0].tmpref.buffer = (void *)uuid; |
| 1724 | op.params[0].tmpref.size = sizeof(*uuid); |
| 1725 | } |
| 1726 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 1727 | TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 1728 | |
| 1729 | return TEEC_InvokeCommand(session, TA_SIMS_CMD_PANIC, |
| 1730 | &op, &ret_orig); |
| 1731 | } |
| 1732 | |
| 1733 | static void test_panic_ca_to_ta(ADBG_Case_t *c, const TEEC_UUID *uuid, |
| 1734 | bool multi_instance) |
| 1735 | { |
| 1736 | TEEC_Result exp_res = TEEC_ERROR_GENERIC; |
| 1737 | uint32_t counter = 0; |
| 1738 | uint32_t ret_orig = 0; |
| 1739 | uint32_t exp_counter = 0; |
| 1740 | TEEC_Session cs[3] = { }; |
| 1741 | |
| 1742 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1743 | xtest_teec_open_session(&cs[0], uuid, NULL, |
| 1744 | &ret_orig))) |
| 1745 | return; |
| 1746 | |
| 1747 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1748 | xtest_teec_open_session(&cs[1], uuid, NULL, |
| 1749 | &ret_orig))) |
| 1750 | goto bail0; |
| 1751 | |
| 1752 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter))) |
| 1753 | goto bail1; |
| 1754 | |
| 1755 | if (!ADBG_EXPECT(c, 0, counter)) |
| 1756 | goto bail1; |
| 1757 | |
| 1758 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[1], &counter))) |
| 1759 | goto bail1; |
| 1760 | |
| 1761 | exp_counter = multi_instance ? 0 : 1; |
Ovidiu Mihalachi | 110aac4 | 2019-09-11 14:08:01 +0300 | [diff] [blame] | 1762 | if (!ADBG_EXPECT(c, exp_counter, counter)) |
Ovidiu Mihalachi | 15cecff | 2019-04-02 16:36:31 +0300 | [diff] [blame] | 1763 | goto bail1; |
| 1764 | |
| 1765 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1766 | trigger_panic(&cs[1], NULL))) |
| 1767 | goto bail1; |
| 1768 | |
| 1769 | exp_res = multi_instance ? TEEC_SUCCESS : TEEC_ERROR_TARGET_DEAD; |
| 1770 | if (!ADBG_EXPECT_TEEC_RESULT(c, exp_res, |
| 1771 | sims_get_counter(&cs[0], &counter))) |
| 1772 | goto bail1; |
| 1773 | |
| 1774 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1775 | sims_get_counter(&cs[1], &counter))) |
| 1776 | goto bail1; |
| 1777 | |
| 1778 | /* Attempt to open a session on panicked context */ |
Ovidiu Mihalachi | 110aac4 | 2019-09-11 14:08:01 +0300 | [diff] [blame] | 1779 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Ovidiu Mihalachi | 15cecff | 2019-04-02 16:36:31 +0300 | [diff] [blame] | 1780 | xtest_teec_open_session(&cs[1], uuid, NULL, |
| 1781 | &ret_orig))) |
| 1782 | goto bail1; |
| 1783 | |
| 1784 | /* Sanity check of still valid TA context */ |
| 1785 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1786 | xtest_teec_open_session(&cs[2], uuid, NULL, |
| 1787 | &ret_orig))) |
| 1788 | goto bail1; |
| 1789 | |
| 1790 | /* Sanity check of still valid TA context */ |
| 1791 | if (multi_instance) { |
| 1792 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1793 | sims_get_counter(&cs[0], &counter))) |
| 1794 | goto bail2; |
| 1795 | |
| 1796 | if (!ADBG_EXPECT(c, 0, counter)) |
| 1797 | goto bail2; |
| 1798 | } |
| 1799 | |
| 1800 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[2], &counter))) |
| 1801 | goto bail2; |
| 1802 | |
Ovidiu Mihalachi | 110aac4 | 2019-09-11 14:08:01 +0300 | [diff] [blame] | 1803 | exp_counter = multi_instance ? 0 : 1; |
| 1804 | if (!ADBG_EXPECT(c, exp_counter, counter)) |
Ovidiu Mihalachi | 15cecff | 2019-04-02 16:36:31 +0300 | [diff] [blame] | 1805 | goto bail2; |
| 1806 | |
| 1807 | bail2: |
| 1808 | TEEC_CloseSession(&cs[2]); |
| 1809 | bail1: |
| 1810 | TEEC_CloseSession(&cs[1]); |
| 1811 | bail0: |
| 1812 | TEEC_CloseSession(&cs[0]); |
| 1813 | } |
| 1814 | |
| 1815 | static void test_panic_ta_to_ta(ADBG_Case_t *c, const TEEC_UUID *uuid1, |
| 1816 | const TEEC_UUID *uuid2) |
| 1817 | { |
| 1818 | uint32_t ret_orig = 0; |
| 1819 | uint32_t counter = 0; |
| 1820 | TEEC_Session cs[3] = { }; |
| 1821 | |
| 1822 | /* Test pre-conditions */ |
| 1823 | /* 2.1 - CA opens a session toward TA1 */ |
| 1824 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1825 | xtest_teec_open_session(&cs[0], uuid1, NULL, |
| 1826 | &ret_orig))) |
| 1827 | return; |
| 1828 | |
| 1829 | /* 2.2 - CA opens a session toward TA2 */ |
| 1830 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1831 | xtest_teec_open_session(&cs[1], uuid2, NULL, |
| 1832 | &ret_orig))) |
| 1833 | goto bail0; |
| 1834 | |
| 1835 | /* 2.3 - TA1 opens a session toward TA2 */ |
| 1836 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, open_sec_session(&cs[0], uuid2))) |
| 1837 | goto bail1; |
| 1838 | |
| 1839 | /* 2.4 - CA invokes TA2 which panics */ |
| 1840 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1841 | trigger_panic(&cs[1], NULL))) |
| 1842 | goto bail1; |
| 1843 | |
| 1844 | /* Expected results */ |
| 1845 | /* 2.5 - Expect CA->TA1 session is still alive */ |
| 1846 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter))) |
| 1847 | goto bail1; |
| 1848 | |
| 1849 | /* 2.6 - Expect CA->TA2 session is properly released */ |
| 1850 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1851 | sims_get_counter(&cs[1], &counter))) |
| 1852 | goto bail1; |
| 1853 | |
| 1854 | bail1: |
| 1855 | TEEC_CloseSession(&cs[1]); |
| 1856 | bail0: |
| 1857 | TEEC_CloseSession(&cs[0]); |
| 1858 | |
| 1859 | memset(cs, 0, sizeof(cs)); |
| 1860 | |
| 1861 | /* Test pre-conditions */ |
| 1862 | /* 2.1 - CA opens a session toward TA1 */ |
| 1863 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1864 | xtest_teec_open_session(&cs[0], uuid1, NULL, |
| 1865 | &ret_orig))) |
| 1866 | return; |
| 1867 | |
| 1868 | /* 2.2 - CA opens a session toward TA2 */ |
| 1869 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1870 | xtest_teec_open_session(&cs[1], uuid2, NULL, |
| 1871 | &ret_orig))) |
| 1872 | goto bail2; |
| 1873 | |
| 1874 | /* 2.3 - TA1 opens a session toward TA2 */ |
| 1875 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, open_sec_session(&cs[0], uuid2))) |
| 1876 | goto bail3; |
| 1877 | |
| 1878 | /* 2.4 - CA invokes TA1 which invokes TA2 which panics */ |
| 1879 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, trigger_panic(&cs[0], uuid2))) |
| 1880 | goto bail3; |
| 1881 | |
| 1882 | /* Expected results */ |
| 1883 | /* 2.5 - Expect CA->TA1 session is still alive */ |
| 1884 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter))) |
| 1885 | goto bail3; |
| 1886 | |
| 1887 | /* 2.6 - Expect CA->TA2 session is properly released */ |
| 1888 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1889 | sims_get_counter(&cs[1], &counter))) |
| 1890 | goto bail3; |
| 1891 | |
| 1892 | bail3: |
| 1893 | TEEC_CloseSession(&cs[1]); |
| 1894 | bail2: |
| 1895 | TEEC_CloseSession(&cs[0]); |
| 1896 | } |
| 1897 | |
| 1898 | static void xtest_tee_test_1021(ADBG_Case_t *c) |
| 1899 | { |
| 1900 | Do_ADBG_BeginSubCase(c, "Multiple Instances Single Session"); |
| 1901 | test_panic_ca_to_ta(c, &miss_test_ta_uuid, true); |
| 1902 | Do_ADBG_EndSubCase(c, "Multiple Instances Single Session"); |
| 1903 | |
| 1904 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Sessions"); |
| 1905 | test_panic_ca_to_ta(c, &sims_test_ta_uuid, false); |
| 1906 | Do_ADBG_EndSubCase(c, "Single Instance Multi Sessions"); |
| 1907 | |
| 1908 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Sessions Keep Alive"); |
| 1909 | test_panic_ca_to_ta(c, &sims_keepalive_test_ta_uuid, false); |
| 1910 | Do_ADBG_EndSubCase(c, "Single Instance Multi Sessions Keep Alive"); |
| 1911 | |
| 1912 | Do_ADBG_BeginSubCase(c, "Multi Sessions TA to TA"); |
| 1913 | test_panic_ta_to_ta(c, &sims_test_ta_uuid, |
| 1914 | &sims_keepalive_test_ta_uuid); |
| 1915 | Do_ADBG_EndSubCase(c, "Multi Sessions TA to TA"); |
| 1916 | } |
| 1917 | ADBG_CASE_DEFINE(regression, 1021, xtest_tee_test_1021, |
| 1918 | "Test panic context release"); |
Jerome Forissier | a9ab5d0 | 2019-03-17 21:14:06 +0100 | [diff] [blame] | 1919 | |
| 1920 | static void xtest_tee_test_1022(ADBG_Case_t *c) |
| 1921 | { |
| 1922 | TEEC_Session session = { 0 }; |
| 1923 | uint32_t ret_orig = 0; |
| 1924 | |
| 1925 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1926 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 1927 | NULL, &ret_orig))) |
| 1928 | return; |
| 1929 | |
| 1930 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1931 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL, NULL, |
| 1932 | &ret_orig)); |
| 1933 | |
| 1934 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 1935 | TEEC_ERROR_TARGET_DEAD, |
| 1936 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL_PANIC, |
| 1937 | NULL, &ret_orig)); |
| 1938 | |
| 1939 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 1940 | |
| 1941 | TEEC_CloseSession(&session); |
| 1942 | } |
| 1943 | ADBG_CASE_DEFINE(regression, 1022, xtest_tee_test_1022, |
| 1944 | "Test dlopen()/dlsym()/dlclose() API"); |
Jerome Forissier | e9571e8 | 2020-02-18 15:26:20 +0100 | [diff] [blame] | 1945 | |
| 1946 | /* |
| 1947 | * Testing the ELF initialization (.init_array) |
| 1948 | * |
| 1949 | * - The TA has a global variable which can also be accessed by the two shared |
| 1950 | * libraries os_test_lib (linked with the TA) and os_test_lib_dl (loaded via |
| 1951 | * dlopen()) |
| 1952 | * - The TA and both libraries have initialization functions (declared with the |
| 1953 | * "constructor" attribute) which perform the following: |
| 1954 | * * The TA multiplies by 10 then adds 1 |
| 1955 | * * os_test_lib multiplies by 10 then adds 2 |
| 1956 | * * os_test_lib_dl multiplies by 10 then adds 3 |
| 1957 | * By testing the variable value we make sure the initializations occurred in |
| 1958 | * the correct order. |
| 1959 | */ |
| 1960 | static void xtest_tee_test_1023(ADBG_Case_t *c) |
| 1961 | { |
| 1962 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1963 | TEEC_Session session = { 0 }; |
| 1964 | uint32_t ret_orig = 0; |
| 1965 | |
| 1966 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, |
| 1967 | TEEC_NONE, TEEC_NONE); |
| 1968 | |
| 1969 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1970 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 1971 | NULL, &ret_orig))) |
| 1972 | return; |
| 1973 | |
| 1974 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1975 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_GET_GLOBAL_VAR, &op, |
| 1976 | &ret_orig)); |
| 1977 | |
| 1978 | /* Expected: initialization of os_test_lib, then TA */ |
| 1979 | (void)ADBG_EXPECT_COMPARE_SIGNED(c, op.params[0].value.a, ==, 21); |
| 1980 | |
| 1981 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1982 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL, NULL, |
| 1983 | &ret_orig)); |
| 1984 | |
| 1985 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1986 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_GET_GLOBAL_VAR, &op, |
| 1987 | &ret_orig)); |
| 1988 | |
| 1989 | /* Expected: initialization of os_test_lib_dl */ |
| 1990 | (void)ADBG_EXPECT_COMPARE_SIGNED(c, op.params[0].value.a, ==, 213); |
| 1991 | |
| 1992 | TEEC_CloseSession(&session); |
| 1993 | } |
| 1994 | ADBG_CASE_DEFINE(regression, 1023, xtest_tee_test_1023, |
| 1995 | "Test ELF initialization (.init_array)"); |
Javier Almansa Sobrino | cddc000 | 2020-02-10 13:35:37 +0000 | [diff] [blame] | 1996 | |
| 1997 | #ifdef CFG_CORE_TPM_EVENT_LOG |
| 1998 | static void xtest_tee_test_1024(ADBG_Case_t *c) |
| 1999 | { |
| 2000 | TEEC_Session session = {}; |
| 2001 | uint32_t ret_orig = 0; |
| 2002 | |
| 2003 | xtest_teec_open_session(&session, &tpm_log_test_ta_uuid, |
| 2004 | NULL, &ret_orig); |
| 2005 | |
| 2006 | Do_ADBG_BeginSubCase(c, "TPM test service invocation"); |
| 2007 | ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(&session, |
| 2008 | TA_TPM_TEST_GET_LOG, |
| 2009 | NULL, &ret_orig)); |
| 2010 | Do_ADBG_EndSubCase(c, "TPM test service invocation"); |
| 2011 | |
| 2012 | Do_ADBG_BeginSubCase(c, "TPM test passing short buffer"); |
| 2013 | ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(&session, |
| 2014 | TA_TPM_TEST_SHORT_BUF, |
| 2015 | NULL, &ret_orig)); |
| 2016 | Do_ADBG_EndSubCase(c, "TPM test passing short buffer"); |
| 2017 | |
| 2018 | TEEC_CloseSession(&session); |
| 2019 | } |
| 2020 | |
| 2021 | ADBG_CASE_DEFINE(regression, 1024, xtest_tee_test_1024, |
| 2022 | "Test PTA_SYSTEM_GET_TPM_EVENT_LOG Service"); |
| 2023 | #endif /* CFG_CORE_TPM_EVENT_LOG */ |
Cedric Neveux | 9f483bb | 2019-03-04 08:58:06 +0100 | [diff] [blame] | 2024 | |
| 2025 | static void xtest_tee_test_1025(ADBG_Case_t *c) |
| 2026 | { |
| 2027 | TEEC_Session session = {}; |
| 2028 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2029 | uint32_t ret_orig = 0; |
| 2030 | uint8_t *empty_buf = NULL; |
Etienne Carriere | 71383d4 | 2020-04-14 12:31:25 +0200 | [diff] [blame] | 2031 | TEEC_SharedMemory shm = { }; |
Etienne Carriere | dba3f3b | 2020-04-08 17:08:16 +0200 | [diff] [blame] | 2032 | TEEC_Result res = TEEC_ERROR_GENERIC; |
Etienne Carriere | 71383d4 | 2020-04-14 12:31:25 +0200 | [diff] [blame] | 2033 | |
| 2034 | Do_ADBG_BeginSubCase(c, "Invalid NULL buffer memref registration"); |
| 2035 | |
| 2036 | memset(&shm, 0, sizeof(shm)); |
| 2037 | shm.flags = TEEC_MEM_INPUT; |
| 2038 | shm.buffer = NULL; |
| 2039 | shm.size = 0; |
| 2040 | |
| 2041 | ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS, |
| 2042 | TEEC_RegisterSharedMemory(&xtest_teec_ctx, &shm)); |
| 2043 | |
| 2044 | memset(&shm, 0, sizeof(shm)); |
| 2045 | shm.flags = TEEC_MEM_OUTPUT; |
| 2046 | shm.buffer = NULL; |
| 2047 | shm.size = 0; |
| 2048 | |
| 2049 | ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS, |
| 2050 | TEEC_RegisterSharedMemory(&xtest_teec_ctx, &shm)); |
| 2051 | |
| 2052 | Do_ADBG_EndSubCase(c, "Invalid NULL buffer memref registration"); |
Cedric Neveux | 9f483bb | 2019-03-04 08:58:06 +0100 | [diff] [blame] | 2053 | |
Julianus Larson | a79e6ee | 2023-05-17 11:35:03 +0200 | [diff] [blame] | 2054 | if (!xtest_teec_ctx.imp.memref_null) { |
Etienne Carriere | 71383d4 | 2020-04-14 12:31:25 +0200 | [diff] [blame] | 2055 | Do_ADBG_Log("Skip subcases: MEMREF_NULL capability not supported"); |
Etienne Carriere | c602a52 | 2020-04-13 18:53:17 +0200 | [diff] [blame] | 2056 | return; |
| 2057 | } |
| 2058 | |
Cedric Neveux | 9f483bb | 2019-03-04 08:58:06 +0100 | [diff] [blame] | 2059 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2060 | xtest_teec_open_session(&session, |
| 2061 | &os_test_ta_uuid, |
| 2062 | NULL, &ret_orig))) |
| 2063 | return; |
| 2064 | |
| 2065 | empty_buf = malloc(1); |
| 2066 | if (!empty_buf) { |
| 2067 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_ERROR_OUT_OF_MEMORY); |
Etienne Carriere | dba3f3b | 2020-04-08 17:08:16 +0200 | [diff] [blame] | 2068 | goto out_session; |
Cedric Neveux | 9f483bb | 2019-03-04 08:58:06 +0100 | [diff] [blame] | 2069 | } |
| 2070 | |
| 2071 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 2072 | TEEC_MEMREF_TEMP_INPUT, |
| 2073 | TEEC_MEMREF_TEMP_OUTPUT, |
| 2074 | TEEC_MEMREF_TEMP_OUTPUT); |
| 2075 | |
| 2076 | Do_ADBG_BeginSubCase(c, |
| 2077 | "Input/Output MEMREF Buffer NULL - Size 0 bytes"); |
| 2078 | |
| 2079 | op.params[0].tmpref.buffer = empty_buf; |
| 2080 | op.params[0].tmpref.size = 0; |
| 2081 | |
| 2082 | op.params[1].tmpref.buffer = NULL; |
| 2083 | op.params[1].tmpref.size = 0; |
| 2084 | |
| 2085 | op.params[2].tmpref.buffer = empty_buf; |
| 2086 | op.params[2].tmpref.size = 0; |
| 2087 | |
| 2088 | op.params[3].tmpref.buffer = NULL; |
| 2089 | op.params[3].tmpref.size = 0; |
| 2090 | |
| 2091 | ADBG_EXPECT(c, TEE_SUCCESS, |
| 2092 | TEEC_InvokeCommand(&session, |
| 2093 | TA_OS_TEST_CMD_NULL_MEMREF_PARAMS, &op, |
| 2094 | &ret_orig)); |
| 2095 | |
| 2096 | Do_ADBG_EndSubCase(c, "Input/Output MEMREF Buffer NULL - Size 0 bytes"); |
| 2097 | |
| 2098 | Do_ADBG_BeginSubCase(c, "Input MEMREF Buffer NULL - Size non 0 bytes"); |
| 2099 | |
| 2100 | op.params[0].tmpref.buffer = empty_buf; |
| 2101 | op.params[0].tmpref.size = 1; |
| 2102 | |
| 2103 | op.params[1].tmpref.buffer = NULL; |
| 2104 | op.params[1].tmpref.size = 0; |
| 2105 | |
| 2106 | op.params[2].tmpref.buffer = empty_buf; |
| 2107 | op.params[2].tmpref.size = 0; |
| 2108 | |
| 2109 | op.params[3].tmpref.buffer = NULL; |
| 2110 | op.params[3].tmpref.size = 0; |
| 2111 | |
| 2112 | ADBG_EXPECT(c, TEE_ERROR_BAD_PARAMETERS, |
| 2113 | TEEC_InvokeCommand(&session, |
| 2114 | TA_OS_TEST_CMD_NULL_MEMREF_PARAMS, &op, |
| 2115 | &ret_orig)); |
| 2116 | |
Etienne Carriere | dba3f3b | 2020-04-08 17:08:16 +0200 | [diff] [blame] | 2117 | TEEC_CloseSession(&session); |
| 2118 | |
Cedric Neveux | 9f483bb | 2019-03-04 08:58:06 +0100 | [diff] [blame] | 2119 | Do_ADBG_EndSubCase(c, "Input MEMREF Buffer NULL - Size non 0 bytes"); |
| 2120 | |
Etienne Carriere | dba3f3b | 2020-04-08 17:08:16 +0200 | [diff] [blame] | 2121 | Do_ADBG_BeginSubCase(c, "Input MEMREF Buffer NULL over PTA invocation"); |
| 2122 | |
| 2123 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
| 2124 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 2125 | &ret_orig); |
| 2126 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 2127 | Do_ADBG_Log(" - 1025 - skip test, pseudo TA not found"); |
| 2128 | goto out; |
| 2129 | } |
| 2130 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2131 | goto out; |
| 2132 | |
| 2133 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, |
| 2134 | TEEC_NONE, TEEC_NONE); |
| 2135 | op.params[0].tmpref.buffer = NULL; |
| 2136 | op.params[0].tmpref.size = 0; |
| 2137 | |
| 2138 | ADBG_EXPECT(c, TEE_SUCCESS, |
| 2139 | TEEC_InvokeCommand(&session, |
| 2140 | PTA_INVOKE_TESTS_CMD_MEMREF_NULL, |
| 2141 | &op, &ret_orig)); |
| 2142 | |
| 2143 | out_session: |
Cedric Neveux | 9f483bb | 2019-03-04 08:58:06 +0100 | [diff] [blame] | 2144 | TEEC_CloseSession(&session); |
Etienne Carriere | dba3f3b | 2020-04-08 17:08:16 +0200 | [diff] [blame] | 2145 | out: |
| 2146 | Do_ADBG_EndSubCase(c, NULL); |
Cedric Neveux | 9f483bb | 2019-03-04 08:58:06 +0100 | [diff] [blame] | 2147 | free(empty_buf); |
| 2148 | } |
| 2149 | ADBG_CASE_DEFINE(regression, 1025, xtest_tee_test_1025, |
| 2150 | "Test memref NULL and/or 0 bytes size"); |
Vesa Jääskeläinen | e8c0c8d | 2020-04-05 20:11:53 +0300 | [diff] [blame] | 2151 | |
Vesa Jääskeläinen | 502c549 | 2020-04-05 20:12:02 +0300 | [diff] [blame] | 2152 | #define TEE_UUID_NS_NAME_SIZE 128 |
| 2153 | |
| 2154 | /* |
| 2155 | * TEE Client UUID name space identifier (UUIDv4) |
| 2156 | * |
| 2157 | * Value here is random UUID that is allocated as name space identifier for |
| 2158 | * forming Client UUID's for TEE environment using UUIDv5 scheme. |
| 2159 | */ |
| 2160 | static const char *client_uuid_linux_ns = "58ac9ca0-2086-4683-a1b8-ec4bc08e01b6"; |
| 2161 | |
Vesa Jääskeläinen | e8c0c8d | 2020-04-05 20:11:53 +0300 | [diff] [blame] | 2162 | /* TEEC_LOGIN_PUBLIC's Client UUID is NIL UUID */ |
| 2163 | static TEEC_UUID client_uuid_public = { }; |
| 2164 | |
| 2165 | static void xtest_tee_test_1026(ADBG_Case_t *c) |
| 2166 | { |
| 2167 | TEEC_Result result = TEEC_ERROR_GENERIC; |
| 2168 | uint32_t ret_orig = 0; |
| 2169 | TEEC_Session session = { }; |
| 2170 | uint32_t login = UINT32_MAX; |
| 2171 | TEEC_UUID client_uuid = { }; |
| 2172 | |
| 2173 | result = TEEC_OpenSession(&xtest_teec_ctx, &session, &os_test_ta_uuid, |
| 2174 | TEEC_LOGIN_PUBLIC, NULL, NULL, &ret_orig); |
| 2175 | |
| 2176 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2177 | return; |
| 2178 | |
| 2179 | result = ta_os_test_cmd_client_identity(&session, &login, |
| 2180 | &client_uuid); |
| 2181 | |
| 2182 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2183 | goto out; |
| 2184 | |
| 2185 | ADBG_EXPECT_COMPARE_UNSIGNED(c, login, ==, TEEC_LOGIN_PUBLIC); |
| 2186 | |
| 2187 | ADBG_EXPECT_EQUAL(c, &client_uuid_public, &client_uuid, |
| 2188 | sizeof(TEEC_UUID)); |
| 2189 | |
| 2190 | out: |
| 2191 | TEEC_CloseSession(&session); |
| 2192 | } |
| 2193 | |
| 2194 | ADBG_CASE_DEFINE(regression, 1026, xtest_tee_test_1026, |
| 2195 | "Session: public login"); |
Vesa Jääskeläinen | 502c549 | 2020-04-05 20:12:02 +0300 | [diff] [blame] | 2196 | |
Etienne Carriere | f461e1d | 2020-05-19 12:42:08 +0200 | [diff] [blame] | 2197 | /* |
| 2198 | * regression_1027 |
| 2199 | * Depends on OpenSSL |
Jerome Forissier | 81e71a8 | 2021-06-16 10:39:12 +0200 | [diff] [blame] | 2200 | * Depends on kernel commit c5b4312bea5d ("tee: optee: Add support for session |
| 2201 | * login client UUID generation") |
| 2202 | * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c5b4312bea5d |
Etienne Carriere | f461e1d | 2020-05-19 12:42:08 +0200 | [diff] [blame] | 2203 | * |
| 2204 | * xtest skips the test when not built with OpenSSL. |
| 2205 | */ |
Vesa Jääskeläinen | 502c549 | 2020-04-05 20:12:02 +0300 | [diff] [blame] | 2206 | static void xtest_tee_test_1027(ADBG_Case_t *c) |
| 2207 | { |
Victor Chong | 8e070bc | 2020-05-13 09:59:33 +0100 | [diff] [blame] | 2208 | #ifdef OPENSSL_FOUND |
Vesa Jääskeläinen | 502c549 | 2020-04-05 20:12:02 +0300 | [diff] [blame] | 2209 | TEEC_Result result = TEEC_ERROR_GENERIC; |
| 2210 | uint32_t ret_orig = 0; |
| 2211 | TEEC_Session session = { }; |
| 2212 | uint32_t login = UINT32_MAX; |
| 2213 | TEEC_UUID client_uuid = { }; |
| 2214 | TEEC_UUID expected_client_uuid = { }; |
| 2215 | TEEC_UUID uuid_ns = { }; |
| 2216 | char uuid_name[TEE_UUID_NS_NAME_SIZE] = { }; |
| 2217 | |
| 2218 | result = xtest_uuid_from_str(&uuid_ns, client_uuid_linux_ns); |
| 2219 | |
| 2220 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2221 | return; |
| 2222 | |
| 2223 | sprintf(uuid_name, "uid=%x", geteuid()); |
| 2224 | |
| 2225 | result = xtest_uuid_v5(&expected_client_uuid, &uuid_ns, uuid_name, |
| 2226 | strlen(uuid_name)); |
| 2227 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2228 | return; |
| 2229 | |
| 2230 | result = TEEC_OpenSession(&xtest_teec_ctx, &session, &os_test_ta_uuid, |
| 2231 | TEEC_LOGIN_USER, NULL, NULL, &ret_orig); |
| 2232 | |
| 2233 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2234 | return; |
| 2235 | |
| 2236 | result = ta_os_test_cmd_client_identity(&session, &login, |
| 2237 | &client_uuid); |
| 2238 | |
| 2239 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2240 | goto out; |
| 2241 | |
| 2242 | ADBG_EXPECT_COMPARE_UNSIGNED(c, login, ==, TEEC_LOGIN_USER); |
| 2243 | |
| 2244 | ADBG_EXPECT_EQUAL(c, &expected_client_uuid, &client_uuid, |
| 2245 | sizeof(TEEC_UUID)); |
| 2246 | |
| 2247 | out: |
| 2248 | TEEC_CloseSession(&session); |
Victor Chong | 8e070bc | 2020-05-13 09:59:33 +0100 | [diff] [blame] | 2249 | #else /*!OPENSSL_FOUND*/ |
| 2250 | UNUSED(c); |
Etienne Carriere | 359b003 | 2020-05-16 05:56:48 +0200 | [diff] [blame] | 2251 | UNUSED(client_uuid_linux_ns); |
Victor Chong | 8e070bc | 2020-05-13 09:59:33 +0100 | [diff] [blame] | 2252 | /* xtest_uuid_v5() depends on OpenSSL */ |
| 2253 | Do_ADBG_Log("OpenSSL not available, skipping test 1027"); |
| 2254 | #endif |
Vesa Jääskeläinen | 502c549 | 2020-04-05 20:12:02 +0300 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | ADBG_CASE_DEFINE(regression, 1027, xtest_tee_test_1027, |
| 2258 | "Session: user login for current user"); |
Vesa Jääskeläinen | 30dd087 | 2020-04-05 20:12:06 +0300 | [diff] [blame] | 2259 | |
Etienne Carriere | f461e1d | 2020-05-19 12:42:08 +0200 | [diff] [blame] | 2260 | /* |
| 2261 | * regression_1028 |
Jerome Forissier | 81e71a8 | 2021-06-16 10:39:12 +0200 | [diff] [blame] | 2262 | * Depends on kernel commit c5b4312bea5d ("tee: optee: Add support for session |
| 2263 | * login client UUID generation") |
| 2264 | * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c5b4312bea5d |
Etienne Carriere | f461e1d | 2020-05-19 12:42:08 +0200 | [diff] [blame] | 2265 | * |
| 2266 | * xtest skips the test when not built with OpenSSL. |
| 2267 | */ |
Vesa Jääskeläinen | 30dd087 | 2020-04-05 20:12:06 +0300 | [diff] [blame] | 2268 | static void xtest_tee_test_1028(ADBG_Case_t *c) |
| 2269 | { |
Victor Chong | 8e070bc | 2020-05-13 09:59:33 +0100 | [diff] [blame] | 2270 | #ifdef OPENSSL_FOUND |
Vesa Jääskeläinen | 30dd087 | 2020-04-05 20:12:06 +0300 | [diff] [blame] | 2271 | TEEC_Result result = TEEC_ERROR_GENERIC; |
| 2272 | uint32_t ret_orig = 0; |
| 2273 | TEEC_Session session = { }; |
| 2274 | uint32_t login = UINT32_MAX; |
| 2275 | TEEC_UUID client_uuid = { }; |
| 2276 | TEEC_UUID expected_client_uuid = { }; |
| 2277 | TEEC_UUID uuid_ns = { }; |
| 2278 | char uuid_name[TEE_UUID_NS_NAME_SIZE] = { }; |
| 2279 | uint32_t group = 0; |
| 2280 | |
| 2281 | group = getegid(); |
| 2282 | |
| 2283 | result = xtest_uuid_from_str(&uuid_ns, client_uuid_linux_ns); |
| 2284 | |
| 2285 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2286 | return; |
| 2287 | |
| 2288 | sprintf(uuid_name, "gid=%x", group); |
| 2289 | |
| 2290 | result = xtest_uuid_v5(&expected_client_uuid, &uuid_ns, uuid_name, |
| 2291 | strlen(uuid_name)); |
| 2292 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2293 | return; |
| 2294 | |
| 2295 | result = TEEC_OpenSession(&xtest_teec_ctx, &session, &os_test_ta_uuid, |
| 2296 | TEEC_LOGIN_GROUP, &group, NULL, &ret_orig); |
| 2297 | |
| 2298 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2299 | return; |
| 2300 | |
| 2301 | result = ta_os_test_cmd_client_identity(&session, &login, |
| 2302 | &client_uuid); |
| 2303 | |
| 2304 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2305 | goto out; |
| 2306 | |
| 2307 | ADBG_EXPECT_COMPARE_UNSIGNED(c, login, ==, TEEC_LOGIN_GROUP); |
| 2308 | |
| 2309 | ADBG_EXPECT_EQUAL(c, &expected_client_uuid, &client_uuid, |
| 2310 | sizeof(TEEC_UUID)); |
| 2311 | |
| 2312 | out: |
| 2313 | TEEC_CloseSession(&session); |
Victor Chong | 8e070bc | 2020-05-13 09:59:33 +0100 | [diff] [blame] | 2314 | #else /*!OPENSSL_FOUND*/ |
| 2315 | UNUSED(c); |
| 2316 | /* xtest_uuid_v5() depends on OpenSSL */ |
| 2317 | Do_ADBG_Log("OpenSSL not available, skipping test 1028"); |
| 2318 | #endif |
Vesa Jääskeläinen | 30dd087 | 2020-04-05 20:12:06 +0300 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | ADBG_CASE_DEFINE(regression, 1028, xtest_tee_test_1028, |
| 2322 | "Session: group login for current user's effective group"); |
Jerome Forissier | 9a7101b | 2020-06-17 17:55:00 +0200 | [diff] [blame] | 2323 | |
| 2324 | static void xtest_tee_test_1029(ADBG_Case_t *c) |
| 2325 | { |
Jerome Forissier | 82e87bb | 2020-08-19 14:00:09 +0200 | [diff] [blame] | 2326 | TEEC_Result res = TEEC_SUCCESS; |
Jerome Forissier | 9a7101b | 2020-06-17 17:55:00 +0200 | [diff] [blame] | 2327 | TEEC_Session session = { 0 }; |
| 2328 | uint32_t ret_orig = 0; |
| 2329 | |
| 2330 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2331 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 2332 | NULL, &ret_orig))) |
| 2333 | return; |
| 2334 | |
| 2335 | Do_ADBG_BeginSubCase(c, "TLS variables (main program)"); |
Jerome Forissier | 82e87bb | 2020-08-19 14:00:09 +0200 | [diff] [blame] | 2336 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TLS_TEST_MAIN, NULL, |
| 2337 | &ret_orig); |
| 2338 | if (res == TEEC_ERROR_NOT_SUPPORTED) |
| 2339 | Do_ADBG_Log(" - 1029 - skip test, " |
| 2340 | "TA returned TEEC_ERROR_NOT_SUPPORTED"); |
| 2341 | else |
| 2342 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jerome Forissier | 9a7101b | 2020-06-17 17:55:00 +0200 | [diff] [blame] | 2343 | Do_ADBG_EndSubCase(c, "TLS variables (main program)"); |
| 2344 | |
| 2345 | Do_ADBG_BeginSubCase(c, "TLS variables (shared library)"); |
Jerome Forissier | 82e87bb | 2020-08-19 14:00:09 +0200 | [diff] [blame] | 2346 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TLS_TEST_SHLIB, NULL, |
| 2347 | &ret_orig); |
| 2348 | if (res == TEEC_ERROR_NOT_SUPPORTED) |
| 2349 | Do_ADBG_Log(" - 1029 - skip test, " |
| 2350 | "TA returned TEEC_ERROR_NOT_SUPPORTED"); |
| 2351 | else |
| 2352 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jerome Forissier | 9a7101b | 2020-06-17 17:55:00 +0200 | [diff] [blame] | 2353 | Do_ADBG_EndSubCase(c, "TLS variables (shared library)"); |
| 2354 | |
| 2355 | TEEC_CloseSession(&session); |
| 2356 | } |
| 2357 | ADBG_CASE_DEFINE(regression, 1029, xtest_tee_test_1029, |
| 2358 | "Test __thread attribute"); |
Jerome Forissier | 4565c45 | 2020-06-17 17:55:00 +0200 | [diff] [blame] | 2359 | |
| 2360 | static void xtest_tee_test_1030(ADBG_Case_t *c) |
| 2361 | { |
| 2362 | TEEC_Session session = { 0 }; |
| 2363 | uint32_t ret_orig = 0; |
| 2364 | |
| 2365 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2366 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 2367 | NULL, &ret_orig))) |
| 2368 | return; |
| 2369 | |
| 2370 | Do_ADBG_BeginSubCase(c, "Before dlopen()"); |
| 2371 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2372 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_DL_PHDR, NULL, |
| 2373 | &ret_orig)); |
| 2374 | Do_ADBG_EndSubCase(c, "Before dlopen()"); |
| 2375 | |
| 2376 | Do_ADBG_BeginSubCase(c, "After dlopen()"); |
| 2377 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2378 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_DL_PHDR_DL, NULL, |
| 2379 | &ret_orig)); |
| 2380 | Do_ADBG_EndSubCase(c, "After dlopen()"); |
| 2381 | |
| 2382 | TEEC_CloseSession(&session); |
| 2383 | } |
| 2384 | ADBG_CASE_DEFINE(regression, 1030, xtest_tee_test_1030, |
| 2385 | "Test dl_iterate_phdr()"); |
Jerome Forissier | 1a205ae | 2020-06-17 17:55:00 +0200 | [diff] [blame] | 2386 | |
| 2387 | #ifndef __clang__ |
| 2388 | static void xtest_tee_test_1031(ADBG_Case_t *c) |
| 2389 | { |
| 2390 | TEEC_Result ret = TEE_SUCCESS; |
| 2391 | TEEC_Session session = { 0 }; |
| 2392 | uint32_t ret_orig = 0; |
| 2393 | |
| 2394 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2395 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 2396 | NULL, &ret_orig))) |
| 2397 | return; |
| 2398 | |
| 2399 | Do_ADBG_BeginSubCase(c, "Global object constructor (main program)"); |
| 2400 | ret = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_CTOR_MAIN, NULL, |
| 2401 | &ret_orig); |
| 2402 | if (ret == TEEC_ERROR_NOT_SUPPORTED) { |
| 2403 | printf("TA not built with C++ support, skipping C++ tests\n"); |
| 2404 | Do_ADBG_EndSubCase(c, "Global object constructor (main program)"); |
| 2405 | goto out; |
| 2406 | |
| 2407 | } |
| 2408 | ADBG_EXPECT_TEEC_SUCCESS(c, ret); |
| 2409 | Do_ADBG_EndSubCase(c, "Global object constructor (main program)"); |
| 2410 | |
| 2411 | Do_ADBG_BeginSubCase(c, "Global object constructor (shared library)"); |
| 2412 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2413 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_CTOR_SHLIB, |
| 2414 | NULL, &ret_orig)); |
| 2415 | Do_ADBG_EndSubCase(c, "Global object constructor (shared library)"); |
| 2416 | |
| 2417 | Do_ADBG_BeginSubCase(c, "Global object constructor (dlopen()ed lib)"); |
| 2418 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2419 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_CTOR_SHLIB_DL, |
| 2420 | NULL, &ret_orig)); |
| 2421 | Do_ADBG_EndSubCase(c, "Global object constructor (dlopen()ed lib)"); |
| 2422 | |
| 2423 | Do_ADBG_BeginSubCase(c, "Exceptions (simple)"); |
| 2424 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2425 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_EXC_MAIN, NULL, |
| 2426 | &ret_orig)); |
| 2427 | Do_ADBG_EndSubCase(c, "Exceptions (simple)"); |
| 2428 | |
| 2429 | Do_ADBG_BeginSubCase(c, "Exceptions (mixed C/C++ frames)"); |
| 2430 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2431 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_EXC_MIXED, NULL, |
| 2432 | &ret_orig)); |
| 2433 | Do_ADBG_EndSubCase(c, "Exceptions (mixed C/C++ frames)"); |
| 2434 | out: |
| 2435 | TEEC_CloseSession(&session); |
| 2436 | } |
| 2437 | ADBG_CASE_DEFINE(regression, 1031, xtest_tee_test_1031, |
| 2438 | "Test C++ features"); |
| 2439 | #endif |
Jens Wiklander | e16da89 | 2020-09-04 09:24:16 +0200 | [diff] [blame] | 2440 | |
| 2441 | static void xtest_tee_test_1032(ADBG_Case_t *c) |
| 2442 | { |
| 2443 | TEEC_Result res = TEEC_SUCCESS; |
| 2444 | TEEC_Context ctx = { }; |
| 2445 | TEEC_SharedMemory shm1 = { |
| 2446 | .buffer = xtest_tee_test_1032, |
| 2447 | .size = 32, |
| 2448 | .flags = TEEC_MEM_INPUT, |
| 2449 | }; |
| 2450 | static const uint8_t dummy_data[32] = { 1, 2, 3, 4, }; |
| 2451 | TEEC_SharedMemory shm2 = { |
| 2452 | .buffer = (void *)dummy_data, |
| 2453 | .size = sizeof(dummy_data), |
| 2454 | .flags = TEEC_MEM_INPUT, |
| 2455 | }; |
| 2456 | |
| 2457 | res = TEEC_InitializeContext(xtest_tee_name, &ctx); |
| 2458 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2459 | return; |
| 2460 | |
| 2461 | res = TEEC_RegisterSharedMemory(&ctx, &shm1); |
| 2462 | if (ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2463 | TEEC_ReleaseSharedMemory(&shm1); |
| 2464 | |
| 2465 | res = TEEC_RegisterSharedMemory(&ctx, &shm2); |
| 2466 | if (ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2467 | TEEC_ReleaseSharedMemory(&shm2); |
| 2468 | |
| 2469 | TEEC_FinalizeContext(&ctx); |
| 2470 | } |
| 2471 | ADBG_CASE_DEFINE(regression, 1032, xtest_tee_test_1032, |
| 2472 | "Register read-only shared memory"); |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 2473 | |
| 2474 | static void xtest_tee_test_1033(ADBG_Case_t *c) |
| 2475 | { |
| 2476 | TEEC_Session session = { }; |
| 2477 | uint32_t ret_orig = 0; |
| 2478 | |
| 2479 | /* TA will ping the test plugin during open session operation */ |
| 2480 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2481 | xtest_teec_open_session(&session, &supp_plugin_test_ta_uuid, |
| 2482 | NULL, &ret_orig))) |
| 2483 | return; |
| 2484 | |
| 2485 | Do_ADBG_BeginSubCase(c, "Pass values to/from a plugin"); |
| 2486 | { |
| 2487 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2488 | |
| 2489 | op.params[0].value.a = 20; |
| 2490 | op.params[0].value.b = 10; |
| 2491 | op.params[1].value.a = '+'; |
| 2492 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, |
| 2493 | TEEC_VALUE_INPUT, TEEC_NONE, |
| 2494 | TEEC_NONE); |
| 2495 | |
| 2496 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2497 | TEEC_InvokeCommand(&session, |
| 2498 | TA_SUPP_PLUGIN_CMD_PASS_VALUES, &op, |
| 2499 | &ret_orig)); |
| 2500 | ADBG_EXPECT(c, 30, op.params[0].value.a); |
| 2501 | |
| 2502 | /* reassign, because the values was changed during previous op */ |
| 2503 | op.params[0].value.a = 20; |
| 2504 | op.params[0].value.b = 10; |
| 2505 | op.params[1].value.a = '-'; |
| 2506 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2507 | TEEC_InvokeCommand(&session, |
| 2508 | TA_SUPP_PLUGIN_CMD_PASS_VALUES, &op, |
| 2509 | &ret_orig)); |
| 2510 | ADBG_EXPECT(c, 10, op.params[0].value.a); |
| 2511 | } |
| 2512 | Do_ADBG_EndSubCase(c, "Pass values to/from a plugin"); |
| 2513 | |
| 2514 | Do_ADBG_BeginSubCase(c, "Pass array to a plugin"); |
| 2515 | { |
| 2516 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Aleksandr Anisimov | 8076839 | 2021-03-05 19:36:20 +0300 | [diff] [blame] | 2517 | uint8_t to_plugin[] = { 0, 1, 2, 3, 4, 5 }; |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 2518 | |
| 2519 | op.params[0].tmpref.buffer = to_plugin; |
| 2520 | op.params[0].tmpref.size = sizeof(to_plugin); |
Jens Wiklander | 104cd06 | 2022-12-09 13:44:26 +0100 | [diff] [blame] | 2521 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, |
Aleksandr Anisimov | 8076839 | 2021-03-05 19:36:20 +0300 | [diff] [blame] | 2522 | TEEC_VALUE_OUTPUT, |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 2523 | TEEC_NONE, TEEC_NONE); |
| 2524 | |
| 2525 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2526 | TEEC_InvokeCommand(&session, |
| 2527 | TA_SUPP_PLUGIN_CMD_WRITE_ARR, |
| 2528 | &op, &ret_orig)); |
| 2529 | |
| 2530 | /* |
Aleksandr Anisimov | 8076839 | 2021-03-05 19:36:20 +0300 | [diff] [blame] | 2531 | * The test plugin must calculate a sum of the input elements |
| 2532 | * and store it to 'op.params[1].value.a' |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 2533 | */ |
Aleksandr Anisimov | 8076839 | 2021-03-05 19:36:20 +0300 | [diff] [blame] | 2534 | ADBG_EXPECT(c, 15, op.params[1].value.a); |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 2535 | } |
| 2536 | Do_ADBG_EndSubCase(c, "Pass array to a plugin"); |
| 2537 | |
| 2538 | Do_ADBG_BeginSubCase(c, "Get array from a plugin"); |
| 2539 | { |
| 2540 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2541 | char from_plugin[64] = { }; |
| 2542 | char expected_arr[] = "Array from plugin"; |
| 2543 | size_t expectes_size = sizeof(expected_arr); |
| 2544 | |
| 2545 | op.params[0].tmpref.buffer = from_plugin; |
| 2546 | op.params[0].tmpref.size = sizeof(from_plugin); |
| 2547 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, |
| 2548 | TEEC_VALUE_OUTPUT, TEEC_NONE, |
| 2549 | TEEC_NONE); |
| 2550 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2551 | TEEC_InvokeCommand(&session, |
| 2552 | TA_SUPP_PLUGIN_CMD_GET_ARR, &op, |
| 2553 | &ret_orig)); |
| 2554 | ADBG_EXPECT(c, expectes_size, op.params[1].value.a); |
| 2555 | ADBG_EXPECT_EQUAL(c, expected_arr, from_plugin, expectes_size); |
| 2556 | } |
| 2557 | Do_ADBG_EndSubCase(c, "Get array from a plugin"); |
| 2558 | |
| 2559 | Do_ADBG_BeginSubCase(c, "Not allow bad input to a plugin"); |
| 2560 | { |
| 2561 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2562 | |
| 2563 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, |
| 2564 | TEEC_NONE, TEEC_NONE); |
| 2565 | ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_BAD_PARAMETERS, |
| 2566 | TEEC_InvokeCommand(&session, |
| 2567 | TA_SUPP_PLUGIN_CMD_BAD_UUID, &op, |
| 2568 | &ret_orig)); |
| 2569 | ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_BAD_PARAMETERS, |
| 2570 | TEEC_InvokeCommand(&session, |
| 2571 | TA_SUPP_PLUGIN_CMD_BAD_IN_DATA, &op, |
| 2572 | &ret_orig)); |
| 2573 | ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_BAD_PARAMETERS, |
| 2574 | TEEC_InvokeCommand(&session, |
| 2575 | TA_SUPP_PLUGIN_CMD_BAD_IN_LEN, &op, |
| 2576 | &ret_orig)); |
| 2577 | } |
| 2578 | Do_ADBG_EndSubCase(c, "Not allow bad input to a plugin"); |
| 2579 | |
| 2580 | Do_ADBG_BeginSubCase(c, "Call an unknown plugin"); |
| 2581 | { |
| 2582 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2583 | |
| 2584 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, |
Vincent Mailhol | 2ea0aa7 | 2023-11-16 20:20:54 +0900 | [diff] [blame] | 2585 | TEEC_NONE, TEEC_NONE); |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 2586 | ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND, |
| 2587 | TEEC_InvokeCommand(&session, |
| 2588 | TA_SUPP_PLUGIN_CMD_UNKNOWN_UUID, |
| 2589 | &op, &ret_orig)); |
| 2590 | } |
| 2591 | Do_ADBG_EndSubCase(c, "Call an unknown plugin"); |
| 2592 | |
| 2593 | TEEC_CloseSession(&session); |
| 2594 | } |
| 2595 | ADBG_CASE_DEFINE(regression, 1033, xtest_tee_test_1033, |
| 2596 | "Test the supplicant plugin framework"); |
Jens Wiklander | 94fb158 | 2021-05-19 10:14:57 +0200 | [diff] [blame] | 2597 | |
| 2598 | static void xtest_tee_test_1034(ADBG_Case_t *c) |
| 2599 | { |
| 2600 | TEEC_Result res = TEEC_SUCCESS; |
| 2601 | TEEC_Session session = { }; |
| 2602 | uint32_t ret_orig = 0; |
| 2603 | |
| 2604 | res = xtest_teec_open_session(&session, &large_ta_uuid, NULL, |
| 2605 | &ret_orig); |
Jerome Forissier | e8be5b5 | 2021-06-29 16:29:06 +0200 | [diff] [blame] | 2606 | if (res == TEEC_ERROR_OUT_OF_MEMORY) { |
| 2607 | Do_ADBG_Log("TEEC_ERROR_OUT_OF_MEMORY - ignored"); |
Tim Lee | 5502a99 | 2023-07-12 16:48:47 +0800 | [diff] [blame] | 2608 | return; |
Jerome Forissier | e8be5b5 | 2021-06-29 16:29:06 +0200 | [diff] [blame] | 2609 | } |
Tim Lee | 5502a99 | 2023-07-12 16:48:47 +0800 | [diff] [blame] | 2610 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 2611 | if (!res) |
| 2612 | TEEC_CloseSession(&session); |
Jens Wiklander | 94fb158 | 2021-05-19 10:14:57 +0200 | [diff] [blame] | 2613 | } |
| 2614 | ADBG_CASE_DEFINE(regression, 1034, xtest_tee_test_1034, |
| 2615 | "Test loading a large TA"); |
Ruchika Gupta | 813b6d4 | 2021-12-01 10:44:14 +0530 | [diff] [blame] | 2616 | |
| 2617 | #if defined(CFG_TA_BTI) |
| 2618 | struct bti_test { |
| 2619 | uint32_t cmd; |
| 2620 | uint32_t func; |
| 2621 | }; |
| 2622 | |
| 2623 | #define BTI_TEST(caller_func, bti_func) { \ |
| 2624 | .cmd = caller_func, \ |
| 2625 | .func = bti_func, \ |
| 2626 | } |
| 2627 | |
| 2628 | static const struct bti_test bti_cases_success[] = { |
| 2629 | BTI_TEST(TA_TEST_USING_BLR, TA_FUNC_BTI_C), |
| 2630 | BTI_TEST(TA_TEST_USING_BLR, TA_FUNC_BTI_JC), |
| 2631 | BTI_TEST(TA_TEST_USING_BR, TA_FUNC_BTI_J), |
| 2632 | BTI_TEST(TA_TEST_USING_BR, TA_FUNC_BTI_JC), |
| 2633 | BTI_TEST(TA_TEST_USING_BR_X16, TA_FUNC_BTI_C), |
| 2634 | BTI_TEST(TA_TEST_USING_BR_X16, TA_FUNC_BTI_J), |
| 2635 | BTI_TEST(TA_TEST_USING_BR_X16, TA_FUNC_BTI_JC), |
| 2636 | }; |
| 2637 | |
| 2638 | static const struct bti_test bti_cases_panic[] = { |
| 2639 | BTI_TEST(TA_TEST_USING_BLR, TA_FUNC_BTI_J), |
| 2640 | BTI_TEST(TA_TEST_USING_BLR, TA_FUNC_BTI_NONE), |
| 2641 | BTI_TEST(TA_TEST_USING_BR, TA_FUNC_BTI_C), |
| 2642 | BTI_TEST(TA_TEST_USING_BR, TA_FUNC_BTI_NONE), |
| 2643 | BTI_TEST(TA_TEST_USING_BR_X16, TA_FUNC_BTI_NONE), |
| 2644 | }; |
| 2645 | |
| 2646 | static void get_cpu_feature(ADBG_Case_t *c, bool *bti) |
| 2647 | { |
| 2648 | TEEC_Session session = {}; |
| 2649 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2650 | uint32_t ret_orig = 0; |
| 2651 | TEEC_Result res; |
| 2652 | |
| 2653 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, |
| 2654 | TEEC_NONE); |
| 2655 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2656 | xtest_teec_open_session(&session, &bti_test_ta_uuid, |
| 2657 | NULL, &ret_orig))) |
| 2658 | return; |
| 2659 | |
| 2660 | res = TEEC_InvokeCommand(&session, TA_FEAT_BTI_IMPLEMENTED, &op, |
| 2661 | &ret_orig); |
| 2662 | if (!res) { |
| 2663 | if(op.params[0].value.a) |
| 2664 | *bti = true; |
| 2665 | Do_ADBG_Log("FEAT_BTI is %simplemented", *bti ? "" : "NOT "); |
| 2666 | } |
| 2667 | |
| 2668 | TEEC_CloseSession(&session); |
| 2669 | } |
| 2670 | |
| 2671 | static void xtest_tee_test_1035(ADBG_Case_t *c) |
| 2672 | { |
| 2673 | TEEC_Session session = {}; |
| 2674 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2675 | struct bti_test const *test = NULL; |
| 2676 | uint32_t ret_orig = 0; |
| 2677 | TEEC_Result res; |
| 2678 | unsigned int n = 0; |
| 2679 | bool cpu_feature_bti = false; |
| 2680 | |
| 2681 | Do_ADBG_BeginSubCase(c, "BTI Implemented"); |
| 2682 | get_cpu_feature(c, &cpu_feature_bti); |
| 2683 | Do_ADBG_EndSubCase(c, "BTI Implemented"); |
| 2684 | |
| 2685 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, |
| 2686 | TEEC_NONE); |
| 2687 | |
| 2688 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2689 | xtest_teec_open_session(&session, &bti_test_ta_uuid, |
| 2690 | NULL, &ret_orig))) |
| 2691 | return; |
| 2692 | |
| 2693 | Do_ADBG_BeginSubCase(c, "BTI Pass Cases"); |
| 2694 | for (n = 0; n < ARRAY_SIZE(bti_cases_success); n++) { |
| 2695 | test = &bti_cases_success[n]; |
| 2696 | |
| 2697 | op.params[0].value.a = test->func; |
| 2698 | |
| 2699 | res = TEEC_InvokeCommand(&session, test->cmd, &op, &ret_orig); |
| 2700 | if (res == TEEC_ERROR_NOT_IMPLEMENTED) { |
| 2701 | Do_ADBG_Log("Binary doesn't support BTI - skip tests"); |
| 2702 | Do_ADBG_EndSubCase(c, "BTI Pass Cases"); |
| 2703 | TEEC_CloseSession(&session); |
| 2704 | return; |
| 2705 | } |
| 2706 | |
| 2707 | Do_ADBG_BeginSubCase(c, "BTI Case %u", n); |
| 2708 | |
| 2709 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 2710 | |
| 2711 | Do_ADBG_EndSubCase(c, "BTI Case %u", n); |
| 2712 | } |
| 2713 | Do_ADBG_EndSubCase(c, "BTI Pass Cases"); |
| 2714 | |
| 2715 | TEEC_CloseSession(&session); |
| 2716 | |
| 2717 | Do_ADBG_BeginSubCase(c, "BTI Exception Generation"); |
| 2718 | for (n = 0; n < ARRAY_SIZE(bti_cases_panic); n++) { |
| 2719 | test = &bti_cases_panic[n]; |
| 2720 | res = TEEC_SUCCESS; |
| 2721 | |
| 2722 | if (cpu_feature_bti) |
| 2723 | res = TEEC_ERROR_TARGET_DEAD; |
| 2724 | |
| 2725 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2726 | xtest_teec_open_session(&session, &bti_test_ta_uuid, |
| 2727 | NULL, &ret_orig))) |
| 2728 | goto out; |
| 2729 | |
| 2730 | Do_ADBG_BeginSubCase(c, "BTI Case %u", n); |
| 2731 | op.params[0].value.a = test->func; |
| 2732 | |
| 2733 | (void)ADBG_EXPECT_TEEC_RESULT(c, res, |
| 2734 | TEEC_InvokeCommand(&session, test->cmd, &op, &ret_orig)); |
| 2735 | |
| 2736 | if (cpu_feature_bti) |
| 2737 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, |
| 2738 | ret_orig); |
| 2739 | |
| 2740 | Do_ADBG_EndSubCase(c, "BTI Case %u", n); |
| 2741 | |
| 2742 | TEEC_CloseSession(&session); |
| 2743 | } |
| 2744 | |
| 2745 | out: |
| 2746 | Do_ADBG_EndSubCase(c, "BTI Exception Generation"); |
| 2747 | } |
| 2748 | ADBG_CASE_DEFINE(regression, 1035, xtest_tee_test_1035, "Test BTI"); |
| 2749 | #endif |
Ruchika Gupta | 4808e38 | 2022-01-28 12:41:21 +0530 | [diff] [blame] | 2750 | |
| 2751 | static void xtest_tee_test_1036(ADBG_Case_t *c) |
| 2752 | { |
| 2753 | TEEC_Session session = { }; |
| 2754 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2755 | uint32_t ret_orig = 0; |
| 2756 | TEEC_Result res = TEEC_SUCCESS; |
| 2757 | |
| 2758 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, |
| 2759 | TEEC_NONE); |
| 2760 | |
| 2761 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2762 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 2763 | NULL, &ret_orig))) |
| 2764 | return; |
| 2765 | |
| 2766 | Do_ADBG_BeginSubCase(c, "PAuth NOP test"); |
| 2767 | |
| 2768 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PAUTH_NOP, &op, |
| 2769 | &ret_orig); |
| 2770 | if (res == TEEC_ERROR_NOT_SUPPORTED) { |
| 2771 | Do_ADBG_Log("Binary doesn't support PAuth - skip tests"); |
| 2772 | goto out; |
| 2773 | } |
| 2774 | |
| 2775 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2776 | goto out; |
| 2777 | |
| 2778 | Do_ADBG_EndSubCase(c, "PAuth NOP test"); |
| 2779 | |
| 2780 | Do_ADBG_BeginSubCase(c, "PAuth PAC corruption"); |
| 2781 | |
| 2782 | ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 2783 | TEEC_InvokeCommand(&session, |
| 2784 | TA_OS_TEST_CMD_PAUTH_CORRUPT_PAC, |
| 2785 | &op, &ret_orig)); |
| 2786 | |
| 2787 | ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 2788 | |
| 2789 | Do_ADBG_EndSubCase(c, "PAuth PAC corruption"); |
| 2790 | |
| 2791 | out: |
| 2792 | TEEC_CloseSession(&session); |
| 2793 | } |
| 2794 | ADBG_CASE_DEFINE(regression, 1036, xtest_tee_test_1036, |
| 2795 | "Test PAuth (Pointer Authentication)"); |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 2796 | |
| 2797 | #define ATT_MAX_KEYSZ 4096 |
| 2798 | |
| 2799 | #ifdef OPENSSL_FOUND |
| 2800 | static RSA *att_key; |
| 2801 | static size_t att_key_size; /* Actual key size (modulus size) in bytes */ |
| 2802 | |
| 2803 | /* |
| 2804 | * buf = [ TA hash (32 bytes SHA256) | Signature (att_key_size bytes) ] |
| 2805 | * Signature = RSA_SSA_PKCS1_PSS_MGF1(SHA256([nonce | TA hash]) |
| 2806 | */ |
| 2807 | static void check_signature(ADBG_Case_t *c, uint8_t *nonce, size_t nonce_size, |
| 2808 | uint8_t *buf) |
| 2809 | { |
| 2810 | unsigned char digest[SHA256_DIGEST_LENGTH] = { }; |
| 2811 | unsigned char *sig = buf + SHA256_DIGEST_LENGTH; |
| 2812 | unsigned char *ta_hash = buf; |
| 2813 | uint8_t decr[ATT_MAX_KEYSZ / 8] = { }; |
| 2814 | SHA256_CTX ctx = { }; |
| 2815 | int salt_len = 32; /* Hard-coded in the PTA */ |
| 2816 | int st = 0; |
| 2817 | |
| 2818 | if (!ADBG_EXPECT_NOT_NULL(c, att_key)) |
| 2819 | return; |
| 2820 | |
| 2821 | SHA256_Init(&ctx); |
| 2822 | SHA256_Update(&ctx, nonce, nonce_size); |
| 2823 | SHA256_Update(&ctx, ta_hash, SHA256_DIGEST_LENGTH); |
| 2824 | SHA256_Final(digest, &ctx); |
| 2825 | |
| 2826 | st = RSA_public_decrypt(att_key_size, sig, decr, att_key, |
| 2827 | RSA_NO_PADDING); |
| 2828 | ADBG_EXPECT_COMPARE_SIGNED(c, st, >, 0); |
| 2829 | st = RSA_verify_PKCS1_PSS_mgf1(att_key, digest, EVP_sha256(), |
| 2830 | EVP_sha256(), decr, salt_len); |
| 2831 | ADBG_EXPECT_COMPARE_SIGNED(c, st, >, 0); |
| 2832 | } |
| 2833 | |
| 2834 | static void free_att_key(void) |
| 2835 | { |
| 2836 | RSA_free(att_key); |
| 2837 | att_key = NULL; |
| 2838 | } |
| 2839 | |
Clement Faure | 44a31d0 | 2022-03-30 10:50:52 +0200 | [diff] [blame] | 2840 | #if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 2841 | static int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) |
| 2842 | { |
| 2843 | if ((r->n == NULL && n == NULL) || (r->e == NULL && e == NULL)) |
| 2844 | return 0; |
| 2845 | |
| 2846 | if (n != NULL) { |
| 2847 | BN_free(r->n); |
| 2848 | r->n = n; |
| 2849 | } |
| 2850 | |
| 2851 | if (e != NULL) { |
| 2852 | BN_free(r->e); |
| 2853 | r->e = e; |
| 2854 | } |
| 2855 | |
| 2856 | if (d != NULL) { |
| 2857 | BN_free(r->d); |
| 2858 | r->d = d; |
| 2859 | } |
| 2860 | |
| 2861 | return 1; |
| 2862 | } |
| 2863 | #endif |
| 2864 | |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 2865 | static void set_att_key(ADBG_Case_t *c, uint8_t *e, size_t e_sz, uint8_t *n, |
| 2866 | size_t n_sz) |
| 2867 | { |
| 2868 | BIGNUM *bn_e = NULL; |
| 2869 | BIGNUM *bn_n = NULL; |
| 2870 | int st = 0; |
| 2871 | |
| 2872 | att_key_size = n_sz; |
| 2873 | att_key = RSA_new(); |
| 2874 | if (!ADBG_EXPECT_NOT_NULL(c, att_key)) |
| 2875 | return; |
| 2876 | |
| 2877 | bn_e = BN_bin2bn(e, e_sz, NULL); |
| 2878 | if (!ADBG_EXPECT_NOT_NULL(c, bn_e)) |
| 2879 | goto err; |
| 2880 | bn_n = BN_bin2bn(n, n_sz, NULL); |
| 2881 | if (!ADBG_EXPECT_NOT_NULL(c, bn_n)) |
| 2882 | goto err; |
| 2883 | |
| 2884 | st = RSA_set0_key(att_key, bn_n, bn_e, BN_new()); |
| 2885 | if (!ADBG_EXPECT_COMPARE_SIGNED(c, st, !=, 0)) |
| 2886 | goto err; |
| 2887 | return; |
| 2888 | err: |
| 2889 | free_att_key(); |
| 2890 | } |
| 2891 | #else |
| 2892 | #define check_signature(...) |
| 2893 | #define set_att_key(...) |
| 2894 | #define free_att_key() |
| 2895 | #endif |
| 2896 | |
| 2897 | /* |
| 2898 | * Verification of the output of the attestation PTA |
| 2899 | * - (If hash != NULL) check buf contains the expected hash |
| 2900 | * - (If OpenSSL is available) Check that the signature is valid |
| 2901 | */ |
| 2902 | static void check_measurement(ADBG_Case_t *c, uint8_t *nonce, size_t nonce_size, |
| 2903 | uint8_t *hash, uint8_t *buf) |
| 2904 | { |
Pierre Moos | c7f733c | 2022-08-22 15:39:22 +0200 | [diff] [blame] | 2905 | (void)nonce; |
| 2906 | (void)nonce_size; |
| 2907 | |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 2908 | if (hash) |
| 2909 | ADBG_EXPECT_BUFFER(c, hash, 32, buf, 32); |
| 2910 | |
| 2911 | check_signature(c, nonce, nonce_size, buf); |
| 2912 | } |
| 2913 | |
| 2914 | /* Invoke attestation PTA to return the public key */ |
| 2915 | static void get_att_public_key(ADBG_Case_t *c) |
| 2916 | { |
| 2917 | uint8_t n[ATT_MAX_KEYSZ / 8] = { }; |
| 2918 | uint8_t e[3] = { }; /* We know e == 65537... */ |
| 2919 | size_t n_sz = sizeof(n); |
| 2920 | size_t e_sz = sizeof(e); |
| 2921 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2922 | TEEC_UUID att_uuid = PTA_ATTESTATION_UUID; |
| 2923 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 2924 | TEEC_Session session = { }; |
| 2925 | uint32_t ret_orig = 0; |
| 2926 | |
| 2927 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, |
| 2928 | TEEC_MEMREF_TEMP_OUTPUT, |
| 2929 | TEEC_VALUE_OUTPUT, TEEC_NONE); |
| 2930 | op.params[0].tmpref.buffer = e; |
| 2931 | op.params[0].tmpref.size = e_sz; |
| 2932 | op.params[1].tmpref.buffer = n; |
| 2933 | op.params[1].tmpref.size = n_sz; |
| 2934 | |
| 2935 | res = xtest_teec_open_session(&session, &att_uuid, NULL, &ret_orig); |
| 2936 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2937 | return; |
| 2938 | |
| 2939 | res = TEEC_InvokeCommand(&session, PTA_ATTESTATION_GET_PUBKEY, &op, |
| 2940 | &ret_orig); |
| 2941 | |
| 2942 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res) || |
| 2943 | !ADBG_EXPECT_COMPARE_UNSIGNED(c, op.params[2].value.a, ==, |
| 2944 | TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256)) |
| 2945 | goto out; |
| 2946 | |
| 2947 | e_sz = op.params[0].tmpref.size; |
| 2948 | n_sz = op.params[1].tmpref.size; |
| 2949 | set_att_key(c, e, e_sz, n, n_sz); |
| 2950 | out: |
| 2951 | TEEC_CloseSession(&session); |
| 2952 | } |
| 2953 | |
| 2954 | /* Invoke attestation PTA to hash the TEE binary */ |
| 2955 | static void attestation_tee(ADBG_Case_t *c) |
| 2956 | { |
| 2957 | uint8_t measurement[TEE_SHA256_HASH_SIZE + ATT_MAX_KEYSZ / 8] = { }; |
| 2958 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2959 | uint8_t nonce[4] = { 0x12, 0x34, 0x56, 0x78 }; |
| 2960 | TEEC_UUID att_uuid = PTA_ATTESTATION_UUID; |
| 2961 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 2962 | TEEC_Session session = { }; |
| 2963 | uint32_t ret_orig = 0; |
| 2964 | |
| 2965 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 2966 | TEEC_MEMREF_TEMP_OUTPUT, |
| 2967 | TEEC_NONE, TEEC_NONE); |
| 2968 | op.params[0].tmpref.buffer = nonce; |
| 2969 | op.params[0].tmpref.size = sizeof(nonce); |
| 2970 | op.params[1].tmpref.buffer = measurement; |
| 2971 | op.params[1].tmpref.size = sizeof(measurement); |
| 2972 | |
| 2973 | res = xtest_teec_open_session(&session, &att_uuid, NULL, &ret_orig); |
| 2974 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2975 | return; |
| 2976 | |
| 2977 | /* Hash TEE and check signature */ |
| 2978 | res = TEEC_InvokeCommand(&session, PTA_ATTESTATION_HASH_TEE_MEMORY, &op, |
| 2979 | &ret_orig); |
| 2980 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 2981 | check_measurement(c, nonce, sizeof(nonce), NULL, measurement); |
| 2982 | |
| 2983 | TEEC_CloseSession(&session); |
| 2984 | } |
| 2985 | |
| 2986 | /* Invoke attestation PTA to obtain the digest contained in the some TA shdr */ |
| 2987 | static void attestation_ta_shdr(ADBG_Case_t *c) |
| 2988 | { |
| 2989 | uint8_t measurement[TEE_SHA256_HASH_SIZE + ATT_MAX_KEYSZ / 8] = { }; |
| 2990 | uint8_t nonce[6] = { 0xa0, 0x98, 0x76, 0x54, 0x32, 0x10 }; |
| 2991 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2992 | uint8_t hash1[TEE_SHA256_HASH_SIZE] = { }; |
| 2993 | uint8_t hash2[TEE_SHA256_HASH_SIZE] = { }; |
| 2994 | TEEC_UUID att_uuid = PTA_ATTESTATION_UUID; |
| 2995 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 2996 | TEEC_Session session = { }; |
| 2997 | uint32_t ret_orig = 0; |
| 2998 | int cmp = 0; |
| 2999 | |
| 3000 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 3001 | TEEC_MEMREF_TEMP_INPUT, |
| 3002 | TEEC_MEMREF_TEMP_OUTPUT, |
| 3003 | TEEC_NONE); |
| 3004 | op.params[0].tmpref.buffer = (void *)&os_test_ta_uuid; |
| 3005 | op.params[0].tmpref.size = sizeof(TEEC_UUID); |
| 3006 | op.params[1].tmpref.buffer = nonce; |
| 3007 | op.params[1].tmpref.size = sizeof(nonce); |
| 3008 | op.params[2].tmpref.buffer = measurement; |
| 3009 | op.params[2].tmpref.size = sizeof(measurement); |
| 3010 | |
| 3011 | res = xtest_teec_open_session(&session, &att_uuid, NULL, &ret_orig); |
| 3012 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 3013 | return; |
| 3014 | |
| 3015 | /* Hash TA and check signature */ |
| 3016 | res = TEEC_InvokeCommand(&session, PTA_ATTESTATION_GET_TA_SHDR_DIGEST, |
| 3017 | &op, &ret_orig); |
| 3018 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 3019 | check_measurement(c, nonce, sizeof(nonce), NULL, measurement); |
| 3020 | /* Save hash */ |
| 3021 | memcpy(hash1, measurement, 32); |
| 3022 | |
| 3023 | /* Hash TA again */ |
| 3024 | memset(measurement, 0, sizeof(measurement)); |
| 3025 | res = TEEC_InvokeCommand(&session, PTA_ATTESTATION_GET_TA_SHDR_DIGEST, |
| 3026 | &op, &ret_orig); |
| 3027 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 3028 | /* New hash should be identical */ |
| 3029 | check_measurement(c, nonce, sizeof(nonce), hash1, measurement); |
| 3030 | |
| 3031 | /* Hash another TA */ |
| 3032 | op.params[0].tmpref.buffer = (void *)&crypt_user_ta_uuid; |
| 3033 | memset(measurement, 0, sizeof(measurement)); |
| 3034 | res = TEEC_InvokeCommand(&session, PTA_ATTESTATION_GET_TA_SHDR_DIGEST, |
| 3035 | &op, &ret_orig); |
| 3036 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 3037 | check_measurement(c, nonce, sizeof(nonce), NULL, measurement); |
| 3038 | memcpy(hash2, measurement, 32); |
| 3039 | /* Different binaries should have different hashes */ |
| 3040 | cmp = memcmp(hash1, hash2, sizeof(hash1)); |
| 3041 | ADBG_EXPECT_COMPARE_SIGNED(c, cmp, !=, 0); |
| 3042 | |
| 3043 | TEEC_CloseSession(&session); |
| 3044 | } |
| 3045 | |
| 3046 | /* |
| 3047 | * Invoke os_test TA which will invoke attestation PTA to obtain a hash of |
| 3048 | * itself. |
| 3049 | */ |
| 3050 | static void attestation_ta_memory(ADBG_Case_t *c) |
| 3051 | { |
| 3052 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 3053 | uint8_t nonce[6] = { 0xa0, 0x98, 0x76, 0x54, 0x32, 0x10 }; |
| 3054 | uint8_t hash1[TEE_SHA256_HASH_SIZE] = { }; |
| 3055 | uint8_t hash2[TEE_SHA256_HASH_SIZE] = { }; |
| 3056 | uint8_t measurement[TEE_SHA256_HASH_SIZE + ATT_MAX_KEYSZ / 8] = { }; |
| 3057 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 3058 | TEEC_Session session = { }; |
| 3059 | uint32_t ret_orig = 0; |
| 3060 | int cmp = 0; |
| 3061 | |
| 3062 | Do_ADBG_BeginSubCase(c, "Consecutive calls"); |
| 3063 | |
| 3064 | /* Open session to os_test TA */ |
| 3065 | res = xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 3066 | &ret_orig); |
| 3067 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 3068 | return; |
| 3069 | |
| 3070 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 3071 | TEEC_MEMREF_TEMP_OUTPUT, |
| 3072 | TEEC_NONE, TEEC_NONE); |
| 3073 | op.params[0].tmpref.buffer = nonce; |
| 3074 | op.params[0].tmpref.size = sizeof(nonce); |
| 3075 | op.params[1].tmpref.buffer = measurement; |
| 3076 | op.params[1].tmpref.size = sizeof(measurement); |
| 3077 | |
| 3078 | /* Hash TA */ |
| 3079 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_ATTESTATION, &op, |
| 3080 | &ret_orig); |
| 3081 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 3082 | |
| 3083 | check_measurement(c, nonce, sizeof(nonce), NULL, measurement); |
| 3084 | memcpy(hash1, measurement, 32); |
| 3085 | |
| 3086 | /* Hash TA again */ |
| 3087 | memset(measurement, 0, sizeof(measurement)); |
| 3088 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_ATTESTATION, &op, |
| 3089 | &ret_orig); |
| 3090 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 3091 | |
| 3092 | /* New hash should be identical to hash1 */ |
| 3093 | check_measurement(c, nonce, sizeof(nonce), hash1, measurement); |
| 3094 | |
| 3095 | Do_ADBG_EndSubCase(c, "Consecutive calls"); |
| 3096 | |
| 3097 | /* Close TA session, will cause unload of TA */ |
| 3098 | TEEC_CloseSession(&session); |
| 3099 | |
| 3100 | Do_ADBG_BeginSubCase(c, "TA reload"); |
| 3101 | |
| 3102 | /* Load TA again and open a new session */ |
| 3103 | res = xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 3104 | &ret_orig); |
| 3105 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 3106 | if (res) |
| 3107 | return; |
| 3108 | |
| 3109 | /* Hash TA one more time */ |
| 3110 | memset(measurement, 0, sizeof(measurement)); |
| 3111 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_ATTESTATION, &op, |
| 3112 | &ret_orig); |
| 3113 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 3114 | |
| 3115 | /* Hash after reload should still be the same */ |
| 3116 | check_measurement(c, nonce, sizeof(nonce), hash1, measurement); |
| 3117 | |
| 3118 | Do_ADBG_EndSubCase(c, "TA reload"); |
| 3119 | |
| 3120 | Do_ADBG_BeginSubCase(c, "Add shared library"); |
| 3121 | |
| 3122 | /* |
| 3123 | * Invoke a TA command that causes some additional code to be mapped |
| 3124 | * (shared library) |
| 3125 | */ |
| 3126 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL, NULL, |
| 3127 | &ret_orig); |
| 3128 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 3129 | |
| 3130 | /* Hash TA one last time */ |
| 3131 | memset(measurement, 0, sizeof(measurement)); |
| 3132 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_ATTESTATION, &op, |
| 3133 | &ret_orig); |
| 3134 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 3135 | |
| 3136 | check_measurement(c, nonce, sizeof(nonce), NULL, measurement); |
| 3137 | memcpy(hash2, measurement, 32); |
| 3138 | |
| 3139 | /* Different binaries mapped mean different hashes */ |
| 3140 | cmp = memcmp(hash1, hash2, sizeof(hash1)); |
| 3141 | ADBG_EXPECT_COMPARE_SIGNED(c, cmp, !=, 0); |
| 3142 | |
| 3143 | Do_ADBG_EndSubCase(c, "Add shared library"); |
| 3144 | |
| 3145 | TEEC_CloseSession(&session); |
| 3146 | } |
| 3147 | |
| 3148 | static void xtest_tee_test_1037(ADBG_Case_t *c) |
| 3149 | { |
| 3150 | TEEC_UUID att_uuid = PTA_ATTESTATION_UUID; |
| 3151 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 3152 | TEEC_Session session = { }; |
| 3153 | uint32_t ret_orig = 0; |
| 3154 | |
| 3155 | res = xtest_teec_open_session(&session, &att_uuid, NULL, &ret_orig); |
| 3156 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 3157 | Do_ADBG_Log(" skip test, pseudo TA not found"); |
| 3158 | return; |
| 3159 | } |
| 3160 | |
chenchaokai | af75193 | 2023-05-29 14:25:50 +0800 | [diff] [blame] | 3161 | TEEC_CloseSession(&session); |
| 3162 | |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 3163 | Do_ADBG_BeginSubCase(c, "Get public key"); |
| 3164 | get_att_public_key(c); |
| 3165 | Do_ADBG_EndSubCase(c, "Get public key"); |
| 3166 | |
| 3167 | Do_ADBG_BeginSubCase(c, "TEE attestation"); |
| 3168 | attestation_tee(c); |
| 3169 | Do_ADBG_EndSubCase(c, "TEE attestation"); |
| 3170 | |
| 3171 | Do_ADBG_BeginSubCase(c, "TA attestation (shdr)"); |
| 3172 | attestation_ta_shdr(c); |
| 3173 | Do_ADBG_EndSubCase(c, "TA attestation (shdr)"); |
| 3174 | |
| 3175 | Do_ADBG_BeginSubCase(c, "TA attestation (memory)"); |
| 3176 | attestation_ta_memory(c); |
| 3177 | Do_ADBG_EndSubCase(c, "TA attestation (memory)"); |
| 3178 | |
| 3179 | free_att_key(); |
| 3180 | } |
| 3181 | ADBG_CASE_DEFINE(regression, 1037, xtest_tee_test_1037, |
| 3182 | "Remote attestation"); |
Jens Wiklander | 50339ef | 2022-04-12 20:47:27 +0200 | [diff] [blame] | 3183 | |
| 3184 | static void xtest_tee_test_1038(ADBG_Case_t *c) |
| 3185 | { |
| 3186 | TEEC_Session session = { }; |
| 3187 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 3188 | uint32_t ret_orig = 0; |
| 3189 | TEEC_Result res = TEEC_SUCCESS; |
| 3190 | |
| 3191 | Do_ADBG_BeginSubCase(c, "MTE use after free"); |
| 3192 | |
| 3193 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, |
| 3194 | TEEC_NONE); |
| 3195 | |
| 3196 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 3197 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 3198 | NULL, &ret_orig))) |
| 3199 | return; |
| 3200 | |
| 3201 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_MEMTAG_USE_AFTER_FREE, |
| 3202 | &op, &ret_orig); |
| 3203 | if (res == TEEC_ERROR_NOT_SUPPORTED) { |
| 3204 | Do_ADBG_Log("Binary doesn't support MTE - skip tests"); |
| 3205 | goto out; |
| 3206 | } |
| 3207 | |
| 3208 | ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, res); |
| 3209 | ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 3210 | TEEC_CloseSession(&session); |
| 3211 | |
| 3212 | Do_ADBG_EndSubCase(c, "MTE use after free"); |
| 3213 | |
| 3214 | Do_ADBG_BeginSubCase(c, "MTE invalid tag"); |
| 3215 | |
| 3216 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, |
| 3217 | TEEC_NONE); |
| 3218 | |
| 3219 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 3220 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 3221 | NULL, &ret_orig))) |
| 3222 | return; |
| 3223 | |
| 3224 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_MEMTAG_INVALID_TAG, |
| 3225 | &op, &ret_orig); |
| 3226 | if (res == TEEC_ERROR_NOT_SUPPORTED) { |
| 3227 | Do_ADBG_Log("Binary doesn't support MTE - skip tests"); |
| 3228 | goto out; |
| 3229 | } |
| 3230 | |
| 3231 | ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, res); |
| 3232 | ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 3233 | |
| 3234 | Do_ADBG_EndSubCase(c, "MTE invalid tag"); |
| 3235 | |
| 3236 | Do_ADBG_BeginSubCase(c, "MTE double free"); |
| 3237 | |
| 3238 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, |
| 3239 | TEEC_NONE); |
| 3240 | |
| 3241 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 3242 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 3243 | NULL, &ret_orig))) |
| 3244 | return; |
| 3245 | |
| 3246 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_MEMTAG_DOUBLE_FREE, |
| 3247 | &op, &ret_orig); |
| 3248 | if (res == TEEC_ERROR_NOT_SUPPORTED) { |
| 3249 | Do_ADBG_Log("Binary doesn't support MTE - skip tests"); |
| 3250 | goto out; |
| 3251 | } |
| 3252 | |
| 3253 | ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, res); |
| 3254 | ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 3255 | |
| 3256 | Do_ADBG_EndSubCase(c, "MTE double free"); |
| 3257 | |
| 3258 | Do_ADBG_BeginSubCase(c, "MTE buffer overrun"); |
| 3259 | |
| 3260 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, |
| 3261 | TEEC_NONE); |
| 3262 | |
| 3263 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 3264 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 3265 | NULL, &ret_orig))) |
| 3266 | return; |
| 3267 | |
| 3268 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_MEMTAG_BUFFER_OVERRUN, |
| 3269 | &op, &ret_orig); |
| 3270 | if (res == TEEC_ERROR_NOT_SUPPORTED) { |
| 3271 | Do_ADBG_Log("Binary doesn't support MTE - skip tests"); |
| 3272 | goto out; |
| 3273 | } |
| 3274 | |
| 3275 | ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, res); |
| 3276 | ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 3277 | |
| 3278 | Do_ADBG_EndSubCase(c, "MTE buffer overrun"); |
| 3279 | |
| 3280 | |
| 3281 | out: |
| 3282 | TEEC_CloseSession(&session); |
| 3283 | } |
| 3284 | ADBG_CASE_DEFINE(regression, 1038, xtest_tee_test_1038, |
| 3285 | "Test MTE (Memory Tag Extension)"); |
Jens Wiklander | dd336da | 2022-09-02 13:57:54 +0200 | [diff] [blame] | 3286 | |
| 3287 | static void xtest_tee_test_1039(ADBG_Case_t *c) |
| 3288 | { |
| 3289 | TEEC_Session session = { }; |
| 3290 | uint32_t ret_orig = 0; |
| 3291 | |
| 3292 | Do_ADBG_BeginSubCase(c, "Load TA with two levels of subkeys"); |
| 3293 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
| 3294 | xtest_teec_open_session(&session, &subkey1_ta_uuid, |
| 3295 | NULL, &ret_orig))) |
| 3296 | TEEC_CloseSession(&session); |
| 3297 | Do_ADBG_EndSubCase(c, "Load TA with two levels of subkeys"); |
| 3298 | |
| 3299 | Do_ADBG_BeginSubCase(c, "Load TA with identity subkey"); |
| 3300 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
| 3301 | xtest_teec_open_session(&session, &subkey2_ta_uuid, |
| 3302 | NULL, &ret_orig))) |
| 3303 | TEEC_CloseSession(&session); |
| 3304 | Do_ADBG_EndSubCase(c, "Load TA with identity subkey"); |
| 3305 | |
| 3306 | } |
Jens Wiklander | dd336da | 2022-09-02 13:57:54 +0200 | [diff] [blame] | 3307 | ADBG_CASE_DEFINE(regression, 1039, xtest_tee_test_1039, |
| 3308 | "Test subkey verification"); |
Jens Wiklander | e1b6445 | 2023-09-01 20:21:16 +0200 | [diff] [blame] | 3309 | |
| 3310 | struct test_1040_thread_arg { |
| 3311 | TEEC_Result res; |
| 3312 | pthread_t thr; |
| 3313 | }; |
| 3314 | |
| 3315 | static void *test_1040_thread(void *arg) |
| 3316 | { |
| 3317 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 3318 | struct test_1040_thread_arg *a = arg; |
| 3319 | TEEC_Result res = TEEC_SUCCESS; |
| 3320 | uint32_t err_orig = 0; |
| 3321 | TEEC_Session session = { }; |
| 3322 | size_t loop_count = 100; |
| 3323 | size_t n = 0; |
| 3324 | |
| 3325 | if (level == 0) |
| 3326 | loop_count /= 2; |
| 3327 | |
| 3328 | while (n < loop_count) { |
| 3329 | res = xtest_teec_open_session(&session, &sims_test_ta_uuid, |
| 3330 | NULL, &err_orig); |
| 3331 | if (res) { |
| 3332 | if (res == TEEC_ERROR_TARGET_DEAD) |
| 3333 | continue; |
| 3334 | a->res = res; |
| 3335 | return NULL; |
| 3336 | } |
| 3337 | |
| 3338 | memset(&op, 0, sizeof(op)); |
| 3339 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 3340 | TEEC_NONE, TEEC_NONE, |
| 3341 | TEEC_NONE); |
| 3342 | res = TEEC_InvokeCommand(&session, TA_SIMS_CMD_PANIC, &op, |
| 3343 | &err_orig); |
| 3344 | TEEC_CloseSession(&session); |
| 3345 | if (res != TEEC_ERROR_TARGET_DEAD) { |
| 3346 | if (res) |
| 3347 | a->res = res; |
| 3348 | else |
| 3349 | a->res = TEEC_ERROR_GENERIC; |
| 3350 | return NULL; |
| 3351 | } |
| 3352 | n++; |
| 3353 | } |
| 3354 | a->res = TEEC_SUCCESS; |
| 3355 | return NULL; |
| 3356 | } |
| 3357 | |
| 3358 | static void xtest_tee_test_1040(ADBG_Case_t *c) |
| 3359 | { |
| 3360 | struct test_1040_thread_arg arg[NUM_THREADS] = { }; |
| 3361 | size_t nt = NUM_THREADS; |
| 3362 | size_t n = 0; |
| 3363 | |
Alvin Chang | 5fae7bd | 2025-03-20 17:14:12 +0800 | [diff] [blame] | 3364 | Do_ADBG_BeginSubCase(c, "Concurrent invoke with panic in TA"); |
Jens Wiklander | e1b6445 | 2023-09-01 20:21:16 +0200 | [diff] [blame] | 3365 | for (n = 0; n < nt; n++) { |
| 3366 | if (!ADBG_EXPECT(c, 0, pthread_create(&arg[n].thr, NULL, |
| 3367 | test_1040_thread, |
| 3368 | arg + n))) |
| 3369 | nt = n; /* break loop and start cleanup */ |
| 3370 | } |
| 3371 | for (n = 0; n < nt; n++) { |
| 3372 | ADBG_EXPECT(c, 0, pthread_join(arg[n].thr, NULL)); |
| 3373 | ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res); |
| 3374 | } |
Alvin Chang | 5fae7bd | 2025-03-20 17:14:12 +0800 | [diff] [blame] | 3375 | Do_ADBG_EndSubCase(c, "Concurrent invoke with panic in TA"); |
Jens Wiklander | e1b6445 | 2023-09-01 20:21:16 +0200 | [diff] [blame] | 3376 | } |
| 3377 | ADBG_CASE_DEFINE(regression, 1040, xtest_tee_test_1040, |
| 3378 | "Test panic in concurrent open/invoke/close session"); |
Jens Wiklander | 6b5d9a3 | 2024-12-10 17:43:47 +0100 | [diff] [blame] | 3379 | |
| 3380 | static void xtest_tee_test_1041(ADBG_Case_t *c) |
| 3381 | { |
| 3382 | const char fname[] = "/dev/tpm0"; |
| 3383 | TEE_Result res = TEEC_SUCCESS; |
| 3384 | TEEC_Session sess = { }; |
| 3385 | uint32_t ret_orig = 0; |
| 3386 | struct stat sb = { }; |
Jerome Forissier | a1739a1 | 2025-01-15 10:10:36 +0100 | [diff] [blame] | 3387 | bool found = false; |
Jens Wiklander | 237d278 | 2025-02-04 14:43:20 +0100 | [diff] [blame] | 3388 | int max_wait = 20; |
Jerome Forissier | a1739a1 | 2025-01-15 10:10:36 +0100 | [diff] [blame] | 3389 | int i = 0; |
Jens Wiklander | 6b5d9a3 | 2024-12-10 17:43:47 +0100 | [diff] [blame] | 3390 | |
| 3391 | res = xtest_teec_open_session(&sess, &(const TEEC_UUID)TA_FTPM_UUID, |
| 3392 | NULL, &ret_orig); |
| 3393 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 3394 | Do_ADBG_Log("skip test, fTPM TA not present"); |
| 3395 | return; |
| 3396 | } |
| 3397 | if (res != TEEC_ERROR_BUSY && ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 3398 | TEEC_CloseSession(&sess); |
| 3399 | |
Jerome Forissier | a1739a1 | 2025-01-15 10:10:36 +0100 | [diff] [blame] | 3400 | /* |
| 3401 | * Check for the presence of the TPM device. Give the kernel some time |
| 3402 | * (5 seconds) otherwise the test may fail if run immediately after |
| 3403 | * boot. |
| 3404 | */ |
Jens Wiklander | 237d278 | 2025-02-04 14:43:20 +0100 | [diff] [blame] | 3405 | for (i = 0; i < max_wait; i++) { |
Jerome Forissier | a1739a1 | 2025-01-15 10:10:36 +0100 | [diff] [blame] | 3406 | if (stat(fname, &sb) == 0) { |
| 3407 | found = true; |
| 3408 | break; |
| 3409 | } |
Jens Wiklander | 237d278 | 2025-02-04 14:43:20 +0100 | [diff] [blame] | 3410 | Do_ADBG_Log("Waiting for TPM device %d / %d", i, max_wait); |
Jerome Forissier | a1739a1 | 2025-01-15 10:10:36 +0100 | [diff] [blame] | 3411 | sleep(1); |
| 3412 | } |
| 3413 | if (!ADBG_EXPECT_TRUE(c, found)) { |
Jens Wiklander | 6b5d9a3 | 2024-12-10 17:43:47 +0100 | [diff] [blame] | 3414 | Do_ADBG_Log("stat(\"%s\"): %s", fname, strerror(errno)); |
| 3415 | if (res != TEEC_ERROR_BUSY) |
| 3416 | Do_ADBG_Log("Perhaps fTPM hasn't finished probing"); |
| 3417 | return; |
| 3418 | } |
| 3419 | |
| 3420 | if (!ADBG_EXPECT_TRUE(c, S_ISCHR(sb.st_mode))) |
| 3421 | Do_ADBG_Log("Expected \"%s\" to be a character device", fname); |
| 3422 | } |
| 3423 | ADBG_CASE_DEFINE(regression, 1041, xtest_tee_test_1041, "Test fTPM sanity"); |