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