Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014, STMicroelectronics International N.V. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
Etienne Carriere | a465355 | 2017-01-11 10:04:24 +0100 | [diff] [blame] | 14 | #include <limits.h> |
| 15 | #include <pthread.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 16 | #include <stdio.h> |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 17 | #include <stdlib.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 18 | #include <string.h> |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 19 | #include <sys/stat.h> |
| 20 | #include <sys/types.h> |
Etienne Carriere | a465355 | 2017-01-11 10:04:24 +0100 | [diff] [blame] | 21 | #include <unistd.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 22 | |
| 23 | #include "xtest_test.h" |
| 24 | #include "xtest_helpers.h" |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 25 | #include <signed_hdr.h> |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 26 | #include <util.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 27 | |
Etienne Carriere | 726d8bc | 2017-03-21 15:45:59 +0100 | [diff] [blame] | 28 | #include <pta_invoke_tests.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 29 | #include <ta_crypt.h> |
| 30 | #include <ta_os_test.h> |
| 31 | #include <ta_create_fail_test.h> |
| 32 | #include <ta_rpc_test.h> |
| 33 | #include <ta_sims_test.h> |
Ovidiu Mihalachi | 15cecff | 2019-04-02 16:36:31 +0300 | [diff] [blame^] | 34 | #include <ta_miss_test.h> |
| 35 | #include <ta_sims_keepalive_test.h> |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 36 | #include <ta_concurrent.h> |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 37 | #include <sdp_basic.h> |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 38 | #ifdef CFG_SECSTOR_TA_MGMT_PTA |
| 39 | #include <pta_secstor_ta_mgmt.h> |
| 40 | #endif |
| 41 | |
| 42 | #ifndef MIN |
| 43 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 44 | #endif |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 45 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 46 | struct xtest_crypto_session { |
| 47 | ADBG_Case_t *c; |
| 48 | TEEC_Session *session; |
| 49 | uint32_t cmd_id_sha256; |
| 50 | uint32_t cmd_id_aes256ecb_encrypt; |
| 51 | uint32_t cmd_id_aes256ecb_decrypt; |
| 52 | }; |
| 53 | |
| 54 | static void xtest_crypto_test(struct xtest_crypto_session *cs) |
| 55 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 56 | uint32_t ret_orig = 0; |
| 57 | uint8_t crypt_out[16] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 58 | uint8_t crypt_in[16] = { 22, 17 }; |
| 59 | |
| 60 | crypt_in[15] = 60; |
| 61 | |
| 62 | Do_ADBG_BeginSubCase(cs->c, "AES encrypt"); |
| 63 | { |
| 64 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 65 | |
| 66 | op.params[0].tmpref.buffer = crypt_in; |
| 67 | op.params[0].tmpref.size = sizeof(crypt_in); |
| 68 | op.params[1].tmpref.buffer = crypt_out; |
| 69 | op.params[1].tmpref.size = sizeof(crypt_out); |
| 70 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 71 | TEEC_MEMREF_TEMP_OUTPUT, |
| 72 | TEEC_NONE, TEEC_NONE); |
| 73 | |
| 74 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 75 | TEEC_InvokeCommand(cs->session, |
| 76 | cs-> |
| 77 | cmd_id_aes256ecb_encrypt, |
| 78 | &op, |
| 79 | &ret_orig)); |
| 80 | } |
| 81 | Do_ADBG_EndSubCase(cs->c, "AES encrypt"); |
| 82 | |
| 83 | Do_ADBG_BeginSubCase(cs->c, "AES decrypt"); |
| 84 | { |
| 85 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 86 | uint8_t out[16] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 87 | |
| 88 | op.params[0].tmpref.buffer = crypt_out; |
| 89 | op.params[0].tmpref.size = sizeof(crypt_out); |
| 90 | op.params[1].tmpref.buffer = out; |
| 91 | op.params[1].tmpref.size = sizeof(out); |
| 92 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 93 | TEEC_MEMREF_TEMP_OUTPUT, |
| 94 | TEEC_NONE, TEEC_NONE); |
| 95 | |
| 96 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 97 | TEEC_InvokeCommand(cs->session, |
| 98 | cs-> |
| 99 | cmd_id_aes256ecb_decrypt, |
| 100 | &op, |
| 101 | &ret_orig)); |
| 102 | |
| 103 | if (!ADBG_EXPECT(cs->c, 0, |
| 104 | memcmp(crypt_in, out, sizeof(crypt_in)))) { |
| 105 | Do_ADBG_Log("crypt_in:"); |
| 106 | Do_ADBG_HexLog(crypt_in, sizeof(crypt_in), 16); |
| 107 | Do_ADBG_Log("out:"); |
| 108 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 109 | } |
| 110 | } |
| 111 | Do_ADBG_EndSubCase(cs->c, "AES decrypt"); |
| 112 | |
| 113 | Do_ADBG_BeginSubCase(cs->c, "SHA-256 test, 3 bytes input"); |
| 114 | { |
| 115 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 116 | static const uint8_t sha256_in[] = { 'a', 'b', 'c' }; |
| 117 | static const uint8_t sha256_out[] = { |
| 118 | 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, |
| 119 | 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, |
| 120 | 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, |
| 121 | 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad |
| 122 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 123 | uint8_t out[32] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 124 | |
| 125 | op.params[0].tmpref.buffer = (void *)sha256_in; |
| 126 | op.params[0].tmpref.size = sizeof(sha256_in); |
| 127 | op.params[1].tmpref.buffer = out; |
| 128 | op.params[1].tmpref.size = sizeof(out); |
| 129 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 130 | TEEC_MEMREF_TEMP_OUTPUT, |
| 131 | TEEC_NONE, TEEC_NONE); |
| 132 | |
| 133 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 134 | TEEC_InvokeCommand(cs->session, |
| 135 | cs-> |
| 136 | cmd_id_sha256, |
| 137 | &op, |
| 138 | &ret_orig)); |
| 139 | |
| 140 | if (!ADBG_EXPECT(cs->c, 0, memcmp(sha256_out, out, |
| 141 | sizeof(sha256_out)))) { |
| 142 | Do_ADBG_Log("sha256_out:"); |
| 143 | Do_ADBG_HexLog(sha256_out, sizeof(sha256_out), 16); |
| 144 | Do_ADBG_Log("out:"); |
| 145 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 146 | } |
| 147 | } |
| 148 | Do_ADBG_EndSubCase(cs->c, "SHA-256 test, 3 bytes input"); |
| 149 | |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 150 | Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 151 | { |
| 152 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 153 | static const uint8_t in[] = { |
| 154 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 155 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 156 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 157 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f |
| 158 | }; |
| 159 | static const uint8_t exp_out[] = { |
| 160 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 161 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 162 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 163 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 164 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 165 | uint8_t out[sizeof(exp_out)] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 166 | |
| 167 | op.params[0].tmpref.buffer = (void *)in; |
| 168 | op.params[0].tmpref.size = sizeof(in); |
| 169 | op.params[1].tmpref.buffer = out; |
| 170 | op.params[1].tmpref.size = sizeof(out); |
| 171 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 172 | TEEC_MEMREF_TEMP_OUTPUT, |
| 173 | TEEC_NONE, TEEC_NONE); |
| 174 | |
| 175 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 176 | TEEC_InvokeCommand(cs->session, |
| 177 | cs-> |
| 178 | cmd_id_aes256ecb_encrypt, |
| 179 | &op, |
| 180 | &ret_orig)); |
| 181 | |
| 182 | if (!ADBG_EXPECT(cs->c, 0, |
| 183 | memcmp(exp_out, out, sizeof(exp_out)))) { |
| 184 | Do_ADBG_Log("exp_out:"); |
| 185 | Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16); |
| 186 | Do_ADBG_Log("out:"); |
| 187 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 188 | } |
| 189 | } |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 190 | Do_ADBG_EndSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 191 | |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 192 | Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 193 | { |
| 194 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 195 | static const uint8_t in[] = { |
| 196 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 197 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 198 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 199 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 200 | }; |
| 201 | static const uint8_t exp_out[] = { |
| 202 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 203 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 204 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 205 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f |
| 206 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 207 | uint8_t out[sizeof(exp_out)] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 208 | |
| 209 | op.params[0].tmpref.buffer = (void *)in; |
| 210 | op.params[0].tmpref.size = sizeof(in); |
| 211 | op.params[1].tmpref.buffer = out; |
| 212 | op.params[1].tmpref.size = sizeof(out); |
| 213 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 214 | TEEC_MEMREF_TEMP_OUTPUT, |
| 215 | TEEC_NONE, TEEC_NONE); |
| 216 | |
| 217 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 218 | TEEC_InvokeCommand(cs->session, |
| 219 | cs-> |
| 220 | cmd_id_aes256ecb_decrypt, |
| 221 | &op, |
| 222 | &ret_orig)); |
| 223 | |
| 224 | if (!ADBG_EXPECT(cs->c, 0, |
| 225 | memcmp(exp_out, out, sizeof(exp_out)))) { |
| 226 | Do_ADBG_Log("exp_out:"); |
| 227 | Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16); |
| 228 | Do_ADBG_Log("out:"); |
| 229 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 230 | } |
| 231 | } |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 232 | Do_ADBG_EndSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static void xtest_tee_test_1001(ADBG_Case_t *c) |
| 236 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 237 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 238 | TEEC_Session session = { }; |
| 239 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 240 | |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 241 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Etienne Carriere | 726d8bc | 2017-03-21 15:45:59 +0100 | [diff] [blame] | 242 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 243 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 244 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 245 | Do_ADBG_Log(" - 1001 - skip test, pseudo TA not found"); |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 246 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 247 | } |
| 248 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 249 | |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 250 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand( |
Etienne Carriere | 726d8bc | 2017-03-21 15:45:59 +0100 | [diff] [blame] | 251 | &session, PTA_INVOKE_TESTS_CMD_SELF_TESTS, NULL, &ret_orig)); |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 252 | TEEC_CloseSession(&session); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 253 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 254 | ADBG_CASE_DEFINE(regression, 1001, xtest_tee_test_1001, "Core self tests"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 255 | |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 256 | static void xtest_tee_test_1002(ADBG_Case_t *c) |
| 257 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 258 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 259 | TEEC_Session session = { }; |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 260 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 261 | uint32_t ret_orig = 0; |
| 262 | uint8_t buf[16 * 1024] = { }; |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 263 | uint8_t exp_sum = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 264 | size_t n = 0; |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 265 | |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 266 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 267 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 268 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 269 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 270 | Do_ADBG_Log(" - 1002 - skip test, pseudo TA not found"); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 271 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 272 | } |
| 273 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 274 | |
| 275 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, |
| 276 | TEEC_NONE, TEEC_NONE); |
| 277 | op.params[0].tmpref.size = sizeof(buf); |
| 278 | op.params[0].tmpref.buffer = buf; |
| 279 | |
| 280 | for (n = 0; n < sizeof(buf); n++) |
| 281 | buf[n] = n + 1; |
| 282 | for (n = 0; n < sizeof(buf); n++) |
| 283 | exp_sum += buf[n]; |
| 284 | |
| 285 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand( |
| 286 | &session, PTA_INVOKE_TESTS_CMD_PARAMS, &op, &ret_orig))) |
| 287 | goto out; |
| 288 | |
| 289 | ADBG_EXPECT_COMPARE_SIGNED(c, exp_sum, ==, buf[0]); |
| 290 | out: |
| 291 | TEEC_CloseSession(&session); |
| 292 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 293 | ADBG_CASE_DEFINE(regression, 1002, xtest_tee_test_1002, "PTA parameters"); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 294 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 295 | struct test_1003_arg { |
| 296 | uint32_t test_type; |
| 297 | size_t repeat; |
| 298 | size_t max_before_lockers; |
| 299 | size_t max_during_lockers; |
| 300 | size_t before_lockers; |
| 301 | size_t during_lockers; |
| 302 | TEEC_Result res; |
| 303 | uint32_t error_orig; |
| 304 | }; |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 305 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 306 | static void *test_1003_thread(void *arg) |
| 307 | { |
| 308 | struct test_1003_arg *a = arg; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 309 | TEEC_Session session = { }; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 310 | size_t rounds = 64 * 1024; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 311 | size_t n = 0; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 312 | |
| 313 | a->res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, |
| 314 | NULL, &a->error_orig); |
| 315 | if (a->res != TEEC_SUCCESS) |
| 316 | return NULL; |
| 317 | |
| 318 | for (n = 0; n < a->repeat; n++) { |
| 319 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 320 | |
| 321 | op.params[0].value.a = a->test_type; |
| 322 | op.params[0].value.b = rounds; |
| 323 | |
| 324 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 325 | TEEC_VALUE_OUTPUT, |
| 326 | TEEC_NONE, TEEC_NONE); |
| 327 | a->res = TEEC_InvokeCommand(&session, |
| 328 | PTA_INVOKE_TESTS_CMD_MUTEX, |
| 329 | &op, &a->error_orig); |
| 330 | if (a->test_type == PTA_MUTEX_TEST_WRITER && |
| 331 | op.params[1].value.b != 1) { |
| 332 | Do_ADBG_Log("n %zu %" PRIu32, n, op.params[1].value.b); |
| 333 | a->res = TEEC_ERROR_BAD_STATE; |
| 334 | a->error_orig = 42; |
| 335 | break; |
| 336 | } |
| 337 | |
| 338 | if (a->test_type == PTA_MUTEX_TEST_READER) { |
| 339 | if (op.params[1].value.a > a->max_before_lockers) |
| 340 | a->max_before_lockers = op.params[1].value.a; |
| 341 | |
| 342 | if (op.params[1].value.b > a->max_during_lockers) |
| 343 | a->max_during_lockers = op.params[1].value.b; |
| 344 | |
| 345 | a->before_lockers += op.params[1].value.a; |
| 346 | a->during_lockers += op.params[1].value.b; |
| 347 | } |
| 348 | } |
| 349 | TEEC_CloseSession(&session); |
| 350 | |
| 351 | return NULL; |
| 352 | } |
| 353 | |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 354 | #define TEST_1003_THREAD_COUNT (3 * 2) |
| 355 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 356 | static void xtest_tee_test_1003(ADBG_Case_t *c) |
| 357 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 358 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 359 | TEEC_Session session = { }; |
| 360 | uint32_t ret_orig = 0; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 361 | size_t repeat = 20; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 362 | struct test_1003_arg arg[TEST_1003_THREAD_COUNT] = { }; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 363 | size_t max_read_concurrency = 0; |
| 364 | size_t max_read_waiters = 0; |
| 365 | size_t num_concurrent_read_lockers = 0; |
| 366 | size_t num_concurrent_read_waiters = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 367 | size_t n = 0; |
| 368 | size_t nt = TEST_1003_THREAD_COUNT; |
| 369 | double mean_read_concurrency = 0; |
| 370 | double mean_read_waiters = 0; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 371 | size_t num_writers = 0; |
| 372 | size_t num_readers = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 373 | pthread_t thr[TEST_1003_THREAD_COUNT] = { }; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 374 | |
| 375 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
| 376 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 377 | &ret_orig); |
| 378 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 379 | Do_ADBG_Log(" - 1003 - skip test, pseudo TA not found"); |
| 380 | return; |
| 381 | } |
| 382 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 383 | TEEC_CloseSession(&session); |
| 384 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 385 | for (n = 0; n < nt; n++) { |
| 386 | if (n % 3) { |
| 387 | arg[n].test_type = PTA_MUTEX_TEST_READER; |
| 388 | num_readers++; |
| 389 | } else { |
| 390 | arg[n].test_type = PTA_MUTEX_TEST_WRITER; |
| 391 | num_writers++; |
| 392 | } |
| 393 | arg[n].repeat = repeat; |
| 394 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 395 | test_1003_thread, arg + n))) |
| 396 | nt = n; /* break loop and start cleanup */ |
| 397 | } |
| 398 | |
| 399 | for (n = 0; n < nt; n++) { |
| 400 | ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)); |
| 401 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res)) |
| 402 | Do_ADBG_Log("error origin %" PRIu32, |
| 403 | arg[n].error_orig); |
| 404 | if (arg[n].test_type == PTA_MUTEX_TEST_READER) { |
| 405 | if (arg[n].max_during_lockers > max_read_concurrency) |
| 406 | max_read_concurrency = |
| 407 | arg[n].max_during_lockers; |
| 408 | |
| 409 | if (arg[n].max_before_lockers > max_read_waiters) |
| 410 | max_read_waiters = arg[n].max_before_lockers; |
| 411 | |
| 412 | num_concurrent_read_lockers += arg[n].during_lockers; |
| 413 | num_concurrent_read_waiters += arg[n].before_lockers; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | mean_read_concurrency = (double)num_concurrent_read_lockers / |
| 418 | (double)(repeat * num_readers); |
| 419 | mean_read_waiters = (double)num_concurrent_read_waiters / |
| 420 | (double)(repeat * num_readers); |
| 421 | |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 422 | Do_ADBG_Log(" Number of parallel threads: %d (%zu writers and %zu readers)", |
| 423 | TEST_1003_THREAD_COUNT, num_writers, num_readers); |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 424 | Do_ADBG_Log(" Max read concurrency: %zu", max_read_concurrency); |
| 425 | Do_ADBG_Log(" Max read waiters: %zu", max_read_waiters); |
| 426 | Do_ADBG_Log(" Mean read concurrency: %g", mean_read_concurrency); |
| 427 | Do_ADBG_Log(" Mean read waiting: %g", mean_read_waiters); |
| 428 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 429 | ADBG_CASE_DEFINE(regression, 1003, xtest_tee_test_1003, |
| 430 | "Core internal read/write mutex"); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 431 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 432 | static void xtest_tee_test_1004(ADBG_Case_t *c) |
| 433 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 434 | TEEC_Session session = { }; |
| 435 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 436 | struct xtest_crypto_session cs = { c, &session, TA_CRYPT_CMD_SHA256, |
| 437 | TA_CRYPT_CMD_AES256ECB_ENC, |
| 438 | TA_CRYPT_CMD_AES256ECB_DEC }; |
| 439 | |
| 440 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, xtest_teec_open_session( |
| 441 | &session, &crypt_user_ta_uuid, |
| 442 | NULL, &ret_orig))) |
| 443 | return; |
| 444 | |
| 445 | /* Run the "complete crypto test suite" */ |
| 446 | xtest_crypto_test(&cs); |
| 447 | |
| 448 | TEEC_CloseSession(&session); |
| 449 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 450 | 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] | 451 | |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 452 | 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] | 453 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 454 | TEEC_Session session = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 455 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 456 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 457 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 458 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 459 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 460 | &ret_orig))) |
| 461 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 462 | |
| 463 | op.params[0].value.a = n; |
| 464 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, |
| 465 | TEEC_NONE); |
| 466 | |
| 467 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 468 | TEEC_ERROR_TARGET_DEAD, |
| 469 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
| 470 | &ret_orig)); |
| 471 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 472 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 473 | TEEC_ERROR_TARGET_DEAD, |
| 474 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 475 | &ret_orig)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 476 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 477 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 478 | |
| 479 | TEEC_CloseSession(&session); |
| 480 | } |
| 481 | |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 482 | static void xtest_tee_test_invalid_mem_access2(ADBG_Case_t *c, unsigned int n, |
| 483 | size_t size) |
| 484 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 485 | TEEC_Session session = { }; |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 486 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 487 | uint32_t ret_orig = 0; |
| 488 | TEEC_SharedMemory shm = { }; |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 489 | |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 490 | shm.size = size; |
| 491 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 492 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 493 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 494 | return; |
| 495 | |
| 496 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 497 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 498 | &ret_orig))) |
| 499 | return; |
| 500 | |
| 501 | op.params[0].value.a = (uint32_t)n; |
| 502 | op.params[1].memref.parent = &shm; |
| 503 | op.params[1].memref.size = size; |
| 504 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_MEMREF_WHOLE, |
| 505 | TEEC_NONE, TEEC_NONE); |
| 506 | |
| 507 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 508 | TEEC_ERROR_TARGET_DEAD, |
| 509 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
| 510 | &ret_orig)); |
| 511 | |
| 512 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 513 | TEEC_ERROR_TARGET_DEAD, |
| 514 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
| 515 | &ret_orig)); |
| 516 | |
| 517 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 518 | |
| 519 | TEEC_CloseSession(&session); |
| 520 | } |
| 521 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 522 | static void xtest_tee_test_1005(ADBG_Case_t *c) |
| 523 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 524 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 525 | #define MAX_SESSIONS 3 |
| 526 | TEEC_Session sessions[MAX_SESSIONS]; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 527 | int i = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 528 | |
| 529 | for (i = 0; i < MAX_SESSIONS; i++) { |
| 530 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Jens Wiklander | eb6bce7 | 2016-09-23 11:37:33 +0200 | [diff] [blame] | 531 | xtest_teec_open_session(&sessions[i], |
| 532 | &concurrent_ta_uuid, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 533 | NULL, &ret_orig))) |
| 534 | break; |
| 535 | } |
| 536 | |
| 537 | for (; --i >= 0; ) |
| 538 | TEEC_CloseSession(&sessions[i]); |
| 539 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 540 | ADBG_CASE_DEFINE(regression, 1005, xtest_tee_test_1005, "Many sessions"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 541 | |
| 542 | static void xtest_tee_test_1006(ADBG_Case_t *c) |
| 543 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 544 | TEEC_Session session = { }; |
| 545 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 546 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 547 | uint8_t buf[32] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 548 | |
| 549 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 550 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 551 | &ret_orig))) |
| 552 | return; |
| 553 | |
| 554 | op.params[0].tmpref.buffer = buf; |
| 555 | op.params[0].tmpref.size = sizeof(buf); |
| 556 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, |
| 557 | TEEC_NONE, TEEC_NONE); |
| 558 | |
| 559 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 560 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BASIC, &op, |
| 561 | &ret_orig)); |
| 562 | |
| 563 | TEEC_CloseSession(&session); |
| 564 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 565 | ADBG_CASE_DEFINE(regression, 1006, xtest_tee_test_1006, |
| 566 | "Test Basic OS features"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 567 | |
| 568 | static void xtest_tee_test_1007(ADBG_Case_t *c) |
| 569 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 570 | TEEC_Session session = { }; |
| 571 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 572 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 573 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 574 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 575 | &ret_orig))) |
| 576 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 577 | |
| 578 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 579 | TEEC_ERROR_TARGET_DEAD, |
| 580 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PANIC, NULL, |
| 581 | &ret_orig)); |
| 582 | |
| 583 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 584 | |
| 585 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 586 | TEEC_ERROR_TARGET_DEAD, |
| 587 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_INIT, NULL, |
| 588 | &ret_orig)); |
| 589 | |
| 590 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 591 | |
| 592 | TEEC_CloseSession(&session); |
| 593 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 594 | ADBG_CASE_DEFINE(regression, 1007, xtest_tee_test_1007, "Test Panic"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 595 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 596 | #ifdef CFG_SECSTOR_TA_MGMT_PTA |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 597 | #ifndef TA_DIR |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 598 | # ifdef __ANDROID__ |
Yongqin Liu | 286f1fc | 2018-06-21 22:09:15 +0800 | [diff] [blame] | 599 | #define TA_DIR "/vendor/lib/optee_armtz" |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 600 | # else |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 601 | #define TA_DIR "/lib/optee_armtz" |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 602 | # endif |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 603 | #endif |
| 604 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 605 | static FILE *open_ta_file(const TEEC_UUID *uuid, const char *mode) |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 606 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 607 | char buf[PATH_MAX] = { }; |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 608 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 609 | snprintf(buf, sizeof(buf), |
Jens Wiklander | 6203b87 | 2016-12-08 19:18:29 +0100 | [diff] [blame] | 610 | "%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] | 611 | TA_DIR, uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion, |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 612 | uuid->clockSeqAndNode[0], uuid->clockSeqAndNode[1], |
| 613 | uuid->clockSeqAndNode[2], uuid->clockSeqAndNode[3], |
| 614 | uuid->clockSeqAndNode[4], uuid->clockSeqAndNode[5], |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 615 | uuid->clockSeqAndNode[6], uuid->clockSeqAndNode[7]); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 616 | |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 617 | return fopen(buf, mode); |
| 618 | } |
| 619 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 620 | 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] | 621 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 622 | TEEC_Session session = { }; |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 623 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 624 | TEEC_UUID uuid = PTA_SECSTOR_TA_MGMT_UUID; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 625 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 626 | uint32_t ret_orig = 0; |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 627 | FILE *f = NULL; |
| 628 | bool r = false; |
| 629 | uint8_t *buf = NULL; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 630 | size_t sz = 0; |
| 631 | size_t fread_res = 0; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 632 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 633 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 634 | xtest_teec_open_session(&session, &uuid, NULL, &ret_orig))) |
| 635 | goto out; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 636 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 637 | f = open_ta_file(&create_fail_test_ta_uuid, "rb"); |
| 638 | if (!ADBG_EXPECT_NOT_NULL(c, f)) |
| 639 | goto out; |
| 640 | if (!ADBG_EXPECT_TRUE(c, !fseek(f, 0, SEEK_END))) |
| 641 | goto out; |
| 642 | sz = ftell(f); |
| 643 | rewind(f); |
| 644 | |
| 645 | buf = malloc(sz); |
| 646 | if (!ADBG_EXPECT_NOT_NULL(c, buf)) |
| 647 | goto out; |
| 648 | |
| 649 | fread_res = fread(buf, 1, sz, f); |
| 650 | if (!ADBG_EXPECT_COMPARE_UNSIGNED(c, fread_res, ==, sz)) |
| 651 | goto out; |
| 652 | |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 653 | fclose(f); |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 654 | f = NULL; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 655 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 656 | buf[MIN(offs, sz)] ^= mask; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 657 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 658 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, |
| 659 | TEEC_NONE, TEEC_NONE); |
| 660 | op.params[0].tmpref.buffer = buf; |
| 661 | op.params[0].tmpref.size = sz; |
| 662 | |
| 663 | res = TEEC_InvokeCommand(&session, PTA_SECSTOR_TA_MGMT_BOOTSTRAP, &op, |
| 664 | &ret_orig); |
| 665 | r = ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_SECURITY, res); |
| 666 | out: |
| 667 | free(buf); |
| 668 | if (f) |
| 669 | fclose(f); |
| 670 | TEEC_CloseSession(&session); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 671 | return r; |
| 672 | } |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 673 | #endif /*CFG_SECSTOR_TA_MGMT_PTA*/ |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 674 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 675 | static void xtest_tee_test_1008(ADBG_Case_t *c) |
| 676 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 677 | TEEC_Session session = { }; |
| 678 | TEEC_Session session_crypt = { }; |
| 679 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 680 | |
| 681 | Do_ADBG_BeginSubCase(c, "Invoke command"); |
| 682 | { |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 683 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 684 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 685 | NULL, &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 686 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 687 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 688 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CLIENT, |
| 689 | NULL, &ret_orig)); |
| 690 | TEEC_CloseSession(&session); |
| 691 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 692 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 693 | } |
| 694 | Do_ADBG_EndSubCase(c, "Invoke command"); |
| 695 | |
| 696 | Do_ADBG_BeginSubCase(c, "Invoke command with timeout"); |
| 697 | { |
| 698 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 699 | |
| 700 | op.params[0].value.a = 2000; |
| 701 | op.paramTypes = TEEC_PARAM_TYPES( |
| 702 | TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 703 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 704 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 705 | xtest_teec_open_session(&session, |
| 706 | &os_test_ta_uuid, |
| 707 | NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 708 | &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 709 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 710 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 711 | TEEC_InvokeCommand(&session, |
| 712 | TA_OS_TEST_CMD_CLIENT_WITH_TIMEOUT, |
| 713 | &op, &ret_orig)); |
| 714 | TEEC_CloseSession(&session); |
| 715 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 716 | } |
| 717 | Do_ADBG_EndSubCase(c, "Invoke command with timeout"); |
| 718 | |
| 719 | Do_ADBG_BeginSubCase(c, "Create session fail"); |
| 720 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 721 | size_t n = 0; |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 722 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 723 | (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC, |
| 724 | xtest_teec_open_session(&session_crypt, |
| 725 | &create_fail_test_ta_uuid, NULL, |
| 726 | &ret_orig)); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 727 | /* |
| 728 | * Run this several times to see that there's no memory leakage. |
| 729 | */ |
| 730 | for (n = 0; n < 100; n++) { |
| 731 | Do_ADBG_Log("n = %zu", n); |
| 732 | (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC, |
| 733 | xtest_teec_open_session(&session_crypt, |
| 734 | &create_fail_test_ta_uuid, |
| 735 | NULL, &ret_orig)); |
| 736 | } |
| 737 | } |
| 738 | Do_ADBG_EndSubCase(c, "Create session fail"); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 739 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 740 | #ifdef CFG_SECSTOR_TA_MGMT_PTA |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 741 | Do_ADBG_BeginSubCase(c, "Load corrupt TA"); |
| 742 | ADBG_EXPECT_TRUE(c, |
| 743 | load_corrupt_ta(c, offsetof(struct shdr, magic), 1)); |
| 744 | ADBG_EXPECT_TRUE(c, |
| 745 | load_corrupt_ta(c, offsetof(struct shdr, img_type), 1)); |
| 746 | ADBG_EXPECT_TRUE(c, |
| 747 | load_corrupt_ta(c, offsetof(struct shdr, img_size), 1)); |
| 748 | ADBG_EXPECT_TRUE(c, |
| 749 | load_corrupt_ta(c, offsetof(struct shdr, algo), 1)); |
| 750 | ADBG_EXPECT_TRUE(c, |
| 751 | load_corrupt_ta(c, offsetof(struct shdr, hash_size), 1)); |
| 752 | ADBG_EXPECT_TRUE(c, |
| 753 | load_corrupt_ta(c, offsetof(struct shdr, sig_size), 1)); |
| 754 | ADBG_EXPECT_TRUE(c, |
| 755 | load_corrupt_ta(c, sizeof(struct shdr), 1)); /* hash */ |
| 756 | ADBG_EXPECT_TRUE(c, |
| 757 | load_corrupt_ta(c, sizeof(struct shdr) + 32, 1)); /* sig */ |
| 758 | ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 3000, 1)); /* payload */ |
Jerome Forissier | 895c5ca | 2019-02-28 17:27:46 +0100 | [diff] [blame] | 759 | ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 8000, 1)); /* payload */ |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 760 | Do_ADBG_EndSubCase(c, "Load corrupt TA"); |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 761 | #endif /*CFG_SECSTOR_TA_MGMT_PTA*/ |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 762 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 763 | ADBG_CASE_DEFINE(regression, 1008, xtest_tee_test_1008, |
| 764 | "TEE internal client API"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 765 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 766 | static void *cancellation_thread(void *arg) |
| 767 | { |
| 768 | /* |
| 769 | * Sleep 0.5 seconds before cancellation to make sure that the other |
| 770 | * thread is in RPC_WAIT. |
| 771 | */ |
| 772 | (void)usleep(500000); |
| 773 | TEEC_RequestCancellation(arg); |
| 774 | return NULL; |
| 775 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 776 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 777 | static void xtest_tee_test_1009_subcase(ADBG_Case_t *c, const char *subcase, |
| 778 | uint32_t timeout, bool cancel) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 779 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 780 | TEEC_Session session = { }; |
| 781 | uint32_t ret_orig = 0; |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 782 | pthread_t thr; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 783 | |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 784 | memset(&thr, 0, sizeof(thr)); |
| 785 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 786 | Do_ADBG_BeginSubCase(c, "%s", subcase); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 787 | { |
| 788 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 789 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 790 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
| 791 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 792 | NULL, &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 793 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 794 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, |
| 795 | TEEC_ORIGIN_TRUSTED_APP, |
| 796 | ret_orig); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 797 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 798 | op.params[0].value.a = timeout; |
| 799 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 800 | TEEC_NONE, |
| 801 | TEEC_NONE, TEEC_NONE); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 802 | if (cancel) { |
| 803 | (void)ADBG_EXPECT(c, 0, |
| 804 | pthread_create(&thr, NULL, |
| 805 | cancellation_thread, &op)); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 806 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 807 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 808 | TEEC_ERROR_CANCEL, |
| 809 | TEEC_InvokeCommand(&session, |
| 810 | TA_OS_TEST_CMD_WAIT, |
| 811 | &op, |
| 812 | &ret_orig)); |
| 813 | } else |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 814 | |
| 815 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 816 | TEEC_InvokeCommand(&session, |
| 817 | TA_OS_TEST_CMD_WAIT, |
| 818 | &op, |
| 819 | &ret_orig)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 820 | if (cancel) |
| 821 | (void)ADBG_EXPECT(c, 0, pthread_join(thr, NULL)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 822 | |
| 823 | TEEC_CloseSession(&session); |
| 824 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 825 | } |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 826 | Do_ADBG_EndSubCase(c, "%s", subcase); |
| 827 | } |
| 828 | |
| 829 | static void xtest_tee_test_1009(ADBG_Case_t *c) |
| 830 | { |
| 831 | xtest_tee_test_1009_subcase(c, "TEE Wait 0.1s", 100, false); |
| 832 | xtest_tee_test_1009_subcase(c, "TEE Wait 0.5s", 500, false); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 833 | xtest_tee_test_1009_subcase(c, "TEE Wait 2s cancel", 2000, true); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 834 | xtest_tee_test_1009_subcase(c, "TEE Wait 2s", 2000, false); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 835 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 836 | ADBG_CASE_DEFINE(regression, 1009, xtest_tee_test_1009, "TEE Wait"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 837 | |
| 838 | static void xtest_tee_test_1010(ADBG_Case_t *c) |
| 839 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 840 | unsigned int n = 0; |
| 841 | unsigned int idx = 0; |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 842 | size_t memref_sz[] = { 1024, 65536 }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 843 | |
| 844 | for (n = 1; n <= 5; n++) { |
| 845 | Do_ADBG_BeginSubCase(c, "Invalid memory access %u", n); |
| 846 | xtest_tee_test_invalid_mem_access(c, n); |
| 847 | Do_ADBG_EndSubCase(c, "Invalid memory access %u", n); |
| 848 | } |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 849 | |
| 850 | for (idx = 0; idx < ARRAY_SIZE(memref_sz); idx++) { |
| 851 | for (n = 1; n <= 5; n++) { |
| 852 | Do_ADBG_BeginSubCase(c, |
Igor Opaniuk | e8236ac | 2018-02-12 12:26:25 +0200 | [diff] [blame] | 853 | "Invalid memory access %u with %zu bytes memref", |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 854 | n, memref_sz[idx]); |
| 855 | xtest_tee_test_invalid_mem_access2(c, n, memref_sz[idx]); |
| 856 | Do_ADBG_EndSubCase(c, |
Igor Opaniuk | e8236ac | 2018-02-12 12:26:25 +0200 | [diff] [blame] | 857 | "Invalid memory access %u with %zu bytes memref", |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 858 | n, memref_sz[idx]); |
| 859 | } |
| 860 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 861 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 862 | ADBG_CASE_DEFINE(regression, 1010, xtest_tee_test_1010, |
| 863 | "Invalid memory access"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 864 | |
| 865 | static void xtest_tee_test_1011(ADBG_Case_t *c) |
| 866 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 867 | TEEC_Session session = { }; |
| 868 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 869 | struct xtest_crypto_session cs = { |
| 870 | c, &session, TA_RPC_CMD_CRYPT_SHA256, |
| 871 | TA_RPC_CMD_CRYPT_AES256ECB_ENC, |
| 872 | TA_RPC_CMD_CRYPT_AES256ECB_DEC |
| 873 | }; |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 874 | struct xtest_crypto_session cs_privmem = { |
| 875 | c, &session, |
| 876 | TA_RPC_CMD_CRYPT_PRIVMEM_SHA256, |
| 877 | TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_ENC, |
| 878 | TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_DEC |
| 879 | }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 880 | TEEC_UUID uuid = rpc_test_ta_uuid; |
| 881 | |
| 882 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 883 | xtest_teec_open_session(&session, &uuid, NULL, &ret_orig))) |
| 884 | return; |
| 885 | |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 886 | Do_ADBG_BeginSubCase(c, "TA-to-TA via non-secure shared memory"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 887 | /* |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 888 | * Run the "complete crypto test suite" using TA-to-TA |
| 889 | * communication |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 890 | */ |
| 891 | xtest_crypto_test(&cs); |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 892 | Do_ADBG_EndSubCase(c, "TA-to-TA via non-secure shared memory"); |
| 893 | |
| 894 | Do_ADBG_BeginSubCase(c, "TA-to-TA via TA private memory"); |
| 895 | /* |
| 896 | * Run the "complete crypto test suite" using TA-to-TA |
| 897 | * communication via TA private memory. |
| 898 | */ |
| 899 | xtest_crypto_test(&cs_privmem); |
| 900 | Do_ADBG_EndSubCase(c, "TA-to-TA via TA private memory"); |
| 901 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 902 | TEEC_CloseSession(&session); |
| 903 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 904 | ADBG_CASE_DEFINE(regression, 1011, xtest_tee_test_1011, |
| 905 | "Test TA-to-TA features with User Crypt TA"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 906 | |
| 907 | /* |
| 908 | * Note that this test is failing when |
| 909 | * - running twice in a raw |
| 910 | * - and the user TA is statically linked |
| 911 | * This is because the counter is not reseted when opening the first session |
| 912 | * in case the TA is statically linked |
| 913 | */ |
| 914 | static void xtest_tee_test_1012(ADBG_Case_t *c) |
| 915 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 916 | TEEC_Session session1 = { }; |
| 917 | TEEC_Session session2 = { }; |
| 918 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 919 | TEEC_UUID uuid = sims_test_ta_uuid; |
| 920 | |
| 921 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Session"); |
| 922 | { |
| 923 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 924 | static const uint8_t in[] = { |
| 925 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 926 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 927 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 928 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 929 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 930 | uint8_t out[32] = { }; |
| 931 | int i = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 932 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 933 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 934 | xtest_teec_open_session(&session1, &uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 935 | &ret_orig))) |
| 936 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 937 | |
| 938 | op.params[0].value.a = 0; |
| 939 | op.params[1].tmpref.buffer = (void *)in; |
| 940 | op.params[1].tmpref.size = sizeof(in); |
| 941 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 942 | TEEC_MEMREF_TEMP_INPUT, |
| 943 | TEEC_NONE, TEEC_NONE); |
| 944 | |
| 945 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 946 | TEEC_InvokeCommand(&session1, TA_SIMS_CMD_WRITE, &op, |
| 947 | &ret_orig)); |
| 948 | |
Jerome Forissier | 3cc0a42 | 2017-12-14 09:53:24 +0100 | [diff] [blame] | 949 | for (i = 1; i < 3; i++) { |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 950 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 951 | xtest_teec_open_session(&session2, &uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 952 | &ret_orig))) |
| 953 | continue; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 954 | |
| 955 | op.params[0].value.a = 0; |
| 956 | op.params[1].tmpref.buffer = out; |
| 957 | op.params[1].tmpref.size = sizeof(out); |
| 958 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 959 | TEEC_MEMREF_TEMP_OUTPUT, |
| 960 | TEEC_NONE, TEEC_NONE); |
| 961 | |
| 962 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 963 | TEEC_InvokeCommand(&session2, TA_SIMS_CMD_READ, |
| 964 | &op, &ret_orig)); |
| 965 | |
| 966 | if (!ADBG_EXPECT_BUFFER(c, in, sizeof(in), out, |
| 967 | sizeof(out))) { |
| 968 | Do_ADBG_Log("in:"); |
| 969 | Do_ADBG_HexLog(in, sizeof(in), 16); |
| 970 | Do_ADBG_Log("out:"); |
| 971 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 972 | } |
| 973 | |
| 974 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, |
| 975 | TEEC_NONE, TEEC_NONE, |
| 976 | TEEC_NONE); |
| 977 | |
| 978 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 979 | TEEC_InvokeCommand(&session1, |
| 980 | TA_SIMS_CMD_GET_COUNTER, |
| 981 | &op, &ret_orig)); |
| 982 | |
| 983 | (void)ADBG_EXPECT(c, 0, op.params[0].value.a); |
| 984 | |
| 985 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 986 | TEEC_InvokeCommand(&session2, |
| 987 | TA_SIMS_CMD_GET_COUNTER, &op, |
| 988 | &ret_orig)); |
| 989 | |
| 990 | (void)ADBG_EXPECT(c, i, op.params[0].value.a); |
| 991 | TEEC_CloseSession(&session2); |
| 992 | } |
| 993 | |
| 994 | memset(out, 0, sizeof(out)); |
| 995 | op.params[0].value.a = 0; |
| 996 | op.params[1].tmpref.buffer = out; |
| 997 | op.params[1].tmpref.size = sizeof(out); |
| 998 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 999 | TEEC_MEMREF_TEMP_OUTPUT, |
| 1000 | TEEC_NONE, TEEC_NONE); |
| 1001 | |
| 1002 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1003 | TEEC_InvokeCommand(&session1, TA_SIMS_CMD_READ, &op, |
| 1004 | &ret_orig)); |
| 1005 | |
| 1006 | if (!ADBG_EXPECT(c, 0, memcmp(in, out, sizeof(in)))) { |
| 1007 | Do_ADBG_Log("in:"); |
| 1008 | Do_ADBG_HexLog(in, sizeof(in), 16); |
| 1009 | Do_ADBG_Log("out:"); |
| 1010 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 1011 | } |
| 1012 | |
| 1013 | TEEC_CloseSession(&session1); |
| 1014 | } |
Ovidiu Mihalachi | 3e6183e | 2019-04-25 10:23:21 +0300 | [diff] [blame] | 1015 | Do_ADBG_EndSubCase(c, "Single Instance Multi Session"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1016 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1017 | ADBG_CASE_DEFINE(regression, 1012, xtest_tee_test_1012, |
| 1018 | "Test Single Instance Multi Session features with SIMS TA"); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1019 | |
| 1020 | struct test_1013_thread_arg { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1021 | const TEEC_UUID *uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1022 | uint32_t cmd; |
| 1023 | uint32_t repeat; |
| 1024 | TEEC_SharedMemory *shm; |
| 1025 | uint32_t error_orig; |
| 1026 | TEEC_Result res; |
| 1027 | uint32_t max_concurrency; |
| 1028 | const uint8_t *in; |
| 1029 | size_t in_len; |
| 1030 | uint8_t *out; |
| 1031 | size_t out_len; |
| 1032 | }; |
| 1033 | |
| 1034 | static void *test_1013_thread(void *arg) |
| 1035 | { |
| 1036 | struct test_1013_thread_arg *a = arg; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1037 | TEEC_Session session = { }; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1038 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1039 | uint8_t p2 = TEEC_NONE; |
| 1040 | uint8_t p3 = TEEC_NONE; |
| 1041 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1042 | a->res = xtest_teec_open_session(&session, a->uuid, NULL, |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1043 | &a->error_orig); |
| 1044 | if (a->res != TEEC_SUCCESS) |
| 1045 | return NULL; |
| 1046 | |
| 1047 | op.params[0].memref.parent = a->shm; |
| 1048 | op.params[0].memref.size = a->shm->size; |
| 1049 | op.params[0].memref.offset = 0; |
| 1050 | op.params[1].value.a = a->repeat; |
| 1051 | op.params[1].value.b = 0; |
| 1052 | op.params[2].tmpref.buffer = (void *)a->in; |
| 1053 | op.params[2].tmpref.size = a->in_len; |
| 1054 | op.params[3].tmpref.buffer = a->out; |
| 1055 | op.params[3].tmpref.size = a->out_len; |
| 1056 | |
| 1057 | if (a->in_len) |
| 1058 | p2 = TEEC_MEMREF_TEMP_INPUT; |
| 1059 | if (a->out_len) |
| 1060 | p3 = TEEC_MEMREF_TEMP_OUTPUT; |
| 1061 | |
| 1062 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, |
| 1063 | TEEC_VALUE_INOUT, p2, p3); |
| 1064 | |
| 1065 | a->res = TEEC_InvokeCommand(&session, a->cmd, &op, &a->error_orig); |
| 1066 | a->max_concurrency = op.params[1].value.b; |
| 1067 | a->out_len = op.params[3].tmpref.size; |
| 1068 | TEEC_CloseSession(&session); |
| 1069 | return NULL; |
| 1070 | } |
| 1071 | |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1072 | #define NUM_THREADS 3 |
| 1073 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1074 | static void xtest_tee_test_1013_single(ADBG_Case_t *c, double *mean_concurrency, |
| 1075 | const TEEC_UUID *uuid) |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1076 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1077 | size_t nt = 0; |
| 1078 | size_t n = 0; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1079 | size_t repeat = 1000; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1080 | TEEC_SharedMemory shm = { }; |
| 1081 | size_t max_concurrency = 0; |
| 1082 | struct test_1013_thread_arg arg[NUM_THREADS] = { }; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1083 | static const uint8_t sha256_in[] = { 'a', 'b', 'c' }; |
| 1084 | static const uint8_t sha256_out[] = { |
| 1085 | 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, |
| 1086 | 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, |
| 1087 | 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, |
| 1088 | 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad |
| 1089 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1090 | uint8_t out[32] = { }; |
| 1091 | pthread_t thr[NUM_THREADS] = { }; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1092 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1093 | Do_ADBG_BeginSubCase(c, "Busy loop repeat %zu", repeat * 10); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1094 | *mean_concurrency = 0; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1095 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1096 | shm.size = sizeof(struct ta_concurrent_shm); |
| 1097 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1098 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1099 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 1100 | return; |
| 1101 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1102 | memset(shm.buffer, 0, shm.size); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1103 | max_concurrency = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1104 | nt = NUM_THREADS; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1105 | |
| 1106 | for (n = 0; n < nt; n++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1107 | arg[n].uuid = uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1108 | arg[n].cmd = TA_CONCURRENT_CMD_BUSY_LOOP; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1109 | arg[n].repeat = repeat * 10; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1110 | arg[n].shm = &shm; |
| 1111 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 1112 | test_1013_thread, arg + n))) |
| 1113 | nt = n; /* break loop and start cleanup */ |
| 1114 | } |
| 1115 | |
| 1116 | for (n = 0; n < nt; n++) { |
| 1117 | ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)); |
| 1118 | ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res); |
| 1119 | if (arg[n].max_concurrency > max_concurrency) |
| 1120 | max_concurrency = arg[n].max_concurrency; |
| 1121 | } |
| 1122 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1123 | /* |
| 1124 | * Concurrency can be limited by several factors, for instance in a |
| 1125 | * single CPU system it's dependent on the Preemtion Model used by |
| 1126 | * the kernel (Preemptible Kernel (Low-Latency Desktop) gives the |
| 1127 | * best result there). |
| 1128 | */ |
| 1129 | (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, >, 0); |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1130 | (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, <=, NUM_THREADS); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1131 | *mean_concurrency += max_concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1132 | Do_ADBG_EndSubCase(c, "Busy loop repeat %zu", repeat * 10); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1133 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1134 | Do_ADBG_BeginSubCase(c, "SHA-256 loop repeat %zu", repeat); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1135 | memset(shm.buffer, 0, shm.size); |
| 1136 | memset(arg, 0, sizeof(arg)); |
| 1137 | max_concurrency = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1138 | nt = NUM_THREADS; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1139 | |
| 1140 | for (n = 0; n < nt; n++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1141 | arg[n].uuid = uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1142 | arg[n].cmd = TA_CONCURRENT_CMD_SHA256; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1143 | arg[n].repeat = repeat; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1144 | arg[n].shm = &shm; |
| 1145 | arg[n].in = sha256_in; |
| 1146 | arg[n].in_len = sizeof(sha256_in); |
| 1147 | arg[n].out = out; |
| 1148 | arg[n].out_len = sizeof(out); |
| 1149 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 1150 | test_1013_thread, arg + n))) |
| 1151 | nt = n; /* break loop and start cleanup */ |
| 1152 | } |
| 1153 | |
| 1154 | for (n = 0; n < nt; n++) { |
| 1155 | if (ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)) && |
| 1156 | ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res)) |
| 1157 | ADBG_EXPECT_BUFFER(c, sha256_out, sizeof(sha256_out), |
| 1158 | arg[n].out, arg[n].out_len); |
| 1159 | if (arg[n].max_concurrency > max_concurrency) |
| 1160 | max_concurrency = arg[n].max_concurrency; |
| 1161 | } |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1162 | *mean_concurrency += max_concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1163 | Do_ADBG_EndSubCase(c, "SHA-256 loop repeat %zu", repeat); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1164 | |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1165 | *mean_concurrency /= 2.0; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1166 | TEEC_ReleaseSharedMemory(&shm); |
| 1167 | } |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1168 | |
| 1169 | static void xtest_tee_test_1013(ADBG_Case_t *c) |
| 1170 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1171 | int i = 0; |
| 1172 | double mean_concurrency = 0; |
| 1173 | double concurrency = 0; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1174 | int nb_loops = 24; |
Jens Wiklander | 6a9d15a | 2016-02-01 10:29:42 +0100 | [diff] [blame] | 1175 | |
| 1176 | if (level == 0) |
| 1177 | nb_loops /= 2; |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1178 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1179 | Do_ADBG_BeginSubCase(c, "Using small concurrency TA"); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1180 | mean_concurrency = 0; |
| 1181 | for (i = 0; i < nb_loops; i++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1182 | xtest_tee_test_1013_single(c, &concurrency, |
| 1183 | &concurrent_ta_uuid); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1184 | mean_concurrency += concurrency; |
| 1185 | } |
| 1186 | mean_concurrency /= nb_loops; |
| 1187 | |
| 1188 | Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS); |
| 1189 | Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency); |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1190 | Do_ADBG_EndSubCase(c, "Using small concurrency TA"); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1191 | |
Jens Wiklander | c9d7b24 | 2016-06-28 18:35:08 +0200 | [diff] [blame] | 1192 | #ifndef CFG_PAGED_USER_TA |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1193 | Do_ADBG_BeginSubCase(c, "Using large concurrency TA"); |
| 1194 | mean_concurrency = 0; |
| 1195 | for (i = 0; i < nb_loops; i++) { |
| 1196 | xtest_tee_test_1013_single(c, &concurrency, |
| 1197 | &concurrent_large_ta_uuid); |
| 1198 | mean_concurrency += concurrency; |
| 1199 | } |
| 1200 | mean_concurrency /= nb_loops; |
| 1201 | |
| 1202 | Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS); |
| 1203 | Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency); |
| 1204 | Do_ADBG_EndSubCase(c, "Using large concurrency TA"); |
Jens Wiklander | c9d7b24 | 2016-06-28 18:35:08 +0200 | [diff] [blame] | 1205 | #endif |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1206 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1207 | ADBG_CASE_DEFINE(regression, 1013, xtest_tee_test_1013, |
| 1208 | "Test concurency with concurrent TA"); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1209 | |
| 1210 | #ifdef CFG_SECURE_DATA_PATH |
| 1211 | static void xtest_tee_test_1014(ADBG_Case_t *c) |
| 1212 | { |
| 1213 | UNUSED(c); |
| 1214 | |
| 1215 | int size = 17000; |
| 1216 | int loop = 10; |
| 1217 | int ion_heap = DEFAULT_ION_HEAP_TYPE; |
| 1218 | int rnd_offset = 1; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1219 | int test = 0; |
| 1220 | int ret = 0; |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1221 | |
| 1222 | test = TEST_NS_TO_TA; |
| 1223 | Do_ADBG_BeginSubCase(c, "SDP: NonSecure client invokes a SDP TA"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1224 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1225 | ADBG_EXPECT(c, 0, ret); |
| 1226 | Do_ADBG_EndSubCase(c, "SDP: NonSecure client invokes a SDP TA"); |
| 1227 | |
| 1228 | test = TEST_TA_TO_TA; |
| 1229 | Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP TA"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1230 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1231 | ADBG_EXPECT(c, 0, ret); |
| 1232 | Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP TA"); |
| 1233 | |
| 1234 | test = TEST_TA_TO_PTA; |
| 1235 | Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP pTA"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1236 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1237 | ADBG_EXPECT(c, 0, ret); |
| 1238 | Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP pTA"); |
| 1239 | |
| 1240 | test = TEST_NS_TO_PTA; |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 1241 | Do_ADBG_BeginSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1242 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1243 | ADBG_EXPECT(c, 1, ret); |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 1244 | Do_ADBG_EndSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)"); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1245 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1246 | ADBG_CASE_DEFINE(regression, 1014, xtest_tee_test_1014, |
| 1247 | "Test secure data path against SDP TAs and pTAs"); |
| 1248 | #endif /*CFG_SECURE_DATA_PATH*/ |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1249 | |
| 1250 | static void xtest_tee_test_1015(ADBG_Case_t *c) |
| 1251 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1252 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1253 | TEEC_Session session = { }; |
| 1254 | uint32_t ret_orig = 0; |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1255 | |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1256 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1257 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 1258 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1259 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 1260 | Do_ADBG_Log(" - 1015 - skip test, pseudo TA not found"); |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1261 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1262 | } |
| 1263 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1264 | |
| 1265 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1266 | TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_FS_HTREE, |
| 1267 | NULL, &ret_orig)); |
| 1268 | TEEC_CloseSession(&session); |
| 1269 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1270 | ADBG_CASE_DEFINE(regression, 1015, xtest_tee_test_1015, |
| 1271 | "FS hash-tree corner cases"); |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1272 | |
| 1273 | static void xtest_tee_test_1016(ADBG_Case_t *c) |
| 1274 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1275 | TEEC_Session session = { }; |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1276 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1277 | uint32_t ret_orig = 0; |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1278 | |
| 1279 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1280 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1281 | &ret_orig))) |
| 1282 | return; |
| 1283 | |
| 1284 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, |
| 1285 | TEEC_NONE); |
| 1286 | |
| 1287 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1288 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TA2TA_MEMREF, &op, |
| 1289 | &ret_orig)); |
| 1290 | |
| 1291 | TEEC_CloseSession(&session); |
| 1292 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1293 | ADBG_CASE_DEFINE(regression, 1016, xtest_tee_test_1016, |
| 1294 | "Test TA to TA transfers (in/out/inout memrefs on the stack)"); |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1295 | |
| 1296 | static void xtest_tee_test_1017(ADBG_Case_t *c) |
| 1297 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1298 | TEEC_Session session = { }; |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1299 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1300 | uint32_t ret_orig = 0; |
| 1301 | TEEC_SharedMemory shm = { }; |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1302 | size_t page_size = 4096; |
| 1303 | |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1304 | shm.size = 8 * page_size; |
| 1305 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1306 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1307 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 1308 | return; |
| 1309 | |
| 1310 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1311 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1312 | &ret_orig))) |
| 1313 | goto out; |
| 1314 | |
| 1315 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, |
| 1316 | TEEC_MEMREF_PARTIAL_INPUT, |
| 1317 | TEEC_MEMREF_PARTIAL_OUTPUT, |
| 1318 | TEEC_MEMREF_PARTIAL_OUTPUT); |
| 1319 | |
| 1320 | /* |
| 1321 | * The first two memrefs are supposed to be combined into in |
| 1322 | * region and the last two memrefs should have one region each |
| 1323 | * when the parameters are mapped for the TA. |
| 1324 | */ |
| 1325 | op.params[0].memref.parent = &shm; |
| 1326 | op.params[0].memref.size = page_size; |
| 1327 | op.params[0].memref.offset = 0; |
| 1328 | |
| 1329 | op.params[1].memref.parent = &shm; |
| 1330 | op.params[1].memref.size = page_size; |
| 1331 | op.params[1].memref.offset = page_size; |
| 1332 | |
| 1333 | op.params[2].memref.parent = &shm; |
| 1334 | op.params[2].memref.size = page_size; |
| 1335 | op.params[2].memref.offset = 4 * page_size; |
| 1336 | |
| 1337 | op.params[3].memref.parent = &shm; |
| 1338 | op.params[3].memref.size = 2 * page_size; |
| 1339 | op.params[3].memref.offset = 6 * page_size; |
| 1340 | |
| 1341 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1342 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PARAMS, &op, |
| 1343 | &ret_orig)); |
| 1344 | |
| 1345 | TEEC_CloseSession(&session); |
| 1346 | out: |
| 1347 | TEEC_ReleaseSharedMemory(&shm); |
| 1348 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1349 | ADBG_CASE_DEFINE(regression, 1017, xtest_tee_test_1017, |
| 1350 | "Test coalescing memrefs"); |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1351 | |
| 1352 | static void xtest_tee_test_1018(ADBG_Case_t *c) |
| 1353 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1354 | TEEC_Session session = { }; |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1355 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1356 | uint32_t ret_orig = 0; |
| 1357 | TEEC_SharedMemory shm = { }; |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1358 | size_t page_size = 4096; |
| 1359 | |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1360 | shm.size = 8 * page_size; |
| 1361 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1362 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1363 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 1364 | return; |
| 1365 | |
| 1366 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1367 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1368 | &ret_orig))) |
| 1369 | goto out; |
| 1370 | |
| 1371 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, |
| 1372 | TEEC_MEMREF_PARTIAL_INPUT, |
| 1373 | TEEC_MEMREF_PARTIAL_OUTPUT, |
| 1374 | TEEC_MEMREF_PARTIAL_OUTPUT); |
| 1375 | |
| 1376 | /* |
| 1377 | * The first two memrefs are supposed to be combined into in |
| 1378 | * region and the last two memrefs should have one region each |
| 1379 | * when the parameters are mapped for the TA. |
| 1380 | */ |
| 1381 | op.params[0].memref.parent = &shm; |
| 1382 | op.params[0].memref.size = page_size; |
| 1383 | op.params[0].memref.offset = 0; |
| 1384 | |
| 1385 | op.params[1].memref.parent = &shm; |
| 1386 | op.params[1].memref.size = page_size; |
| 1387 | op.params[1].memref.offset = page_size; |
| 1388 | |
| 1389 | op.params[2].memref.parent = &shm; |
| 1390 | op.params[2].memref.size = page_size; |
| 1391 | op.params[2].memref.offset = 4 * page_size; |
| 1392 | |
| 1393 | op.params[3].memref.parent = &shm; |
| 1394 | op.params[3].memref.size = 3 * page_size; |
| 1395 | op.params[3].memref.offset = 6 * page_size; |
| 1396 | |
| 1397 | /* |
| 1398 | * Depending on the tee driver we may have different error codes. |
| 1399 | * What's most important is that secure world doesn't panic and |
| 1400 | * that someone detects an error. |
| 1401 | */ |
| 1402 | ADBG_EXPECT_NOT(c, TEE_SUCCESS, |
| 1403 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PARAMS, &op, |
| 1404 | &ret_orig)); |
| 1405 | |
| 1406 | TEEC_CloseSession(&session); |
| 1407 | out: |
| 1408 | TEEC_ReleaseSharedMemory(&shm); |
| 1409 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1410 | ADBG_CASE_DEFINE(regression, 1018, xtest_tee_test_1018, |
| 1411 | "Test memref out of bounds"); |
Jerome Forissier | 53bde72 | 2018-05-31 09:14:54 +0200 | [diff] [blame] | 1412 | |
Victor Chong | 3ff36f5 | 2018-06-07 04:37:00 +0100 | [diff] [blame] | 1413 | #if defined(CFG_TA_DYNLINK) |
Jerome Forissier | 53bde72 | 2018-05-31 09:14:54 +0200 | [diff] [blame] | 1414 | static void xtest_tee_test_1019(ADBG_Case_t *c) |
| 1415 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1416 | TEEC_Session session = { }; |
| 1417 | uint32_t ret_orig = 0; |
Jerome Forissier | 53bde72 | 2018-05-31 09:14:54 +0200 | [diff] [blame] | 1418 | |
| 1419 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1420 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1421 | &ret_orig))) |
| 1422 | return; |
| 1423 | |
| 1424 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1425 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB, NULL, |
| 1426 | &ret_orig)); |
| 1427 | |
| 1428 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 1429 | TEEC_ERROR_TARGET_DEAD, |
| 1430 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_PANIC, |
| 1431 | NULL, &ret_orig)); |
| 1432 | |
| 1433 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 1434 | |
| 1435 | TEEC_CloseSession(&session); |
| 1436 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1437 | ADBG_CASE_DEFINE(regression, 1019, xtest_tee_test_1019, |
| 1438 | "Test dynamically linked TA"); |
| 1439 | #endif /*CFG_TA_DYNLINK*/ |
Jerome Forissier | 3357f87 | 2018-10-05 15:13:44 +0200 | [diff] [blame] | 1440 | |
| 1441 | static void xtest_tee_test_1020(ADBG_Case_t *c) |
| 1442 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1443 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1444 | TEEC_Session session = { }; |
| 1445 | uint32_t ret_orig = 0; |
Jerome Forissier | 3357f87 | 2018-10-05 15:13:44 +0200 | [diff] [blame] | 1446 | |
| 1447 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
| 1448 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 1449 | &ret_orig); |
| 1450 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 1451 | Do_ADBG_Log(" - 1020 - skip test, pseudo TA not found"); |
| 1452 | return; |
| 1453 | } |
| 1454 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 1455 | |
| 1456 | res = TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_LOCKDEP, |
| 1457 | NULL, &ret_orig); |
| 1458 | if (res != TEEC_SUCCESS) { |
| 1459 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TRUSTED_APP, |
| 1460 | ret_orig); |
| 1461 | if (res == TEEC_ERROR_NOT_SUPPORTED) { |
| 1462 | Do_ADBG_Log(" - 1020 - skip test, feature not " |
| 1463 | "implemented"); |
| 1464 | goto out; |
| 1465 | } |
| 1466 | /* Error */ |
| 1467 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 1468 | } |
| 1469 | out: |
| 1470 | TEEC_CloseSession(&session); |
| 1471 | } |
| 1472 | ADBG_CASE_DEFINE(regression, 1020, xtest_tee_test_1020, |
| 1473 | "Test lockdep algorithm"); |
Ovidiu Mihalachi | 15cecff | 2019-04-02 16:36:31 +0300 | [diff] [blame^] | 1474 | |
| 1475 | static TEEC_Result open_sec_session(TEEC_Session *session, |
| 1476 | const TEEC_UUID *uuid) |
| 1477 | { |
| 1478 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1479 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1480 | uint32_t ret_orig = 0; |
| 1481 | |
| 1482 | op.params[0].tmpref.buffer = (void *)uuid; |
| 1483 | op.params[0].tmpref.size = sizeof(*uuid); |
| 1484 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 1485 | TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 1486 | |
| 1487 | res = TEEC_InvokeCommand(session, TA_SIMS_OPEN_TA_SESSION, |
| 1488 | &op, &ret_orig); |
| 1489 | if (res != TEEC_SUCCESS) |
| 1490 | return TEEC_ERROR_GENERIC; |
| 1491 | |
| 1492 | return res; |
| 1493 | } |
| 1494 | |
| 1495 | static TEEC_Result sims_get_counter(TEEC_Session *session, |
| 1496 | uint32_t *counter) |
| 1497 | { |
| 1498 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1499 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1500 | uint32_t ret_orig = 0; |
| 1501 | |
| 1502 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, |
| 1503 | TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 1504 | |
| 1505 | res = TEEC_InvokeCommand(session, TA_SIMS_CMD_GET_COUNTER, |
| 1506 | &op, &ret_orig); |
| 1507 | if (res == TEEC_SUCCESS) |
| 1508 | *counter = op.params[0].value.a; |
| 1509 | |
| 1510 | return res; |
| 1511 | } |
| 1512 | |
| 1513 | static TEEC_Result trigger_panic(TEEC_Session *session, |
| 1514 | const TEEC_UUID *uuid) |
| 1515 | { |
| 1516 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1517 | uint32_t ret_orig = 0; |
| 1518 | |
| 1519 | if (!uuid) { |
| 1520 | op.params[0].tmpref.buffer = NULL; |
| 1521 | op.params[0].tmpref.size = 0; |
| 1522 | } else { |
| 1523 | op.params[0].tmpref.buffer = (void *)uuid; |
| 1524 | op.params[0].tmpref.size = sizeof(*uuid); |
| 1525 | } |
| 1526 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 1527 | TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 1528 | |
| 1529 | return TEEC_InvokeCommand(session, TA_SIMS_CMD_PANIC, |
| 1530 | &op, &ret_orig); |
| 1531 | } |
| 1532 | |
| 1533 | static void test_panic_ca_to_ta(ADBG_Case_t *c, const TEEC_UUID *uuid, |
| 1534 | bool multi_instance) |
| 1535 | { |
| 1536 | TEEC_Result exp_res = TEEC_ERROR_GENERIC; |
| 1537 | uint32_t counter = 0; |
| 1538 | uint32_t ret_orig = 0; |
| 1539 | uint32_t exp_counter = 0; |
| 1540 | TEEC_Session cs[3] = { }; |
| 1541 | |
| 1542 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1543 | xtest_teec_open_session(&cs[0], uuid, NULL, |
| 1544 | &ret_orig))) |
| 1545 | return; |
| 1546 | |
| 1547 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1548 | xtest_teec_open_session(&cs[1], uuid, NULL, |
| 1549 | &ret_orig))) |
| 1550 | goto bail0; |
| 1551 | |
| 1552 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter))) |
| 1553 | goto bail1; |
| 1554 | |
| 1555 | if (!ADBG_EXPECT(c, 0, counter)) |
| 1556 | goto bail1; |
| 1557 | |
| 1558 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[1], &counter))) |
| 1559 | goto bail1; |
| 1560 | |
| 1561 | exp_counter = multi_instance ? 0 : 1; |
| 1562 | if (ADBG_EXPECT(c, exp_counter, counter)) |
| 1563 | goto bail1; |
| 1564 | |
| 1565 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1566 | trigger_panic(&cs[1], NULL))) |
| 1567 | goto bail1; |
| 1568 | |
| 1569 | exp_res = multi_instance ? TEEC_SUCCESS : TEEC_ERROR_TARGET_DEAD; |
| 1570 | if (!ADBG_EXPECT_TEEC_RESULT(c, exp_res, |
| 1571 | sims_get_counter(&cs[0], &counter))) |
| 1572 | goto bail1; |
| 1573 | |
| 1574 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1575 | sims_get_counter(&cs[1], &counter))) |
| 1576 | goto bail1; |
| 1577 | |
| 1578 | /* Attempt to open a session on panicked context */ |
| 1579 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1580 | xtest_teec_open_session(&cs[1], uuid, NULL, |
| 1581 | &ret_orig))) |
| 1582 | goto bail1; |
| 1583 | |
| 1584 | /* Sanity check of still valid TA context */ |
| 1585 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1586 | xtest_teec_open_session(&cs[2], uuid, NULL, |
| 1587 | &ret_orig))) |
| 1588 | goto bail1; |
| 1589 | |
| 1590 | /* Sanity check of still valid TA context */ |
| 1591 | if (multi_instance) { |
| 1592 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1593 | sims_get_counter(&cs[0], &counter))) |
| 1594 | goto bail2; |
| 1595 | |
| 1596 | if (!ADBG_EXPECT(c, 0, counter)) |
| 1597 | goto bail2; |
| 1598 | } |
| 1599 | |
| 1600 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[2], &counter))) |
| 1601 | goto bail2; |
| 1602 | |
| 1603 | if (!ADBG_EXPECT(c, 0, counter)) |
| 1604 | goto bail2; |
| 1605 | |
| 1606 | bail2: |
| 1607 | TEEC_CloseSession(&cs[2]); |
| 1608 | bail1: |
| 1609 | TEEC_CloseSession(&cs[1]); |
| 1610 | bail0: |
| 1611 | TEEC_CloseSession(&cs[0]); |
| 1612 | } |
| 1613 | |
| 1614 | static void test_panic_ta_to_ta(ADBG_Case_t *c, const TEEC_UUID *uuid1, |
| 1615 | const TEEC_UUID *uuid2) |
| 1616 | { |
| 1617 | uint32_t ret_orig = 0; |
| 1618 | uint32_t counter = 0; |
| 1619 | TEEC_Session cs[3] = { }; |
| 1620 | |
| 1621 | /* Test pre-conditions */ |
| 1622 | /* 2.1 - CA opens a session toward TA1 */ |
| 1623 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1624 | xtest_teec_open_session(&cs[0], uuid1, NULL, |
| 1625 | &ret_orig))) |
| 1626 | return; |
| 1627 | |
| 1628 | /* 2.2 - CA opens a session toward TA2 */ |
| 1629 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1630 | xtest_teec_open_session(&cs[1], uuid2, NULL, |
| 1631 | &ret_orig))) |
| 1632 | goto bail0; |
| 1633 | |
| 1634 | /* 2.3 - TA1 opens a session toward TA2 */ |
| 1635 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, open_sec_session(&cs[0], uuid2))) |
| 1636 | goto bail1; |
| 1637 | |
| 1638 | /* 2.4 - CA invokes TA2 which panics */ |
| 1639 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1640 | trigger_panic(&cs[1], NULL))) |
| 1641 | goto bail1; |
| 1642 | |
| 1643 | /* Expected results */ |
| 1644 | /* 2.5 - Expect CA->TA1 session is still alive */ |
| 1645 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter))) |
| 1646 | goto bail1; |
| 1647 | |
| 1648 | /* 2.6 - Expect CA->TA2 session is properly released */ |
| 1649 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1650 | sims_get_counter(&cs[1], &counter))) |
| 1651 | goto bail1; |
| 1652 | |
| 1653 | bail1: |
| 1654 | TEEC_CloseSession(&cs[1]); |
| 1655 | bail0: |
| 1656 | TEEC_CloseSession(&cs[0]); |
| 1657 | |
| 1658 | memset(cs, 0, sizeof(cs)); |
| 1659 | |
| 1660 | /* Test pre-conditions */ |
| 1661 | /* 2.1 - CA opens a session toward TA1 */ |
| 1662 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1663 | xtest_teec_open_session(&cs[0], uuid1, NULL, |
| 1664 | &ret_orig))) |
| 1665 | return; |
| 1666 | |
| 1667 | /* 2.2 - CA opens a session toward TA2 */ |
| 1668 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1669 | xtest_teec_open_session(&cs[1], uuid2, NULL, |
| 1670 | &ret_orig))) |
| 1671 | goto bail2; |
| 1672 | |
| 1673 | /* 2.3 - TA1 opens a session toward TA2 */ |
| 1674 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, open_sec_session(&cs[0], uuid2))) |
| 1675 | goto bail3; |
| 1676 | |
| 1677 | /* 2.4 - CA invokes TA1 which invokes TA2 which panics */ |
| 1678 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, trigger_panic(&cs[0], uuid2))) |
| 1679 | goto bail3; |
| 1680 | |
| 1681 | /* Expected results */ |
| 1682 | /* 2.5 - Expect CA->TA1 session is still alive */ |
| 1683 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter))) |
| 1684 | goto bail3; |
| 1685 | |
| 1686 | /* 2.6 - Expect CA->TA2 session is properly released */ |
| 1687 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1688 | sims_get_counter(&cs[1], &counter))) |
| 1689 | goto bail3; |
| 1690 | |
| 1691 | bail3: |
| 1692 | TEEC_CloseSession(&cs[1]); |
| 1693 | bail2: |
| 1694 | TEEC_CloseSession(&cs[0]); |
| 1695 | } |
| 1696 | |
| 1697 | static void xtest_tee_test_1021(ADBG_Case_t *c) |
| 1698 | { |
| 1699 | Do_ADBG_BeginSubCase(c, "Multiple Instances Single Session"); |
| 1700 | test_panic_ca_to_ta(c, &miss_test_ta_uuid, true); |
| 1701 | Do_ADBG_EndSubCase(c, "Multiple Instances Single Session"); |
| 1702 | |
| 1703 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Sessions"); |
| 1704 | test_panic_ca_to_ta(c, &sims_test_ta_uuid, false); |
| 1705 | Do_ADBG_EndSubCase(c, "Single Instance Multi Sessions"); |
| 1706 | |
| 1707 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Sessions Keep Alive"); |
| 1708 | test_panic_ca_to_ta(c, &sims_keepalive_test_ta_uuid, false); |
| 1709 | Do_ADBG_EndSubCase(c, "Single Instance Multi Sessions Keep Alive"); |
| 1710 | |
| 1711 | Do_ADBG_BeginSubCase(c, "Multi Sessions TA to TA"); |
| 1712 | test_panic_ta_to_ta(c, &sims_test_ta_uuid, |
| 1713 | &sims_keepalive_test_ta_uuid); |
| 1714 | Do_ADBG_EndSubCase(c, "Multi Sessions TA to TA"); |
| 1715 | } |
| 1716 | ADBG_CASE_DEFINE(regression, 1021, xtest_tee_test_1021, |
| 1717 | "Test panic context release"); |