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