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