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))) |
Jens Wiklander | 6987a82 | 2019-06-28 12:47:42 +0200 | [diff] [blame] | 499 | goto rel_shm; |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 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); |
Jens Wiklander | 6987a82 | 2019-06-28 12:47:42 +0200 | [diff] [blame] | 520 | rel_shm: |
| 521 | TEEC_ReleaseSharedMemory(&shm); |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 522 | } |
| 523 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 524 | static void xtest_tee_test_1005(ADBG_Case_t *c) |
| 525 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 526 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 527 | #define MAX_SESSIONS 3 |
| 528 | TEEC_Session sessions[MAX_SESSIONS]; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 529 | int i = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 530 | |
| 531 | for (i = 0; i < MAX_SESSIONS; i++) { |
| 532 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Jens Wiklander | eb6bce7 | 2016-09-23 11:37:33 +0200 | [diff] [blame] | 533 | xtest_teec_open_session(&sessions[i], |
| 534 | &concurrent_ta_uuid, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 535 | NULL, &ret_orig))) |
| 536 | break; |
| 537 | } |
| 538 | |
| 539 | for (; --i >= 0; ) |
| 540 | TEEC_CloseSession(&sessions[i]); |
| 541 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 542 | ADBG_CASE_DEFINE(regression, 1005, xtest_tee_test_1005, "Many sessions"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 543 | |
| 544 | static void xtest_tee_test_1006(ADBG_Case_t *c) |
| 545 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 546 | TEEC_Session session = { }; |
| 547 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 548 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 549 | uint8_t buf[32] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 550 | |
| 551 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 552 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 553 | &ret_orig))) |
| 554 | return; |
| 555 | |
| 556 | op.params[0].tmpref.buffer = buf; |
| 557 | op.params[0].tmpref.size = sizeof(buf); |
| 558 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, |
| 559 | TEEC_NONE, TEEC_NONE); |
| 560 | |
| 561 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 562 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BASIC, &op, |
| 563 | &ret_orig)); |
| 564 | |
| 565 | TEEC_CloseSession(&session); |
| 566 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 567 | ADBG_CASE_DEFINE(regression, 1006, xtest_tee_test_1006, |
| 568 | "Test Basic OS features"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 569 | |
| 570 | static void xtest_tee_test_1007(ADBG_Case_t *c) |
| 571 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 572 | TEEC_Session session = { }; |
| 573 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 574 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 575 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 576 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 577 | &ret_orig))) |
| 578 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 579 | |
| 580 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 581 | TEEC_ERROR_TARGET_DEAD, |
| 582 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PANIC, NULL, |
| 583 | &ret_orig)); |
| 584 | |
| 585 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 586 | |
| 587 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 588 | TEEC_ERROR_TARGET_DEAD, |
| 589 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_INIT, NULL, |
| 590 | &ret_orig)); |
| 591 | |
| 592 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 593 | |
| 594 | TEEC_CloseSession(&session); |
| 595 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 596 | ADBG_CASE_DEFINE(regression, 1007, xtest_tee_test_1007, "Test Panic"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 597 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 598 | #ifdef CFG_SECSTOR_TA_MGMT_PTA |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 599 | #ifndef TA_DIR |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 600 | # ifdef __ANDROID__ |
Yongqin Liu | 286f1fc | 2018-06-21 22:09:15 +0800 | [diff] [blame] | 601 | #define TA_DIR "/vendor/lib/optee_armtz" |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 602 | # else |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 603 | #define TA_DIR "/lib/optee_armtz" |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 604 | # endif |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 605 | #endif |
| 606 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 607 | static FILE *open_ta_file(const TEEC_UUID *uuid, const char *mode) |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 608 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 609 | char buf[PATH_MAX] = { }; |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 610 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 611 | snprintf(buf, sizeof(buf), |
Jens Wiklander | 6203b87 | 2016-12-08 19:18:29 +0100 | [diff] [blame] | 612 | "%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] | 613 | TA_DIR, uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion, |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 614 | uuid->clockSeqAndNode[0], uuid->clockSeqAndNode[1], |
| 615 | uuid->clockSeqAndNode[2], uuid->clockSeqAndNode[3], |
| 616 | uuid->clockSeqAndNode[4], uuid->clockSeqAndNode[5], |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 617 | uuid->clockSeqAndNode[6], uuid->clockSeqAndNode[7]); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 618 | |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 619 | return fopen(buf, mode); |
| 620 | } |
| 621 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 622 | 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] | 623 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 624 | TEEC_Session session = { }; |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 625 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 626 | TEEC_UUID uuid = PTA_SECSTOR_TA_MGMT_UUID; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 627 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 628 | uint32_t ret_orig = 0; |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 629 | FILE *f = NULL; |
| 630 | bool r = false; |
| 631 | uint8_t *buf = NULL; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 632 | size_t sz = 0; |
| 633 | size_t fread_res = 0; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 634 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 635 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 636 | xtest_teec_open_session(&session, &uuid, NULL, &ret_orig))) |
| 637 | goto out; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 638 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 639 | f = open_ta_file(&create_fail_test_ta_uuid, "rb"); |
| 640 | if (!ADBG_EXPECT_NOT_NULL(c, f)) |
| 641 | goto out; |
| 642 | if (!ADBG_EXPECT_TRUE(c, !fseek(f, 0, SEEK_END))) |
| 643 | goto out; |
| 644 | sz = ftell(f); |
| 645 | rewind(f); |
| 646 | |
| 647 | buf = malloc(sz); |
| 648 | if (!ADBG_EXPECT_NOT_NULL(c, buf)) |
| 649 | goto out; |
| 650 | |
| 651 | fread_res = fread(buf, 1, sz, f); |
| 652 | if (!ADBG_EXPECT_COMPARE_UNSIGNED(c, fread_res, ==, sz)) |
| 653 | goto out; |
| 654 | |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 655 | fclose(f); |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 656 | f = NULL; |
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 | buf[MIN(offs, sz)] ^= mask; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 659 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 660 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, |
| 661 | TEEC_NONE, TEEC_NONE); |
| 662 | op.params[0].tmpref.buffer = buf; |
| 663 | op.params[0].tmpref.size = sz; |
| 664 | |
| 665 | res = TEEC_InvokeCommand(&session, PTA_SECSTOR_TA_MGMT_BOOTSTRAP, &op, |
| 666 | &ret_orig); |
| 667 | r = ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_SECURITY, res); |
| 668 | out: |
| 669 | free(buf); |
| 670 | if (f) |
| 671 | fclose(f); |
| 672 | TEEC_CloseSession(&session); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 673 | return r; |
| 674 | } |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 675 | #endif /*CFG_SECSTOR_TA_MGMT_PTA*/ |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 676 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 677 | static void xtest_tee_test_1008(ADBG_Case_t *c) |
| 678 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 679 | TEEC_Session session = { }; |
| 680 | TEEC_Session session_crypt = { }; |
| 681 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 682 | |
| 683 | Do_ADBG_BeginSubCase(c, "Invoke command"); |
| 684 | { |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 685 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 686 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 687 | NULL, &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 688 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 689 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 690 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CLIENT, |
| 691 | NULL, &ret_orig)); |
| 692 | TEEC_CloseSession(&session); |
| 693 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 694 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 695 | } |
| 696 | Do_ADBG_EndSubCase(c, "Invoke command"); |
| 697 | |
| 698 | Do_ADBG_BeginSubCase(c, "Invoke command with timeout"); |
| 699 | { |
| 700 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 701 | |
| 702 | op.params[0].value.a = 2000; |
| 703 | op.paramTypes = TEEC_PARAM_TYPES( |
| 704 | TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 705 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 706 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 707 | xtest_teec_open_session(&session, |
| 708 | &os_test_ta_uuid, |
| 709 | NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 710 | &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 711 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 712 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 713 | TEEC_InvokeCommand(&session, |
| 714 | TA_OS_TEST_CMD_CLIENT_WITH_TIMEOUT, |
| 715 | &op, &ret_orig)); |
| 716 | TEEC_CloseSession(&session); |
| 717 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 718 | } |
| 719 | Do_ADBG_EndSubCase(c, "Invoke command with timeout"); |
| 720 | |
| 721 | Do_ADBG_BeginSubCase(c, "Create session fail"); |
| 722 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 723 | size_t n = 0; |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 724 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 725 | (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC, |
| 726 | xtest_teec_open_session(&session_crypt, |
| 727 | &create_fail_test_ta_uuid, NULL, |
| 728 | &ret_orig)); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 729 | /* |
| 730 | * Run this several times to see that there's no memory leakage. |
| 731 | */ |
| 732 | for (n = 0; n < 100; n++) { |
| 733 | Do_ADBG_Log("n = %zu", n); |
| 734 | (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC, |
| 735 | xtest_teec_open_session(&session_crypt, |
| 736 | &create_fail_test_ta_uuid, |
| 737 | NULL, &ret_orig)); |
| 738 | } |
| 739 | } |
| 740 | Do_ADBG_EndSubCase(c, "Create session fail"); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 741 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 742 | #ifdef CFG_SECSTOR_TA_MGMT_PTA |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 743 | Do_ADBG_BeginSubCase(c, "Load corrupt TA"); |
| 744 | ADBG_EXPECT_TRUE(c, |
| 745 | load_corrupt_ta(c, offsetof(struct shdr, magic), 1)); |
| 746 | ADBG_EXPECT_TRUE(c, |
| 747 | load_corrupt_ta(c, offsetof(struct shdr, img_type), 1)); |
| 748 | ADBG_EXPECT_TRUE(c, |
| 749 | load_corrupt_ta(c, offsetof(struct shdr, img_size), 1)); |
| 750 | ADBG_EXPECT_TRUE(c, |
| 751 | load_corrupt_ta(c, offsetof(struct shdr, algo), 1)); |
| 752 | ADBG_EXPECT_TRUE(c, |
| 753 | load_corrupt_ta(c, offsetof(struct shdr, hash_size), 1)); |
| 754 | ADBG_EXPECT_TRUE(c, |
| 755 | load_corrupt_ta(c, offsetof(struct shdr, sig_size), 1)); |
| 756 | ADBG_EXPECT_TRUE(c, |
| 757 | load_corrupt_ta(c, sizeof(struct shdr), 1)); /* hash */ |
| 758 | ADBG_EXPECT_TRUE(c, |
| 759 | load_corrupt_ta(c, sizeof(struct shdr) + 32, 1)); /* sig */ |
| 760 | ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 3000, 1)); /* payload */ |
Jerome Forissier | 895c5ca | 2019-02-28 17:27:46 +0100 | [diff] [blame] | 761 | ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 8000, 1)); /* payload */ |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 762 | Do_ADBG_EndSubCase(c, "Load corrupt TA"); |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 763 | #endif /*CFG_SECSTOR_TA_MGMT_PTA*/ |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 764 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 765 | ADBG_CASE_DEFINE(regression, 1008, xtest_tee_test_1008, |
| 766 | "TEE internal client API"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 767 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 768 | static void *cancellation_thread(void *arg) |
| 769 | { |
| 770 | /* |
| 771 | * Sleep 0.5 seconds before cancellation to make sure that the other |
| 772 | * thread is in RPC_WAIT. |
| 773 | */ |
| 774 | (void)usleep(500000); |
| 775 | TEEC_RequestCancellation(arg); |
| 776 | return NULL; |
| 777 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 778 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 779 | static void xtest_tee_test_1009_subcase(ADBG_Case_t *c, const char *subcase, |
| 780 | uint32_t timeout, bool cancel) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 781 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 782 | TEEC_Session session = { }; |
| 783 | uint32_t ret_orig = 0; |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 784 | pthread_t thr; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 785 | |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 786 | memset(&thr, 0, sizeof(thr)); |
| 787 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 788 | Do_ADBG_BeginSubCase(c, "%s", subcase); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 789 | { |
| 790 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 791 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 792 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
| 793 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 794 | NULL, &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 795 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 796 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, |
| 797 | TEEC_ORIGIN_TRUSTED_APP, |
| 798 | ret_orig); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 799 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 800 | op.params[0].value.a = timeout; |
| 801 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 802 | TEEC_NONE, |
| 803 | TEEC_NONE, TEEC_NONE); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 804 | if (cancel) { |
| 805 | (void)ADBG_EXPECT(c, 0, |
| 806 | pthread_create(&thr, NULL, |
| 807 | cancellation_thread, &op)); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 808 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 809 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 810 | TEEC_ERROR_CANCEL, |
| 811 | TEEC_InvokeCommand(&session, |
| 812 | TA_OS_TEST_CMD_WAIT, |
| 813 | &op, |
| 814 | &ret_orig)); |
| 815 | } else |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 816 | |
| 817 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 818 | TEEC_InvokeCommand(&session, |
| 819 | TA_OS_TEST_CMD_WAIT, |
| 820 | &op, |
| 821 | &ret_orig)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 822 | if (cancel) |
| 823 | (void)ADBG_EXPECT(c, 0, pthread_join(thr, NULL)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 824 | |
| 825 | TEEC_CloseSession(&session); |
| 826 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 827 | } |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 828 | Do_ADBG_EndSubCase(c, "%s", subcase); |
| 829 | } |
| 830 | |
| 831 | static void xtest_tee_test_1009(ADBG_Case_t *c) |
| 832 | { |
| 833 | xtest_tee_test_1009_subcase(c, "TEE Wait 0.1s", 100, false); |
| 834 | xtest_tee_test_1009_subcase(c, "TEE Wait 0.5s", 500, false); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 835 | xtest_tee_test_1009_subcase(c, "TEE Wait 2s cancel", 2000, true); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 836 | xtest_tee_test_1009_subcase(c, "TEE Wait 2s", 2000, false); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 837 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 838 | ADBG_CASE_DEFINE(regression, 1009, xtest_tee_test_1009, "TEE Wait"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 839 | |
| 840 | static void xtest_tee_test_1010(ADBG_Case_t *c) |
| 841 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 842 | unsigned int n = 0; |
| 843 | unsigned int idx = 0; |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 844 | size_t memref_sz[] = { 1024, 65536 }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 845 | |
| 846 | for (n = 1; n <= 5; n++) { |
| 847 | Do_ADBG_BeginSubCase(c, "Invalid memory access %u", n); |
| 848 | xtest_tee_test_invalid_mem_access(c, n); |
| 849 | Do_ADBG_EndSubCase(c, "Invalid memory access %u", n); |
| 850 | } |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 851 | |
| 852 | for (idx = 0; idx < ARRAY_SIZE(memref_sz); idx++) { |
| 853 | for (n = 1; n <= 5; n++) { |
| 854 | Do_ADBG_BeginSubCase(c, |
Igor Opaniuk | e8236ac | 2018-02-12 12:26:25 +0200 | [diff] [blame] | 855 | "Invalid memory access %u with %zu bytes memref", |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 856 | n, memref_sz[idx]); |
| 857 | xtest_tee_test_invalid_mem_access2(c, n, memref_sz[idx]); |
| 858 | Do_ADBG_EndSubCase(c, |
Igor Opaniuk | e8236ac | 2018-02-12 12:26:25 +0200 | [diff] [blame] | 859 | "Invalid memory access %u with %zu bytes memref", |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 860 | n, memref_sz[idx]); |
| 861 | } |
| 862 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 863 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 864 | ADBG_CASE_DEFINE(regression, 1010, xtest_tee_test_1010, |
| 865 | "Invalid memory access"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 866 | |
| 867 | static void xtest_tee_test_1011(ADBG_Case_t *c) |
| 868 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 869 | TEEC_Session session = { }; |
| 870 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 871 | struct xtest_crypto_session cs = { |
| 872 | c, &session, TA_RPC_CMD_CRYPT_SHA256, |
| 873 | TA_RPC_CMD_CRYPT_AES256ECB_ENC, |
| 874 | TA_RPC_CMD_CRYPT_AES256ECB_DEC |
| 875 | }; |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 876 | struct xtest_crypto_session cs_privmem = { |
| 877 | c, &session, |
| 878 | TA_RPC_CMD_CRYPT_PRIVMEM_SHA256, |
| 879 | TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_ENC, |
| 880 | TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_DEC |
| 881 | }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 882 | TEEC_UUID uuid = rpc_test_ta_uuid; |
| 883 | |
| 884 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 885 | xtest_teec_open_session(&session, &uuid, NULL, &ret_orig))) |
| 886 | return; |
| 887 | |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 888 | Do_ADBG_BeginSubCase(c, "TA-to-TA via non-secure shared memory"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 889 | /* |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 890 | * Run the "complete crypto test suite" using TA-to-TA |
| 891 | * communication |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 892 | */ |
| 893 | xtest_crypto_test(&cs); |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 894 | Do_ADBG_EndSubCase(c, "TA-to-TA via non-secure shared memory"); |
| 895 | |
| 896 | Do_ADBG_BeginSubCase(c, "TA-to-TA via TA private memory"); |
| 897 | /* |
| 898 | * Run the "complete crypto test suite" using TA-to-TA |
| 899 | * communication via TA private memory. |
| 900 | */ |
| 901 | xtest_crypto_test(&cs_privmem); |
| 902 | Do_ADBG_EndSubCase(c, "TA-to-TA via TA private memory"); |
| 903 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 904 | TEEC_CloseSession(&session); |
| 905 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 906 | ADBG_CASE_DEFINE(regression, 1011, xtest_tee_test_1011, |
| 907 | "Test TA-to-TA features with User Crypt TA"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 908 | |
| 909 | /* |
| 910 | * Note that this test is failing when |
| 911 | * - running twice in a raw |
| 912 | * - and the user TA is statically linked |
| 913 | * This is because the counter is not reseted when opening the first session |
| 914 | * in case the TA is statically linked |
| 915 | */ |
| 916 | static void xtest_tee_test_1012(ADBG_Case_t *c) |
| 917 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 918 | TEEC_Session session1 = { }; |
| 919 | TEEC_Session session2 = { }; |
| 920 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 921 | TEEC_UUID uuid = sims_test_ta_uuid; |
| 922 | |
| 923 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Session"); |
| 924 | { |
| 925 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 926 | static const uint8_t in[] = { |
| 927 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 928 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 929 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 930 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 931 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 932 | uint8_t out[32] = { }; |
| 933 | int i = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 934 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 935 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 936 | xtest_teec_open_session(&session1, &uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 937 | &ret_orig))) |
| 938 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 939 | |
| 940 | op.params[0].value.a = 0; |
| 941 | op.params[1].tmpref.buffer = (void *)in; |
| 942 | op.params[1].tmpref.size = sizeof(in); |
| 943 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 944 | TEEC_MEMREF_TEMP_INPUT, |
| 945 | TEEC_NONE, TEEC_NONE); |
| 946 | |
| 947 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 948 | TEEC_InvokeCommand(&session1, TA_SIMS_CMD_WRITE, &op, |
| 949 | &ret_orig)); |
| 950 | |
Jerome Forissier | 3cc0a42 | 2017-12-14 09:53:24 +0100 | [diff] [blame] | 951 | for (i = 1; i < 3; i++) { |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 952 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 953 | xtest_teec_open_session(&session2, &uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 954 | &ret_orig))) |
| 955 | continue; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 956 | |
| 957 | op.params[0].value.a = 0; |
| 958 | op.params[1].tmpref.buffer = out; |
| 959 | op.params[1].tmpref.size = sizeof(out); |
| 960 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 961 | TEEC_MEMREF_TEMP_OUTPUT, |
| 962 | TEEC_NONE, TEEC_NONE); |
| 963 | |
| 964 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 965 | TEEC_InvokeCommand(&session2, TA_SIMS_CMD_READ, |
| 966 | &op, &ret_orig)); |
| 967 | |
| 968 | if (!ADBG_EXPECT_BUFFER(c, in, sizeof(in), out, |
| 969 | sizeof(out))) { |
| 970 | Do_ADBG_Log("in:"); |
| 971 | Do_ADBG_HexLog(in, sizeof(in), 16); |
| 972 | Do_ADBG_Log("out:"); |
| 973 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 974 | } |
| 975 | |
| 976 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, |
| 977 | TEEC_NONE, TEEC_NONE, |
| 978 | TEEC_NONE); |
| 979 | |
| 980 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 981 | TEEC_InvokeCommand(&session1, |
| 982 | TA_SIMS_CMD_GET_COUNTER, |
| 983 | &op, &ret_orig)); |
| 984 | |
| 985 | (void)ADBG_EXPECT(c, 0, op.params[0].value.a); |
| 986 | |
| 987 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 988 | TEEC_InvokeCommand(&session2, |
| 989 | TA_SIMS_CMD_GET_COUNTER, &op, |
| 990 | &ret_orig)); |
| 991 | |
| 992 | (void)ADBG_EXPECT(c, i, op.params[0].value.a); |
| 993 | TEEC_CloseSession(&session2); |
| 994 | } |
| 995 | |
| 996 | memset(out, 0, sizeof(out)); |
| 997 | op.params[0].value.a = 0; |
| 998 | op.params[1].tmpref.buffer = out; |
| 999 | op.params[1].tmpref.size = sizeof(out); |
| 1000 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 1001 | TEEC_MEMREF_TEMP_OUTPUT, |
| 1002 | TEEC_NONE, TEEC_NONE); |
| 1003 | |
| 1004 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1005 | TEEC_InvokeCommand(&session1, TA_SIMS_CMD_READ, &op, |
| 1006 | &ret_orig)); |
| 1007 | |
| 1008 | if (!ADBG_EXPECT(c, 0, memcmp(in, out, sizeof(in)))) { |
| 1009 | Do_ADBG_Log("in:"); |
| 1010 | Do_ADBG_HexLog(in, sizeof(in), 16); |
| 1011 | Do_ADBG_Log("out:"); |
| 1012 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 1013 | } |
| 1014 | |
| 1015 | TEEC_CloseSession(&session1); |
| 1016 | } |
Ovidiu Mihalachi | 3e6183e | 2019-04-25 10:23:21 +0300 | [diff] [blame] | 1017 | Do_ADBG_EndSubCase(c, "Single Instance Multi Session"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1018 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1019 | ADBG_CASE_DEFINE(regression, 1012, xtest_tee_test_1012, |
| 1020 | "Test Single Instance Multi Session features with SIMS TA"); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1021 | |
| 1022 | struct test_1013_thread_arg { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1023 | const TEEC_UUID *uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1024 | uint32_t cmd; |
| 1025 | uint32_t repeat; |
| 1026 | TEEC_SharedMemory *shm; |
| 1027 | uint32_t error_orig; |
| 1028 | TEEC_Result res; |
| 1029 | uint32_t max_concurrency; |
| 1030 | const uint8_t *in; |
| 1031 | size_t in_len; |
| 1032 | uint8_t *out; |
| 1033 | size_t out_len; |
| 1034 | }; |
| 1035 | |
| 1036 | static void *test_1013_thread(void *arg) |
| 1037 | { |
| 1038 | struct test_1013_thread_arg *a = arg; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1039 | TEEC_Session session = { }; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1040 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1041 | uint8_t p2 = TEEC_NONE; |
| 1042 | uint8_t p3 = TEEC_NONE; |
| 1043 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1044 | a->res = xtest_teec_open_session(&session, a->uuid, NULL, |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1045 | &a->error_orig); |
| 1046 | if (a->res != TEEC_SUCCESS) |
| 1047 | return NULL; |
| 1048 | |
| 1049 | op.params[0].memref.parent = a->shm; |
| 1050 | op.params[0].memref.size = a->shm->size; |
| 1051 | op.params[0].memref.offset = 0; |
| 1052 | op.params[1].value.a = a->repeat; |
| 1053 | op.params[1].value.b = 0; |
| 1054 | op.params[2].tmpref.buffer = (void *)a->in; |
| 1055 | op.params[2].tmpref.size = a->in_len; |
| 1056 | op.params[3].tmpref.buffer = a->out; |
| 1057 | op.params[3].tmpref.size = a->out_len; |
| 1058 | |
| 1059 | if (a->in_len) |
| 1060 | p2 = TEEC_MEMREF_TEMP_INPUT; |
| 1061 | if (a->out_len) |
| 1062 | p3 = TEEC_MEMREF_TEMP_OUTPUT; |
| 1063 | |
| 1064 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, |
| 1065 | TEEC_VALUE_INOUT, p2, p3); |
| 1066 | |
| 1067 | a->res = TEEC_InvokeCommand(&session, a->cmd, &op, &a->error_orig); |
| 1068 | a->max_concurrency = op.params[1].value.b; |
| 1069 | a->out_len = op.params[3].tmpref.size; |
| 1070 | TEEC_CloseSession(&session); |
| 1071 | return NULL; |
| 1072 | } |
| 1073 | |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1074 | #define NUM_THREADS 3 |
| 1075 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1076 | static void xtest_tee_test_1013_single(ADBG_Case_t *c, double *mean_concurrency, |
| 1077 | const TEEC_UUID *uuid) |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1078 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1079 | size_t nt = 0; |
| 1080 | size_t n = 0; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1081 | size_t repeat = 1000; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1082 | TEEC_SharedMemory shm = { }; |
| 1083 | size_t max_concurrency = 0; |
| 1084 | struct test_1013_thread_arg arg[NUM_THREADS] = { }; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1085 | static const uint8_t sha256_in[] = { 'a', 'b', 'c' }; |
| 1086 | static const uint8_t sha256_out[] = { |
| 1087 | 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, |
| 1088 | 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, |
| 1089 | 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, |
| 1090 | 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad |
| 1091 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1092 | uint8_t out[32] = { }; |
| 1093 | pthread_t thr[NUM_THREADS] = { }; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1094 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1095 | Do_ADBG_BeginSubCase(c, "Busy loop repeat %zu", repeat * 10); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1096 | *mean_concurrency = 0; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1097 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1098 | shm.size = sizeof(struct ta_concurrent_shm); |
| 1099 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1100 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1101 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 1102 | return; |
| 1103 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1104 | memset(shm.buffer, 0, shm.size); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1105 | max_concurrency = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1106 | nt = NUM_THREADS; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1107 | |
| 1108 | for (n = 0; n < nt; n++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1109 | arg[n].uuid = uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1110 | arg[n].cmd = TA_CONCURRENT_CMD_BUSY_LOOP; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1111 | arg[n].repeat = repeat * 10; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1112 | arg[n].shm = &shm; |
| 1113 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 1114 | test_1013_thread, arg + n))) |
| 1115 | nt = n; /* break loop and start cleanup */ |
| 1116 | } |
| 1117 | |
| 1118 | for (n = 0; n < nt; n++) { |
| 1119 | ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)); |
| 1120 | ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res); |
| 1121 | if (arg[n].max_concurrency > max_concurrency) |
| 1122 | max_concurrency = arg[n].max_concurrency; |
| 1123 | } |
| 1124 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1125 | /* |
| 1126 | * Concurrency can be limited by several factors, for instance in a |
| 1127 | * single CPU system it's dependent on the Preemtion Model used by |
| 1128 | * the kernel (Preemptible Kernel (Low-Latency Desktop) gives the |
| 1129 | * best result there). |
| 1130 | */ |
| 1131 | (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, >, 0); |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1132 | (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, <=, NUM_THREADS); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1133 | *mean_concurrency += max_concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1134 | Do_ADBG_EndSubCase(c, "Busy loop repeat %zu", repeat * 10); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1135 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1136 | Do_ADBG_BeginSubCase(c, "SHA-256 loop repeat %zu", repeat); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1137 | memset(shm.buffer, 0, shm.size); |
| 1138 | memset(arg, 0, sizeof(arg)); |
| 1139 | max_concurrency = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1140 | nt = NUM_THREADS; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1141 | |
| 1142 | for (n = 0; n < nt; n++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1143 | arg[n].uuid = uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1144 | arg[n].cmd = TA_CONCURRENT_CMD_SHA256; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1145 | arg[n].repeat = repeat; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1146 | arg[n].shm = &shm; |
| 1147 | arg[n].in = sha256_in; |
| 1148 | arg[n].in_len = sizeof(sha256_in); |
| 1149 | arg[n].out = out; |
| 1150 | arg[n].out_len = sizeof(out); |
| 1151 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 1152 | test_1013_thread, arg + n))) |
| 1153 | nt = n; /* break loop and start cleanup */ |
| 1154 | } |
| 1155 | |
| 1156 | for (n = 0; n < nt; n++) { |
| 1157 | if (ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)) && |
| 1158 | ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res)) |
| 1159 | ADBG_EXPECT_BUFFER(c, sha256_out, sizeof(sha256_out), |
| 1160 | arg[n].out, arg[n].out_len); |
| 1161 | if (arg[n].max_concurrency > max_concurrency) |
| 1162 | max_concurrency = arg[n].max_concurrency; |
| 1163 | } |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1164 | *mean_concurrency += max_concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1165 | Do_ADBG_EndSubCase(c, "SHA-256 loop repeat %zu", repeat); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1166 | |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1167 | *mean_concurrency /= 2.0; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1168 | TEEC_ReleaseSharedMemory(&shm); |
| 1169 | } |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1170 | |
| 1171 | static void xtest_tee_test_1013(ADBG_Case_t *c) |
| 1172 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1173 | int i = 0; |
| 1174 | double mean_concurrency = 0; |
| 1175 | double concurrency = 0; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1176 | int nb_loops = 24; |
Jens Wiklander | 6a9d15a | 2016-02-01 10:29:42 +0100 | [diff] [blame] | 1177 | |
| 1178 | if (level == 0) |
| 1179 | nb_loops /= 2; |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1180 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1181 | Do_ADBG_BeginSubCase(c, "Using small concurrency TA"); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1182 | mean_concurrency = 0; |
| 1183 | for (i = 0; i < nb_loops; i++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1184 | xtest_tee_test_1013_single(c, &concurrency, |
| 1185 | &concurrent_ta_uuid); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1186 | mean_concurrency += concurrency; |
| 1187 | } |
| 1188 | mean_concurrency /= nb_loops; |
| 1189 | |
| 1190 | Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS); |
| 1191 | Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency); |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1192 | Do_ADBG_EndSubCase(c, "Using small concurrency TA"); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1193 | |
Jens Wiklander | c9d7b24 | 2016-06-28 18:35:08 +0200 | [diff] [blame] | 1194 | #ifndef CFG_PAGED_USER_TA |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1195 | Do_ADBG_BeginSubCase(c, "Using large concurrency TA"); |
| 1196 | mean_concurrency = 0; |
| 1197 | for (i = 0; i < nb_loops; i++) { |
| 1198 | xtest_tee_test_1013_single(c, &concurrency, |
| 1199 | &concurrent_large_ta_uuid); |
| 1200 | mean_concurrency += concurrency; |
| 1201 | } |
| 1202 | mean_concurrency /= nb_loops; |
| 1203 | |
| 1204 | Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS); |
| 1205 | Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency); |
| 1206 | Do_ADBG_EndSubCase(c, "Using large concurrency TA"); |
Jens Wiklander | c9d7b24 | 2016-06-28 18:35:08 +0200 | [diff] [blame] | 1207 | #endif |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1208 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1209 | ADBG_CASE_DEFINE(regression, 1013, xtest_tee_test_1013, |
| 1210 | "Test concurency with concurrent TA"); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1211 | |
| 1212 | #ifdef CFG_SECURE_DATA_PATH |
| 1213 | static void xtest_tee_test_1014(ADBG_Case_t *c) |
| 1214 | { |
| 1215 | UNUSED(c); |
| 1216 | |
| 1217 | int size = 17000; |
| 1218 | int loop = 10; |
| 1219 | int ion_heap = DEFAULT_ION_HEAP_TYPE; |
| 1220 | int rnd_offset = 1; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1221 | int test = 0; |
| 1222 | int ret = 0; |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1223 | |
| 1224 | test = TEST_NS_TO_TA; |
| 1225 | Do_ADBG_BeginSubCase(c, "SDP: NonSecure client invokes a SDP TA"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1226 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1227 | ADBG_EXPECT(c, 0, ret); |
| 1228 | Do_ADBG_EndSubCase(c, "SDP: NonSecure client invokes a SDP TA"); |
| 1229 | |
| 1230 | test = TEST_TA_TO_TA; |
| 1231 | Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP TA"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1232 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1233 | ADBG_EXPECT(c, 0, ret); |
| 1234 | Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP TA"); |
| 1235 | |
| 1236 | test = TEST_TA_TO_PTA; |
| 1237 | Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP pTA"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1238 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1239 | ADBG_EXPECT(c, 0, ret); |
| 1240 | Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP pTA"); |
| 1241 | |
| 1242 | test = TEST_NS_TO_PTA; |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 1243 | Do_ADBG_BeginSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1244 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1245 | ADBG_EXPECT(c, 1, ret); |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 1246 | Do_ADBG_EndSubCase(c, "SDP: NSec CA invokes SDP pTA (should fail)"); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1247 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1248 | ADBG_CASE_DEFINE(regression, 1014, xtest_tee_test_1014, |
| 1249 | "Test secure data path against SDP TAs and pTAs"); |
| 1250 | #endif /*CFG_SECURE_DATA_PATH*/ |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1251 | |
| 1252 | static void xtest_tee_test_1015(ADBG_Case_t *c) |
| 1253 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1254 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1255 | TEEC_Session session = { }; |
| 1256 | uint32_t ret_orig = 0; |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1257 | |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1258 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1259 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 1260 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1261 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 1262 | Do_ADBG_Log(" - 1015 - skip test, pseudo TA not found"); |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1263 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1264 | } |
| 1265 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1266 | |
| 1267 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1268 | TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_FS_HTREE, |
| 1269 | NULL, &ret_orig)); |
| 1270 | TEEC_CloseSession(&session); |
| 1271 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1272 | ADBG_CASE_DEFINE(regression, 1015, xtest_tee_test_1015, |
| 1273 | "FS hash-tree corner cases"); |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1274 | |
| 1275 | static void xtest_tee_test_1016(ADBG_Case_t *c) |
| 1276 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1277 | TEEC_Session session = { }; |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1278 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1279 | uint32_t ret_orig = 0; |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1280 | |
| 1281 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1282 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1283 | &ret_orig))) |
| 1284 | return; |
| 1285 | |
| 1286 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, |
| 1287 | TEEC_NONE); |
| 1288 | |
| 1289 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1290 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TA2TA_MEMREF, &op, |
| 1291 | &ret_orig)); |
| 1292 | |
| 1293 | TEEC_CloseSession(&session); |
| 1294 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1295 | ADBG_CASE_DEFINE(regression, 1016, xtest_tee_test_1016, |
| 1296 | "Test TA to TA transfers (in/out/inout memrefs on the stack)"); |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1297 | |
| 1298 | static void xtest_tee_test_1017(ADBG_Case_t *c) |
| 1299 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1300 | TEEC_Session session = { }; |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1301 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1302 | uint32_t ret_orig = 0; |
| 1303 | TEEC_SharedMemory shm = { }; |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1304 | size_t page_size = 4096; |
| 1305 | |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1306 | shm.size = 8 * page_size; |
| 1307 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1308 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1309 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 1310 | return; |
| 1311 | |
| 1312 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1313 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1314 | &ret_orig))) |
| 1315 | goto out; |
| 1316 | |
| 1317 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, |
| 1318 | TEEC_MEMREF_PARTIAL_INPUT, |
| 1319 | TEEC_MEMREF_PARTIAL_OUTPUT, |
| 1320 | TEEC_MEMREF_PARTIAL_OUTPUT); |
| 1321 | |
| 1322 | /* |
| 1323 | * The first two memrefs are supposed to be combined into in |
| 1324 | * region and the last two memrefs should have one region each |
| 1325 | * when the parameters are mapped for the TA. |
| 1326 | */ |
| 1327 | op.params[0].memref.parent = &shm; |
| 1328 | op.params[0].memref.size = page_size; |
| 1329 | op.params[0].memref.offset = 0; |
| 1330 | |
| 1331 | op.params[1].memref.parent = &shm; |
| 1332 | op.params[1].memref.size = page_size; |
| 1333 | op.params[1].memref.offset = page_size; |
| 1334 | |
| 1335 | op.params[2].memref.parent = &shm; |
| 1336 | op.params[2].memref.size = page_size; |
| 1337 | op.params[2].memref.offset = 4 * page_size; |
| 1338 | |
| 1339 | op.params[3].memref.parent = &shm; |
| 1340 | op.params[3].memref.size = 2 * page_size; |
| 1341 | op.params[3].memref.offset = 6 * page_size; |
| 1342 | |
| 1343 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1344 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PARAMS, &op, |
| 1345 | &ret_orig)); |
| 1346 | |
| 1347 | TEEC_CloseSession(&session); |
| 1348 | out: |
| 1349 | TEEC_ReleaseSharedMemory(&shm); |
| 1350 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1351 | ADBG_CASE_DEFINE(regression, 1017, xtest_tee_test_1017, |
| 1352 | "Test coalescing memrefs"); |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1353 | |
| 1354 | static void xtest_tee_test_1018(ADBG_Case_t *c) |
| 1355 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1356 | TEEC_Session session = { }; |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1357 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1358 | uint32_t ret_orig = 0; |
| 1359 | TEEC_SharedMemory shm = { }; |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1360 | size_t page_size = 4096; |
| 1361 | |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1362 | shm.size = 8 * page_size; |
| 1363 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1364 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1365 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 1366 | return; |
| 1367 | |
| 1368 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1369 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1370 | &ret_orig))) |
| 1371 | goto out; |
| 1372 | |
| 1373 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, |
| 1374 | TEEC_MEMREF_PARTIAL_INPUT, |
| 1375 | TEEC_MEMREF_PARTIAL_OUTPUT, |
| 1376 | TEEC_MEMREF_PARTIAL_OUTPUT); |
| 1377 | |
| 1378 | /* |
| 1379 | * The first two memrefs are supposed to be combined into in |
| 1380 | * region and the last two memrefs should have one region each |
| 1381 | * when the parameters are mapped for the TA. |
| 1382 | */ |
| 1383 | op.params[0].memref.parent = &shm; |
| 1384 | op.params[0].memref.size = page_size; |
| 1385 | op.params[0].memref.offset = 0; |
| 1386 | |
| 1387 | op.params[1].memref.parent = &shm; |
| 1388 | op.params[1].memref.size = page_size; |
| 1389 | op.params[1].memref.offset = page_size; |
| 1390 | |
| 1391 | op.params[2].memref.parent = &shm; |
| 1392 | op.params[2].memref.size = page_size; |
| 1393 | op.params[2].memref.offset = 4 * page_size; |
| 1394 | |
| 1395 | op.params[3].memref.parent = &shm; |
| 1396 | op.params[3].memref.size = 3 * page_size; |
| 1397 | op.params[3].memref.offset = 6 * page_size; |
| 1398 | |
| 1399 | /* |
| 1400 | * Depending on the tee driver we may have different error codes. |
| 1401 | * What's most important is that secure world doesn't panic and |
| 1402 | * that someone detects an error. |
| 1403 | */ |
| 1404 | ADBG_EXPECT_NOT(c, TEE_SUCCESS, |
| 1405 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PARAMS, &op, |
| 1406 | &ret_orig)); |
| 1407 | |
| 1408 | TEEC_CloseSession(&session); |
| 1409 | out: |
| 1410 | TEEC_ReleaseSharedMemory(&shm); |
| 1411 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1412 | ADBG_CASE_DEFINE(regression, 1018, xtest_tee_test_1018, |
| 1413 | "Test memref out of bounds"); |
Jerome Forissier | 53bde72 | 2018-05-31 09:14:54 +0200 | [diff] [blame] | 1414 | |
Victor Chong | 3ff36f5 | 2018-06-07 04:37:00 +0100 | [diff] [blame] | 1415 | #if defined(CFG_TA_DYNLINK) |
Jerome Forissier | 53bde72 | 2018-05-31 09:14:54 +0200 | [diff] [blame] | 1416 | static void xtest_tee_test_1019(ADBG_Case_t *c) |
| 1417 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1418 | TEEC_Session session = { }; |
| 1419 | uint32_t ret_orig = 0; |
Jerome Forissier | 53bde72 | 2018-05-31 09:14:54 +0200 | [diff] [blame] | 1420 | |
| 1421 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1422 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1423 | &ret_orig))) |
| 1424 | return; |
| 1425 | |
| 1426 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1427 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB, NULL, |
| 1428 | &ret_orig)); |
| 1429 | |
| 1430 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 1431 | TEEC_ERROR_TARGET_DEAD, |
| 1432 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_PANIC, |
| 1433 | NULL, &ret_orig)); |
| 1434 | |
| 1435 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 1436 | |
| 1437 | TEEC_CloseSession(&session); |
| 1438 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1439 | ADBG_CASE_DEFINE(regression, 1019, xtest_tee_test_1019, |
| 1440 | "Test dynamically linked TA"); |
| 1441 | #endif /*CFG_TA_DYNLINK*/ |
Jerome Forissier | 3357f87 | 2018-10-05 15:13:44 +0200 | [diff] [blame] | 1442 | |
| 1443 | static void xtest_tee_test_1020(ADBG_Case_t *c) |
| 1444 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1445 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1446 | TEEC_Session session = { }; |
| 1447 | uint32_t ret_orig = 0; |
Jerome Forissier | 3357f87 | 2018-10-05 15:13:44 +0200 | [diff] [blame] | 1448 | |
| 1449 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
| 1450 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 1451 | &ret_orig); |
| 1452 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 1453 | Do_ADBG_Log(" - 1020 - skip test, pseudo TA not found"); |
| 1454 | return; |
| 1455 | } |
| 1456 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 1457 | |
| 1458 | res = TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_LOCKDEP, |
| 1459 | NULL, &ret_orig); |
| 1460 | if (res != TEEC_SUCCESS) { |
| 1461 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TRUSTED_APP, |
| 1462 | ret_orig); |
| 1463 | if (res == TEEC_ERROR_NOT_SUPPORTED) { |
| 1464 | Do_ADBG_Log(" - 1020 - skip test, feature not " |
| 1465 | "implemented"); |
| 1466 | goto out; |
| 1467 | } |
| 1468 | /* Error */ |
| 1469 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 1470 | } |
| 1471 | out: |
| 1472 | TEEC_CloseSession(&session); |
| 1473 | } |
| 1474 | ADBG_CASE_DEFINE(regression, 1020, xtest_tee_test_1020, |
| 1475 | "Test lockdep algorithm"); |
Ovidiu Mihalachi | 15cecff | 2019-04-02 16:36:31 +0300 | [diff] [blame] | 1476 | |
| 1477 | static TEEC_Result open_sec_session(TEEC_Session *session, |
| 1478 | const TEEC_UUID *uuid) |
| 1479 | { |
| 1480 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1481 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1482 | uint32_t ret_orig = 0; |
| 1483 | |
| 1484 | op.params[0].tmpref.buffer = (void *)uuid; |
| 1485 | op.params[0].tmpref.size = sizeof(*uuid); |
| 1486 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 1487 | TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 1488 | |
| 1489 | res = TEEC_InvokeCommand(session, TA_SIMS_OPEN_TA_SESSION, |
| 1490 | &op, &ret_orig); |
| 1491 | if (res != TEEC_SUCCESS) |
| 1492 | return TEEC_ERROR_GENERIC; |
| 1493 | |
| 1494 | return res; |
| 1495 | } |
| 1496 | |
| 1497 | static TEEC_Result sims_get_counter(TEEC_Session *session, |
| 1498 | uint32_t *counter) |
| 1499 | { |
| 1500 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1501 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1502 | uint32_t ret_orig = 0; |
| 1503 | |
| 1504 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, |
| 1505 | TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 1506 | |
| 1507 | res = TEEC_InvokeCommand(session, TA_SIMS_CMD_GET_COUNTER, |
| 1508 | &op, &ret_orig); |
| 1509 | if (res == TEEC_SUCCESS) |
| 1510 | *counter = op.params[0].value.a; |
| 1511 | |
| 1512 | return res; |
| 1513 | } |
| 1514 | |
| 1515 | static TEEC_Result trigger_panic(TEEC_Session *session, |
| 1516 | const TEEC_UUID *uuid) |
| 1517 | { |
| 1518 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1519 | uint32_t ret_orig = 0; |
| 1520 | |
| 1521 | if (!uuid) { |
| 1522 | op.params[0].tmpref.buffer = NULL; |
| 1523 | op.params[0].tmpref.size = 0; |
| 1524 | } else { |
| 1525 | op.params[0].tmpref.buffer = (void *)uuid; |
| 1526 | op.params[0].tmpref.size = sizeof(*uuid); |
| 1527 | } |
| 1528 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 1529 | TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 1530 | |
| 1531 | return TEEC_InvokeCommand(session, TA_SIMS_CMD_PANIC, |
| 1532 | &op, &ret_orig); |
| 1533 | } |
| 1534 | |
| 1535 | static void test_panic_ca_to_ta(ADBG_Case_t *c, const TEEC_UUID *uuid, |
| 1536 | bool multi_instance) |
| 1537 | { |
| 1538 | TEEC_Result exp_res = TEEC_ERROR_GENERIC; |
| 1539 | uint32_t counter = 0; |
| 1540 | uint32_t ret_orig = 0; |
| 1541 | uint32_t exp_counter = 0; |
| 1542 | TEEC_Session cs[3] = { }; |
| 1543 | |
| 1544 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1545 | xtest_teec_open_session(&cs[0], uuid, NULL, |
| 1546 | &ret_orig))) |
| 1547 | return; |
| 1548 | |
| 1549 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1550 | xtest_teec_open_session(&cs[1], uuid, NULL, |
| 1551 | &ret_orig))) |
| 1552 | goto bail0; |
| 1553 | |
| 1554 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter))) |
| 1555 | goto bail1; |
| 1556 | |
| 1557 | if (!ADBG_EXPECT(c, 0, counter)) |
| 1558 | goto bail1; |
| 1559 | |
| 1560 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[1], &counter))) |
| 1561 | goto bail1; |
| 1562 | |
| 1563 | exp_counter = multi_instance ? 0 : 1; |
| 1564 | if (ADBG_EXPECT(c, exp_counter, counter)) |
| 1565 | goto bail1; |
| 1566 | |
| 1567 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1568 | trigger_panic(&cs[1], NULL))) |
| 1569 | goto bail1; |
| 1570 | |
| 1571 | exp_res = multi_instance ? TEEC_SUCCESS : TEEC_ERROR_TARGET_DEAD; |
| 1572 | if (!ADBG_EXPECT_TEEC_RESULT(c, exp_res, |
| 1573 | sims_get_counter(&cs[0], &counter))) |
| 1574 | goto bail1; |
| 1575 | |
| 1576 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1577 | sims_get_counter(&cs[1], &counter))) |
| 1578 | goto bail1; |
| 1579 | |
| 1580 | /* Attempt to open a session on panicked context */ |
| 1581 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1582 | xtest_teec_open_session(&cs[1], uuid, NULL, |
| 1583 | &ret_orig))) |
| 1584 | goto bail1; |
| 1585 | |
| 1586 | /* Sanity check of still valid TA context */ |
| 1587 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1588 | xtest_teec_open_session(&cs[2], uuid, NULL, |
| 1589 | &ret_orig))) |
| 1590 | goto bail1; |
| 1591 | |
| 1592 | /* Sanity check of still valid TA context */ |
| 1593 | if (multi_instance) { |
| 1594 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1595 | sims_get_counter(&cs[0], &counter))) |
| 1596 | goto bail2; |
| 1597 | |
| 1598 | if (!ADBG_EXPECT(c, 0, counter)) |
| 1599 | goto bail2; |
| 1600 | } |
| 1601 | |
| 1602 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[2], &counter))) |
| 1603 | goto bail2; |
| 1604 | |
| 1605 | if (!ADBG_EXPECT(c, 0, counter)) |
| 1606 | goto bail2; |
| 1607 | |
| 1608 | bail2: |
| 1609 | TEEC_CloseSession(&cs[2]); |
| 1610 | bail1: |
| 1611 | TEEC_CloseSession(&cs[1]); |
| 1612 | bail0: |
| 1613 | TEEC_CloseSession(&cs[0]); |
| 1614 | } |
| 1615 | |
| 1616 | static void test_panic_ta_to_ta(ADBG_Case_t *c, const TEEC_UUID *uuid1, |
| 1617 | const TEEC_UUID *uuid2) |
| 1618 | { |
| 1619 | uint32_t ret_orig = 0; |
| 1620 | uint32_t counter = 0; |
| 1621 | TEEC_Session cs[3] = { }; |
| 1622 | |
| 1623 | /* Test pre-conditions */ |
| 1624 | /* 2.1 - CA opens a session toward TA1 */ |
| 1625 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1626 | xtest_teec_open_session(&cs[0], uuid1, NULL, |
| 1627 | &ret_orig))) |
| 1628 | return; |
| 1629 | |
| 1630 | /* 2.2 - CA opens a session toward TA2 */ |
| 1631 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1632 | xtest_teec_open_session(&cs[1], uuid2, NULL, |
| 1633 | &ret_orig))) |
| 1634 | goto bail0; |
| 1635 | |
| 1636 | /* 2.3 - TA1 opens a session toward TA2 */ |
| 1637 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, open_sec_session(&cs[0], uuid2))) |
| 1638 | goto bail1; |
| 1639 | |
| 1640 | /* 2.4 - CA invokes TA2 which panics */ |
| 1641 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1642 | trigger_panic(&cs[1], NULL))) |
| 1643 | goto bail1; |
| 1644 | |
| 1645 | /* Expected results */ |
| 1646 | /* 2.5 - Expect CA->TA1 session is still alive */ |
| 1647 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter))) |
| 1648 | goto bail1; |
| 1649 | |
| 1650 | /* 2.6 - Expect CA->TA2 session is properly released */ |
| 1651 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1652 | sims_get_counter(&cs[1], &counter))) |
| 1653 | goto bail1; |
| 1654 | |
| 1655 | bail1: |
| 1656 | TEEC_CloseSession(&cs[1]); |
| 1657 | bail0: |
| 1658 | TEEC_CloseSession(&cs[0]); |
| 1659 | |
| 1660 | memset(cs, 0, sizeof(cs)); |
| 1661 | |
| 1662 | /* Test pre-conditions */ |
| 1663 | /* 2.1 - CA opens a session toward TA1 */ |
| 1664 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1665 | xtest_teec_open_session(&cs[0], uuid1, NULL, |
| 1666 | &ret_orig))) |
| 1667 | return; |
| 1668 | |
| 1669 | /* 2.2 - CA opens a session toward TA2 */ |
| 1670 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1671 | xtest_teec_open_session(&cs[1], uuid2, NULL, |
| 1672 | &ret_orig))) |
| 1673 | goto bail2; |
| 1674 | |
| 1675 | /* 2.3 - TA1 opens a session toward TA2 */ |
| 1676 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, open_sec_session(&cs[0], uuid2))) |
| 1677 | goto bail3; |
| 1678 | |
| 1679 | /* 2.4 - CA invokes TA1 which invokes TA2 which panics */ |
| 1680 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, trigger_panic(&cs[0], uuid2))) |
| 1681 | goto bail3; |
| 1682 | |
| 1683 | /* Expected results */ |
| 1684 | /* 2.5 - Expect CA->TA1 session is still alive */ |
| 1685 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter))) |
| 1686 | goto bail3; |
| 1687 | |
| 1688 | /* 2.6 - Expect CA->TA2 session is properly released */ |
| 1689 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1690 | sims_get_counter(&cs[1], &counter))) |
| 1691 | goto bail3; |
| 1692 | |
| 1693 | bail3: |
| 1694 | TEEC_CloseSession(&cs[1]); |
| 1695 | bail2: |
| 1696 | TEEC_CloseSession(&cs[0]); |
| 1697 | } |
| 1698 | |
| 1699 | static void xtest_tee_test_1021(ADBG_Case_t *c) |
| 1700 | { |
| 1701 | Do_ADBG_BeginSubCase(c, "Multiple Instances Single Session"); |
| 1702 | test_panic_ca_to_ta(c, &miss_test_ta_uuid, true); |
| 1703 | Do_ADBG_EndSubCase(c, "Multiple Instances Single Session"); |
| 1704 | |
| 1705 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Sessions"); |
| 1706 | test_panic_ca_to_ta(c, &sims_test_ta_uuid, false); |
| 1707 | Do_ADBG_EndSubCase(c, "Single Instance Multi Sessions"); |
| 1708 | |
| 1709 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Sessions Keep Alive"); |
| 1710 | test_panic_ca_to_ta(c, &sims_keepalive_test_ta_uuid, false); |
| 1711 | Do_ADBG_EndSubCase(c, "Single Instance Multi Sessions Keep Alive"); |
| 1712 | |
| 1713 | Do_ADBG_BeginSubCase(c, "Multi Sessions TA to TA"); |
| 1714 | test_panic_ta_to_ta(c, &sims_test_ta_uuid, |
| 1715 | &sims_keepalive_test_ta_uuid); |
| 1716 | Do_ADBG_EndSubCase(c, "Multi Sessions TA to TA"); |
| 1717 | } |
| 1718 | ADBG_CASE_DEFINE(regression, 1021, xtest_tee_test_1021, |
| 1719 | "Test panic context release"); |
Jerome Forissier | a9ab5d0 | 2019-03-17 21:14:06 +0100 | [diff] [blame] | 1720 | |
| 1721 | static void xtest_tee_test_1022(ADBG_Case_t *c) |
| 1722 | { |
| 1723 | TEEC_Session session = { 0 }; |
| 1724 | uint32_t ret_orig = 0; |
| 1725 | |
| 1726 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1727 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 1728 | NULL, &ret_orig))) |
| 1729 | return; |
| 1730 | |
| 1731 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1732 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL, NULL, |
| 1733 | &ret_orig)); |
| 1734 | |
| 1735 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 1736 | TEEC_ERROR_TARGET_DEAD, |
| 1737 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL_PANIC, |
| 1738 | NULL, &ret_orig)); |
| 1739 | |
| 1740 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 1741 | |
| 1742 | TEEC_CloseSession(&session); |
| 1743 | } |
| 1744 | ADBG_CASE_DEFINE(regression, 1022, xtest_tee_test_1022, |
| 1745 | "Test dlopen()/dlsym()/dlclose() API"); |