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