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