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