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