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