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