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