Etienne Carriere | 9b7b70d | 2020-05-16 10:27:23 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 2 | /* |
Javier Almansa Sobrino | cddc000 | 2020-02-10 13:35:37 +0000 | [diff] [blame] | 3 | * Copyright (c) 2020, ARM Limited. All rights reserved. |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 4 | * Copyright (c) 2014, STMicroelectronics International N.V. |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 7 | #include <errno.h> |
Etienne Carriere | a465355 | 2017-01-11 10:04:24 +0100 | [diff] [blame] | 8 | #include <limits.h> |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 9 | #ifdef OPENSSL_FOUND |
| 10 | #include <openssl/bn.h> |
| 11 | #include <openssl/err.h> |
| 12 | #include <openssl/evp.h> |
| 13 | #include <openssl/rsa.h> |
| 14 | #include <openssl/sha.h> |
| 15 | #endif |
| 16 | #include <pta_attestation.h> |
| 17 | #include <pta_invoke_tests.h> |
| 18 | #include <pta_secstor_ta_mgmt.h> |
Etienne Carriere | a465355 | 2017-01-11 10:04:24 +0100 | [diff] [blame] | 19 | #include <pthread.h> |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 20 | #include <sdp_basic.h> |
| 21 | #include <signed_hdr.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 22 | #include <stdio.h> |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 23 | #include <stdlib.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 24 | #include <string.h> |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 25 | #include <sys/stat.h> |
| 26 | #include <sys/types.h> |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 27 | #include <ta_arm_bti.h> |
| 28 | #include <ta_concurrent.h> |
| 29 | #include <ta_create_fail_test.h> |
| 30 | #include <ta_crypt.h> |
| 31 | #include <ta_miss_test.h> |
| 32 | #include <ta_os_test.h> |
| 33 | #include <ta_rpc_test.h> |
| 34 | #include <ta_sims_keepalive_test.h> |
| 35 | #include <ta_sims_test.h> |
| 36 | #include <ta_supp_plugin.h> |
| 37 | #include <ta_tpm_log_test.h> |
| 38 | #include <test_supp_plugin.h> |
Etienne Carriere | a465355 | 2017-01-11 10:04:24 +0100 | [diff] [blame] | 39 | #include <unistd.h> |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 40 | #include <utee_defines.h> |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 41 | #include <util.h> |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 42 | |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 43 | #include "xtest_helpers.h" |
| 44 | #include "xtest_test.h" |
| 45 | #include "xtest_uuid_helpers.h" |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 46 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 47 | #ifndef MIN |
| 48 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 49 | #endif |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 50 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 51 | struct xtest_crypto_session { |
| 52 | ADBG_Case_t *c; |
| 53 | TEEC_Session *session; |
| 54 | uint32_t cmd_id_sha256; |
| 55 | uint32_t cmd_id_aes256ecb_encrypt; |
| 56 | uint32_t cmd_id_aes256ecb_decrypt; |
| 57 | }; |
| 58 | |
| 59 | static void xtest_crypto_test(struct xtest_crypto_session *cs) |
| 60 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 61 | uint32_t ret_orig = 0; |
| 62 | uint8_t crypt_out[16] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 63 | uint8_t crypt_in[16] = { 22, 17 }; |
| 64 | |
| 65 | crypt_in[15] = 60; |
| 66 | |
| 67 | Do_ADBG_BeginSubCase(cs->c, "AES encrypt"); |
| 68 | { |
| 69 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 70 | |
| 71 | op.params[0].tmpref.buffer = crypt_in; |
| 72 | op.params[0].tmpref.size = sizeof(crypt_in); |
| 73 | op.params[1].tmpref.buffer = crypt_out; |
| 74 | op.params[1].tmpref.size = sizeof(crypt_out); |
| 75 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 76 | TEEC_MEMREF_TEMP_OUTPUT, |
| 77 | TEEC_NONE, TEEC_NONE); |
| 78 | |
| 79 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 80 | TEEC_InvokeCommand(cs->session, |
| 81 | cs-> |
| 82 | cmd_id_aes256ecb_encrypt, |
| 83 | &op, |
| 84 | &ret_orig)); |
| 85 | } |
| 86 | Do_ADBG_EndSubCase(cs->c, "AES encrypt"); |
| 87 | |
| 88 | Do_ADBG_BeginSubCase(cs->c, "AES decrypt"); |
| 89 | { |
| 90 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 91 | uint8_t out[16] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 92 | |
| 93 | op.params[0].tmpref.buffer = crypt_out; |
| 94 | op.params[0].tmpref.size = sizeof(crypt_out); |
| 95 | op.params[1].tmpref.buffer = out; |
| 96 | op.params[1].tmpref.size = sizeof(out); |
| 97 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 98 | TEEC_MEMREF_TEMP_OUTPUT, |
| 99 | TEEC_NONE, TEEC_NONE); |
| 100 | |
| 101 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 102 | TEEC_InvokeCommand(cs->session, |
| 103 | cs-> |
| 104 | cmd_id_aes256ecb_decrypt, |
| 105 | &op, |
| 106 | &ret_orig)); |
| 107 | |
| 108 | if (!ADBG_EXPECT(cs->c, 0, |
| 109 | memcmp(crypt_in, out, sizeof(crypt_in)))) { |
| 110 | Do_ADBG_Log("crypt_in:"); |
| 111 | Do_ADBG_HexLog(crypt_in, sizeof(crypt_in), 16); |
| 112 | Do_ADBG_Log("out:"); |
| 113 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 114 | } |
| 115 | } |
| 116 | Do_ADBG_EndSubCase(cs->c, "AES decrypt"); |
| 117 | |
| 118 | Do_ADBG_BeginSubCase(cs->c, "SHA-256 test, 3 bytes input"); |
| 119 | { |
| 120 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 121 | static const uint8_t sha256_in[] = { 'a', 'b', 'c' }; |
| 122 | static const uint8_t sha256_out[] = { |
| 123 | 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, |
| 124 | 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, |
| 125 | 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, |
| 126 | 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad |
| 127 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 128 | uint8_t out[32] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 129 | |
| 130 | op.params[0].tmpref.buffer = (void *)sha256_in; |
| 131 | op.params[0].tmpref.size = sizeof(sha256_in); |
| 132 | op.params[1].tmpref.buffer = out; |
| 133 | op.params[1].tmpref.size = sizeof(out); |
| 134 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 135 | TEEC_MEMREF_TEMP_OUTPUT, |
| 136 | TEEC_NONE, TEEC_NONE); |
| 137 | |
| 138 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 139 | TEEC_InvokeCommand(cs->session, |
| 140 | cs-> |
| 141 | cmd_id_sha256, |
| 142 | &op, |
| 143 | &ret_orig)); |
| 144 | |
| 145 | if (!ADBG_EXPECT(cs->c, 0, memcmp(sha256_out, out, |
| 146 | sizeof(sha256_out)))) { |
| 147 | Do_ADBG_Log("sha256_out:"); |
| 148 | Do_ADBG_HexLog(sha256_out, sizeof(sha256_out), 16); |
| 149 | Do_ADBG_Log("out:"); |
| 150 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 151 | } |
| 152 | } |
| 153 | Do_ADBG_EndSubCase(cs->c, "SHA-256 test, 3 bytes input"); |
| 154 | |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 155 | Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 156 | { |
| 157 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 158 | static const uint8_t in[] = { |
| 159 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 160 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 161 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 162 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f |
| 163 | }; |
| 164 | static const uint8_t exp_out[] = { |
| 165 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 166 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 167 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 168 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 169 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 170 | uint8_t out[sizeof(exp_out)] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 171 | |
| 172 | op.params[0].tmpref.buffer = (void *)in; |
| 173 | op.params[0].tmpref.size = sizeof(in); |
| 174 | op.params[1].tmpref.buffer = out; |
| 175 | op.params[1].tmpref.size = sizeof(out); |
| 176 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 177 | TEEC_MEMREF_TEMP_OUTPUT, |
| 178 | TEEC_NONE, TEEC_NONE); |
| 179 | |
| 180 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 181 | TEEC_InvokeCommand(cs->session, |
| 182 | cs-> |
| 183 | cmd_id_aes256ecb_encrypt, |
| 184 | &op, |
| 185 | &ret_orig)); |
| 186 | |
| 187 | if (!ADBG_EXPECT(cs->c, 0, |
| 188 | memcmp(exp_out, out, sizeof(exp_out)))) { |
| 189 | Do_ADBG_Log("exp_out:"); |
| 190 | Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16); |
| 191 | Do_ADBG_Log("out:"); |
| 192 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 193 | } |
| 194 | } |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 195 | Do_ADBG_EndSubCase(cs->c, "AES-256 ECB encrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 196 | |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 197 | Do_ADBG_BeginSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 198 | { |
| 199 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 200 | static const uint8_t in[] = { |
| 201 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 202 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 203 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 204 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 205 | }; |
| 206 | static const uint8_t exp_out[] = { |
| 207 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 208 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 209 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 210 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f |
| 211 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 212 | uint8_t out[sizeof(exp_out)] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 213 | |
| 214 | op.params[0].tmpref.buffer = (void *)in; |
| 215 | op.params[0].tmpref.size = sizeof(in); |
| 216 | op.params[1].tmpref.buffer = out; |
| 217 | op.params[1].tmpref.size = sizeof(out); |
| 218 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 219 | TEEC_MEMREF_TEMP_OUTPUT, |
| 220 | TEEC_NONE, TEEC_NONE); |
| 221 | |
| 222 | (void)ADBG_EXPECT_TEEC_SUCCESS(cs->c, |
| 223 | TEEC_InvokeCommand(cs->session, |
| 224 | cs-> |
| 225 | cmd_id_aes256ecb_decrypt, |
| 226 | &op, |
| 227 | &ret_orig)); |
| 228 | |
| 229 | if (!ADBG_EXPECT(cs->c, 0, |
| 230 | memcmp(exp_out, out, sizeof(exp_out)))) { |
| 231 | Do_ADBG_Log("exp_out:"); |
| 232 | Do_ADBG_HexLog(exp_out, sizeof(exp_out), 16); |
| 233 | Do_ADBG_Log("out:"); |
| 234 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 235 | } |
| 236 | } |
Etienne Carriere | a319852 | 2017-10-26 09:48:55 +0200 | [diff] [blame] | 237 | Do_ADBG_EndSubCase(cs->c, "AES-256 ECB decrypt (32B, fixed key)"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static void xtest_tee_test_1001(ADBG_Case_t *c) |
| 241 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 242 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 243 | TEEC_Session session = { }; |
| 244 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 245 | |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 246 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Etienne Carriere | 726d8bc | 2017-03-21 15:45:59 +0100 | [diff] [blame] | 247 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 248 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 249 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 250 | Do_ADBG_Log(" - 1001 - skip test, pseudo TA not found"); |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 251 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 252 | } |
Etienne Carriere | 3ea9672 | 2022-03-11 09:16:40 +0100 | [diff] [blame^] | 253 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 254 | return; |
| 255 | |
| 256 | Do_ADBG_BeginSubCase(c, "Core self tests"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 257 | |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 258 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand( |
Etienne Carriere | 726d8bc | 2017-03-21 15:45:59 +0100 | [diff] [blame] | 259 | &session, PTA_INVOKE_TESTS_CMD_SELF_TESTS, NULL, &ret_orig)); |
Etienne Carriere | 3ea9672 | 2022-03-11 09:16:40 +0100 | [diff] [blame^] | 260 | |
| 261 | Do_ADBG_EndSubCase(c, "Core self tests"); |
| 262 | |
| 263 | Do_ADBG_BeginSubCase(c, "Core dt_driver self tests"); |
| 264 | |
| 265 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand( |
| 266 | &session, PTA_INVOKE_TESTS_CMD_DT_DRIVER_TESTS, NULL, |
| 267 | &ret_orig)); |
| 268 | |
| 269 | Do_ADBG_EndSubCase(c, "Core dt_driver self tests"); |
| 270 | |
Jens Wiklander | cf16e84 | 2016-02-10 09:07:09 +0100 | [diff] [blame] | 271 | TEEC_CloseSession(&session); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 272 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 273 | ADBG_CASE_DEFINE(regression, 1001, xtest_tee_test_1001, "Core self tests"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 274 | |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 275 | static void xtest_tee_test_1002(ADBG_Case_t *c) |
| 276 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 277 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 278 | TEEC_Session session = { }; |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 279 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 280 | uint32_t ret_orig = 0; |
| 281 | uint8_t buf[16 * 1024] = { }; |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 282 | uint8_t exp_sum = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 283 | size_t n = 0; |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 284 | |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 285 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 286 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 287 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 288 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 289 | Do_ADBG_Log(" - 1002 - skip test, pseudo TA not found"); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 290 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 291 | } |
| 292 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 293 | |
| 294 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, |
| 295 | TEEC_NONE, TEEC_NONE); |
| 296 | op.params[0].tmpref.size = sizeof(buf); |
| 297 | op.params[0].tmpref.buffer = buf; |
| 298 | |
| 299 | for (n = 0; n < sizeof(buf); n++) |
| 300 | buf[n] = n + 1; |
| 301 | for (n = 0; n < sizeof(buf); n++) |
| 302 | exp_sum += buf[n]; |
| 303 | |
| 304 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand( |
| 305 | &session, PTA_INVOKE_TESTS_CMD_PARAMS, &op, &ret_orig))) |
| 306 | goto out; |
| 307 | |
| 308 | ADBG_EXPECT_COMPARE_SIGNED(c, exp_sum, ==, buf[0]); |
| 309 | out: |
| 310 | TEEC_CloseSession(&session); |
| 311 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 312 | ADBG_CASE_DEFINE(regression, 1002, xtest_tee_test_1002, "PTA parameters"); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 313 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 314 | struct test_1003_arg { |
| 315 | uint32_t test_type; |
| 316 | size_t repeat; |
| 317 | size_t max_before_lockers; |
| 318 | size_t max_during_lockers; |
| 319 | size_t before_lockers; |
| 320 | size_t during_lockers; |
| 321 | TEEC_Result res; |
| 322 | uint32_t error_orig; |
| 323 | }; |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 324 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 325 | static void *test_1003_thread(void *arg) |
| 326 | { |
| 327 | struct test_1003_arg *a = arg; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 328 | TEEC_Session session = { }; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 329 | size_t rounds = 64 * 1024; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 330 | size_t n = 0; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 331 | |
| 332 | a->res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, |
| 333 | NULL, &a->error_orig); |
| 334 | if (a->res != TEEC_SUCCESS) |
| 335 | return NULL; |
| 336 | |
| 337 | for (n = 0; n < a->repeat; n++) { |
| 338 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 339 | |
| 340 | op.params[0].value.a = a->test_type; |
| 341 | op.params[0].value.b = rounds; |
| 342 | |
| 343 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 344 | TEEC_VALUE_OUTPUT, |
| 345 | TEEC_NONE, TEEC_NONE); |
| 346 | a->res = TEEC_InvokeCommand(&session, |
| 347 | PTA_INVOKE_TESTS_CMD_MUTEX, |
| 348 | &op, &a->error_orig); |
| 349 | if (a->test_type == PTA_MUTEX_TEST_WRITER && |
| 350 | op.params[1].value.b != 1) { |
| 351 | Do_ADBG_Log("n %zu %" PRIu32, n, op.params[1].value.b); |
| 352 | a->res = TEEC_ERROR_BAD_STATE; |
| 353 | a->error_orig = 42; |
| 354 | break; |
| 355 | } |
| 356 | |
| 357 | if (a->test_type == PTA_MUTEX_TEST_READER) { |
| 358 | if (op.params[1].value.a > a->max_before_lockers) |
| 359 | a->max_before_lockers = op.params[1].value.a; |
| 360 | |
| 361 | if (op.params[1].value.b > a->max_during_lockers) |
| 362 | a->max_during_lockers = op.params[1].value.b; |
| 363 | |
| 364 | a->before_lockers += op.params[1].value.a; |
| 365 | a->during_lockers += op.params[1].value.b; |
| 366 | } |
| 367 | } |
| 368 | TEEC_CloseSession(&session); |
| 369 | |
| 370 | return NULL; |
| 371 | } |
| 372 | |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 373 | #define TEST_1003_THREAD_COUNT (3 * 2) |
| 374 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 375 | static void xtest_tee_test_1003(ADBG_Case_t *c) |
| 376 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 377 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 378 | TEEC_Session session = { }; |
| 379 | uint32_t ret_orig = 0; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 380 | size_t repeat = 20; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 381 | struct test_1003_arg arg[TEST_1003_THREAD_COUNT] = { }; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 382 | size_t max_read_concurrency = 0; |
| 383 | size_t max_read_waiters = 0; |
| 384 | size_t num_concurrent_read_lockers = 0; |
| 385 | size_t num_concurrent_read_waiters = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 386 | size_t n = 0; |
| 387 | size_t nt = TEST_1003_THREAD_COUNT; |
| 388 | double mean_read_concurrency = 0; |
| 389 | double mean_read_waiters = 0; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 390 | size_t num_writers = 0; |
| 391 | size_t num_readers = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 392 | pthread_t thr[TEST_1003_THREAD_COUNT] = { }; |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 393 | |
| 394 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
| 395 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 396 | &ret_orig); |
| 397 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 398 | Do_ADBG_Log(" - 1003 - skip test, pseudo TA not found"); |
| 399 | return; |
| 400 | } |
| 401 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 402 | TEEC_CloseSession(&session); |
| 403 | |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 404 | for (n = 0; n < nt; n++) { |
| 405 | if (n % 3) { |
| 406 | arg[n].test_type = PTA_MUTEX_TEST_READER; |
| 407 | num_readers++; |
| 408 | } else { |
| 409 | arg[n].test_type = PTA_MUTEX_TEST_WRITER; |
| 410 | num_writers++; |
| 411 | } |
| 412 | arg[n].repeat = repeat; |
| 413 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 414 | test_1003_thread, arg + n))) |
| 415 | nt = n; /* break loop and start cleanup */ |
| 416 | } |
| 417 | |
| 418 | for (n = 0; n < nt; n++) { |
| 419 | ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)); |
| 420 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res)) |
| 421 | Do_ADBG_Log("error origin %" PRIu32, |
| 422 | arg[n].error_orig); |
| 423 | if (arg[n].test_type == PTA_MUTEX_TEST_READER) { |
| 424 | if (arg[n].max_during_lockers > max_read_concurrency) |
| 425 | max_read_concurrency = |
| 426 | arg[n].max_during_lockers; |
| 427 | |
| 428 | if (arg[n].max_before_lockers > max_read_waiters) |
| 429 | max_read_waiters = arg[n].max_before_lockers; |
| 430 | |
| 431 | num_concurrent_read_lockers += arg[n].during_lockers; |
| 432 | num_concurrent_read_waiters += arg[n].before_lockers; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | mean_read_concurrency = (double)num_concurrent_read_lockers / |
| 437 | (double)(repeat * num_readers); |
| 438 | mean_read_waiters = (double)num_concurrent_read_waiters / |
| 439 | (double)(repeat * num_readers); |
| 440 | |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 441 | Do_ADBG_Log(" Number of parallel threads: %d (%zu writers and %zu readers)", |
| 442 | TEST_1003_THREAD_COUNT, num_writers, num_readers); |
Jens Wiklander | 0c86bc3 | 2017-11-13 19:52:03 +0100 | [diff] [blame] | 443 | Do_ADBG_Log(" Max read concurrency: %zu", max_read_concurrency); |
| 444 | Do_ADBG_Log(" Max read waiters: %zu", max_read_waiters); |
| 445 | Do_ADBG_Log(" Mean read concurrency: %g", mean_read_concurrency); |
| 446 | Do_ADBG_Log(" Mean read waiting: %g", mean_read_waiters); |
| 447 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 448 | ADBG_CASE_DEFINE(regression, 1003, xtest_tee_test_1003, |
| 449 | "Core internal read/write mutex"); |
Jens Wiklander | 1d70a11 | 2017-10-16 15:16:39 +0200 | [diff] [blame] | 450 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 451 | static void xtest_tee_test_1004(ADBG_Case_t *c) |
| 452 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 453 | TEEC_Session session = { }; |
| 454 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 455 | struct xtest_crypto_session cs = { c, &session, TA_CRYPT_CMD_SHA256, |
| 456 | TA_CRYPT_CMD_AES256ECB_ENC, |
| 457 | TA_CRYPT_CMD_AES256ECB_DEC }; |
| 458 | |
| 459 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, xtest_teec_open_session( |
| 460 | &session, &crypt_user_ta_uuid, |
| 461 | NULL, &ret_orig))) |
| 462 | return; |
| 463 | |
| 464 | /* Run the "complete crypto test suite" */ |
| 465 | xtest_crypto_test(&cs); |
| 466 | |
| 467 | TEEC_CloseSession(&session); |
| 468 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 469 | 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] | 470 | |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 471 | 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] | 472 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 473 | TEEC_Session session = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 474 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 475 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 476 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 477 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 478 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 479 | &ret_orig))) |
| 480 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 481 | |
| 482 | op.params[0].value.a = n; |
| 483 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, |
| 484 | TEEC_NONE); |
| 485 | |
| 486 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 487 | TEEC_ERROR_TARGET_DEAD, |
| 488 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
| 489 | &ret_orig)); |
| 490 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 491 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 492 | TEEC_ERROR_TARGET_DEAD, |
| 493 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 494 | &ret_orig)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 495 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 496 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 497 | |
| 498 | TEEC_CloseSession(&session); |
| 499 | } |
| 500 | |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 501 | static void xtest_tee_test_invalid_mem_access2(ADBG_Case_t *c, unsigned int n, |
| 502 | size_t size) |
| 503 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 504 | TEEC_Session session = { }; |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 505 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 506 | uint32_t ret_orig = 0; |
| 507 | TEEC_SharedMemory shm = { }; |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 508 | |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 509 | shm.size = size; |
| 510 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 511 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 512 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 513 | return; |
| 514 | |
| 515 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 516 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 517 | &ret_orig))) |
Jens Wiklander | 6987a82 | 2019-06-28 12:47:42 +0200 | [diff] [blame] | 518 | goto rel_shm; |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 519 | |
| 520 | op.params[0].value.a = (uint32_t)n; |
| 521 | op.params[1].memref.parent = &shm; |
| 522 | op.params[1].memref.size = size; |
| 523 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_MEMREF_WHOLE, |
| 524 | TEEC_NONE, TEEC_NONE); |
| 525 | |
| 526 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 527 | TEEC_ERROR_TARGET_DEAD, |
| 528 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
| 529 | &ret_orig)); |
| 530 | |
| 531 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 532 | TEEC_ERROR_TARGET_DEAD, |
| 533 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BAD_MEM_ACCESS, &op, |
| 534 | &ret_orig)); |
| 535 | |
| 536 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 537 | |
| 538 | TEEC_CloseSession(&session); |
Jens Wiklander | 6987a82 | 2019-06-28 12:47:42 +0200 | [diff] [blame] | 539 | rel_shm: |
| 540 | TEEC_ReleaseSharedMemory(&shm); |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 541 | } |
| 542 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 543 | static void xtest_tee_test_1005(ADBG_Case_t *c) |
| 544 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 545 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 546 | #define MAX_SESSIONS 3 |
| 547 | TEEC_Session sessions[MAX_SESSIONS]; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 548 | int i = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 549 | |
| 550 | for (i = 0; i < MAX_SESSIONS; i++) { |
| 551 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Jens Wiklander | eb6bce7 | 2016-09-23 11:37:33 +0200 | [diff] [blame] | 552 | xtest_teec_open_session(&sessions[i], |
| 553 | &concurrent_ta_uuid, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 554 | NULL, &ret_orig))) |
| 555 | break; |
| 556 | } |
| 557 | |
| 558 | for (; --i >= 0; ) |
| 559 | TEEC_CloseSession(&sessions[i]); |
| 560 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 561 | ADBG_CASE_DEFINE(regression, 1005, xtest_tee_test_1005, "Many sessions"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 562 | |
| 563 | static void xtest_tee_test_1006(ADBG_Case_t *c) |
| 564 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 565 | TEEC_Session session = { }; |
| 566 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 567 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 568 | uint8_t buf[32] = { }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 569 | |
| 570 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 571 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 572 | &ret_orig))) |
| 573 | return; |
| 574 | |
| 575 | op.params[0].tmpref.buffer = buf; |
| 576 | op.params[0].tmpref.size = sizeof(buf); |
| 577 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, |
| 578 | TEEC_NONE, TEEC_NONE); |
| 579 | |
| 580 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 581 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_BASIC, &op, |
| 582 | &ret_orig)); |
| 583 | |
| 584 | TEEC_CloseSession(&session); |
| 585 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 586 | ADBG_CASE_DEFINE(regression, 1006, xtest_tee_test_1006, |
| 587 | "Test Basic OS features"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 588 | |
| 589 | static void xtest_tee_test_1007(ADBG_Case_t *c) |
| 590 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 591 | TEEC_Session session = { }; |
| 592 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 593 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 594 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 595 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 596 | &ret_orig))) |
| 597 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 598 | |
| 599 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 600 | TEEC_ERROR_TARGET_DEAD, |
| 601 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PANIC, NULL, |
| 602 | &ret_orig)); |
| 603 | |
| 604 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 605 | |
| 606 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 607 | TEEC_ERROR_TARGET_DEAD, |
| 608 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_INIT, NULL, |
| 609 | &ret_orig)); |
| 610 | |
| 611 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 612 | |
| 613 | TEEC_CloseSession(&session); |
| 614 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 615 | ADBG_CASE_DEFINE(regression, 1007, xtest_tee_test_1007, "Test Panic"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 616 | |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 617 | #ifndef TA_DIR |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 618 | # ifdef __ANDROID__ |
Yongqin Liu | 286f1fc | 2018-06-21 22:09:15 +0800 | [diff] [blame] | 619 | #define TA_DIR "/vendor/lib/optee_armtz" |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 620 | # else |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 621 | #define TA_DIR "/lib/optee_armtz" |
Victor Chong | 3d8798f | 2017-03-01 18:31:48 +0000 | [diff] [blame] | 622 | # endif |
Jerome Forissier | f02a221 | 2015-10-29 14:33:35 +0100 | [diff] [blame] | 623 | #endif |
| 624 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 625 | static FILE *open_ta_file(const TEEC_UUID *uuid, const char *mode) |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 626 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 627 | char buf[PATH_MAX] = { }; |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 628 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 629 | snprintf(buf, sizeof(buf), |
Jens Wiklander | 6203b87 | 2016-12-08 19:18:29 +0100 | [diff] [blame] | 630 | "%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] | 631 | TA_DIR, uuid->timeLow, uuid->timeMid, uuid->timeHiAndVersion, |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 632 | uuid->clockSeqAndNode[0], uuid->clockSeqAndNode[1], |
| 633 | uuid->clockSeqAndNode[2], uuid->clockSeqAndNode[3], |
| 634 | uuid->clockSeqAndNode[4], uuid->clockSeqAndNode[5], |
David Brown | b2865ab | 2016-08-02 11:44:41 -0600 | [diff] [blame] | 635 | uuid->clockSeqAndNode[6], uuid->clockSeqAndNode[7]); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 636 | |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 637 | return fopen(buf, mode); |
| 638 | } |
| 639 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 640 | 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] | 641 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 642 | TEEC_Session session = { }; |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 643 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 644 | TEEC_UUID uuid = PTA_SECSTOR_TA_MGMT_UUID; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 645 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 646 | uint32_t ret_orig = 0; |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 647 | FILE *f = NULL; |
| 648 | bool r = false; |
| 649 | uint8_t *buf = NULL; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 650 | size_t sz = 0; |
| 651 | size_t fread_res = 0; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 652 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 653 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 654 | xtest_teec_open_session(&session, &uuid, NULL, &ret_orig))) |
| 655 | goto out; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 656 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 657 | f = open_ta_file(&create_fail_test_ta_uuid, "rb"); |
| 658 | if (!ADBG_EXPECT_NOT_NULL(c, f)) |
| 659 | goto out; |
| 660 | if (!ADBG_EXPECT_TRUE(c, !fseek(f, 0, SEEK_END))) |
| 661 | goto out; |
| 662 | sz = ftell(f); |
| 663 | rewind(f); |
| 664 | |
| 665 | buf = malloc(sz); |
| 666 | if (!ADBG_EXPECT_NOT_NULL(c, buf)) |
| 667 | goto out; |
| 668 | |
| 669 | fread_res = fread(buf, 1, sz, f); |
| 670 | if (!ADBG_EXPECT_COMPARE_UNSIGNED(c, fread_res, ==, sz)) |
| 671 | goto out; |
| 672 | |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 673 | fclose(f); |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 674 | f = NULL; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 675 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 676 | buf[MIN(offs, sz)] ^= mask; |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 677 | |
Jens Wiklander | ec545fb | 2017-11-24 16:58:07 +0100 | [diff] [blame] | 678 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, |
| 679 | TEEC_NONE, TEEC_NONE); |
| 680 | op.params[0].tmpref.buffer = buf; |
| 681 | op.params[0].tmpref.size = sz; |
| 682 | |
| 683 | res = TEEC_InvokeCommand(&session, PTA_SECSTOR_TA_MGMT_BOOTSTRAP, &op, |
| 684 | &ret_orig); |
| 685 | r = ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_SECURITY, res); |
| 686 | out: |
| 687 | free(buf); |
| 688 | if (f) |
| 689 | fclose(f); |
| 690 | TEEC_CloseSession(&session); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 691 | return r; |
| 692 | } |
Jens Wiklander | e1a201d | 2020-02-12 18:36:20 +0100 | [diff] [blame] | 693 | |
| 694 | static void test_1008_corrupt_ta(ADBG_Case_t *c) |
| 695 | { |
| 696 | TEEC_UUID uuid = PTA_SECSTOR_TA_MGMT_UUID; |
| 697 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 698 | TEEC_Session session = { }; |
| 699 | uint32_t ret_orig = 0; |
| 700 | |
| 701 | res = xtest_teec_open_session(&session, &uuid, NULL, &ret_orig); |
| 702 | if (res) { |
| 703 | if (ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND, |
| 704 | res)) |
Joakim Bech | a1212b6 | 2020-04-07 12:06:00 +0200 | [diff] [blame] | 705 | Do_ADBG_Log("PTA Secure Storage TA Management not found: skip test"); |
Jens Wiklander | e1a201d | 2020-02-12 18:36:20 +0100 | [diff] [blame] | 706 | return; |
| 707 | } |
| 708 | TEEC_CloseSession(&session); |
| 709 | |
| 710 | ADBG_EXPECT_TRUE(c, |
| 711 | load_corrupt_ta(c, offsetof(struct shdr, magic), 1)); |
| 712 | ADBG_EXPECT_TRUE(c, |
| 713 | load_corrupt_ta(c, offsetof(struct shdr, img_type), 1)); |
| 714 | ADBG_EXPECT_TRUE(c, |
| 715 | load_corrupt_ta(c, offsetof(struct shdr, img_size), 1)); |
| 716 | ADBG_EXPECT_TRUE(c, |
| 717 | load_corrupt_ta(c, offsetof(struct shdr, algo), 1)); |
| 718 | ADBG_EXPECT_TRUE(c, |
| 719 | load_corrupt_ta(c, offsetof(struct shdr, hash_size), 1)); |
| 720 | ADBG_EXPECT_TRUE(c, |
| 721 | load_corrupt_ta(c, offsetof(struct shdr, sig_size), 1)); |
| 722 | ADBG_EXPECT_TRUE(c, |
| 723 | load_corrupt_ta(c, sizeof(struct shdr), 1)); /* hash */ |
| 724 | ADBG_EXPECT_TRUE(c, |
| 725 | load_corrupt_ta(c, sizeof(struct shdr) + 32, 1)); /* sig */ |
| 726 | ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 3000, 1)); /* payload */ |
| 727 | ADBG_EXPECT_TRUE(c, load_corrupt_ta(c, 8000, 1)); /* payload */ |
| 728 | } |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 729 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 730 | static void xtest_tee_test_1008(ADBG_Case_t *c) |
| 731 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 732 | TEEC_Session session = { }; |
| 733 | TEEC_Session session_crypt = { }; |
| 734 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 735 | |
| 736 | Do_ADBG_BeginSubCase(c, "Invoke command"); |
| 737 | { |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 738 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 739 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 740 | NULL, &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 741 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 742 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 743 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CLIENT, |
| 744 | NULL, &ret_orig)); |
| 745 | TEEC_CloseSession(&session); |
| 746 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 747 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 748 | } |
| 749 | Do_ADBG_EndSubCase(c, "Invoke command"); |
| 750 | |
| 751 | Do_ADBG_BeginSubCase(c, "Invoke command with timeout"); |
| 752 | { |
| 753 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 754 | |
| 755 | op.params[0].value.a = 2000; |
| 756 | op.paramTypes = TEEC_PARAM_TYPES( |
| 757 | TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 758 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 759 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 760 | xtest_teec_open_session(&session, |
| 761 | &os_test_ta_uuid, |
| 762 | NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 763 | &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 764 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 765 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 766 | TEEC_InvokeCommand(&session, |
| 767 | TA_OS_TEST_CMD_CLIENT_WITH_TIMEOUT, |
| 768 | &op, &ret_orig)); |
| 769 | TEEC_CloseSession(&session); |
| 770 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 771 | } |
| 772 | Do_ADBG_EndSubCase(c, "Invoke command with timeout"); |
| 773 | |
| 774 | Do_ADBG_BeginSubCase(c, "Create session fail"); |
| 775 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 776 | size_t n = 0; |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 777 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 778 | for (n = 0; n < 100; n++) { |
| 779 | Do_ADBG_Log("n = %zu", n); |
| 780 | (void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC, |
| 781 | xtest_teec_open_session(&session_crypt, |
| 782 | &create_fail_test_ta_uuid, |
| 783 | NULL, &ret_orig)); |
Jerome Forissier | ec7a31f | 2020-11-20 11:30:06 +0100 | [diff] [blame] | 784 | /* level > 0 may be used to detect/debug memory leaks */ |
| 785 | if (!level) |
| 786 | break; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | Do_ADBG_EndSubCase(c, "Create session fail"); |
Jens Wiklander | b794089 | 2015-10-23 16:02:40 +0200 | [diff] [blame] | 790 | |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 791 | Do_ADBG_BeginSubCase(c, "Load corrupt TA"); |
Jens Wiklander | e1a201d | 2020-02-12 18:36:20 +0100 | [diff] [blame] | 792 | test_1008_corrupt_ta(c); |
Jens Wiklander | 4441fe2 | 2015-10-23 16:53:02 +0200 | [diff] [blame] | 793 | Do_ADBG_EndSubCase(c, "Load corrupt TA"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 794 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 795 | ADBG_CASE_DEFINE(regression, 1008, xtest_tee_test_1008, |
| 796 | "TEE internal client API"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 797 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 798 | static void *cancellation_thread(void *arg) |
| 799 | { |
| 800 | /* |
| 801 | * Sleep 0.5 seconds before cancellation to make sure that the other |
| 802 | * thread is in RPC_WAIT. |
| 803 | */ |
| 804 | (void)usleep(500000); |
| 805 | TEEC_RequestCancellation(arg); |
| 806 | return NULL; |
| 807 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 808 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 809 | static void xtest_tee_test_1009_subcase(ADBG_Case_t *c, const char *subcase, |
| 810 | uint32_t timeout, bool cancel) |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 811 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 812 | TEEC_Session session = { }; |
| 813 | uint32_t ret_orig = 0; |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 814 | pthread_t thr; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 815 | |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 816 | memset(&thr, 0, sizeof(thr)); |
| 817 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 818 | Do_ADBG_BeginSubCase(c, "%s", subcase); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 819 | { |
| 820 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 821 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 822 | if (ADBG_EXPECT_TEEC_SUCCESS(c, |
| 823 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 824 | NULL, &ret_orig))) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 825 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 826 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, |
| 827 | TEEC_ORIGIN_TRUSTED_APP, |
| 828 | ret_orig); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 829 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 830 | op.params[0].value.a = timeout; |
| 831 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 832 | TEEC_NONE, |
| 833 | TEEC_NONE, TEEC_NONE); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 834 | if (cancel) { |
| 835 | (void)ADBG_EXPECT(c, 0, |
| 836 | pthread_create(&thr, NULL, |
| 837 | cancellation_thread, &op)); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 838 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 839 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 840 | TEEC_ERROR_CANCEL, |
| 841 | TEEC_InvokeCommand(&session, |
| 842 | TA_OS_TEST_CMD_WAIT, |
| 843 | &op, |
| 844 | &ret_orig)); |
| 845 | } else |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 846 | |
| 847 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 848 | TEEC_InvokeCommand(&session, |
| 849 | TA_OS_TEST_CMD_WAIT, |
| 850 | &op, |
| 851 | &ret_orig)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 852 | if (cancel) |
| 853 | (void)ADBG_EXPECT(c, 0, pthread_join(thr, NULL)); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 854 | |
| 855 | TEEC_CloseSession(&session); |
| 856 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 857 | } |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 858 | Do_ADBG_EndSubCase(c, "%s", subcase); |
| 859 | } |
| 860 | |
| 861 | static void xtest_tee_test_1009(ADBG_Case_t *c) |
| 862 | { |
| 863 | xtest_tee_test_1009_subcase(c, "TEE Wait 0.1s", 100, false); |
| 864 | xtest_tee_test_1009_subcase(c, "TEE Wait 0.5s", 500, false); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 865 | xtest_tee_test_1009_subcase(c, "TEE Wait 2s cancel", 2000, true); |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 866 | xtest_tee_test_1009_subcase(c, "TEE Wait 2s", 2000, false); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 867 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 868 | ADBG_CASE_DEFINE(regression, 1009, xtest_tee_test_1009, "TEE Wait"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 869 | |
| 870 | static void xtest_tee_test_1010(ADBG_Case_t *c) |
| 871 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 872 | unsigned int n = 0; |
| 873 | unsigned int idx = 0; |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 874 | size_t memref_sz[] = { 1024, 65536 }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 875 | |
Jerome Forissier | e4c33f4 | 2021-09-21 11:26:17 +0200 | [diff] [blame] | 876 | for (n = 1; n <= 7; n++) { |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 877 | Do_ADBG_BeginSubCase(c, "Invalid memory access %u", n); |
| 878 | xtest_tee_test_invalid_mem_access(c, n); |
| 879 | Do_ADBG_EndSubCase(c, "Invalid memory access %u", n); |
| 880 | } |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 881 | |
| 882 | for (idx = 0; idx < ARRAY_SIZE(memref_sz); idx++) { |
| 883 | for (n = 1; n <= 5; n++) { |
| 884 | Do_ADBG_BeginSubCase(c, |
Igor Opaniuk | e8236ac | 2018-02-12 12:26:25 +0200 | [diff] [blame] | 885 | "Invalid memory access %u with %zu bytes memref", |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 886 | n, memref_sz[idx]); |
| 887 | xtest_tee_test_invalid_mem_access2(c, n, memref_sz[idx]); |
| 888 | Do_ADBG_EndSubCase(c, |
Igor Opaniuk | e8236ac | 2018-02-12 12:26:25 +0200 | [diff] [blame] | 889 | "Invalid memory access %u with %zu bytes memref", |
Etienne Carriere | 92c3442 | 2018-02-09 13:11:40 +0100 | [diff] [blame] | 890 | n, memref_sz[idx]); |
| 891 | } |
| 892 | } |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 893 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 894 | ADBG_CASE_DEFINE(regression, 1010, xtest_tee_test_1010, |
| 895 | "Invalid memory access"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 896 | |
| 897 | static void xtest_tee_test_1011(ADBG_Case_t *c) |
| 898 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 899 | TEEC_Session session = { }; |
| 900 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 901 | struct xtest_crypto_session cs = { |
| 902 | c, &session, TA_RPC_CMD_CRYPT_SHA256, |
| 903 | TA_RPC_CMD_CRYPT_AES256ECB_ENC, |
| 904 | TA_RPC_CMD_CRYPT_AES256ECB_DEC |
| 905 | }; |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 906 | struct xtest_crypto_session cs_privmem = { |
| 907 | c, &session, |
| 908 | TA_RPC_CMD_CRYPT_PRIVMEM_SHA256, |
| 909 | TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_ENC, |
| 910 | TA_RPC_CMD_CRYPT_PRIVMEM_AES256ECB_DEC |
| 911 | }; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 912 | TEEC_UUID uuid = rpc_test_ta_uuid; |
| 913 | |
| 914 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 915 | xtest_teec_open_session(&session, &uuid, NULL, &ret_orig))) |
| 916 | return; |
| 917 | |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 918 | Do_ADBG_BeginSubCase(c, "TA-to-TA via non-secure shared memory"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 919 | /* |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 920 | * Run the "complete crypto test suite" using TA-to-TA |
| 921 | * communication |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 922 | */ |
| 923 | xtest_crypto_test(&cs); |
Jens Wiklander | f7b9c63 | 2017-01-03 17:32:26 +0100 | [diff] [blame] | 924 | Do_ADBG_EndSubCase(c, "TA-to-TA via non-secure shared memory"); |
| 925 | |
| 926 | Do_ADBG_BeginSubCase(c, "TA-to-TA via TA private memory"); |
| 927 | /* |
| 928 | * Run the "complete crypto test suite" using TA-to-TA |
| 929 | * communication via TA private memory. |
| 930 | */ |
| 931 | xtest_crypto_test(&cs_privmem); |
| 932 | Do_ADBG_EndSubCase(c, "TA-to-TA via TA private memory"); |
| 933 | |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 934 | TEEC_CloseSession(&session); |
| 935 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 936 | ADBG_CASE_DEFINE(regression, 1011, xtest_tee_test_1011, |
| 937 | "Test TA-to-TA features with User Crypt TA"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 938 | |
| 939 | /* |
| 940 | * Note that this test is failing when |
| 941 | * - running twice in a raw |
| 942 | * - and the user TA is statically linked |
| 943 | * This is because the counter is not reseted when opening the first session |
| 944 | * in case the TA is statically linked |
| 945 | */ |
| 946 | static void xtest_tee_test_1012(ADBG_Case_t *c) |
| 947 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 948 | TEEC_Session session1 = { }; |
| 949 | TEEC_Session session2 = { }; |
| 950 | uint32_t ret_orig = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 951 | TEEC_UUID uuid = sims_test_ta_uuid; |
| 952 | |
| 953 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Session"); |
| 954 | { |
| 955 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 956 | static const uint8_t in[] = { |
| 957 | 0x5A, 0x6E, 0x04, 0x57, 0x08, 0xFB, 0x71, 0x96, |
| 958 | 0xF0, 0x2E, 0x55, 0x3D, 0x02, 0xC3, 0xA6, 0x92, |
| 959 | 0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6, |
| 960 | 0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E |
| 961 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 962 | uint8_t out[32] = { }; |
| 963 | int i = 0; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 964 | |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 965 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 966 | xtest_teec_open_session(&session1, &uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 967 | &ret_orig))) |
| 968 | return; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 969 | |
| 970 | op.params[0].value.a = 0; |
| 971 | op.params[1].tmpref.buffer = (void *)in; |
| 972 | op.params[1].tmpref.size = sizeof(in); |
| 973 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 974 | TEEC_MEMREF_TEMP_INPUT, |
| 975 | TEEC_NONE, TEEC_NONE); |
| 976 | |
| 977 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 978 | TEEC_InvokeCommand(&session1, TA_SIMS_CMD_WRITE, &op, |
| 979 | &ret_orig)); |
| 980 | |
Jerome Forissier | 3cc0a42 | 2017-12-14 09:53:24 +0100 | [diff] [blame] | 981 | for (i = 1; i < 3; i++) { |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 982 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 983 | xtest_teec_open_session(&session2, &uuid, NULL, |
Volodymyr Babchuk | ae3dcd7 | 2016-10-20 16:51:59 +0300 | [diff] [blame] | 984 | &ret_orig))) |
| 985 | continue; |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 986 | |
| 987 | op.params[0].value.a = 0; |
| 988 | op.params[1].tmpref.buffer = out; |
| 989 | op.params[1].tmpref.size = sizeof(out); |
| 990 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 991 | TEEC_MEMREF_TEMP_OUTPUT, |
| 992 | TEEC_NONE, TEEC_NONE); |
| 993 | |
| 994 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 995 | TEEC_InvokeCommand(&session2, TA_SIMS_CMD_READ, |
| 996 | &op, &ret_orig)); |
| 997 | |
| 998 | if (!ADBG_EXPECT_BUFFER(c, in, sizeof(in), out, |
| 999 | sizeof(out))) { |
| 1000 | Do_ADBG_Log("in:"); |
| 1001 | Do_ADBG_HexLog(in, sizeof(in), 16); |
| 1002 | Do_ADBG_Log("out:"); |
| 1003 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 1004 | } |
| 1005 | |
| 1006 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, |
| 1007 | TEEC_NONE, TEEC_NONE, |
| 1008 | TEEC_NONE); |
| 1009 | |
| 1010 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1011 | TEEC_InvokeCommand(&session1, |
| 1012 | TA_SIMS_CMD_GET_COUNTER, |
| 1013 | &op, &ret_orig)); |
| 1014 | |
| 1015 | (void)ADBG_EXPECT(c, 0, op.params[0].value.a); |
| 1016 | |
| 1017 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1018 | TEEC_InvokeCommand(&session2, |
| 1019 | TA_SIMS_CMD_GET_COUNTER, &op, |
| 1020 | &ret_orig)); |
| 1021 | |
| 1022 | (void)ADBG_EXPECT(c, i, op.params[0].value.a); |
| 1023 | TEEC_CloseSession(&session2); |
| 1024 | } |
| 1025 | |
| 1026 | memset(out, 0, sizeof(out)); |
| 1027 | op.params[0].value.a = 0; |
| 1028 | op.params[1].tmpref.buffer = out; |
| 1029 | op.params[1].tmpref.size = sizeof(out); |
| 1030 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, |
| 1031 | TEEC_MEMREF_TEMP_OUTPUT, |
| 1032 | TEEC_NONE, TEEC_NONE); |
| 1033 | |
| 1034 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1035 | TEEC_InvokeCommand(&session1, TA_SIMS_CMD_READ, &op, |
| 1036 | &ret_orig)); |
| 1037 | |
| 1038 | if (!ADBG_EXPECT(c, 0, memcmp(in, out, sizeof(in)))) { |
| 1039 | Do_ADBG_Log("in:"); |
| 1040 | Do_ADBG_HexLog(in, sizeof(in), 16); |
| 1041 | Do_ADBG_Log("out:"); |
| 1042 | Do_ADBG_HexLog(out, sizeof(out), 16); |
| 1043 | } |
| 1044 | |
| 1045 | TEEC_CloseSession(&session1); |
| 1046 | } |
Ovidiu Mihalachi | 3e6183e | 2019-04-25 10:23:21 +0300 | [diff] [blame] | 1047 | Do_ADBG_EndSubCase(c, "Single Instance Multi Session"); |
Pascal Brand | c639ac8 | 2015-07-02 08:53:34 +0200 | [diff] [blame] | 1048 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1049 | ADBG_CASE_DEFINE(regression, 1012, xtest_tee_test_1012, |
| 1050 | "Test Single Instance Multi Session features with SIMS TA"); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1051 | |
| 1052 | struct test_1013_thread_arg { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1053 | const TEEC_UUID *uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1054 | uint32_t cmd; |
| 1055 | uint32_t repeat; |
| 1056 | TEEC_SharedMemory *shm; |
| 1057 | uint32_t error_orig; |
| 1058 | TEEC_Result res; |
| 1059 | uint32_t max_concurrency; |
| 1060 | const uint8_t *in; |
| 1061 | size_t in_len; |
| 1062 | uint8_t *out; |
| 1063 | size_t out_len; |
| 1064 | }; |
| 1065 | |
| 1066 | static void *test_1013_thread(void *arg) |
| 1067 | { |
| 1068 | struct test_1013_thread_arg *a = arg; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1069 | TEEC_Session session = { }; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1070 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1071 | uint8_t p2 = TEEC_NONE; |
| 1072 | uint8_t p3 = TEEC_NONE; |
| 1073 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1074 | a->res = xtest_teec_open_session(&session, a->uuid, NULL, |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1075 | &a->error_orig); |
| 1076 | if (a->res != TEEC_SUCCESS) |
| 1077 | return NULL; |
| 1078 | |
| 1079 | op.params[0].memref.parent = a->shm; |
| 1080 | op.params[0].memref.size = a->shm->size; |
| 1081 | op.params[0].memref.offset = 0; |
| 1082 | op.params[1].value.a = a->repeat; |
| 1083 | op.params[1].value.b = 0; |
| 1084 | op.params[2].tmpref.buffer = (void *)a->in; |
| 1085 | op.params[2].tmpref.size = a->in_len; |
| 1086 | op.params[3].tmpref.buffer = a->out; |
| 1087 | op.params[3].tmpref.size = a->out_len; |
| 1088 | |
| 1089 | if (a->in_len) |
| 1090 | p2 = TEEC_MEMREF_TEMP_INPUT; |
| 1091 | if (a->out_len) |
| 1092 | p3 = TEEC_MEMREF_TEMP_OUTPUT; |
| 1093 | |
| 1094 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, |
| 1095 | TEEC_VALUE_INOUT, p2, p3); |
| 1096 | |
| 1097 | a->res = TEEC_InvokeCommand(&session, a->cmd, &op, &a->error_orig); |
| 1098 | a->max_concurrency = op.params[1].value.b; |
| 1099 | a->out_len = op.params[3].tmpref.size; |
| 1100 | TEEC_CloseSession(&session); |
| 1101 | return NULL; |
| 1102 | } |
| 1103 | |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1104 | #define NUM_THREADS 3 |
| 1105 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1106 | static void xtest_tee_test_1013_single(ADBG_Case_t *c, double *mean_concurrency, |
| 1107 | const TEEC_UUID *uuid) |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1108 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1109 | size_t nt = 0; |
| 1110 | size_t n = 0; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1111 | size_t repeat = 1000; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1112 | TEEC_SharedMemory shm = { }; |
| 1113 | size_t max_concurrency = 0; |
| 1114 | struct test_1013_thread_arg arg[NUM_THREADS] = { }; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1115 | static const uint8_t sha256_in[] = { 'a', 'b', 'c' }; |
| 1116 | static const uint8_t sha256_out[] = { |
| 1117 | 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, |
| 1118 | 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, |
| 1119 | 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, |
| 1120 | 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad |
| 1121 | }; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1122 | uint8_t out[32] = { }; |
| 1123 | pthread_t thr[NUM_THREADS] = { }; |
Jerome Forissier | fbdc175 | 2021-06-29 11:25:35 +0200 | [diff] [blame] | 1124 | bool skip = false; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1125 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1126 | Do_ADBG_BeginSubCase(c, "Busy loop repeat %zu", repeat * 10); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1127 | *mean_concurrency = 0; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1128 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1129 | shm.size = sizeof(struct ta_concurrent_shm); |
| 1130 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1131 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1132 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 1133 | return; |
| 1134 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1135 | memset(shm.buffer, 0, shm.size); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1136 | max_concurrency = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1137 | nt = NUM_THREADS; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1138 | |
| 1139 | for (n = 0; n < nt; n++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1140 | arg[n].uuid = uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1141 | arg[n].cmd = TA_CONCURRENT_CMD_BUSY_LOOP; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1142 | arg[n].repeat = repeat * 10; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1143 | arg[n].shm = &shm; |
| 1144 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 1145 | test_1013_thread, arg + n))) |
| 1146 | nt = n; /* break loop and start cleanup */ |
| 1147 | } |
| 1148 | |
| 1149 | for (n = 0; n < nt; n++) { |
| 1150 | ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)); |
Jerome Forissier | fbdc175 | 2021-06-29 11:25:35 +0200 | [diff] [blame] | 1151 | if (arg[n].res == TEEC_ERROR_OUT_OF_MEMORY && |
| 1152 | !memcmp(uuid, &concurrent_large_ta_uuid, sizeof(*uuid))) { |
| 1153 | Do_ADBG_Log("TEEC_ERROR_OUT_OF_MEMORY - ignored"); |
| 1154 | skip = true; |
| 1155 | continue; |
| 1156 | } |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1157 | ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res); |
| 1158 | if (arg[n].max_concurrency > max_concurrency) |
| 1159 | max_concurrency = arg[n].max_concurrency; |
| 1160 | } |
| 1161 | |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1162 | /* |
| 1163 | * Concurrency can be limited by several factors, for instance in a |
Joakim Bech | a1212b6 | 2020-04-07 12:06:00 +0200 | [diff] [blame] | 1164 | * single CPU system it's dependent on the Preemption Model used by |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1165 | * the kernel (Preemptible Kernel (Low-Latency Desktop) gives the |
| 1166 | * best result there). |
| 1167 | */ |
Jerome Forissier | fbdc175 | 2021-06-29 11:25:35 +0200 | [diff] [blame] | 1168 | if (!skip) { |
| 1169 | (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, >, 0); |
| 1170 | (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, <=, |
| 1171 | NUM_THREADS); |
| 1172 | *mean_concurrency += max_concurrency; |
| 1173 | } |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1174 | Do_ADBG_EndSubCase(c, "Busy loop repeat %zu", repeat * 10); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1175 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1176 | Do_ADBG_BeginSubCase(c, "SHA-256 loop repeat %zu", repeat); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1177 | memset(shm.buffer, 0, shm.size); |
| 1178 | memset(arg, 0, sizeof(arg)); |
| 1179 | max_concurrency = 0; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1180 | nt = NUM_THREADS; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1181 | |
| 1182 | for (n = 0; n < nt; n++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1183 | arg[n].uuid = uuid; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1184 | arg[n].cmd = TA_CONCURRENT_CMD_SHA256; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1185 | arg[n].repeat = repeat; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1186 | arg[n].shm = &shm; |
| 1187 | arg[n].in = sha256_in; |
| 1188 | arg[n].in_len = sizeof(sha256_in); |
| 1189 | arg[n].out = out; |
| 1190 | arg[n].out_len = sizeof(out); |
| 1191 | if (!ADBG_EXPECT(c, 0, pthread_create(thr + n, NULL, |
| 1192 | test_1013_thread, arg + n))) |
| 1193 | nt = n; /* break loop and start cleanup */ |
| 1194 | } |
| 1195 | |
| 1196 | for (n = 0; n < nt; n++) { |
Jerome Forissier | fbdc175 | 2021-06-29 11:25:35 +0200 | [diff] [blame] | 1197 | ADBG_EXPECT(c, 0, pthread_join(thr[n], NULL)); |
| 1198 | if (arg[n].res == TEEC_ERROR_OUT_OF_MEMORY && |
| 1199 | !memcmp(uuid, &concurrent_large_ta_uuid, sizeof(*uuid))) { |
| 1200 | Do_ADBG_Log("TEEC_ERROR_OUT_OF_MEMORY - ignored"); |
| 1201 | continue; |
| 1202 | } |
| 1203 | if (ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res)) |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1204 | ADBG_EXPECT_BUFFER(c, sha256_out, sizeof(sha256_out), |
| 1205 | arg[n].out, arg[n].out_len); |
| 1206 | if (arg[n].max_concurrency > max_concurrency) |
| 1207 | max_concurrency = arg[n].max_concurrency; |
| 1208 | } |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1209 | *mean_concurrency += max_concurrency; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1210 | Do_ADBG_EndSubCase(c, "SHA-256 loop repeat %zu", repeat); |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1211 | |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1212 | *mean_concurrency /= 2.0; |
Jens Wiklander | ac27ec1 | 2015-07-15 15:23:14 +0200 | [diff] [blame] | 1213 | TEEC_ReleaseSharedMemory(&shm); |
| 1214 | } |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1215 | |
| 1216 | static void xtest_tee_test_1013(ADBG_Case_t *c) |
| 1217 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1218 | int i = 0; |
| 1219 | double mean_concurrency = 0; |
| 1220 | double concurrency = 0; |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1221 | int nb_loops = 24; |
Jens Wiklander | 6a9d15a | 2016-02-01 10:29:42 +0100 | [diff] [blame] | 1222 | |
| 1223 | if (level == 0) |
| 1224 | nb_loops /= 2; |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1225 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1226 | Do_ADBG_BeginSubCase(c, "Using small concurrency TA"); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1227 | mean_concurrency = 0; |
| 1228 | for (i = 0; i < nb_loops; i++) { |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1229 | xtest_tee_test_1013_single(c, &concurrency, |
| 1230 | &concurrent_ta_uuid); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1231 | mean_concurrency += concurrency; |
| 1232 | } |
| 1233 | mean_concurrency /= nb_loops; |
| 1234 | |
| 1235 | Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS); |
| 1236 | Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency); |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1237 | Do_ADBG_EndSubCase(c, "Using small concurrency TA"); |
Pascal Brand | 4fa3558 | 2015-12-17 10:59:12 +0100 | [diff] [blame] | 1238 | |
Jens Wiklander | 7067297 | 2016-04-06 00:01:45 +0200 | [diff] [blame] | 1239 | Do_ADBG_BeginSubCase(c, "Using large concurrency TA"); |
| 1240 | mean_concurrency = 0; |
| 1241 | for (i = 0; i < nb_loops; i++) { |
| 1242 | xtest_tee_test_1013_single(c, &concurrency, |
| 1243 | &concurrent_large_ta_uuid); |
| 1244 | mean_concurrency += concurrency; |
| 1245 | } |
| 1246 | mean_concurrency /= nb_loops; |
| 1247 | |
| 1248 | Do_ADBG_Log(" Number of parallel threads: %d", NUM_THREADS); |
| 1249 | Do_ADBG_Log(" Mean concurrency: %g", mean_concurrency); |
| 1250 | Do_ADBG_EndSubCase(c, "Using large concurrency TA"); |
| 1251 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1252 | ADBG_CASE_DEFINE(regression, 1013, xtest_tee_test_1013, |
Joakim Bech | a1212b6 | 2020-04-07 12:06:00 +0200 | [diff] [blame] | 1253 | "Test concurrency with concurrent TA"); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1254 | |
| 1255 | #ifdef CFG_SECURE_DATA_PATH |
| 1256 | static void xtest_tee_test_1014(ADBG_Case_t *c) |
| 1257 | { |
| 1258 | UNUSED(c); |
| 1259 | |
| 1260 | int size = 17000; |
| 1261 | int loop = 10; |
| 1262 | int ion_heap = DEFAULT_ION_HEAP_TYPE; |
| 1263 | int rnd_offset = 1; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1264 | int test = 0; |
| 1265 | int ret = 0; |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1266 | |
| 1267 | test = TEST_NS_TO_TA; |
| 1268 | Do_ADBG_BeginSubCase(c, "SDP: NonSecure client invokes a SDP TA"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1269 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1270 | ADBG_EXPECT(c, 0, ret); |
| 1271 | Do_ADBG_EndSubCase(c, "SDP: NonSecure client invokes a SDP TA"); |
| 1272 | |
| 1273 | test = TEST_TA_TO_TA; |
| 1274 | Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a SDP TA"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1275 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1276 | ADBG_EXPECT(c, 0, ret); |
| 1277 | Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a SDP TA"); |
| 1278 | |
| 1279 | test = TEST_TA_TO_PTA; |
Igor Opaniuk | 2e0a679 | 2021-01-09 00:51:19 +0200 | [diff] [blame] | 1280 | Do_ADBG_BeginSubCase(c, "SDP: SDP TA invokes a test pTA (invoke_tests.pta)"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1281 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1282 | ADBG_EXPECT(c, 0, ret); |
Igor Opaniuk | 2e0a679 | 2021-01-09 00:51:19 +0200 | [diff] [blame] | 1283 | Do_ADBG_EndSubCase(c, "SDP: SDP TA invokes a test pTA (invoke_tests.pta)"); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1284 | |
| 1285 | test = TEST_NS_TO_PTA; |
Igor Opaniuk | 2e0a679 | 2021-01-09 00:51:19 +0200 | [diff] [blame] | 1286 | Do_ADBG_BeginSubCase(c, "SDP: NSec CA invokes a test pTA (invoke_tests.pta) (should fail)"); |
Etienne Carriere | b9a9582 | 2017-04-26 15:03:53 +0200 | [diff] [blame] | 1287 | ret = sdp_basic_test(test, size, loop, ion_heap, rnd_offset, 0); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1288 | ADBG_EXPECT(c, 1, ret); |
Igor Opaniuk | 2e0a679 | 2021-01-09 00:51:19 +0200 | [diff] [blame] | 1289 | Do_ADBG_EndSubCase(c, "SDP: NSec CA invokes a test pTA (invoke_tests.pta) (should fail)"); |
Etienne Carriere | d9be3dc | 2018-04-25 18:30:19 +0200 | [diff] [blame] | 1290 | |
| 1291 | Do_ADBG_BeginSubCase(c, "SDP: Invoke TA with out of bounds SDP memref"); |
| 1292 | ret = sdp_out_of_bounds_memref_test(size, ion_heap, 0); |
| 1293 | ADBG_EXPECT(c, 0, ret); |
| 1294 | Do_ADBG_EndSubCase(c, NULL); |
Etienne Carriere | 50abf9a | 2017-03-24 11:33:50 +0100 | [diff] [blame] | 1295 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1296 | ADBG_CASE_DEFINE(regression, 1014, xtest_tee_test_1014, |
| 1297 | "Test secure data path against SDP TAs and pTAs"); |
| 1298 | #endif /*CFG_SECURE_DATA_PATH*/ |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1299 | |
Jerome Forissier | f425994 | 2022-01-11 14:27:05 +0100 | [diff] [blame] | 1300 | #ifdef CFG_REE_FS |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1301 | static void xtest_tee_test_1015(ADBG_Case_t *c) |
| 1302 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1303 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1304 | TEEC_Session session = { }; |
| 1305 | uint32_t ret_orig = 0; |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1306 | |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1307 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1308 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 1309 | &ret_orig); |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1310 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 1311 | Do_ADBG_Log(" - 1015 - skip test, pseudo TA not found"); |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1312 | return; |
Etienne Carriere | 1109316 | 2017-10-26 09:49:04 +0200 | [diff] [blame] | 1313 | } |
| 1314 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jens Wiklander | 272d364 | 2017-04-03 13:03:47 +0200 | [diff] [blame] | 1315 | |
| 1316 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1317 | TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_FS_HTREE, |
| 1318 | NULL, &ret_orig)); |
| 1319 | TEEC_CloseSession(&session); |
| 1320 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1321 | ADBG_CASE_DEFINE(regression, 1015, xtest_tee_test_1015, |
| 1322 | "FS hash-tree corner cases"); |
Jerome Forissier | f425994 | 2022-01-11 14:27:05 +0100 | [diff] [blame] | 1323 | #endif /*CFG_REE_FS*/ |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1324 | |
| 1325 | static void xtest_tee_test_1016(ADBG_Case_t *c) |
| 1326 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1327 | TEEC_Session session = { }; |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1328 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1329 | uint32_t ret_orig = 0; |
Jerome Forissier | e916b10 | 2017-06-07 17:55:52 +0200 | [diff] [blame] | 1330 | |
| 1331 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1332 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1333 | &ret_orig))) |
| 1334 | return; |
| 1335 | |
| 1336 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, |
| 1337 | TEEC_NONE); |
| 1338 | |
| 1339 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1340 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TA2TA_MEMREF, &op, |
| 1341 | &ret_orig)); |
| 1342 | |
| 1343 | TEEC_CloseSession(&session); |
| 1344 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1345 | ADBG_CASE_DEFINE(regression, 1016, xtest_tee_test_1016, |
| 1346 | "Test TA to TA transfers (in/out/inout memrefs on the stack)"); |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1347 | |
| 1348 | static void xtest_tee_test_1017(ADBG_Case_t *c) |
| 1349 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1350 | TEEC_Session session = { }; |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1351 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1352 | uint32_t ret_orig = 0; |
| 1353 | TEEC_SharedMemory shm = { }; |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1354 | size_t page_size = 4096; |
| 1355 | |
Jens Wiklander | 87e8170 | 2018-03-20 12:00:00 +0800 | [diff] [blame] | 1356 | shm.size = 8 * page_size; |
| 1357 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1358 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1359 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm))) |
| 1360 | return; |
| 1361 | |
| 1362 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1363 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1364 | &ret_orig))) |
| 1365 | goto out; |
| 1366 | |
| 1367 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, |
| 1368 | TEEC_MEMREF_PARTIAL_INPUT, |
| 1369 | TEEC_MEMREF_PARTIAL_OUTPUT, |
| 1370 | TEEC_MEMREF_PARTIAL_OUTPUT); |
| 1371 | |
| 1372 | /* |
| 1373 | * The first two memrefs are supposed to be combined into in |
| 1374 | * region and the last two memrefs should have one region each |
| 1375 | * when the parameters are mapped for the TA. |
| 1376 | */ |
| 1377 | op.params[0].memref.parent = &shm; |
| 1378 | op.params[0].memref.size = page_size; |
| 1379 | op.params[0].memref.offset = 0; |
| 1380 | |
| 1381 | op.params[1].memref.parent = &shm; |
| 1382 | op.params[1].memref.size = page_size; |
| 1383 | op.params[1].memref.offset = page_size; |
| 1384 | |
| 1385 | op.params[2].memref.parent = &shm; |
| 1386 | op.params[2].memref.size = page_size; |
| 1387 | op.params[2].memref.offset = 4 * page_size; |
| 1388 | |
| 1389 | op.params[3].memref.parent = &shm; |
| 1390 | op.params[3].memref.size = 2 * page_size; |
| 1391 | op.params[3].memref.offset = 6 * page_size; |
| 1392 | |
| 1393 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1394 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PARAMS, &op, |
| 1395 | &ret_orig)); |
| 1396 | |
| 1397 | TEEC_CloseSession(&session); |
| 1398 | out: |
| 1399 | TEEC_ReleaseSharedMemory(&shm); |
| 1400 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1401 | ADBG_CASE_DEFINE(regression, 1017, xtest_tee_test_1017, |
| 1402 | "Test coalescing memrefs"); |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1403 | |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1404 | static void invoke_1byte_out_of_bounds(ADBG_Case_t *c, TEEC_Session *session, |
| 1405 | TEEC_SharedMemory *shm) |
| 1406 | { |
| 1407 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1408 | TEEC_Result ret = TEEC_ERROR_GENERIC; |
| 1409 | uint32_t ret_orig = 0; |
| 1410 | |
| 1411 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, |
| 1412 | TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 1413 | |
| 1414 | op.params[0].memref.parent = shm; |
| 1415 | op.params[0].memref.size = shm->size / 2; |
| 1416 | op.params[0].memref.offset = shm->size - (shm->size / 2) + 1; |
| 1417 | |
| 1418 | ret = TEEC_InvokeCommand(session, TA_OS_TEST_CMD_PARAMS, |
| 1419 | &op, &ret_orig); |
| 1420 | |
Etienne Carriere | 48fa1b2 | 2020-04-08 13:42:01 +0200 | [diff] [blame] | 1421 | ADBG_EXPECT_COMPARE_UNSIGNED(c, ret_orig, !=, TEEC_ORIGIN_TRUSTED_APP); |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1422 | if (ret != TEEC_ERROR_BAD_PARAMETERS && ret != TEEC_ERROR_GENERIC) { |
| 1423 | ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS, ret); |
| 1424 | ADBG_EXPECT(c, TEEC_ERROR_GENERIC, ret); |
| 1425 | } |
| 1426 | } |
| 1427 | |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1428 | static void xtest_tee_test_1018(ADBG_Case_t *c) |
| 1429 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1430 | TEEC_Session session = { }; |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1431 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1432 | uint32_t ret_orig = 0; |
| 1433 | TEEC_SharedMemory shm = { }; |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1434 | TEEC_Result ret = TEEC_ERROR_GENERIC; |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1435 | size_t page_size = 4096; |
Joakim Bech | a1212b6 | 2020-04-07 12:06:00 +0200 | [diff] [blame] | 1436 | /* Intentionally not 4kB aligned and odd */ |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1437 | uint8_t buffer[6001] = { }; |
| 1438 | |
| 1439 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1440 | xtest_teec_open_session(&session, |
| 1441 | &os_test_ta_uuid, |
| 1442 | NULL, |
| 1443 | &ret_orig))) |
| 1444 | return; |
| 1445 | |
Joakim Bech | a1212b6 | 2020-04-07 12:06:00 +0200 | [diff] [blame] | 1446 | Do_ADBG_BeginSubCase(c, "Out of bounds > 4kB on allocated shm"); |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1447 | |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1448 | shm.size = 8 * page_size; |
| 1449 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1450 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1451 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, |
| 1452 | &shm))) |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1453 | goto out; |
| 1454 | |
| 1455 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, |
| 1456 | TEEC_MEMREF_PARTIAL_INPUT, |
| 1457 | TEEC_MEMREF_PARTIAL_OUTPUT, |
| 1458 | TEEC_MEMREF_PARTIAL_OUTPUT); |
| 1459 | |
| 1460 | /* |
| 1461 | * The first two memrefs are supposed to be combined into in |
| 1462 | * region and the last two memrefs should have one region each |
| 1463 | * when the parameters are mapped for the TA. |
| 1464 | */ |
| 1465 | op.params[0].memref.parent = &shm; |
| 1466 | op.params[0].memref.size = page_size; |
| 1467 | op.params[0].memref.offset = 0; |
| 1468 | |
| 1469 | op.params[1].memref.parent = &shm; |
| 1470 | op.params[1].memref.size = page_size; |
| 1471 | op.params[1].memref.offset = page_size; |
| 1472 | |
| 1473 | op.params[2].memref.parent = &shm; |
| 1474 | op.params[2].memref.size = page_size; |
| 1475 | op.params[2].memref.offset = 4 * page_size; |
| 1476 | |
| 1477 | op.params[3].memref.parent = &shm; |
| 1478 | op.params[3].memref.size = 3 * page_size; |
| 1479 | op.params[3].memref.offset = 6 * page_size; |
| 1480 | |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1481 | ret = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PARAMS, &op, |
| 1482 | &ret_orig); |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1483 | |
Etienne Carriere | 48fa1b2 | 2020-04-08 13:42:01 +0200 | [diff] [blame] | 1484 | ADBG_EXPECT_COMPARE_UNSIGNED(c, ret_orig, !=, TEEC_ORIGIN_TRUSTED_APP); |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1485 | if (ret != TEEC_ERROR_BAD_PARAMETERS && ret != TEEC_ERROR_GENERIC) { |
| 1486 | ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS, ret); |
| 1487 | ADBG_EXPECT(c, TEEC_ERROR_GENERIC, ret); |
| 1488 | } |
| 1489 | |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1490 | TEEC_ReleaseSharedMemory(&shm); |
Etienne Carriere | 84382b3 | 2018-04-25 18:30:30 +0200 | [diff] [blame] | 1491 | Do_ADBG_EndSubCase(c, NULL); |
| 1492 | |
| 1493 | Do_ADBG_BeginSubCase(c, "Out of bounds by 1 byte on registered shm"); |
| 1494 | |
| 1495 | memset(&shm, 0, sizeof(shm)); |
| 1496 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1497 | shm.buffer = buffer; |
| 1498 | shm.size = sizeof(buffer); |
| 1499 | |
| 1500 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1501 | TEEC_RegisterSharedMemory(&xtest_teec_ctx, |
| 1502 | &shm))) |
| 1503 | goto out; |
| 1504 | |
| 1505 | invoke_1byte_out_of_bounds(c, &session, &shm); |
| 1506 | |
| 1507 | TEEC_ReleaseSharedMemory(&shm); |
| 1508 | Do_ADBG_EndSubCase(c, NULL); |
| 1509 | |
| 1510 | Do_ADBG_BeginSubCase(c, "Out of bounds by 1 byte ref on allocated shm"); |
| 1511 | |
| 1512 | memset(&shm, 0, sizeof(shm)); |
| 1513 | shm.size = sizeof(buffer); |
| 1514 | shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT; |
| 1515 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1516 | TEEC_AllocateSharedMemory(&xtest_teec_ctx, |
| 1517 | &shm))) |
| 1518 | goto out; |
| 1519 | |
| 1520 | invoke_1byte_out_of_bounds(c, &session, &shm); |
| 1521 | |
| 1522 | TEEC_ReleaseSharedMemory(&shm); |
| 1523 | Do_ADBG_EndSubCase(c, NULL); |
| 1524 | |
| 1525 | out: |
| 1526 | TEEC_CloseSession(&session); |
Jens Wiklander | bb10bcd | 2018-03-20 12:50:58 +0800 | [diff] [blame] | 1527 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1528 | ADBG_CASE_DEFINE(regression, 1018, xtest_tee_test_1018, |
| 1529 | "Test memref out of bounds"); |
Jerome Forissier | 53bde72 | 2018-05-31 09:14:54 +0200 | [diff] [blame] | 1530 | |
Jerome Forissier | 53bde72 | 2018-05-31 09:14:54 +0200 | [diff] [blame] | 1531 | static void xtest_tee_test_1019(ADBG_Case_t *c) |
| 1532 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1533 | TEEC_Session session = { }; |
| 1534 | uint32_t ret_orig = 0; |
Jerome Forissier | 53bde72 | 2018-05-31 09:14:54 +0200 | [diff] [blame] | 1535 | |
| 1536 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1537 | xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 1538 | &ret_orig))) |
| 1539 | return; |
| 1540 | |
| 1541 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1542 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB, NULL, |
| 1543 | &ret_orig)); |
| 1544 | |
| 1545 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 1546 | TEEC_ERROR_TARGET_DEAD, |
| 1547 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_PANIC, |
| 1548 | NULL, &ret_orig)); |
| 1549 | |
| 1550 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 1551 | |
| 1552 | TEEC_CloseSession(&session); |
| 1553 | } |
Jens Wiklander | 14f4887 | 2018-06-29 15:30:13 +0200 | [diff] [blame] | 1554 | ADBG_CASE_DEFINE(regression, 1019, xtest_tee_test_1019, |
| 1555 | "Test dynamically linked TA"); |
Jerome Forissier | 3357f87 | 2018-10-05 15:13:44 +0200 | [diff] [blame] | 1556 | |
| 1557 | static void xtest_tee_test_1020(ADBG_Case_t *c) |
| 1558 | { |
Etienne Carriere | e4ec9e4 | 2019-03-28 13:30:21 +0100 | [diff] [blame] | 1559 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1560 | TEEC_Session session = { }; |
| 1561 | uint32_t ret_orig = 0; |
Jerome Forissier | 3357f87 | 2018-10-05 15:13:44 +0200 | [diff] [blame] | 1562 | |
| 1563 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
| 1564 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 1565 | &ret_orig); |
| 1566 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 1567 | Do_ADBG_Log(" - 1020 - skip test, pseudo TA not found"); |
| 1568 | return; |
| 1569 | } |
| 1570 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 1571 | |
| 1572 | res = TEEC_InvokeCommand(&session, PTA_INVOKE_TESTS_CMD_LOCKDEP, |
| 1573 | NULL, &ret_orig); |
| 1574 | if (res != TEEC_SUCCESS) { |
| 1575 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TRUSTED_APP, |
| 1576 | ret_orig); |
| 1577 | if (res == TEEC_ERROR_NOT_SUPPORTED) { |
| 1578 | Do_ADBG_Log(" - 1020 - skip test, feature not " |
| 1579 | "implemented"); |
| 1580 | goto out; |
| 1581 | } |
| 1582 | /* Error */ |
| 1583 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 1584 | } |
| 1585 | out: |
| 1586 | TEEC_CloseSession(&session); |
| 1587 | } |
| 1588 | ADBG_CASE_DEFINE(regression, 1020, xtest_tee_test_1020, |
| 1589 | "Test lockdep algorithm"); |
Ovidiu Mihalachi | 15cecff | 2019-04-02 16:36:31 +0300 | [diff] [blame] | 1590 | |
| 1591 | static TEEC_Result open_sec_session(TEEC_Session *session, |
| 1592 | const TEEC_UUID *uuid) |
| 1593 | { |
| 1594 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1595 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1596 | uint32_t ret_orig = 0; |
| 1597 | |
| 1598 | op.params[0].tmpref.buffer = (void *)uuid; |
| 1599 | op.params[0].tmpref.size = sizeof(*uuid); |
| 1600 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 1601 | TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 1602 | |
| 1603 | res = TEEC_InvokeCommand(session, TA_SIMS_OPEN_TA_SESSION, |
| 1604 | &op, &ret_orig); |
| 1605 | if (res != TEEC_SUCCESS) |
| 1606 | return TEEC_ERROR_GENERIC; |
| 1607 | |
| 1608 | return res; |
| 1609 | } |
| 1610 | |
| 1611 | static TEEC_Result sims_get_counter(TEEC_Session *session, |
| 1612 | uint32_t *counter) |
| 1613 | { |
| 1614 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 1615 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1616 | uint32_t ret_orig = 0; |
| 1617 | |
| 1618 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, |
| 1619 | TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 1620 | |
| 1621 | res = TEEC_InvokeCommand(session, TA_SIMS_CMD_GET_COUNTER, |
| 1622 | &op, &ret_orig); |
| 1623 | if (res == TEEC_SUCCESS) |
| 1624 | *counter = op.params[0].value.a; |
| 1625 | |
| 1626 | return res; |
| 1627 | } |
| 1628 | |
| 1629 | static TEEC_Result trigger_panic(TEEC_Session *session, |
| 1630 | const TEEC_UUID *uuid) |
| 1631 | { |
| 1632 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1633 | uint32_t ret_orig = 0; |
| 1634 | |
| 1635 | if (!uuid) { |
| 1636 | op.params[0].tmpref.buffer = NULL; |
| 1637 | op.params[0].tmpref.size = 0; |
| 1638 | } else { |
| 1639 | op.params[0].tmpref.buffer = (void *)uuid; |
| 1640 | op.params[0].tmpref.size = sizeof(*uuid); |
| 1641 | } |
| 1642 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 1643 | TEEC_NONE, TEEC_NONE, TEEC_NONE); |
| 1644 | |
| 1645 | return TEEC_InvokeCommand(session, TA_SIMS_CMD_PANIC, |
| 1646 | &op, &ret_orig); |
| 1647 | } |
| 1648 | |
| 1649 | static void test_panic_ca_to_ta(ADBG_Case_t *c, const TEEC_UUID *uuid, |
| 1650 | bool multi_instance) |
| 1651 | { |
| 1652 | TEEC_Result exp_res = TEEC_ERROR_GENERIC; |
| 1653 | uint32_t counter = 0; |
| 1654 | uint32_t ret_orig = 0; |
| 1655 | uint32_t exp_counter = 0; |
| 1656 | TEEC_Session cs[3] = { }; |
| 1657 | |
| 1658 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1659 | xtest_teec_open_session(&cs[0], uuid, NULL, |
| 1660 | &ret_orig))) |
| 1661 | return; |
| 1662 | |
| 1663 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1664 | xtest_teec_open_session(&cs[1], uuid, NULL, |
| 1665 | &ret_orig))) |
| 1666 | goto bail0; |
| 1667 | |
| 1668 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter))) |
| 1669 | goto bail1; |
| 1670 | |
| 1671 | if (!ADBG_EXPECT(c, 0, counter)) |
| 1672 | goto bail1; |
| 1673 | |
| 1674 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[1], &counter))) |
| 1675 | goto bail1; |
| 1676 | |
| 1677 | exp_counter = multi_instance ? 0 : 1; |
Ovidiu Mihalachi | 110aac4 | 2019-09-11 14:08:01 +0300 | [diff] [blame] | 1678 | if (!ADBG_EXPECT(c, exp_counter, counter)) |
Ovidiu Mihalachi | 15cecff | 2019-04-02 16:36:31 +0300 | [diff] [blame] | 1679 | goto bail1; |
| 1680 | |
| 1681 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1682 | trigger_panic(&cs[1], NULL))) |
| 1683 | goto bail1; |
| 1684 | |
| 1685 | exp_res = multi_instance ? TEEC_SUCCESS : TEEC_ERROR_TARGET_DEAD; |
| 1686 | if (!ADBG_EXPECT_TEEC_RESULT(c, exp_res, |
| 1687 | sims_get_counter(&cs[0], &counter))) |
| 1688 | goto bail1; |
| 1689 | |
| 1690 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1691 | sims_get_counter(&cs[1], &counter))) |
| 1692 | goto bail1; |
| 1693 | |
| 1694 | /* Attempt to open a session on panicked context */ |
Ovidiu Mihalachi | 110aac4 | 2019-09-11 14:08:01 +0300 | [diff] [blame] | 1695 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
Ovidiu Mihalachi | 15cecff | 2019-04-02 16:36:31 +0300 | [diff] [blame] | 1696 | xtest_teec_open_session(&cs[1], uuid, NULL, |
| 1697 | &ret_orig))) |
| 1698 | goto bail1; |
| 1699 | |
| 1700 | /* Sanity check of still valid TA context */ |
| 1701 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1702 | xtest_teec_open_session(&cs[2], uuid, NULL, |
| 1703 | &ret_orig))) |
| 1704 | goto bail1; |
| 1705 | |
| 1706 | /* Sanity check of still valid TA context */ |
| 1707 | if (multi_instance) { |
| 1708 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1709 | sims_get_counter(&cs[0], &counter))) |
| 1710 | goto bail2; |
| 1711 | |
| 1712 | if (!ADBG_EXPECT(c, 0, counter)) |
| 1713 | goto bail2; |
| 1714 | } |
| 1715 | |
| 1716 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[2], &counter))) |
| 1717 | goto bail2; |
| 1718 | |
Ovidiu Mihalachi | 110aac4 | 2019-09-11 14:08:01 +0300 | [diff] [blame] | 1719 | exp_counter = multi_instance ? 0 : 1; |
| 1720 | if (!ADBG_EXPECT(c, exp_counter, counter)) |
Ovidiu Mihalachi | 15cecff | 2019-04-02 16:36:31 +0300 | [diff] [blame] | 1721 | goto bail2; |
| 1722 | |
| 1723 | bail2: |
| 1724 | TEEC_CloseSession(&cs[2]); |
| 1725 | bail1: |
| 1726 | TEEC_CloseSession(&cs[1]); |
| 1727 | bail0: |
| 1728 | TEEC_CloseSession(&cs[0]); |
| 1729 | } |
| 1730 | |
| 1731 | static void test_panic_ta_to_ta(ADBG_Case_t *c, const TEEC_UUID *uuid1, |
| 1732 | const TEEC_UUID *uuid2) |
| 1733 | { |
| 1734 | uint32_t ret_orig = 0; |
| 1735 | uint32_t counter = 0; |
| 1736 | TEEC_Session cs[3] = { }; |
| 1737 | |
| 1738 | /* Test pre-conditions */ |
| 1739 | /* 2.1 - CA opens a session toward TA1 */ |
| 1740 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1741 | xtest_teec_open_session(&cs[0], uuid1, NULL, |
| 1742 | &ret_orig))) |
| 1743 | return; |
| 1744 | |
| 1745 | /* 2.2 - CA opens a session toward TA2 */ |
| 1746 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1747 | xtest_teec_open_session(&cs[1], uuid2, NULL, |
| 1748 | &ret_orig))) |
| 1749 | goto bail0; |
| 1750 | |
| 1751 | /* 2.3 - TA1 opens a session toward TA2 */ |
| 1752 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, open_sec_session(&cs[0], uuid2))) |
| 1753 | goto bail1; |
| 1754 | |
| 1755 | /* 2.4 - CA invokes TA2 which panics */ |
| 1756 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1757 | trigger_panic(&cs[1], NULL))) |
| 1758 | goto bail1; |
| 1759 | |
| 1760 | /* Expected results */ |
| 1761 | /* 2.5 - Expect CA->TA1 session is still alive */ |
| 1762 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter))) |
| 1763 | goto bail1; |
| 1764 | |
| 1765 | /* 2.6 - Expect CA->TA2 session is properly released */ |
| 1766 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1767 | sims_get_counter(&cs[1], &counter))) |
| 1768 | goto bail1; |
| 1769 | |
| 1770 | bail1: |
| 1771 | TEEC_CloseSession(&cs[1]); |
| 1772 | bail0: |
| 1773 | TEEC_CloseSession(&cs[0]); |
| 1774 | |
| 1775 | memset(cs, 0, sizeof(cs)); |
| 1776 | |
| 1777 | /* Test pre-conditions */ |
| 1778 | /* 2.1 - CA opens a session toward TA1 */ |
| 1779 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1780 | xtest_teec_open_session(&cs[0], uuid1, NULL, |
| 1781 | &ret_orig))) |
| 1782 | return; |
| 1783 | |
| 1784 | /* 2.2 - CA opens a session toward TA2 */ |
| 1785 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1786 | xtest_teec_open_session(&cs[1], uuid2, NULL, |
| 1787 | &ret_orig))) |
| 1788 | goto bail2; |
| 1789 | |
| 1790 | /* 2.3 - TA1 opens a session toward TA2 */ |
| 1791 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, open_sec_session(&cs[0], uuid2))) |
| 1792 | goto bail3; |
| 1793 | |
| 1794 | /* 2.4 - CA invokes TA1 which invokes TA2 which panics */ |
| 1795 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, trigger_panic(&cs[0], uuid2))) |
| 1796 | goto bail3; |
| 1797 | |
| 1798 | /* Expected results */ |
| 1799 | /* 2.5 - Expect CA->TA1 session is still alive */ |
| 1800 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, sims_get_counter(&cs[0], &counter))) |
| 1801 | goto bail3; |
| 1802 | |
| 1803 | /* 2.6 - Expect CA->TA2 session is properly released */ |
| 1804 | if (!ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 1805 | sims_get_counter(&cs[1], &counter))) |
| 1806 | goto bail3; |
| 1807 | |
| 1808 | bail3: |
| 1809 | TEEC_CloseSession(&cs[1]); |
| 1810 | bail2: |
| 1811 | TEEC_CloseSession(&cs[0]); |
| 1812 | } |
| 1813 | |
| 1814 | static void xtest_tee_test_1021(ADBG_Case_t *c) |
| 1815 | { |
| 1816 | Do_ADBG_BeginSubCase(c, "Multiple Instances Single Session"); |
| 1817 | test_panic_ca_to_ta(c, &miss_test_ta_uuid, true); |
| 1818 | Do_ADBG_EndSubCase(c, "Multiple Instances Single Session"); |
| 1819 | |
| 1820 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Sessions"); |
| 1821 | test_panic_ca_to_ta(c, &sims_test_ta_uuid, false); |
| 1822 | Do_ADBG_EndSubCase(c, "Single Instance Multi Sessions"); |
| 1823 | |
| 1824 | Do_ADBG_BeginSubCase(c, "Single Instance Multi Sessions Keep Alive"); |
| 1825 | test_panic_ca_to_ta(c, &sims_keepalive_test_ta_uuid, false); |
| 1826 | Do_ADBG_EndSubCase(c, "Single Instance Multi Sessions Keep Alive"); |
| 1827 | |
| 1828 | Do_ADBG_BeginSubCase(c, "Multi Sessions TA to TA"); |
| 1829 | test_panic_ta_to_ta(c, &sims_test_ta_uuid, |
| 1830 | &sims_keepalive_test_ta_uuid); |
| 1831 | Do_ADBG_EndSubCase(c, "Multi Sessions TA to TA"); |
| 1832 | } |
| 1833 | ADBG_CASE_DEFINE(regression, 1021, xtest_tee_test_1021, |
| 1834 | "Test panic context release"); |
Jerome Forissier | a9ab5d0 | 2019-03-17 21:14:06 +0100 | [diff] [blame] | 1835 | |
| 1836 | static void xtest_tee_test_1022(ADBG_Case_t *c) |
| 1837 | { |
| 1838 | TEEC_Session session = { 0 }; |
| 1839 | uint32_t ret_orig = 0; |
| 1840 | |
| 1841 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1842 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 1843 | NULL, &ret_orig))) |
| 1844 | return; |
| 1845 | |
| 1846 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1847 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL, NULL, |
| 1848 | &ret_orig)); |
| 1849 | |
| 1850 | (void)ADBG_EXPECT_TEEC_RESULT(c, |
| 1851 | TEEC_ERROR_TARGET_DEAD, |
| 1852 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL_PANIC, |
| 1853 | NULL, &ret_orig)); |
| 1854 | |
| 1855 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 1856 | |
| 1857 | TEEC_CloseSession(&session); |
| 1858 | } |
| 1859 | ADBG_CASE_DEFINE(regression, 1022, xtest_tee_test_1022, |
| 1860 | "Test dlopen()/dlsym()/dlclose() API"); |
Jerome Forissier | e9571e8 | 2020-02-18 15:26:20 +0100 | [diff] [blame] | 1861 | |
| 1862 | /* |
| 1863 | * Testing the ELF initialization (.init_array) |
| 1864 | * |
| 1865 | * - The TA has a global variable which can also be accessed by the two shared |
| 1866 | * libraries os_test_lib (linked with the TA) and os_test_lib_dl (loaded via |
| 1867 | * dlopen()) |
| 1868 | * - The TA and both libraries have initialization functions (declared with the |
| 1869 | * "constructor" attribute) which perform the following: |
| 1870 | * * The TA multiplies by 10 then adds 1 |
| 1871 | * * os_test_lib multiplies by 10 then adds 2 |
| 1872 | * * os_test_lib_dl multiplies by 10 then adds 3 |
| 1873 | * By testing the variable value we make sure the initializations occurred in |
| 1874 | * the correct order. |
| 1875 | */ |
| 1876 | static void xtest_tee_test_1023(ADBG_Case_t *c) |
| 1877 | { |
| 1878 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1879 | TEEC_Session session = { 0 }; |
| 1880 | uint32_t ret_orig = 0; |
| 1881 | |
| 1882 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, |
| 1883 | TEEC_NONE, TEEC_NONE); |
| 1884 | |
| 1885 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1886 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 1887 | NULL, &ret_orig))) |
| 1888 | return; |
| 1889 | |
| 1890 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1891 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_GET_GLOBAL_VAR, &op, |
| 1892 | &ret_orig)); |
| 1893 | |
| 1894 | /* Expected: initialization of os_test_lib, then TA */ |
| 1895 | (void)ADBG_EXPECT_COMPARE_SIGNED(c, op.params[0].value.a, ==, 21); |
| 1896 | |
| 1897 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1898 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL, NULL, |
| 1899 | &ret_orig)); |
| 1900 | |
| 1901 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1902 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_GET_GLOBAL_VAR, &op, |
| 1903 | &ret_orig)); |
| 1904 | |
| 1905 | /* Expected: initialization of os_test_lib_dl */ |
| 1906 | (void)ADBG_EXPECT_COMPARE_SIGNED(c, op.params[0].value.a, ==, 213); |
| 1907 | |
| 1908 | TEEC_CloseSession(&session); |
| 1909 | } |
| 1910 | ADBG_CASE_DEFINE(regression, 1023, xtest_tee_test_1023, |
| 1911 | "Test ELF initialization (.init_array)"); |
Javier Almansa Sobrino | cddc000 | 2020-02-10 13:35:37 +0000 | [diff] [blame] | 1912 | |
| 1913 | #ifdef CFG_CORE_TPM_EVENT_LOG |
| 1914 | static void xtest_tee_test_1024(ADBG_Case_t *c) |
| 1915 | { |
| 1916 | TEEC_Session session = {}; |
| 1917 | uint32_t ret_orig = 0; |
| 1918 | |
| 1919 | xtest_teec_open_session(&session, &tpm_log_test_ta_uuid, |
| 1920 | NULL, &ret_orig); |
| 1921 | |
| 1922 | Do_ADBG_BeginSubCase(c, "TPM test service invocation"); |
| 1923 | ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(&session, |
| 1924 | TA_TPM_TEST_GET_LOG, |
| 1925 | NULL, &ret_orig)); |
| 1926 | Do_ADBG_EndSubCase(c, "TPM test service invocation"); |
| 1927 | |
| 1928 | Do_ADBG_BeginSubCase(c, "TPM test passing short buffer"); |
| 1929 | ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_InvokeCommand(&session, |
| 1930 | TA_TPM_TEST_SHORT_BUF, |
| 1931 | NULL, &ret_orig)); |
| 1932 | Do_ADBG_EndSubCase(c, "TPM test passing short buffer"); |
| 1933 | |
| 1934 | TEEC_CloseSession(&session); |
| 1935 | } |
| 1936 | |
| 1937 | ADBG_CASE_DEFINE(regression, 1024, xtest_tee_test_1024, |
| 1938 | "Test PTA_SYSTEM_GET_TPM_EVENT_LOG Service"); |
| 1939 | #endif /* CFG_CORE_TPM_EVENT_LOG */ |
Cedric Neveux | 9f483bb | 2019-03-04 08:58:06 +0100 | [diff] [blame] | 1940 | |
| 1941 | static void xtest_tee_test_1025(ADBG_Case_t *c) |
| 1942 | { |
| 1943 | TEEC_Session session = {}; |
| 1944 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 1945 | uint32_t ret_orig = 0; |
| 1946 | uint8_t *empty_buf = NULL; |
Etienne Carriere | 71383d4 | 2020-04-14 12:31:25 +0200 | [diff] [blame] | 1947 | TEEC_SharedMemory shm = { }; |
Etienne Carriere | dba3f3b | 2020-04-08 17:08:16 +0200 | [diff] [blame] | 1948 | TEEC_Result res = TEEC_ERROR_GENERIC; |
Etienne Carriere | 71383d4 | 2020-04-14 12:31:25 +0200 | [diff] [blame] | 1949 | |
| 1950 | Do_ADBG_BeginSubCase(c, "Invalid NULL buffer memref registration"); |
| 1951 | |
| 1952 | memset(&shm, 0, sizeof(shm)); |
| 1953 | shm.flags = TEEC_MEM_INPUT; |
| 1954 | shm.buffer = NULL; |
| 1955 | shm.size = 0; |
| 1956 | |
| 1957 | ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS, |
| 1958 | TEEC_RegisterSharedMemory(&xtest_teec_ctx, &shm)); |
| 1959 | |
| 1960 | memset(&shm, 0, sizeof(shm)); |
| 1961 | shm.flags = TEEC_MEM_OUTPUT; |
| 1962 | shm.buffer = NULL; |
| 1963 | shm.size = 0; |
| 1964 | |
| 1965 | ADBG_EXPECT(c, TEEC_ERROR_BAD_PARAMETERS, |
| 1966 | TEEC_RegisterSharedMemory(&xtest_teec_ctx, &shm)); |
| 1967 | |
| 1968 | Do_ADBG_EndSubCase(c, "Invalid NULL buffer memref registration"); |
Cedric Neveux | 9f483bb | 2019-03-04 08:58:06 +0100 | [diff] [blame] | 1969 | |
Etienne Carriere | c602a52 | 2020-04-13 18:53:17 +0200 | [diff] [blame] | 1970 | if (!xtest_teec_ctx.memref_null) { |
Etienne Carriere | 71383d4 | 2020-04-14 12:31:25 +0200 | [diff] [blame] | 1971 | Do_ADBG_Log("Skip subcases: MEMREF_NULL capability not supported"); |
Etienne Carriere | c602a52 | 2020-04-13 18:53:17 +0200 | [diff] [blame] | 1972 | return; |
| 1973 | } |
| 1974 | |
Cedric Neveux | 9f483bb | 2019-03-04 08:58:06 +0100 | [diff] [blame] | 1975 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 1976 | xtest_teec_open_session(&session, |
| 1977 | &os_test_ta_uuid, |
| 1978 | NULL, &ret_orig))) |
| 1979 | return; |
| 1980 | |
| 1981 | empty_buf = malloc(1); |
| 1982 | if (!empty_buf) { |
| 1983 | (void)ADBG_EXPECT_TEEC_SUCCESS(c, TEEC_ERROR_OUT_OF_MEMORY); |
Etienne Carriere | dba3f3b | 2020-04-08 17:08:16 +0200 | [diff] [blame] | 1984 | goto out_session; |
Cedric Neveux | 9f483bb | 2019-03-04 08:58:06 +0100 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 1988 | TEEC_MEMREF_TEMP_INPUT, |
| 1989 | TEEC_MEMREF_TEMP_OUTPUT, |
| 1990 | TEEC_MEMREF_TEMP_OUTPUT); |
| 1991 | |
| 1992 | Do_ADBG_BeginSubCase(c, |
| 1993 | "Input/Output MEMREF Buffer NULL - Size 0 bytes"); |
| 1994 | |
| 1995 | op.params[0].tmpref.buffer = empty_buf; |
| 1996 | op.params[0].tmpref.size = 0; |
| 1997 | |
| 1998 | op.params[1].tmpref.buffer = NULL; |
| 1999 | op.params[1].tmpref.size = 0; |
| 2000 | |
| 2001 | op.params[2].tmpref.buffer = empty_buf; |
| 2002 | op.params[2].tmpref.size = 0; |
| 2003 | |
| 2004 | op.params[3].tmpref.buffer = NULL; |
| 2005 | op.params[3].tmpref.size = 0; |
| 2006 | |
| 2007 | ADBG_EXPECT(c, TEE_SUCCESS, |
| 2008 | TEEC_InvokeCommand(&session, |
| 2009 | TA_OS_TEST_CMD_NULL_MEMREF_PARAMS, &op, |
| 2010 | &ret_orig)); |
| 2011 | |
| 2012 | Do_ADBG_EndSubCase(c, "Input/Output MEMREF Buffer NULL - Size 0 bytes"); |
| 2013 | |
| 2014 | Do_ADBG_BeginSubCase(c, "Input MEMREF Buffer NULL - Size non 0 bytes"); |
| 2015 | |
| 2016 | op.params[0].tmpref.buffer = empty_buf; |
| 2017 | op.params[0].tmpref.size = 1; |
| 2018 | |
| 2019 | op.params[1].tmpref.buffer = NULL; |
| 2020 | op.params[1].tmpref.size = 0; |
| 2021 | |
| 2022 | op.params[2].tmpref.buffer = empty_buf; |
| 2023 | op.params[2].tmpref.size = 0; |
| 2024 | |
| 2025 | op.params[3].tmpref.buffer = NULL; |
| 2026 | op.params[3].tmpref.size = 0; |
| 2027 | |
| 2028 | ADBG_EXPECT(c, TEE_ERROR_BAD_PARAMETERS, |
| 2029 | TEEC_InvokeCommand(&session, |
| 2030 | TA_OS_TEST_CMD_NULL_MEMREF_PARAMS, &op, |
| 2031 | &ret_orig)); |
| 2032 | |
Etienne Carriere | dba3f3b | 2020-04-08 17:08:16 +0200 | [diff] [blame] | 2033 | TEEC_CloseSession(&session); |
| 2034 | |
Cedric Neveux | 9f483bb | 2019-03-04 08:58:06 +0100 | [diff] [blame] | 2035 | Do_ADBG_EndSubCase(c, "Input MEMREF Buffer NULL - Size non 0 bytes"); |
| 2036 | |
Etienne Carriere | dba3f3b | 2020-04-08 17:08:16 +0200 | [diff] [blame] | 2037 | Do_ADBG_BeginSubCase(c, "Input MEMREF Buffer NULL over PTA invocation"); |
| 2038 | |
| 2039 | /* Pseudo TA is optional: warn and nicely exit if not found */ |
| 2040 | res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL, |
| 2041 | &ret_orig); |
| 2042 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 2043 | Do_ADBG_Log(" - 1025 - skip test, pseudo TA not found"); |
| 2044 | goto out; |
| 2045 | } |
| 2046 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2047 | goto out; |
| 2048 | |
| 2049 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, |
| 2050 | TEEC_NONE, TEEC_NONE); |
| 2051 | op.params[0].tmpref.buffer = NULL; |
| 2052 | op.params[0].tmpref.size = 0; |
| 2053 | |
| 2054 | ADBG_EXPECT(c, TEE_SUCCESS, |
| 2055 | TEEC_InvokeCommand(&session, |
| 2056 | PTA_INVOKE_TESTS_CMD_MEMREF_NULL, |
| 2057 | &op, &ret_orig)); |
| 2058 | |
| 2059 | out_session: |
Cedric Neveux | 9f483bb | 2019-03-04 08:58:06 +0100 | [diff] [blame] | 2060 | TEEC_CloseSession(&session); |
Etienne Carriere | dba3f3b | 2020-04-08 17:08:16 +0200 | [diff] [blame] | 2061 | out: |
| 2062 | Do_ADBG_EndSubCase(c, NULL); |
Cedric Neveux | 9f483bb | 2019-03-04 08:58:06 +0100 | [diff] [blame] | 2063 | free(empty_buf); |
| 2064 | } |
| 2065 | ADBG_CASE_DEFINE(regression, 1025, xtest_tee_test_1025, |
| 2066 | "Test memref NULL and/or 0 bytes size"); |
Vesa Jääskeläinen | e8c0c8d | 2020-04-05 20:11:53 +0300 | [diff] [blame] | 2067 | |
Vesa Jääskeläinen | 502c549 | 2020-04-05 20:12:02 +0300 | [diff] [blame] | 2068 | #define TEE_UUID_NS_NAME_SIZE 128 |
| 2069 | |
| 2070 | /* |
| 2071 | * TEE Client UUID name space identifier (UUIDv4) |
| 2072 | * |
| 2073 | * Value here is random UUID that is allocated as name space identifier for |
| 2074 | * forming Client UUID's for TEE environment using UUIDv5 scheme. |
| 2075 | */ |
| 2076 | static const char *client_uuid_linux_ns = "58ac9ca0-2086-4683-a1b8-ec4bc08e01b6"; |
| 2077 | |
Vesa Jääskeläinen | e8c0c8d | 2020-04-05 20:11:53 +0300 | [diff] [blame] | 2078 | /* TEEC_LOGIN_PUBLIC's Client UUID is NIL UUID */ |
| 2079 | static TEEC_UUID client_uuid_public = { }; |
| 2080 | |
| 2081 | static void xtest_tee_test_1026(ADBG_Case_t *c) |
| 2082 | { |
| 2083 | TEEC_Result result = TEEC_ERROR_GENERIC; |
| 2084 | uint32_t ret_orig = 0; |
| 2085 | TEEC_Session session = { }; |
| 2086 | uint32_t login = UINT32_MAX; |
| 2087 | TEEC_UUID client_uuid = { }; |
| 2088 | |
| 2089 | result = TEEC_OpenSession(&xtest_teec_ctx, &session, &os_test_ta_uuid, |
| 2090 | TEEC_LOGIN_PUBLIC, NULL, NULL, &ret_orig); |
| 2091 | |
| 2092 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2093 | return; |
| 2094 | |
| 2095 | result = ta_os_test_cmd_client_identity(&session, &login, |
| 2096 | &client_uuid); |
| 2097 | |
| 2098 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2099 | goto out; |
| 2100 | |
| 2101 | ADBG_EXPECT_COMPARE_UNSIGNED(c, login, ==, TEEC_LOGIN_PUBLIC); |
| 2102 | |
| 2103 | ADBG_EXPECT_EQUAL(c, &client_uuid_public, &client_uuid, |
| 2104 | sizeof(TEEC_UUID)); |
| 2105 | |
| 2106 | out: |
| 2107 | TEEC_CloseSession(&session); |
| 2108 | } |
| 2109 | |
| 2110 | ADBG_CASE_DEFINE(regression, 1026, xtest_tee_test_1026, |
| 2111 | "Session: public login"); |
Vesa Jääskeläinen | 502c549 | 2020-04-05 20:12:02 +0300 | [diff] [blame] | 2112 | |
Etienne Carriere | f461e1d | 2020-05-19 12:42:08 +0200 | [diff] [blame] | 2113 | /* |
| 2114 | * regression_1027 |
| 2115 | * Depends on OpenSSL |
Jerome Forissier | 81e71a8 | 2021-06-16 10:39:12 +0200 | [diff] [blame] | 2116 | * Depends on kernel commit c5b4312bea5d ("tee: optee: Add support for session |
| 2117 | * login client UUID generation") |
| 2118 | * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c5b4312bea5d |
Etienne Carriere | f461e1d | 2020-05-19 12:42:08 +0200 | [diff] [blame] | 2119 | * |
| 2120 | * xtest skips the test when not built with OpenSSL. |
| 2121 | */ |
Vesa Jääskeläinen | 502c549 | 2020-04-05 20:12:02 +0300 | [diff] [blame] | 2122 | static void xtest_tee_test_1027(ADBG_Case_t *c) |
| 2123 | { |
Victor Chong | 8e070bc | 2020-05-13 09:59:33 +0100 | [diff] [blame] | 2124 | #ifdef OPENSSL_FOUND |
Vesa Jääskeläinen | 502c549 | 2020-04-05 20:12:02 +0300 | [diff] [blame] | 2125 | TEEC_Result result = TEEC_ERROR_GENERIC; |
| 2126 | uint32_t ret_orig = 0; |
| 2127 | TEEC_Session session = { }; |
| 2128 | uint32_t login = UINT32_MAX; |
| 2129 | TEEC_UUID client_uuid = { }; |
| 2130 | TEEC_UUID expected_client_uuid = { }; |
| 2131 | TEEC_UUID uuid_ns = { }; |
| 2132 | char uuid_name[TEE_UUID_NS_NAME_SIZE] = { }; |
| 2133 | |
| 2134 | result = xtest_uuid_from_str(&uuid_ns, client_uuid_linux_ns); |
| 2135 | |
| 2136 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2137 | return; |
| 2138 | |
| 2139 | sprintf(uuid_name, "uid=%x", geteuid()); |
| 2140 | |
| 2141 | result = xtest_uuid_v5(&expected_client_uuid, &uuid_ns, uuid_name, |
| 2142 | strlen(uuid_name)); |
| 2143 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2144 | return; |
| 2145 | |
| 2146 | result = TEEC_OpenSession(&xtest_teec_ctx, &session, &os_test_ta_uuid, |
| 2147 | TEEC_LOGIN_USER, NULL, NULL, &ret_orig); |
| 2148 | |
| 2149 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2150 | return; |
| 2151 | |
| 2152 | result = ta_os_test_cmd_client_identity(&session, &login, |
| 2153 | &client_uuid); |
| 2154 | |
| 2155 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2156 | goto out; |
| 2157 | |
| 2158 | ADBG_EXPECT_COMPARE_UNSIGNED(c, login, ==, TEEC_LOGIN_USER); |
| 2159 | |
| 2160 | ADBG_EXPECT_EQUAL(c, &expected_client_uuid, &client_uuid, |
| 2161 | sizeof(TEEC_UUID)); |
| 2162 | |
| 2163 | out: |
| 2164 | TEEC_CloseSession(&session); |
Victor Chong | 8e070bc | 2020-05-13 09:59:33 +0100 | [diff] [blame] | 2165 | #else /*!OPENSSL_FOUND*/ |
| 2166 | UNUSED(c); |
Etienne Carriere | 359b003 | 2020-05-16 05:56:48 +0200 | [diff] [blame] | 2167 | UNUSED(client_uuid_linux_ns); |
Victor Chong | 8e070bc | 2020-05-13 09:59:33 +0100 | [diff] [blame] | 2168 | /* xtest_uuid_v5() depends on OpenSSL */ |
| 2169 | Do_ADBG_Log("OpenSSL not available, skipping test 1027"); |
| 2170 | #endif |
Vesa Jääskeläinen | 502c549 | 2020-04-05 20:12:02 +0300 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | ADBG_CASE_DEFINE(regression, 1027, xtest_tee_test_1027, |
| 2174 | "Session: user login for current user"); |
Vesa Jääskeläinen | 30dd087 | 2020-04-05 20:12:06 +0300 | [diff] [blame] | 2175 | |
Etienne Carriere | f461e1d | 2020-05-19 12:42:08 +0200 | [diff] [blame] | 2176 | /* |
| 2177 | * regression_1028 |
Jerome Forissier | 81e71a8 | 2021-06-16 10:39:12 +0200 | [diff] [blame] | 2178 | * Depends on kernel commit c5b4312bea5d ("tee: optee: Add support for session |
| 2179 | * login client UUID generation") |
| 2180 | * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c5b4312bea5d |
Etienne Carriere | f461e1d | 2020-05-19 12:42:08 +0200 | [diff] [blame] | 2181 | * |
| 2182 | * xtest skips the test when not built with OpenSSL. |
| 2183 | */ |
Vesa Jääskeläinen | 30dd087 | 2020-04-05 20:12:06 +0300 | [diff] [blame] | 2184 | static void xtest_tee_test_1028(ADBG_Case_t *c) |
| 2185 | { |
Victor Chong | 8e070bc | 2020-05-13 09:59:33 +0100 | [diff] [blame] | 2186 | #ifdef OPENSSL_FOUND |
Vesa Jääskeläinen | 30dd087 | 2020-04-05 20:12:06 +0300 | [diff] [blame] | 2187 | TEEC_Result result = TEEC_ERROR_GENERIC; |
| 2188 | uint32_t ret_orig = 0; |
| 2189 | TEEC_Session session = { }; |
| 2190 | uint32_t login = UINT32_MAX; |
| 2191 | TEEC_UUID client_uuid = { }; |
| 2192 | TEEC_UUID expected_client_uuid = { }; |
| 2193 | TEEC_UUID uuid_ns = { }; |
| 2194 | char uuid_name[TEE_UUID_NS_NAME_SIZE] = { }; |
| 2195 | uint32_t group = 0; |
| 2196 | |
| 2197 | group = getegid(); |
| 2198 | |
| 2199 | result = xtest_uuid_from_str(&uuid_ns, client_uuid_linux_ns); |
| 2200 | |
| 2201 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2202 | return; |
| 2203 | |
| 2204 | sprintf(uuid_name, "gid=%x", group); |
| 2205 | |
| 2206 | result = xtest_uuid_v5(&expected_client_uuid, &uuid_ns, uuid_name, |
| 2207 | strlen(uuid_name)); |
| 2208 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2209 | return; |
| 2210 | |
| 2211 | result = TEEC_OpenSession(&xtest_teec_ctx, &session, &os_test_ta_uuid, |
| 2212 | TEEC_LOGIN_GROUP, &group, NULL, &ret_orig); |
| 2213 | |
| 2214 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2215 | return; |
| 2216 | |
| 2217 | result = ta_os_test_cmd_client_identity(&session, &login, |
| 2218 | &client_uuid); |
| 2219 | |
| 2220 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, result)) |
| 2221 | goto out; |
| 2222 | |
| 2223 | ADBG_EXPECT_COMPARE_UNSIGNED(c, login, ==, TEEC_LOGIN_GROUP); |
| 2224 | |
| 2225 | ADBG_EXPECT_EQUAL(c, &expected_client_uuid, &client_uuid, |
| 2226 | sizeof(TEEC_UUID)); |
| 2227 | |
| 2228 | out: |
| 2229 | TEEC_CloseSession(&session); |
Victor Chong | 8e070bc | 2020-05-13 09:59:33 +0100 | [diff] [blame] | 2230 | #else /*!OPENSSL_FOUND*/ |
| 2231 | UNUSED(c); |
| 2232 | /* xtest_uuid_v5() depends on OpenSSL */ |
| 2233 | Do_ADBG_Log("OpenSSL not available, skipping test 1028"); |
| 2234 | #endif |
Vesa Jääskeläinen | 30dd087 | 2020-04-05 20:12:06 +0300 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | ADBG_CASE_DEFINE(regression, 1028, xtest_tee_test_1028, |
| 2238 | "Session: group login for current user's effective group"); |
Jerome Forissier | 9a7101b | 2020-06-17 17:55:00 +0200 | [diff] [blame] | 2239 | |
| 2240 | static void xtest_tee_test_1029(ADBG_Case_t *c) |
| 2241 | { |
Jerome Forissier | 82e87bb | 2020-08-19 14:00:09 +0200 | [diff] [blame] | 2242 | TEEC_Result res = TEEC_SUCCESS; |
Jerome Forissier | 9a7101b | 2020-06-17 17:55:00 +0200 | [diff] [blame] | 2243 | TEEC_Session session = { 0 }; |
| 2244 | uint32_t ret_orig = 0; |
| 2245 | |
| 2246 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2247 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 2248 | NULL, &ret_orig))) |
| 2249 | return; |
| 2250 | |
| 2251 | Do_ADBG_BeginSubCase(c, "TLS variables (main program)"); |
Jerome Forissier | 82e87bb | 2020-08-19 14:00:09 +0200 | [diff] [blame] | 2252 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TLS_TEST_MAIN, NULL, |
| 2253 | &ret_orig); |
| 2254 | if (res == TEEC_ERROR_NOT_SUPPORTED) |
| 2255 | Do_ADBG_Log(" - 1029 - skip test, " |
| 2256 | "TA returned TEEC_ERROR_NOT_SUPPORTED"); |
| 2257 | else |
| 2258 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jerome Forissier | 9a7101b | 2020-06-17 17:55:00 +0200 | [diff] [blame] | 2259 | Do_ADBG_EndSubCase(c, "TLS variables (main program)"); |
| 2260 | |
| 2261 | Do_ADBG_BeginSubCase(c, "TLS variables (shared library)"); |
Jerome Forissier | 82e87bb | 2020-08-19 14:00:09 +0200 | [diff] [blame] | 2262 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TLS_TEST_SHLIB, NULL, |
| 2263 | &ret_orig); |
| 2264 | if (res == TEEC_ERROR_NOT_SUPPORTED) |
| 2265 | Do_ADBG_Log(" - 1029 - skip test, " |
| 2266 | "TA returned TEEC_ERROR_NOT_SUPPORTED"); |
| 2267 | else |
| 2268 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jerome Forissier | 9a7101b | 2020-06-17 17:55:00 +0200 | [diff] [blame] | 2269 | Do_ADBG_EndSubCase(c, "TLS variables (shared library)"); |
| 2270 | |
| 2271 | TEEC_CloseSession(&session); |
| 2272 | } |
| 2273 | ADBG_CASE_DEFINE(regression, 1029, xtest_tee_test_1029, |
| 2274 | "Test __thread attribute"); |
Jerome Forissier | 4565c45 | 2020-06-17 17:55:00 +0200 | [diff] [blame] | 2275 | |
| 2276 | static void xtest_tee_test_1030(ADBG_Case_t *c) |
| 2277 | { |
| 2278 | TEEC_Session session = { 0 }; |
| 2279 | uint32_t ret_orig = 0; |
| 2280 | |
| 2281 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2282 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 2283 | NULL, &ret_orig))) |
| 2284 | return; |
| 2285 | |
| 2286 | Do_ADBG_BeginSubCase(c, "Before dlopen()"); |
| 2287 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2288 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_DL_PHDR, NULL, |
| 2289 | &ret_orig)); |
| 2290 | Do_ADBG_EndSubCase(c, "Before dlopen()"); |
| 2291 | |
| 2292 | Do_ADBG_BeginSubCase(c, "After dlopen()"); |
| 2293 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2294 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_DL_PHDR_DL, NULL, |
| 2295 | &ret_orig)); |
| 2296 | Do_ADBG_EndSubCase(c, "After dlopen()"); |
| 2297 | |
| 2298 | TEEC_CloseSession(&session); |
| 2299 | } |
| 2300 | ADBG_CASE_DEFINE(regression, 1030, xtest_tee_test_1030, |
| 2301 | "Test dl_iterate_phdr()"); |
Jerome Forissier | 1a205ae | 2020-06-17 17:55:00 +0200 | [diff] [blame] | 2302 | |
| 2303 | #ifndef __clang__ |
| 2304 | static void xtest_tee_test_1031(ADBG_Case_t *c) |
| 2305 | { |
| 2306 | TEEC_Result ret = TEE_SUCCESS; |
| 2307 | TEEC_Session session = { 0 }; |
| 2308 | uint32_t ret_orig = 0; |
| 2309 | |
| 2310 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2311 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 2312 | NULL, &ret_orig))) |
| 2313 | return; |
| 2314 | |
| 2315 | Do_ADBG_BeginSubCase(c, "Global object constructor (main program)"); |
| 2316 | ret = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_CTOR_MAIN, NULL, |
| 2317 | &ret_orig); |
| 2318 | if (ret == TEEC_ERROR_NOT_SUPPORTED) { |
| 2319 | printf("TA not built with C++ support, skipping C++ tests\n"); |
| 2320 | Do_ADBG_EndSubCase(c, "Global object constructor (main program)"); |
| 2321 | goto out; |
| 2322 | |
| 2323 | } |
| 2324 | ADBG_EXPECT_TEEC_SUCCESS(c, ret); |
| 2325 | Do_ADBG_EndSubCase(c, "Global object constructor (main program)"); |
| 2326 | |
| 2327 | Do_ADBG_BeginSubCase(c, "Global object constructor (shared library)"); |
| 2328 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2329 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_CTOR_SHLIB, |
| 2330 | NULL, &ret_orig)); |
| 2331 | Do_ADBG_EndSubCase(c, "Global object constructor (shared library)"); |
| 2332 | |
| 2333 | Do_ADBG_BeginSubCase(c, "Global object constructor (dlopen()ed lib)"); |
| 2334 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2335 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_CTOR_SHLIB_DL, |
| 2336 | NULL, &ret_orig)); |
| 2337 | Do_ADBG_EndSubCase(c, "Global object constructor (dlopen()ed lib)"); |
| 2338 | |
| 2339 | Do_ADBG_BeginSubCase(c, "Exceptions (simple)"); |
| 2340 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2341 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_EXC_MAIN, NULL, |
| 2342 | &ret_orig)); |
| 2343 | Do_ADBG_EndSubCase(c, "Exceptions (simple)"); |
| 2344 | |
| 2345 | Do_ADBG_BeginSubCase(c, "Exceptions (mixed C/C++ frames)"); |
| 2346 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2347 | TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CXX_EXC_MIXED, NULL, |
| 2348 | &ret_orig)); |
| 2349 | Do_ADBG_EndSubCase(c, "Exceptions (mixed C/C++ frames)"); |
| 2350 | out: |
| 2351 | TEEC_CloseSession(&session); |
| 2352 | } |
| 2353 | ADBG_CASE_DEFINE(regression, 1031, xtest_tee_test_1031, |
| 2354 | "Test C++ features"); |
| 2355 | #endif |
Jens Wiklander | e16da89 | 2020-09-04 09:24:16 +0200 | [diff] [blame] | 2356 | |
| 2357 | static void xtest_tee_test_1032(ADBG_Case_t *c) |
| 2358 | { |
| 2359 | TEEC_Result res = TEEC_SUCCESS; |
| 2360 | TEEC_Context ctx = { }; |
| 2361 | TEEC_SharedMemory shm1 = { |
| 2362 | .buffer = xtest_tee_test_1032, |
| 2363 | .size = 32, |
| 2364 | .flags = TEEC_MEM_INPUT, |
| 2365 | }; |
| 2366 | static const uint8_t dummy_data[32] = { 1, 2, 3, 4, }; |
| 2367 | TEEC_SharedMemory shm2 = { |
| 2368 | .buffer = (void *)dummy_data, |
| 2369 | .size = sizeof(dummy_data), |
| 2370 | .flags = TEEC_MEM_INPUT, |
| 2371 | }; |
| 2372 | |
| 2373 | res = TEEC_InitializeContext(xtest_tee_name, &ctx); |
| 2374 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2375 | return; |
| 2376 | |
| 2377 | res = TEEC_RegisterSharedMemory(&ctx, &shm1); |
| 2378 | if (ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2379 | TEEC_ReleaseSharedMemory(&shm1); |
| 2380 | |
| 2381 | res = TEEC_RegisterSharedMemory(&ctx, &shm2); |
| 2382 | if (ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2383 | TEEC_ReleaseSharedMemory(&shm2); |
| 2384 | |
| 2385 | TEEC_FinalizeContext(&ctx); |
| 2386 | } |
| 2387 | ADBG_CASE_DEFINE(regression, 1032, xtest_tee_test_1032, |
| 2388 | "Register read-only shared memory"); |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 2389 | |
| 2390 | static void xtest_tee_test_1033(ADBG_Case_t *c) |
| 2391 | { |
| 2392 | TEEC_Session session = { }; |
| 2393 | uint32_t ret_orig = 0; |
| 2394 | |
| 2395 | /* TA will ping the test plugin during open session operation */ |
| 2396 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2397 | xtest_teec_open_session(&session, &supp_plugin_test_ta_uuid, |
| 2398 | NULL, &ret_orig))) |
| 2399 | return; |
| 2400 | |
| 2401 | Do_ADBG_BeginSubCase(c, "Pass values to/from a plugin"); |
| 2402 | { |
| 2403 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2404 | |
| 2405 | op.params[0].value.a = 20; |
| 2406 | op.params[0].value.b = 10; |
| 2407 | op.params[1].value.a = '+'; |
| 2408 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, |
| 2409 | TEEC_VALUE_INPUT, TEEC_NONE, |
| 2410 | TEEC_NONE); |
| 2411 | |
| 2412 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2413 | TEEC_InvokeCommand(&session, |
| 2414 | TA_SUPP_PLUGIN_CMD_PASS_VALUES, &op, |
| 2415 | &ret_orig)); |
| 2416 | ADBG_EXPECT(c, 30, op.params[0].value.a); |
| 2417 | |
| 2418 | /* reassign, because the values was changed during previous op */ |
| 2419 | op.params[0].value.a = 20; |
| 2420 | op.params[0].value.b = 10; |
| 2421 | op.params[1].value.a = '-'; |
| 2422 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2423 | TEEC_InvokeCommand(&session, |
| 2424 | TA_SUPP_PLUGIN_CMD_PASS_VALUES, &op, |
| 2425 | &ret_orig)); |
| 2426 | ADBG_EXPECT(c, 10, op.params[0].value.a); |
| 2427 | } |
| 2428 | Do_ADBG_EndSubCase(c, "Pass values to/from a plugin"); |
| 2429 | |
| 2430 | Do_ADBG_BeginSubCase(c, "Pass array to a plugin"); |
| 2431 | { |
| 2432 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
Aleksandr Anisimov | 8076839 | 2021-03-05 19:36:20 +0300 | [diff] [blame] | 2433 | uint8_t to_plugin[] = { 0, 1, 2, 3, 4, 5 }; |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 2434 | |
| 2435 | op.params[0].tmpref.buffer = to_plugin; |
| 2436 | op.params[0].tmpref.size = sizeof(to_plugin); |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 2437 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
Aleksandr Anisimov | 8076839 | 2021-03-05 19:36:20 +0300 | [diff] [blame] | 2438 | TEEC_VALUE_OUTPUT, |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 2439 | TEEC_NONE, TEEC_NONE); |
| 2440 | |
| 2441 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2442 | TEEC_InvokeCommand(&session, |
| 2443 | TA_SUPP_PLUGIN_CMD_WRITE_ARR, |
| 2444 | &op, &ret_orig)); |
| 2445 | |
| 2446 | /* |
Aleksandr Anisimov | 8076839 | 2021-03-05 19:36:20 +0300 | [diff] [blame] | 2447 | * The test plugin must calculate a sum of the input elements |
| 2448 | * and store it to 'op.params[1].value.a' |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 2449 | */ |
Aleksandr Anisimov | 8076839 | 2021-03-05 19:36:20 +0300 | [diff] [blame] | 2450 | ADBG_EXPECT(c, 15, op.params[1].value.a); |
Aleksandr Anisimov | 01f6f06 | 2021-01-19 11:02:25 +0300 | [diff] [blame] | 2451 | } |
| 2452 | Do_ADBG_EndSubCase(c, "Pass array to a plugin"); |
| 2453 | |
| 2454 | Do_ADBG_BeginSubCase(c, "Get array from a plugin"); |
| 2455 | { |
| 2456 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2457 | char from_plugin[64] = { }; |
| 2458 | char expected_arr[] = "Array from plugin"; |
| 2459 | size_t expectes_size = sizeof(expected_arr); |
| 2460 | |
| 2461 | op.params[0].tmpref.buffer = from_plugin; |
| 2462 | op.params[0].tmpref.size = sizeof(from_plugin); |
| 2463 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, |
| 2464 | TEEC_VALUE_OUTPUT, TEEC_NONE, |
| 2465 | TEEC_NONE); |
| 2466 | ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2467 | TEEC_InvokeCommand(&session, |
| 2468 | TA_SUPP_PLUGIN_CMD_GET_ARR, &op, |
| 2469 | &ret_orig)); |
| 2470 | ADBG_EXPECT(c, expectes_size, op.params[1].value.a); |
| 2471 | ADBG_EXPECT_EQUAL(c, expected_arr, from_plugin, expectes_size); |
| 2472 | } |
| 2473 | Do_ADBG_EndSubCase(c, "Get array from a plugin"); |
| 2474 | |
| 2475 | Do_ADBG_BeginSubCase(c, "Not allow bad input to a plugin"); |
| 2476 | { |
| 2477 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2478 | |
| 2479 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, |
| 2480 | TEEC_NONE, TEEC_NONE); |
| 2481 | ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_BAD_PARAMETERS, |
| 2482 | TEEC_InvokeCommand(&session, |
| 2483 | TA_SUPP_PLUGIN_CMD_BAD_UUID, &op, |
| 2484 | &ret_orig)); |
| 2485 | ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_BAD_PARAMETERS, |
| 2486 | TEEC_InvokeCommand(&session, |
| 2487 | TA_SUPP_PLUGIN_CMD_BAD_IN_DATA, &op, |
| 2488 | &ret_orig)); |
| 2489 | ADBG_EXPECT_TEEC_RESULT(c, TEE_ERROR_BAD_PARAMETERS, |
| 2490 | TEEC_InvokeCommand(&session, |
| 2491 | TA_SUPP_PLUGIN_CMD_BAD_IN_LEN, &op, |
| 2492 | &ret_orig)); |
| 2493 | } |
| 2494 | Do_ADBG_EndSubCase(c, "Not allow bad input to a plugin"); |
| 2495 | |
| 2496 | Do_ADBG_BeginSubCase(c, "Call an unknown plugin"); |
| 2497 | { |
| 2498 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2499 | |
| 2500 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, |
| 2501 | TEEC_NONE, TEEC_NONE); |
| 2502 | ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND, |
| 2503 | TEEC_InvokeCommand(&session, |
| 2504 | TA_SUPP_PLUGIN_CMD_UNKNOWN_UUID, |
| 2505 | &op, &ret_orig)); |
| 2506 | } |
| 2507 | Do_ADBG_EndSubCase(c, "Call an unknown plugin"); |
| 2508 | |
| 2509 | TEEC_CloseSession(&session); |
| 2510 | } |
| 2511 | ADBG_CASE_DEFINE(regression, 1033, xtest_tee_test_1033, |
| 2512 | "Test the supplicant plugin framework"); |
Jens Wiklander | 94fb158 | 2021-05-19 10:14:57 +0200 | [diff] [blame] | 2513 | |
| 2514 | static void xtest_tee_test_1034(ADBG_Case_t *c) |
| 2515 | { |
| 2516 | TEEC_Result res = TEEC_SUCCESS; |
| 2517 | TEEC_Session session = { }; |
| 2518 | uint32_t ret_orig = 0; |
| 2519 | |
| 2520 | res = xtest_teec_open_session(&session, &large_ta_uuid, NULL, |
| 2521 | &ret_orig); |
Jerome Forissier | e8be5b5 | 2021-06-29 16:29:06 +0200 | [diff] [blame] | 2522 | if (res == TEEC_ERROR_OUT_OF_MEMORY) { |
| 2523 | Do_ADBG_Log("TEEC_ERROR_OUT_OF_MEMORY - ignored"); |
| 2524 | } else { |
| 2525 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
Jens Wiklander | 94fb158 | 2021-05-19 10:14:57 +0200 | [diff] [blame] | 2526 | TEEC_CloseSession(&session); |
Jerome Forissier | e8be5b5 | 2021-06-29 16:29:06 +0200 | [diff] [blame] | 2527 | } |
Jens Wiklander | 94fb158 | 2021-05-19 10:14:57 +0200 | [diff] [blame] | 2528 | } |
| 2529 | ADBG_CASE_DEFINE(regression, 1034, xtest_tee_test_1034, |
| 2530 | "Test loading a large TA"); |
Ruchika Gupta | 813b6d4 | 2021-12-01 10:44:14 +0530 | [diff] [blame] | 2531 | |
| 2532 | #if defined(CFG_TA_BTI) |
| 2533 | struct bti_test { |
| 2534 | uint32_t cmd; |
| 2535 | uint32_t func; |
| 2536 | }; |
| 2537 | |
| 2538 | #define BTI_TEST(caller_func, bti_func) { \ |
| 2539 | .cmd = caller_func, \ |
| 2540 | .func = bti_func, \ |
| 2541 | } |
| 2542 | |
| 2543 | static const struct bti_test bti_cases_success[] = { |
| 2544 | BTI_TEST(TA_TEST_USING_BLR, TA_FUNC_BTI_C), |
| 2545 | BTI_TEST(TA_TEST_USING_BLR, TA_FUNC_BTI_JC), |
| 2546 | BTI_TEST(TA_TEST_USING_BR, TA_FUNC_BTI_J), |
| 2547 | BTI_TEST(TA_TEST_USING_BR, TA_FUNC_BTI_JC), |
| 2548 | BTI_TEST(TA_TEST_USING_BR_X16, TA_FUNC_BTI_C), |
| 2549 | BTI_TEST(TA_TEST_USING_BR_X16, TA_FUNC_BTI_J), |
| 2550 | BTI_TEST(TA_TEST_USING_BR_X16, TA_FUNC_BTI_JC), |
| 2551 | }; |
| 2552 | |
| 2553 | static const struct bti_test bti_cases_panic[] = { |
| 2554 | BTI_TEST(TA_TEST_USING_BLR, TA_FUNC_BTI_J), |
| 2555 | BTI_TEST(TA_TEST_USING_BLR, TA_FUNC_BTI_NONE), |
| 2556 | BTI_TEST(TA_TEST_USING_BR, TA_FUNC_BTI_C), |
| 2557 | BTI_TEST(TA_TEST_USING_BR, TA_FUNC_BTI_NONE), |
| 2558 | BTI_TEST(TA_TEST_USING_BR_X16, TA_FUNC_BTI_NONE), |
| 2559 | }; |
| 2560 | |
| 2561 | static void get_cpu_feature(ADBG_Case_t *c, bool *bti) |
| 2562 | { |
| 2563 | TEEC_Session session = {}; |
| 2564 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2565 | uint32_t ret_orig = 0; |
| 2566 | TEEC_Result res; |
| 2567 | |
| 2568 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, |
| 2569 | TEEC_NONE); |
| 2570 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2571 | xtest_teec_open_session(&session, &bti_test_ta_uuid, |
| 2572 | NULL, &ret_orig))) |
| 2573 | return; |
| 2574 | |
| 2575 | res = TEEC_InvokeCommand(&session, TA_FEAT_BTI_IMPLEMENTED, &op, |
| 2576 | &ret_orig); |
| 2577 | if (!res) { |
| 2578 | if(op.params[0].value.a) |
| 2579 | *bti = true; |
| 2580 | Do_ADBG_Log("FEAT_BTI is %simplemented", *bti ? "" : "NOT "); |
| 2581 | } |
| 2582 | |
| 2583 | TEEC_CloseSession(&session); |
| 2584 | } |
| 2585 | |
| 2586 | static void xtest_tee_test_1035(ADBG_Case_t *c) |
| 2587 | { |
| 2588 | TEEC_Session session = {}; |
| 2589 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2590 | struct bti_test const *test = NULL; |
| 2591 | uint32_t ret_orig = 0; |
| 2592 | TEEC_Result res; |
| 2593 | unsigned int n = 0; |
| 2594 | bool cpu_feature_bti = false; |
| 2595 | |
| 2596 | Do_ADBG_BeginSubCase(c, "BTI Implemented"); |
| 2597 | get_cpu_feature(c, &cpu_feature_bti); |
| 2598 | Do_ADBG_EndSubCase(c, "BTI Implemented"); |
| 2599 | |
| 2600 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, |
| 2601 | TEEC_NONE); |
| 2602 | |
| 2603 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2604 | xtest_teec_open_session(&session, &bti_test_ta_uuid, |
| 2605 | NULL, &ret_orig))) |
| 2606 | return; |
| 2607 | |
| 2608 | Do_ADBG_BeginSubCase(c, "BTI Pass Cases"); |
| 2609 | for (n = 0; n < ARRAY_SIZE(bti_cases_success); n++) { |
| 2610 | test = &bti_cases_success[n]; |
| 2611 | |
| 2612 | op.params[0].value.a = test->func; |
| 2613 | |
| 2614 | res = TEEC_InvokeCommand(&session, test->cmd, &op, &ret_orig); |
| 2615 | if (res == TEEC_ERROR_NOT_IMPLEMENTED) { |
| 2616 | Do_ADBG_Log("Binary doesn't support BTI - skip tests"); |
| 2617 | Do_ADBG_EndSubCase(c, "BTI Pass Cases"); |
| 2618 | TEEC_CloseSession(&session); |
| 2619 | return; |
| 2620 | } |
| 2621 | |
| 2622 | Do_ADBG_BeginSubCase(c, "BTI Case %u", n); |
| 2623 | |
| 2624 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 2625 | |
| 2626 | Do_ADBG_EndSubCase(c, "BTI Case %u", n); |
| 2627 | } |
| 2628 | Do_ADBG_EndSubCase(c, "BTI Pass Cases"); |
| 2629 | |
| 2630 | TEEC_CloseSession(&session); |
| 2631 | |
| 2632 | Do_ADBG_BeginSubCase(c, "BTI Exception Generation"); |
| 2633 | for (n = 0; n < ARRAY_SIZE(bti_cases_panic); n++) { |
| 2634 | test = &bti_cases_panic[n]; |
| 2635 | res = TEEC_SUCCESS; |
| 2636 | |
| 2637 | if (cpu_feature_bti) |
| 2638 | res = TEEC_ERROR_TARGET_DEAD; |
| 2639 | |
| 2640 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2641 | xtest_teec_open_session(&session, &bti_test_ta_uuid, |
| 2642 | NULL, &ret_orig))) |
| 2643 | goto out; |
| 2644 | |
| 2645 | Do_ADBG_BeginSubCase(c, "BTI Case %u", n); |
| 2646 | op.params[0].value.a = test->func; |
| 2647 | |
| 2648 | (void)ADBG_EXPECT_TEEC_RESULT(c, res, |
| 2649 | TEEC_InvokeCommand(&session, test->cmd, &op, &ret_orig)); |
| 2650 | |
| 2651 | if (cpu_feature_bti) |
| 2652 | (void)ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, |
| 2653 | ret_orig); |
| 2654 | |
| 2655 | Do_ADBG_EndSubCase(c, "BTI Case %u", n); |
| 2656 | |
| 2657 | TEEC_CloseSession(&session); |
| 2658 | } |
| 2659 | |
| 2660 | out: |
| 2661 | Do_ADBG_EndSubCase(c, "BTI Exception Generation"); |
| 2662 | } |
| 2663 | ADBG_CASE_DEFINE(regression, 1035, xtest_tee_test_1035, "Test BTI"); |
| 2664 | #endif |
Ruchika Gupta | 4808e38 | 2022-01-28 12:41:21 +0530 | [diff] [blame] | 2665 | |
| 2666 | static void xtest_tee_test_1036(ADBG_Case_t *c) |
| 2667 | { |
| 2668 | TEEC_Session session = { }; |
| 2669 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2670 | uint32_t ret_orig = 0; |
| 2671 | TEEC_Result res = TEEC_SUCCESS; |
| 2672 | |
| 2673 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, |
| 2674 | TEEC_NONE); |
| 2675 | |
| 2676 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, |
| 2677 | xtest_teec_open_session(&session, &os_test_ta_uuid, |
| 2678 | NULL, &ret_orig))) |
| 2679 | return; |
| 2680 | |
| 2681 | Do_ADBG_BeginSubCase(c, "PAuth NOP test"); |
| 2682 | |
| 2683 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PAUTH_NOP, &op, |
| 2684 | &ret_orig); |
| 2685 | if (res == TEEC_ERROR_NOT_SUPPORTED) { |
| 2686 | Do_ADBG_Log("Binary doesn't support PAuth - skip tests"); |
| 2687 | goto out; |
| 2688 | } |
| 2689 | |
| 2690 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2691 | goto out; |
| 2692 | |
| 2693 | Do_ADBG_EndSubCase(c, "PAuth NOP test"); |
| 2694 | |
| 2695 | Do_ADBG_BeginSubCase(c, "PAuth PAC corruption"); |
| 2696 | |
| 2697 | ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_TARGET_DEAD, |
| 2698 | TEEC_InvokeCommand(&session, |
| 2699 | TA_OS_TEST_CMD_PAUTH_CORRUPT_PAC, |
| 2700 | &op, &ret_orig)); |
| 2701 | |
| 2702 | ADBG_EXPECT_TEEC_ERROR_ORIGIN(c, TEEC_ORIGIN_TEE, ret_orig); |
| 2703 | |
| 2704 | Do_ADBG_EndSubCase(c, "PAuth PAC corruption"); |
| 2705 | |
| 2706 | out: |
| 2707 | TEEC_CloseSession(&session); |
| 2708 | } |
| 2709 | ADBG_CASE_DEFINE(regression, 1036, xtest_tee_test_1036, |
| 2710 | "Test PAuth (Pointer Authentication)"); |
Jerome Forissier | 0915b22 | 2021-10-27 18:20:59 +0200 | [diff] [blame] | 2711 | |
| 2712 | #define ATT_MAX_KEYSZ 4096 |
| 2713 | |
| 2714 | #ifdef OPENSSL_FOUND |
| 2715 | static RSA *att_key; |
| 2716 | static size_t att_key_size; /* Actual key size (modulus size) in bytes */ |
| 2717 | |
| 2718 | /* |
| 2719 | * buf = [ TA hash (32 bytes SHA256) | Signature (att_key_size bytes) ] |
| 2720 | * Signature = RSA_SSA_PKCS1_PSS_MGF1(SHA256([nonce | TA hash]) |
| 2721 | */ |
| 2722 | static void check_signature(ADBG_Case_t *c, uint8_t *nonce, size_t nonce_size, |
| 2723 | uint8_t *buf) |
| 2724 | { |
| 2725 | unsigned char digest[SHA256_DIGEST_LENGTH] = { }; |
| 2726 | unsigned char *sig = buf + SHA256_DIGEST_LENGTH; |
| 2727 | unsigned char *ta_hash = buf; |
| 2728 | uint8_t decr[ATT_MAX_KEYSZ / 8] = { }; |
| 2729 | SHA256_CTX ctx = { }; |
| 2730 | int salt_len = 32; /* Hard-coded in the PTA */ |
| 2731 | int st = 0; |
| 2732 | |
| 2733 | if (!ADBG_EXPECT_NOT_NULL(c, att_key)) |
| 2734 | return; |
| 2735 | |
| 2736 | SHA256_Init(&ctx); |
| 2737 | SHA256_Update(&ctx, nonce, nonce_size); |
| 2738 | SHA256_Update(&ctx, ta_hash, SHA256_DIGEST_LENGTH); |
| 2739 | SHA256_Final(digest, &ctx); |
| 2740 | |
| 2741 | st = RSA_public_decrypt(att_key_size, sig, decr, att_key, |
| 2742 | RSA_NO_PADDING); |
| 2743 | ADBG_EXPECT_COMPARE_SIGNED(c, st, >, 0); |
| 2744 | st = RSA_verify_PKCS1_PSS_mgf1(att_key, digest, EVP_sha256(), |
| 2745 | EVP_sha256(), decr, salt_len); |
| 2746 | ADBG_EXPECT_COMPARE_SIGNED(c, st, >, 0); |
| 2747 | } |
| 2748 | |
| 2749 | static void free_att_key(void) |
| 2750 | { |
| 2751 | RSA_free(att_key); |
| 2752 | att_key = NULL; |
| 2753 | } |
| 2754 | |
| 2755 | static void set_att_key(ADBG_Case_t *c, uint8_t *e, size_t e_sz, uint8_t *n, |
| 2756 | size_t n_sz) |
| 2757 | { |
| 2758 | BIGNUM *bn_e = NULL; |
| 2759 | BIGNUM *bn_n = NULL; |
| 2760 | int st = 0; |
| 2761 | |
| 2762 | att_key_size = n_sz; |
| 2763 | att_key = RSA_new(); |
| 2764 | if (!ADBG_EXPECT_NOT_NULL(c, att_key)) |
| 2765 | return; |
| 2766 | |
| 2767 | bn_e = BN_bin2bn(e, e_sz, NULL); |
| 2768 | if (!ADBG_EXPECT_NOT_NULL(c, bn_e)) |
| 2769 | goto err; |
| 2770 | bn_n = BN_bin2bn(n, n_sz, NULL); |
| 2771 | if (!ADBG_EXPECT_NOT_NULL(c, bn_n)) |
| 2772 | goto err; |
| 2773 | |
| 2774 | st = RSA_set0_key(att_key, bn_n, bn_e, BN_new()); |
| 2775 | if (!ADBG_EXPECT_COMPARE_SIGNED(c, st, !=, 0)) |
| 2776 | goto err; |
| 2777 | return; |
| 2778 | err: |
| 2779 | free_att_key(); |
| 2780 | } |
| 2781 | #else |
| 2782 | #define check_signature(...) |
| 2783 | #define set_att_key(...) |
| 2784 | #define free_att_key() |
| 2785 | #endif |
| 2786 | |
| 2787 | /* |
| 2788 | * Verification of the output of the attestation PTA |
| 2789 | * - (If hash != NULL) check buf contains the expected hash |
| 2790 | * - (If OpenSSL is available) Check that the signature is valid |
| 2791 | */ |
| 2792 | static void check_measurement(ADBG_Case_t *c, uint8_t *nonce, size_t nonce_size, |
| 2793 | uint8_t *hash, uint8_t *buf) |
| 2794 | { |
| 2795 | if (hash) |
| 2796 | ADBG_EXPECT_BUFFER(c, hash, 32, buf, 32); |
| 2797 | |
| 2798 | check_signature(c, nonce, nonce_size, buf); |
| 2799 | } |
| 2800 | |
| 2801 | /* Invoke attestation PTA to return the public key */ |
| 2802 | static void get_att_public_key(ADBG_Case_t *c) |
| 2803 | { |
| 2804 | uint8_t n[ATT_MAX_KEYSZ / 8] = { }; |
| 2805 | uint8_t e[3] = { }; /* We know e == 65537... */ |
| 2806 | size_t n_sz = sizeof(n); |
| 2807 | size_t e_sz = sizeof(e); |
| 2808 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2809 | TEEC_UUID att_uuid = PTA_ATTESTATION_UUID; |
| 2810 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 2811 | TEEC_Session session = { }; |
| 2812 | uint32_t ret_orig = 0; |
| 2813 | |
| 2814 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, |
| 2815 | TEEC_MEMREF_TEMP_OUTPUT, |
| 2816 | TEEC_VALUE_OUTPUT, TEEC_NONE); |
| 2817 | op.params[0].tmpref.buffer = e; |
| 2818 | op.params[0].tmpref.size = e_sz; |
| 2819 | op.params[1].tmpref.buffer = n; |
| 2820 | op.params[1].tmpref.size = n_sz; |
| 2821 | |
| 2822 | res = xtest_teec_open_session(&session, &att_uuid, NULL, &ret_orig); |
| 2823 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2824 | return; |
| 2825 | |
| 2826 | res = TEEC_InvokeCommand(&session, PTA_ATTESTATION_GET_PUBKEY, &op, |
| 2827 | &ret_orig); |
| 2828 | |
| 2829 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res) || |
| 2830 | !ADBG_EXPECT_COMPARE_UNSIGNED(c, op.params[2].value.a, ==, |
| 2831 | TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256)) |
| 2832 | goto out; |
| 2833 | |
| 2834 | e_sz = op.params[0].tmpref.size; |
| 2835 | n_sz = op.params[1].tmpref.size; |
| 2836 | set_att_key(c, e, e_sz, n, n_sz); |
| 2837 | out: |
| 2838 | TEEC_CloseSession(&session); |
| 2839 | } |
| 2840 | |
| 2841 | /* Invoke attestation PTA to hash the TEE binary */ |
| 2842 | static void attestation_tee(ADBG_Case_t *c) |
| 2843 | { |
| 2844 | uint8_t measurement[TEE_SHA256_HASH_SIZE + ATT_MAX_KEYSZ / 8] = { }; |
| 2845 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2846 | uint8_t nonce[4] = { 0x12, 0x34, 0x56, 0x78 }; |
| 2847 | TEEC_UUID att_uuid = PTA_ATTESTATION_UUID; |
| 2848 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 2849 | TEEC_Session session = { }; |
| 2850 | uint32_t ret_orig = 0; |
| 2851 | |
| 2852 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 2853 | TEEC_MEMREF_TEMP_OUTPUT, |
| 2854 | TEEC_NONE, TEEC_NONE); |
| 2855 | op.params[0].tmpref.buffer = nonce; |
| 2856 | op.params[0].tmpref.size = sizeof(nonce); |
| 2857 | op.params[1].tmpref.buffer = measurement; |
| 2858 | op.params[1].tmpref.size = sizeof(measurement); |
| 2859 | |
| 2860 | res = xtest_teec_open_session(&session, &att_uuid, NULL, &ret_orig); |
| 2861 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2862 | return; |
| 2863 | |
| 2864 | /* Hash TEE and check signature */ |
| 2865 | res = TEEC_InvokeCommand(&session, PTA_ATTESTATION_HASH_TEE_MEMORY, &op, |
| 2866 | &ret_orig); |
| 2867 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 2868 | check_measurement(c, nonce, sizeof(nonce), NULL, measurement); |
| 2869 | |
| 2870 | TEEC_CloseSession(&session); |
| 2871 | } |
| 2872 | |
| 2873 | /* Invoke attestation PTA to obtain the digest contained in the some TA shdr */ |
| 2874 | static void attestation_ta_shdr(ADBG_Case_t *c) |
| 2875 | { |
| 2876 | uint8_t measurement[TEE_SHA256_HASH_SIZE + ATT_MAX_KEYSZ / 8] = { }; |
| 2877 | uint8_t nonce[6] = { 0xa0, 0x98, 0x76, 0x54, 0x32, 0x10 }; |
| 2878 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2879 | uint8_t hash1[TEE_SHA256_HASH_SIZE] = { }; |
| 2880 | uint8_t hash2[TEE_SHA256_HASH_SIZE] = { }; |
| 2881 | TEEC_UUID att_uuid = PTA_ATTESTATION_UUID; |
| 2882 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 2883 | TEEC_Session session = { }; |
| 2884 | uint32_t ret_orig = 0; |
| 2885 | int cmp = 0; |
| 2886 | |
| 2887 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 2888 | TEEC_MEMREF_TEMP_INPUT, |
| 2889 | TEEC_MEMREF_TEMP_OUTPUT, |
| 2890 | TEEC_NONE); |
| 2891 | op.params[0].tmpref.buffer = (void *)&os_test_ta_uuid; |
| 2892 | op.params[0].tmpref.size = sizeof(TEEC_UUID); |
| 2893 | op.params[1].tmpref.buffer = nonce; |
| 2894 | op.params[1].tmpref.size = sizeof(nonce); |
| 2895 | op.params[2].tmpref.buffer = measurement; |
| 2896 | op.params[2].tmpref.size = sizeof(measurement); |
| 2897 | |
| 2898 | res = xtest_teec_open_session(&session, &att_uuid, NULL, &ret_orig); |
| 2899 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2900 | return; |
| 2901 | |
| 2902 | /* Hash TA and check signature */ |
| 2903 | res = TEEC_InvokeCommand(&session, PTA_ATTESTATION_GET_TA_SHDR_DIGEST, |
| 2904 | &op, &ret_orig); |
| 2905 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 2906 | check_measurement(c, nonce, sizeof(nonce), NULL, measurement); |
| 2907 | /* Save hash */ |
| 2908 | memcpy(hash1, measurement, 32); |
| 2909 | |
| 2910 | /* Hash TA again */ |
| 2911 | memset(measurement, 0, sizeof(measurement)); |
| 2912 | res = TEEC_InvokeCommand(&session, PTA_ATTESTATION_GET_TA_SHDR_DIGEST, |
| 2913 | &op, &ret_orig); |
| 2914 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 2915 | /* New hash should be identical */ |
| 2916 | check_measurement(c, nonce, sizeof(nonce), hash1, measurement); |
| 2917 | |
| 2918 | /* Hash another TA */ |
| 2919 | op.params[0].tmpref.buffer = (void *)&crypt_user_ta_uuid; |
| 2920 | memset(measurement, 0, sizeof(measurement)); |
| 2921 | res = TEEC_InvokeCommand(&session, PTA_ATTESTATION_GET_TA_SHDR_DIGEST, |
| 2922 | &op, &ret_orig); |
| 2923 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 2924 | check_measurement(c, nonce, sizeof(nonce), NULL, measurement); |
| 2925 | memcpy(hash2, measurement, 32); |
| 2926 | /* Different binaries should have different hashes */ |
| 2927 | cmp = memcmp(hash1, hash2, sizeof(hash1)); |
| 2928 | ADBG_EXPECT_COMPARE_SIGNED(c, cmp, !=, 0); |
| 2929 | |
| 2930 | TEEC_CloseSession(&session); |
| 2931 | } |
| 2932 | |
| 2933 | /* |
| 2934 | * Invoke os_test TA which will invoke attestation PTA to obtain a hash of |
| 2935 | * itself. |
| 2936 | */ |
| 2937 | static void attestation_ta_memory(ADBG_Case_t *c) |
| 2938 | { |
| 2939 | TEEC_Operation op = TEEC_OPERATION_INITIALIZER; |
| 2940 | uint8_t nonce[6] = { 0xa0, 0x98, 0x76, 0x54, 0x32, 0x10 }; |
| 2941 | uint8_t hash1[TEE_SHA256_HASH_SIZE] = { }; |
| 2942 | uint8_t hash2[TEE_SHA256_HASH_SIZE] = { }; |
| 2943 | uint8_t measurement[TEE_SHA256_HASH_SIZE + ATT_MAX_KEYSZ / 8] = { }; |
| 2944 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 2945 | TEEC_Session session = { }; |
| 2946 | uint32_t ret_orig = 0; |
| 2947 | int cmp = 0; |
| 2948 | |
| 2949 | Do_ADBG_BeginSubCase(c, "Consecutive calls"); |
| 2950 | |
| 2951 | /* Open session to os_test TA */ |
| 2952 | res = xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 2953 | &ret_orig); |
| 2954 | if (!ADBG_EXPECT_TEEC_SUCCESS(c, res)) |
| 2955 | return; |
| 2956 | |
| 2957 | op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, |
| 2958 | TEEC_MEMREF_TEMP_OUTPUT, |
| 2959 | TEEC_NONE, TEEC_NONE); |
| 2960 | op.params[0].tmpref.buffer = nonce; |
| 2961 | op.params[0].tmpref.size = sizeof(nonce); |
| 2962 | op.params[1].tmpref.buffer = measurement; |
| 2963 | op.params[1].tmpref.size = sizeof(measurement); |
| 2964 | |
| 2965 | /* Hash TA */ |
| 2966 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_ATTESTATION, &op, |
| 2967 | &ret_orig); |
| 2968 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 2969 | |
| 2970 | check_measurement(c, nonce, sizeof(nonce), NULL, measurement); |
| 2971 | memcpy(hash1, measurement, 32); |
| 2972 | |
| 2973 | /* Hash TA again */ |
| 2974 | memset(measurement, 0, sizeof(measurement)); |
| 2975 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_ATTESTATION, &op, |
| 2976 | &ret_orig); |
| 2977 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 2978 | |
| 2979 | /* New hash should be identical to hash1 */ |
| 2980 | check_measurement(c, nonce, sizeof(nonce), hash1, measurement); |
| 2981 | |
| 2982 | Do_ADBG_EndSubCase(c, "Consecutive calls"); |
| 2983 | |
| 2984 | /* Close TA session, will cause unload of TA */ |
| 2985 | TEEC_CloseSession(&session); |
| 2986 | |
| 2987 | Do_ADBG_BeginSubCase(c, "TA reload"); |
| 2988 | |
| 2989 | /* Load TA again and open a new session */ |
| 2990 | res = xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, |
| 2991 | &ret_orig); |
| 2992 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 2993 | if (res) |
| 2994 | return; |
| 2995 | |
| 2996 | /* Hash TA one more time */ |
| 2997 | memset(measurement, 0, sizeof(measurement)); |
| 2998 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_ATTESTATION, &op, |
| 2999 | &ret_orig); |
| 3000 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 3001 | |
| 3002 | /* Hash after reload should still be the same */ |
| 3003 | check_measurement(c, nonce, sizeof(nonce), hash1, measurement); |
| 3004 | |
| 3005 | Do_ADBG_EndSubCase(c, "TA reload"); |
| 3006 | |
| 3007 | Do_ADBG_BeginSubCase(c, "Add shared library"); |
| 3008 | |
| 3009 | /* |
| 3010 | * Invoke a TA command that causes some additional code to be mapped |
| 3011 | * (shared library) |
| 3012 | */ |
| 3013 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_CALL_LIB_DL, NULL, |
| 3014 | &ret_orig); |
| 3015 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 3016 | |
| 3017 | /* Hash TA one last time */ |
| 3018 | memset(measurement, 0, sizeof(measurement)); |
| 3019 | res = TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_ATTESTATION, &op, |
| 3020 | &ret_orig); |
| 3021 | ADBG_EXPECT_TEEC_SUCCESS(c, res); |
| 3022 | |
| 3023 | check_measurement(c, nonce, sizeof(nonce), NULL, measurement); |
| 3024 | memcpy(hash2, measurement, 32); |
| 3025 | |
| 3026 | /* Different binaries mapped mean different hashes */ |
| 3027 | cmp = memcmp(hash1, hash2, sizeof(hash1)); |
| 3028 | ADBG_EXPECT_COMPARE_SIGNED(c, cmp, !=, 0); |
| 3029 | |
| 3030 | Do_ADBG_EndSubCase(c, "Add shared library"); |
| 3031 | |
| 3032 | TEEC_CloseSession(&session); |
| 3033 | } |
| 3034 | |
| 3035 | static void xtest_tee_test_1037(ADBG_Case_t *c) |
| 3036 | { |
| 3037 | TEEC_UUID att_uuid = PTA_ATTESTATION_UUID; |
| 3038 | TEEC_Result res = TEEC_ERROR_GENERIC; |
| 3039 | TEEC_Session session = { }; |
| 3040 | uint32_t ret_orig = 0; |
| 3041 | |
| 3042 | res = xtest_teec_open_session(&session, &att_uuid, NULL, &ret_orig); |
| 3043 | if (res == TEEC_ERROR_ITEM_NOT_FOUND) { |
| 3044 | Do_ADBG_Log(" skip test, pseudo TA not found"); |
| 3045 | return; |
| 3046 | } |
| 3047 | |
| 3048 | Do_ADBG_BeginSubCase(c, "Get public key"); |
| 3049 | get_att_public_key(c); |
| 3050 | Do_ADBG_EndSubCase(c, "Get public key"); |
| 3051 | |
| 3052 | Do_ADBG_BeginSubCase(c, "TEE attestation"); |
| 3053 | attestation_tee(c); |
| 3054 | Do_ADBG_EndSubCase(c, "TEE attestation"); |
| 3055 | |
| 3056 | Do_ADBG_BeginSubCase(c, "TA attestation (shdr)"); |
| 3057 | attestation_ta_shdr(c); |
| 3058 | Do_ADBG_EndSubCase(c, "TA attestation (shdr)"); |
| 3059 | |
| 3060 | Do_ADBG_BeginSubCase(c, "TA attestation (memory)"); |
| 3061 | attestation_ta_memory(c); |
| 3062 | Do_ADBG_EndSubCase(c, "TA attestation (memory)"); |
| 3063 | |
| 3064 | free_att_key(); |
| 3065 | } |
| 3066 | ADBG_CASE_DEFINE(regression, 1037, xtest_tee_test_1037, |
| 3067 | "Remote attestation"); |