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