From 1013c491940a8af27fbf5dcecf1d53275bc99c60 Mon Sep 17 00:00:00 2001 From: Jon Mason Date: Sat, 15 Jul 2023 15:08:43 -0400 Subject: [PATCH 01/18] xtest: regression_1000: remove unneeded stat.h include Hack to work around musl compile error: In file included from optee-test/3.17.0-r0/recipe-sysroot/usr/include/sys/stat.h:23, from optee-test/3.17.0-r0/git/host/xtest/regression_1000.c:25: optee-test/3.17.0-r0/recipe-sysroot/usr/include/bits/stat.h:17:26: error: expected identifier or '(' before '[' token 17 | unsigned __unused[2]; | ^ stat.h is not needed, since it is not being used in this file. So removing it. Signed-off-by: Jon Mason Reviewed-by: Jerome Forissier Acked-by: Jens Wiklander --- host/xtest/regression_1000.c | 1 - 1 file changed, 1 deletion(-) diff --git a/host/xtest/regression_1000.c b/host/xtest/regression_1000.c index cd11f933c..8e338e59d 100644 --- a/host/xtest/regression_1000.c +++ b/host/xtest/regression_1000.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include From e1b6445131df68d6e42430fee3cebceecf206526 Mon Sep 17 00:00:00 2001 From: Jens Wiklander Date: Fri, 1 Sep 2023 20:21:16 +0200 Subject: [PATCH 02/18] xtest: regression: add case 1040 Adds regression case 1040 to test panic in concurrent open/invoke/close session. Signed-off-by: Jens Wiklander Reviewed-by: Etienne Carriere --- host/xtest/regression_1000.c | 72 +++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/host/xtest/regression_1000.c b/host/xtest/regression_1000.c index 8e338e59d..7b487b67e 100644 --- a/host/xtest/regression_1000.c +++ b/host/xtest/regression_1000.c @@ -3270,7 +3270,75 @@ static void xtest_tee_test_1039(ADBG_Case_t *c) Do_ADBG_EndSubCase(c, "Load TA with identity subkey"); } - - ADBG_CASE_DEFINE(regression, 1039, xtest_tee_test_1039, "Test subkey verification"); + +struct test_1040_thread_arg { + TEEC_Result res; + pthread_t thr; +}; + +static void *test_1040_thread(void *arg) +{ + TEEC_Operation op = TEEC_OPERATION_INITIALIZER; + struct test_1040_thread_arg *a = arg; + TEEC_Result res = TEEC_SUCCESS; + uint32_t err_orig = 0; + TEEC_Session session = { }; + size_t loop_count = 100; + size_t n = 0; + + if (level == 0) + loop_count /= 2; + + while (n < loop_count) { + res = xtest_teec_open_session(&session, &sims_test_ta_uuid, + NULL, &err_orig); + if (res) { + if (res == TEEC_ERROR_TARGET_DEAD) + continue; + a->res = res; + return NULL; + } + + memset(&op, 0, sizeof(op)); + op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, + TEEC_NONE, TEEC_NONE, + TEEC_NONE); + res = TEEC_InvokeCommand(&session, TA_SIMS_CMD_PANIC, &op, + &err_orig); + TEEC_CloseSession(&session); + if (res != TEEC_ERROR_TARGET_DEAD) { + if (res) + a->res = res; + else + a->res = TEEC_ERROR_GENERIC; + return NULL; + } + n++; + } + a->res = TEEC_SUCCESS; + return NULL; +} + +static void xtest_tee_test_1040(ADBG_Case_t *c) +{ + struct test_1040_thread_arg arg[NUM_THREADS] = { }; + size_t nt = NUM_THREADS; + size_t n = 0; + + Do_ADBG_BeginSubCase(c, "Concurent invoke with panic in TA"); + for (n = 0; n < nt; n++) { + if (!ADBG_EXPECT(c, 0, pthread_create(&arg[n].thr, NULL, + test_1040_thread, + arg + n))) + nt = n; /* break loop and start cleanup */ + } + for (n = 0; n < nt; n++) { + ADBG_EXPECT(c, 0, pthread_join(arg[n].thr, NULL)); + ADBG_EXPECT_TEEC_SUCCESS(c, arg[n].res); + } + Do_ADBG_EndSubCase(c, "Concurent invoke with panic in TA"); +} +ADBG_CASE_DEFINE(regression, 1040, xtest_tee_test_1040, + "Test panic in concurrent open/invoke/close session"); From b49d6965716e4b4bc4b84b0f3866ca2043becde9 Mon Sep 17 00:00:00 2001 From: Weizhao Jiang Date: Fri, 22 Sep 2023 16:39:16 -0700 Subject: [PATCH 03/18] xtest: add command to get system time Command format: xtest --stats --time Acked-by: Etienne Carriere Reviewed-by: Jerome Forissier Tested-by: Weizhao Jiang Signed-off-by: Weizhao Jiang --- host/xtest/stats.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/host/xtest/stats.c b/host/xtest/stats.c index 2bf9828d3..16c410e10 100644 --- a/host/xtest/stats.c +++ b/host/xtest/stats.c @@ -28,6 +28,7 @@ #define STATS_CMD_ALLOC_STATS 1 #define STATS_CMD_MEMLEAK_STATS 2 #define STATS_CMD_TA_STATS 3 +#define STATS_CMD_GET_TIME 4 #define TEE_ALLOCATOR_DESC_LENGTH 32 struct malloc_stats { @@ -312,6 +313,36 @@ static int stat_loaded_ta(int argc, char *argv[]) return close_sess(&ctx, &sess); } +static int stat_system_time(int argc, char *argv[]) +{ + TEEC_Context ctx = { }; + TEEC_Session sess = { }; + TEEC_Result res = TEEC_ERROR_GENERIC; + uint32_t eo = 0; + TEEC_Operation op = { }; + + UNUSED(argv); + if (argc != 1) + return usage(); + + open_sess(&ctx, &sess); + op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, + TEEC_VALUE_OUTPUT, + TEEC_NONE, TEEC_NONE); + res = TEEC_InvokeCommand(&sess, STATS_CMD_GET_TIME, &op, &eo); + if (res != TEEC_SUCCESS) + errx(EXIT_FAILURE, + "TEEC_InvokeCommand: res %#"PRIx32" err_orig %#"PRIx32, + res, eo); + + printf("REE time: %"PRId32" seconds, %"PRId32" milliseconds\n", + op.params[0].value.a, op.params[0].value.b); + printf("TEE time: %"PRId32" seconds, %"PRId32" milliseconds\n", + op.params[1].value.a, op.params[1].value.b); + + return close_sess(&ctx, &sess); +} + int stats_runner_cmd_parser(int argc, char *argv[]) { if (argc > 1) { @@ -323,6 +354,8 @@ int stats_runner_cmd_parser(int argc, char *argv[]) return stat_memleak(argc - 1, argv + 1); if (!strcmp(argv[1], "--ta")) return stat_loaded_ta(argc - 1, argv + 1); + if (!strcmp(argv[1], "--time")) + return stat_system_time(argc - 1, argv + 1); } return usage(); From 1c3d6be5eaa6174e3dbabf60928d15628e39b994 Mon Sep 17 00:00:00 2001 From: Jens Wiklander Date: Mon, 29 May 2023 12:25:22 +0200 Subject: [PATCH 04/18] ta/crypt: update to mbedTLS 3.4.0 API The mbedtls_pk_parse_key() has two new paramters with the new 3.x API in. Fix the call of mbedtls_pk_parse_key(). The X.509 self test is removed so remove the call to that test in the TA. Signed-off-by: Jens Wiklander Reviewed-by: Jerome Forissier --- ta/crypt/mbedtls_taf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ta/crypt/mbedtls_taf.c b/ta/crypt/mbedtls_taf.c index ad6492bcd..f7670bfed 100644 --- a/ta/crypt/mbedtls_taf.c +++ b/ta/crypt/mbedtls_taf.c @@ -55,7 +55,6 @@ ta_entry_mbedtls_self_tests(uint32_t param_type, DO_MBEDTLS_SELF_TEST(base64); DO_MBEDTLS_SELF_TEST(mpi); DO_MBEDTLS_SELF_TEST(rsa); - DO_MBEDTLS_SELF_TEST(x509); return TEE_SUCCESS; #else @@ -187,7 +186,8 @@ static TEE_Result parse_issuer_key(mbedtls_pk_context *pk) return TEE_ERROR_OUT_OF_MEMORY; memcpy(buf, mid_key, mid_key_size); - ret = mbedtls_pk_parse_key(pk, buf, mid_key_size + 1, NULL, 0); + ret = mbedtls_pk_parse_key(pk, buf, mid_key_size + 1, + NULL, 0, NULL, NULL); TEE_Free(buf); if (ret) { EMSG("mbedtls_pk_parse_key: failed: %#x", ret); @@ -275,7 +275,7 @@ TEE_Result ta_entry_mbedtls_sign_cert(uint32_t param_type, goto out; } - mbedtls_x509write_crt_set_md_alg(&crt, csr.sig_md); + mbedtls_x509write_crt_set_md_alg(&crt, csr.MBEDTLS_PRIVATE(sig_md)); mbedtls_x509write_crt_set_subject_key(&crt, &csr.pk); mbedtls_x509write_crt_set_issuer_key(&crt, &issuer_key); From eb88481a115447d77e9e95d8754656f813a72960 Mon Sep 17 00:00:00 2001 From: Jens Wiklander Date: Thu, 26 Oct 2023 16:54:13 +0200 Subject: [PATCH 05/18] scripts/rsp_to_gcm_test.py: add license and copyright When scripts/rsp_to_gcm_test.py was originally added license and copyright wasn't explicitly included. Fix that by adding a license and backdated copyright. Fixes: f6efe24adcf5 ("regression: 4005: add NIST aes-gcm vectors") Signed-off-by: Jens Wiklander Acked-by: Jerome Forissier --- scripts/rsp_to_gcm_test.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/rsp_to_gcm_test.py b/scripts/rsp_to_gcm_test.py index e4418be0e..cef4598f2 100755 --- a/scripts/rsp_to_gcm_test.py +++ b/scripts/rsp_to_gcm_test.py @@ -1,4 +1,8 @@ #!/usr/bin/env python3 +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2017, Linaro Limited +# modes = {'encrypt': 0, 'decrypt': 1} From c6de6934bf6dc9775e443686d8adae9582f44d53 Mon Sep 17 00:00:00 2001 From: Jerome Forissier Date: Fri, 3 Nov 2023 10:52:16 +0100 Subject: [PATCH 06/18] gp: disable tests gp_50360, gp_50398, gp_50400, gp_50402, gp_50404 and gp_50406 Some tests for TEE_AllocateOperation() are invalid because they assume the function should reject non-zero maxKeySize values but the specification was clarified to explicitly allow them. Add a patch file to disable those tests. Signed-off-by: Jerome Forissier Acked-by: Etienne Carriere Acked-by: Vincent Mailhol --- .../gp/patches/0016-TEE_Crypto_API.xml.patch | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 host/xtest/gp/patches/0016-TEE_Crypto_API.xml.patch diff --git a/host/xtest/gp/patches/0016-TEE_Crypto_API.xml.patch b/host/xtest/gp/patches/0016-TEE_Crypto_API.xml.patch new file mode 100644 index 000000000..562874cdf --- /dev/null +++ b/host/xtest/gp/patches/0016-TEE_Crypto_API.xml.patch @@ -0,0 +1,134 @@ +From e1e4ae13b9c5fb9928c94e05f0fa5c17769fd5bd Mon Sep 17 00:00:00 2001 +From: Jerome Forissier +Date: Fri, 3 Nov 2023 10:41:57 +0100 +Subject: [PATCH] TEE_Crypto_API.xml + +Disabling cases: + +- Invoke_Crypto_AllocateOperation_TEE_ALG_MD5_size_not_appropriate (3b-4d-15) +- Invoke_Crypto_AllocateOperation_TEE_ALG_SHA1_size_not_appropriate (3b-86-3d) +- Invoke_Crypto_AllocateOperation_TEE_ALG_SHA224_size_not_appropriate (3b-91-91) +- Invoke_Crypto_AllocateOperation_TEE_ALG_SHA256_size_not_appropriate (3b-c6-3c) +- Invoke_Crypto_AllocateOperation_TEE_ALG_SHA384_size_not_appropriate (3b-b0-94) +- Invoke_Crypto_AllocateOperation_TEE_ALG_SHA512_size_not_appropriate (3b-f6-b8) + +These tests assume that TEE_AllocateOperation() must reject non-zero +values for maxKeySize when the algorithm is MD5 or SHA (since the +parameter is not applicable). But The GlobalPlatform TEE Internal Core +API v1.1.2 has clarified the requirement, see: + + 6.2.1 TEE_AllocateOperation + + [...] The parameter maxKeySize MUST be a valid value as defined in Table + 5-9 for the algorithm, for algorithms referenced in Table 5-9. For all + other algorithms, the maxKeySize parameter may have any value. + +Link: https://github.com/OP-TEE/optee_os/pull/6416 +Signed-off-by: Jerome Forissier +--- + packages/Crypto/xmlstable/TEE_Crypto_API.xml | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/packages/Crypto/xmlstable/TEE_Crypto_API.xml b/packages/Crypto/xmlstable/TEE_Crypto_API.xml +index b824637..b1cd7b0 100644 +--- a/packages/Crypto/xmlstable/TEE_Crypto_API.xml ++++ b/packages/Crypto/xmlstable/TEE_Crypto_API.xml +@@ -149178,6 +149178,7 @@ + + + ++ + + + +@@ -156360,6 +156362,7 @@ + + + ++ + + + +@@ -156738,6 +156742,7 @@ + + + ++ + + + +@@ -157116,6 +157122,7 @@ + + + ++ + + + +@@ -157494,6 +157502,7 @@ + + + ++ + + + +@@ -157872,6 +157882,7 @@ + + + ++ + + + +-- +2.34.1 + From a2c1ce3a8c31f4262923fa6954b121f31102ddcd Mon Sep 17 00:00:00 2001 From: Clement Faure Date: Mon, 6 Nov 2023 09:42:53 +0100 Subject: [PATCH 07/18] ta: os_test: fix TA time wrap test In the TA time wrap test, the TA time is set to its maximum value. After one second delay, the TA time was compared to the system time. The comparaison with the system time might not be pertinent as it is most likely more than dozen seconds. Compare the wrapped time to a fixed value instead. Signed-off-by: Clement Faure Acked-by: Etienne Carriere Acked-by: Jens Wiklander --- ta/os_test/os_test.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ta/os_test/os_test.c b/ta/os_test/os_test.c index d6edb3df9..d40e8f91b 100644 --- a/ta/os_test/os_test.c +++ b/ta/os_test/os_test.c @@ -635,10 +635,9 @@ static TEE_Result test_time(void) printf("TA time %u.%03u\n", (unsigned int)t.seconds, (unsigned int)t.millis); - if (t.seconds > sys_t.seconds) { - EMSG("Unexpected wrapped time %u.%03u (sys_t %u.%03u)\n", - (unsigned int)t.seconds, (unsigned int)t.millis, - (unsigned int)sys_t.seconds, (unsigned int)sys_t.millis); + if (t.seconds > 1) { + EMSG("Unexpected wrapped time %u.%03u\n", + (unsigned int)t.seconds, (unsigned int)t.millis); return TEE_ERROR_BAD_STATE; } From 566541415edd162bca26f79dcc245822875a9228 Mon Sep 17 00:00:00 2001 From: Etienne Carriere Date: Fri, 10 Nov 2023 17:44:55 +0100 Subject: [PATCH 08/18] ta: os_test: remove deprecated macro related to libmpa Removes macros TB_PRINT_BIGINT() and TB_ASSERT_HEX_PRINT_VALUE() that are never used. These macros depend in TEE_STRING_MODE_HEX_UC which has been removed from optee_os. It was removed from OP-TEE because it was related to libmpa removed from OP-TEE OS since release tag 3.9.0, by commit 7fb525f1f8a6 ("Remove libmpa in favor of libmbedtls"). Link: https://github.com/OP-TEE/optee_os/pull/6451 Acked-by: Jens Wiklander Signed-off-by: Etienne Carriere --- ta/os_test/include/tb_asserts.h | 12 ------------ ta/os_test/include/tb_macros.h | 11 ----------- 2 files changed, 23 deletions(-) diff --git a/ta/os_test/include/tb_asserts.h b/ta/os_test/include/tb_asserts.h index de476b9ce..844d0c3b3 100644 --- a/ta/os_test/include/tb_asserts.h +++ b/ta/os_test/include/tb_asserts.h @@ -73,18 +73,6 @@ do { \ }; \ } while (0) -/* - * TB_ASSERT_HEX_VALUE checks that a prints to the string v in hex. - */ -#define TB_ASSERT_HEX_PRINT_VALUE(a, v) \ -do { \ - char *_str_; \ - _str_ = TEE_BigIntConvertToString(NULL, \ - TEE_STRING_MODE_HEX_UC, (a)); \ - TB_ASSERT_STR_EQ(_str_, (v)); \ - TEE_Free(_str_); \ -} while (0) - /* * TB_ASSERT_POINTER_NULL(p) checks that p is null */ diff --git a/ta/os_test/include/tb_macros.h b/ta/os_test/include/tb_macros.h index cd7f0b943..7ad9f374f 100644 --- a/ta/os_test/include/tb_macros.h +++ b/ta/os_test/include/tb_macros.h @@ -54,15 +54,4 @@ */ #define DEL_BIGINT(name) TEE_Free(name) -/* - * TB_PRINT_BIGINT prints the mpanum in base 16. - */ -#define TB_PRINT_BIGINT(n) \ -do { \ - char *str; \ - str = TEE_BigIntConvertToString(NULL, TEE_STRING_MODE_HEX_UC, 0, (n)); \ - printf("%s\n", str); \ - TEE_Free(str); \ -} while (0) - #endif From 2182e211aa1b046798a2e79a23facb2d4efe8e41 Mon Sep 17 00:00:00 2001 From: Julien Jayat Date: Tue, 17 Oct 2023 19:42:07 +0200 Subject: [PATCH 09/18] xtest: add help for --stats --time The command 'xtest --stats --time' is now documented in the usage description. Acked-by: Etienne Carriere Acked-by: Jerome Forissier Signed-off-by: Julien Jayat --- host/xtest/stats.c | 1 + 1 file changed, 1 insertion(+) diff --git a/host/xtest/stats.c b/host/xtest/stats.c index 16c410e10..e6acb8b4b 100644 --- a/host/xtest/stats.c +++ b/host/xtest/stats.c @@ -58,6 +58,7 @@ static int usage(void) fprintf(stderr, " --alloc Print allocation statistics\n"); fprintf(stderr, " --memleak Dump memory leak data on secure console\n"); fprintf(stderr, " --ta Print loaded TAs context\n"); + fprintf(stderr, " --time Print REE and TEE time\n"); return EXIT_FAILURE; } From 2ea0aa70b2d694cacf227bb59c0546157c409f63 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Thu, 16 Nov 2023 20:20:54 +0900 Subject: [PATCH 10/18] regression 1033: remove trailing space characters As advised by the Linux kernel coding style [1] which OP-TEE follows: [...] don't leave whitespace at the end of lines. [1] https://www.kernel.org/doc/html/latest/process/coding-style.html#indentation Signed-off-by: Vincent Mailhol Acked-by: Etienne Carriere Reviewed-by: Jens Wiklander --- host/xtest/regression_1000.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/xtest/regression_1000.c b/host/xtest/regression_1000.c index 7b487b67e..54aaa7a23 100644 --- a/host/xtest/regression_1000.c +++ b/host/xtest/regression_1000.c @@ -2548,7 +2548,7 @@ static void xtest_tee_test_1033(ADBG_Case_t *c) TEEC_Operation op = TEEC_OPERATION_INITIALIZER; op.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, - TEEC_NONE, TEEC_NONE); + TEEC_NONE, TEEC_NONE); ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_ITEM_NOT_FOUND, TEEC_InvokeCommand(&session, TA_SUPP_PLUGIN_CMD_UNKNOWN_UUID, From bbbb485955d040b301c1ca6e1ea7706589d9e1a4 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Thu, 16 Nov 2023 16:19:06 +0900 Subject: [PATCH 11/18] ta: os_test: undefine TA2TA_BUF_SIZE TA2TA_BUF_SIZE is used to defined some test arrays. Using a macro instead of a const int declaration is good as it forces the declared arrays not to be variable length arrays. However, TA2TA_BUF_SIZE is defined in the middle of the translation unit. Because its use is local to ta_entry_ta2ta_memref(), undefine it after the function to make the visibility of the macro scoped. Signed-off-by: Vincent Mailhol Acked-by: Etienne Carriere Reviewed-by: Jens Wiklander --- ta/os_test/os_test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ta/os_test/os_test.c b/ta/os_test/os_test.c index d40e8f91b..14b8f8984 100644 --- a/ta/os_test/os_test.c +++ b/ta/os_test/os_test.c @@ -1173,6 +1173,7 @@ TEE_Result ta_entry_ta2ta_memref(uint32_t param_types, TEE_Param params[4]) TEE_CloseTASession(sess); return res; } +#undef TA2TA_BUF_SIZE TEE_Result ta_entry_ta2ta_memref_mix(uint32_t param_types, TEE_Param params[4]) { From c7391616cb442ab58914acf26122c09b5fc560c5 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Sun, 19 Nov 2023 13:11:12 +0900 Subject: [PATCH 12/18] ta: os_test: return TEE_ERROR_BAD_PARAMETERS for incorrect parameters The TEE_ERROR_BAD_PARAMETERS return code should be prefered over TEE_ERROR_GENERIC for any failed check on the parameters. Signed-off-by: Vincent Mailhol Reviewed-by: Etienne Carriere Reviewed-by: Jens Wiklander --- ta/os_test/os_test.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ta/os_test/os_test.c b/ta/os_test/os_test.c index 14b8f8984..e34eab408 100644 --- a/ta/os_test/os_test.c +++ b/ta/os_test/os_test.c @@ -476,7 +476,7 @@ static TEE_Result test_mem_access_right(uint32_t param_types, if (param_types != TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT, 0, 0, 0)) - return TEE_ERROR_GENERIC; + return TEE_ERROR_BAD_PARAMETERS; /* test access rights on memref parameter */ res = TEE_CheckMemoryAccessRights(TEE_MEMORY_ACCESS_READ | @@ -983,7 +983,7 @@ TEE_Result ta_entry_params_access_rights(uint32_t param_types, TEE_Param params[ if (param_types != TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT, TEE_PARAM_TYPE_MEMREF_INPUT, 0, 0)) - return TEE_ERROR_GENERIC; + return TEE_ERROR_BAD_PARAMETERS; res = TEE_CheckMemoryAccessRights(TEE_MEMORY_ACCESS_READ | TEE_MEMORY_ACCESS_ANY_OWNER, @@ -1038,7 +1038,7 @@ TEE_Result ta_entry_bad_mem_access(uint32_t param_types, TEE_Param params[4]) if (param_types != TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT, 0, 0, 0) && param_types != TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_MEMREF_INOUT, 0, 0)) - return TEE_ERROR_GENERIC; + return TEE_ERROR_BAD_PARAMETERS; switch (params[0].value.a) { case 1: @@ -1102,7 +1102,7 @@ TEE_Result ta_entry_ta2ta_memref(uint32_t param_types, TEE_Param params[4]) (void)params; if (param_types != TEE_PARAM_TYPES(0, 0, 0, 0)) - return TEE_ERROR_GENERIC; + return TEE_ERROR_BAD_PARAMETERS; res = TEE_OpenTASession(&test_uuid, TEE_TIMEOUT_INFINITE, 0, NULL, &sess, &ret_orig); @@ -1186,12 +1186,12 @@ TEE_Result ta_entry_ta2ta_memref_mix(uint32_t param_types, TEE_Param params[4]) if (param_types != TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT, TEE_PARAM_TYPE_MEMREF_INOUT, TEE_PARAM_TYPE_MEMREF_OUTPUT, 0)) - return TEE_ERROR_GENERIC; + return TEE_ERROR_BAD_PARAMETERS; bufsize = params[0].memref.size; if (params[1].memref.size != bufsize || params[2].memref.size != bufsize) - return TEE_ERROR_GENERIC; + return TEE_ERROR_BAD_PARAMETERS; in = params[0].memref.buffer; inout = params[1].memref.buffer; From 4e5d6c0991e29374455faf643436b843a33f0cb1 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Sun, 19 Nov 2023 13:20:47 +0900 Subject: [PATCH 13/18] ta: os_test: do not print caller function name in EMSG() EMSG() already prints the caller function name (and the line number). As such, no need to hardcode it. Remove all usage of caller function name in EMSG(). Signed-off-by: Vincent Mailhol Reviewed-by: Etienne Carriere Reviewed-by: Jens Wiklander --- ta/os_test/os_test.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/ta/os_test/os_test.c b/ta/os_test/os_test.c index e34eab408..0f7aeb04a 100644 --- a/ta/os_test/os_test.c +++ b/ta/os_test/os_test.c @@ -534,7 +534,7 @@ static TEE_Result test_mem_access_right(uint32_t param_types, res = TEE_OpenTASession(&test_uuid, TEE_TIMEOUT_INFINITE, 0, NULL, &sess, &ret_orig); if (res != TEE_SUCCESS) { - EMSG("test_mem_access_right: TEE_OpenTASession failed\n"); + EMSG("TEE_OpenTASession failed\n"); goto cleanup_return; } @@ -548,7 +548,7 @@ static TEE_Result test_mem_access_right(uint32_t param_types, TA_OS_TEST_CMD_PARAMS_ACCESS, l_pts, l_params, &ret_orig); if (res != TEE_SUCCESS) { - EMSG("test_mem_access_right: TEE_InvokeTACommand failed\n"); + EMSG("TEE_InvokeTACommand failed\n"); goto cleanup_return; } @@ -884,15 +884,14 @@ TEE_Result ta_entry_client_with_timeout(uint32_t param_types, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)) { - EMSG("ta_entry_client_with_timeout: bad parameters\n"); + EMSG("bad parameters\n"); return TEE_ERROR_BAD_PARAMETERS; } res = TEE_OpenTASession(&os_test_uuid, TEE_TIMEOUT_INFINITE, 0, NULL, &sess, &ret_orig); if (res != TEE_SUCCESS) { - EMSG( - "ta_entry_client_with_timeout: TEE_OpenTASession failed\n"); + EMSG("TEE_OpenTASession failed\n"); return res; } @@ -902,9 +901,8 @@ TEE_Result ta_entry_client_with_timeout(uint32_t param_types, &ret_orig); if (ret_orig != TEE_ORIGIN_TRUSTED_APP || res != TEE_ERROR_CANCEL) { - EMSG("ta_entry_client_with_timeout: TEE_InvokeTACommand: " - "res 0x%x ret_orig 0x%x\n", (unsigned int)res, - (unsigned int)ret_orig); + EMSG("TEE_InvokeTACommand: res 0x%x ret_orig 0x%x\n", + (unsigned int)res, (unsigned int)ret_orig); res = TEE_ERROR_GENERIC; } else res = TEE_SUCCESS; @@ -945,7 +943,7 @@ TEE_Result ta_entry_client(uint32_t param_types, TEE_Param params[4]) res = TEE_OpenTASession(&crypt_uuid, TEE_TIMEOUT_INFINITE, 0, NULL, &sess, &ret_orig); if (res != TEE_SUCCESS) { - EMSG("ta_entry_client: TEE_OpenTASession failed\n"); + EMSG("TEE_OpenTASession failed\n"); goto cleanup_return; } @@ -960,12 +958,12 @@ TEE_Result ta_entry_client(uint32_t param_types, TEE_Param params[4]) TA_CRYPT_CMD_SHA256, l_pts, l_params, &ret_orig); if (res != TEE_SUCCESS) { - EMSG("ta_entry_client: TEE_InvokeTACommand failed\n"); + EMSG("TEE_InvokeTACommand failed\n"); goto cleanup_return; } if (TEE_MemCompare(sha256_out, out, sizeof(sha256_out)) != 0) { - EMSG("ta_entry_client: out parameter failed\n"); + EMSG("out parameter failed\n"); res = TEE_ERROR_GENERIC; goto cleanup_return; } From 9748d2a9dcf60afd30331d503d8eb99d61ef9235 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Thu, 16 Nov 2023 20:30:00 +0900 Subject: [PATCH 14/18] ta: os_test: do not call TEE_CloseTASession() if session is not opened MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Global Platform specification [1] tells us that the session parameter of TEE_CloseTASession() is: An opened session handle The behaviour is unspecified if the session handle is not opened. Make sure not to call TEE_CloseTASession() with an invalid session handle when TEE_OpenTASession() fails by either: - doing an early return - adding an additional cleanup label [1] TEE Internal Core API Specification – Public Release v1.3.1, §4.9.2 "TEE_CloseTASession" Signed-off-by: Vincent Mailhol Reviewed-by: Etienne Carriere Reviewed-by: Jens Wiklander --- ta/os_test/os_test.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/ta/os_test/os_test.c b/ta/os_test/os_test.c index 0f7aeb04a..b16bcafd9 100644 --- a/ta/os_test/os_test.c +++ b/ta/os_test/os_test.c @@ -535,7 +535,7 @@ static TEE_Result test_mem_access_right(uint32_t param_types, &sess, &ret_orig); if (res != TEE_SUCCESS) { EMSG("TEE_OpenTASession failed\n"); - goto cleanup_return; + return res; } l_pts = TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT, @@ -547,12 +547,9 @@ static TEE_Result test_mem_access_right(uint32_t param_types, res = TEE_InvokeTACommand(sess, TEE_TIMEOUT_INFINITE, TA_OS_TEST_CMD_PARAMS_ACCESS, l_pts, l_params, &ret_orig); - if (res != TEE_SUCCESS) { + if (res != TEE_SUCCESS) EMSG("TEE_InvokeTACommand failed\n"); - goto cleanup_return; - } -cleanup_return: TEE_CloseTASession(sess); return res; } @@ -944,7 +941,7 @@ TEE_Result ta_entry_client(uint32_t param_types, TEE_Param params[4]) &sess, &ret_orig); if (res != TEE_SUCCESS) { EMSG("TEE_OpenTASession failed\n"); - goto cleanup_return; + goto cleanup_free; } l_pts = TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT, @@ -959,18 +956,19 @@ TEE_Result ta_entry_client(uint32_t param_types, TEE_Param params[4]) &ret_orig); if (res != TEE_SUCCESS) { EMSG("TEE_InvokeTACommand failed\n"); - goto cleanup_return; + goto cleanup_close_session; } if (TEE_MemCompare(sha256_out, out, sizeof(sha256_out)) != 0) { EMSG("out parameter failed\n"); res = TEE_ERROR_GENERIC; - goto cleanup_return; + goto cleanup_close_session; } -cleanup_return: - TEE_Free(in); +cleanup_close_session: TEE_CloseTASession(sess); +cleanup_free: + TEE_Free(in); return res; } @@ -1106,7 +1104,7 @@ TEE_Result ta_entry_ta2ta_memref(uint32_t param_types, TEE_Param params[4]) &sess, &ret_orig); if (res != TEE_SUCCESS) { EMSG("TEE_OpenTASession failed"); - goto cleanup_return; + return res; } l_pts = TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT, From da741cd77ecfece144c003d55505aba8b00c0c81 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Thu, 16 Nov 2023 20:20:54 +0900 Subject: [PATCH 15/18] regression 1016: add a subtest for non-NULL memref of size 0 Add a subtest to assert that the implementation allows to forward non-NULL memref from a TA to another TA. Regression 1016 already contains tests related to forwarding memref between TAs. Thus extend this existing test with the subtest described above instead of writing a new one. The Global Platform specification allows this, however, at the time of writing, optee-os will panic. A fix is proposed at [1]. [1] core: tee_svc.c: allow to pass non-NULL memref of size 0 Link: https://github.com/OP-TEE/optee_os/pull/6405 Signed-off-by: Vincent Mailhol Reviewed-by: Etienne Carriere Reviewed-by: Jens Wiklander --- host/xtest/regression_1000.c | 19 +++++++++++++++ ta/os_test/include/os_test.h | 2 ++ ta/os_test/include/ta_os_test.h | 1 + ta/os_test/os_test.c | 42 +++++++++++++++++++++++++++++++++ ta/os_test/ta_entry.c | 3 +++ 5 files changed, 67 insertions(+) diff --git a/host/xtest/regression_1000.c b/host/xtest/regression_1000.c index 54aaa7a23..f123c9050 100644 --- a/host/xtest/regression_1000.c +++ b/host/xtest/regression_1000.c @@ -1377,6 +1377,7 @@ static void xtest_tee_test_1016(ADBG_Case_t *c) TEEC_Session session = { }; TEEC_Operation op = TEEC_OPERATION_INITIALIZER; uint32_t ret_orig = 0; + int dummy = 0; if (!ADBG_EXPECT_TEEC_SUCCESS(c, xtest_teec_open_session(&session, &os_test_ta_uuid, NULL, @@ -1390,6 +1391,24 @@ static void xtest_tee_test_1016(ADBG_Case_t *c) TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TA2TA_MEMREF, &op, &ret_orig)); + op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, + TEEC_MEMREF_TEMP_INOUT, + TEEC_MEMREF_TEMP_OUTPUT, + TEEC_NONE); + + op.params[0].tmpref.buffer = &dummy; + op.params[0].tmpref.size = 0; + + op.params[1].tmpref.buffer = &dummy; + op.params[1].tmpref.size = 0; + + op.params[2].tmpref.buffer = &dummy; + op.params[2].tmpref.size = 0; + + (void)ADBG_EXPECT_TEEC_SUCCESS(c, + TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_TA2TA_MEMREF_SIZE0, + &op, &ret_orig)); + TEEC_CloseSession(&session); } ADBG_CASE_DEFINE(regression, 1016, xtest_tee_test_1016, diff --git a/ta/os_test/include/os_test.h b/ta/os_test/include/os_test.h index a3defc87a..62c237852 100644 --- a/ta/os_test/include/os_test.h +++ b/ta/os_test/include/os_test.h @@ -20,6 +20,8 @@ TEE_Result ta_entry_bad_mem_access(uint32_t param_types, TEE_Param params[4]); TEE_Result ta_entry_ta2ta_memref(uint32_t param_types, TEE_Param params[4]); TEE_Result ta_entry_ta2ta_memref_mix(uint32_t param_types, TEE_Param params[4]); +TEE_Result ta_entry_ta2ta_memref_size0(uint32_t param_types, + TEE_Param params[4]); TEE_Result ta_entry_params(uint32_t param_types, TEE_Param params[4]); TEE_Result ta_entry_null_memref(uint32_t param_types, TEE_Param params[4]); TEE_Result ta_entry_call_lib(uint32_t param_types, TEE_Param params[4]); diff --git a/ta/os_test/include/ta_os_test.h b/ta/os_test/include/ta_os_test.h index 95edcd9f4..93785e2d9 100644 --- a/ta/os_test/include/ta_os_test.h +++ b/ta/os_test/include/ta_os_test.h @@ -46,5 +46,6 @@ #define TA_OS_TEST_CMD_MEMTAG_INVALID_TAG 34 #define TA_OS_TEST_CMD_MEMTAG_DOUBLE_FREE 35 #define TA_OS_TEST_CMD_MEMTAG_BUFFER_OVERRUN 36 +#define TA_OS_TEST_CMD_TA2TA_MEMREF_SIZE0 37 #endif /*TA_OS_TEST_H */ diff --git a/ta/os_test/os_test.c b/ta/os_test/os_test.c index b16bcafd9..e8b549458 100644 --- a/ta/os_test/os_test.c +++ b/ta/os_test/os_test.c @@ -1171,6 +1171,48 @@ TEE_Result ta_entry_ta2ta_memref(uint32_t param_types, TEE_Param params[4]) } #undef TA2TA_BUF_SIZE +TEE_Result ta_entry_ta2ta_memref_size0(uint32_t param_types, TEE_Param params[4]) +{ + static const TEE_UUID test_uuid = TA_OS_TEST_UUID; + TEE_TASessionHandle sess = TEE_HANDLE_NULL; + uint32_t ret_orig = 0; + TEE_Result res = TEE_ERROR_GENERIC; + + if (param_types != TEE_PARAM_TYPES(TEE_PARAM_TYPE_MEMREF_INPUT, + TEE_PARAM_TYPE_MEMREF_INOUT, + TEE_PARAM_TYPE_MEMREF_OUTPUT, + TEE_PARAM_TYPE_NONE)) + return TEE_ERROR_BAD_PARAMETERS; + + /* + * This test expects all memory references to be non-NULL but + * all sizes to be zero. + */ + if (!params[0].memref.buffer || params[0].memref.size || + !params[1].memref.buffer || params[1].memref.size || + !params[2].memref.buffer || params[2].memref.size) + return TEE_ERROR_BAD_PARAMETERS; + + res = TEE_OpenTASession(&test_uuid, TEE_TIMEOUT_INFINITE, 0, NULL, + &sess, &ret_orig); + if (res != TEE_SUCCESS) { + EMSG("TEE_OpenTASession failed"); + return res; + } + + /* + * TA basically does nothing. The actual test just consists + * into validating that passing non-NULL memref of size zero + * does not panic. + */ + res = TEE_InvokeTACommand(sess, TEE_TIMEOUT_INFINITE, + TA_OS_TEST_CMD_TA2TA_MEMREF_MIX, + param_types, params, &ret_orig); + + TEE_CloseTASession(sess); + return res; +} + TEE_Result ta_entry_ta2ta_memref_mix(uint32_t param_types, TEE_Param params[4]) { uint8_t *in = NULL; diff --git a/ta/os_test/ta_entry.c b/ta/os_test/ta_entry.c index 092b3570f..aaccf0ffa 100644 --- a/ta/os_test/ta_entry.c +++ b/ta/os_test/ta_entry.c @@ -92,6 +92,9 @@ TEE_Result TA_InvokeCommandEntryPoint(void *pSessionContext, case TA_OS_TEST_CMD_TA2TA_MEMREF: return ta_entry_ta2ta_memref(nParamTypes, pParams); + case TA_OS_TEST_CMD_TA2TA_MEMREF_SIZE0: + return ta_entry_ta2ta_memref_size0(nParamTypes, pParams); + case TA_OS_TEST_CMD_TA2TA_MEMREF_MIX: return ta_entry_ta2ta_memref_mix(nParamTypes, pParams); From 2153a15e9043d1ac71a789496ed89cef601911e3 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Tue, 31 Oct 2023 03:15:43 +0900 Subject: [PATCH 16/18] xtest: pkcs11_1009: remove trailing space characters As advised by the Linux kernel coding style [1] which OP-TEE follows: [...] don't leave whitespace at the end of lines. [1] https://www.kernel.org/doc/html/latest/process/coding-style.html#indentation Signed-off-by: Vincent Mailhol Reviewed-by: Etienne Carriere Acked-by: Jens Wiklander --- host/xtest/pkcs11_1000.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/xtest/pkcs11_1000.c b/host/xtest/pkcs11_1000.c index a55691ddc..2f2098188 100644 --- a/host/xtest/pkcs11_1000.c +++ b/host/xtest/pkcs11_1000.c @@ -2209,7 +2209,7 @@ static void xtest_pkcs11_test_1009(ADBG_Case_t *c) } /* - * Test 4 verification + * Test 4 verification * Error - Signature Length Range with C_VerifyFinal */ if (test->in != NULL) { From 6c03fb5241505d7e89b5c31ff4358396baa2caa5 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Tue, 31 Oct 2023 03:15:57 +0900 Subject: [PATCH 17/18] xtest: pkcs11: skip tests 1003 and 1027 if no openssl If OPENSSL_FOUND is not defined, compilation fails with below error: optee-test/host/xtest/pkcs11_1000.c: In function 'init_user_test_token_acl_auth': optee-test/host/xtest/pkcs11_1000.c:848:11: error: implicit declaration of function 'xtest_uuid_v5' [-Werror=implicit-function-declaration] 848 | result = xtest_uuid_v5(&expected_client_uuid, &uuid_ns, uuid_name, | ^~~~~~~~~~~~~ optee-test/host/xtest/pkcs11_1000.c:848:11: error: nested extern declaration of 'xtest_uuid_v5' [-Werror=nested-externs] To reproduce the above, pass "WITH_OPENSSL=n" to make or "-DCMAKE_DISABLE_FIND_PACKAGE_OpenSSL=TRUE" to cmake. Add preprocessor directives to skip tests 1003 and 1027 if openssl is not present. Also exclude their unique dependencies to avoid getting some -Wunused-function alerts. Signed-off-by: Vincent Mailhol Reviewed-by: Etienne Carriere Acked-by: Jens Wiklander --- host/xtest/pkcs11_1000.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/host/xtest/pkcs11_1000.c b/host/xtest/pkcs11_1000.c index 2f2098188..9dccd1f04 100644 --- a/host/xtest/pkcs11_1000.c +++ b/host/xtest/pkcs11_1000.c @@ -684,6 +684,7 @@ static CK_RV init_user_test_token_pin_auth(CK_SLOT_ID slot) return rv; } +#ifdef OPENSSL_FOUND static CK_RV test_already_initialized_token(ADBG_Case_t *c, CK_SLOT_ID slot) { CK_RV rv = CKR_GENERAL_ERROR; @@ -1079,9 +1080,11 @@ static CK_RV test_set_pin(ADBG_Case_t *c, CK_SLOT_ID slot, return rv; } +#endif /*OPENSSL_FOUND*/ static void xtest_pkcs11_test_1003(ADBG_Case_t *c) { +#ifdef OPENSSL_FOUND CK_RV rv = CKR_GENERAL_ERROR; CK_FUNCTION_LIST_PTR ckfunc_list = NULL; CK_SLOT_ID slot = 0; @@ -1138,6 +1141,11 @@ static void xtest_pkcs11_test_1003(ADBG_Case_t *c) out: rv = close_lib(); ADBG_EXPECT_CK_OK(c, rv); +#else /*!OPENSSL_FOUND*/ + UNUSED(c); + /* xtest_uuid_v5() depends on OpenSSL */ + Do_ADBG_Log("OpenSSL not available, skipping test 1003"); +#endif /*OPENSSL_FOUND*/ } ADBG_CASE_DEFINE(pkcs11, 1003, xtest_pkcs11_test_1003, "PKCS11: Login to PKCS#11 token with PIN based authentication"); @@ -8625,6 +8633,7 @@ static void xtest_pkcs11_test_1026(ADBG_Case_t *c) ADBG_CASE_DEFINE(pkcs11, 1026, xtest_pkcs11_test_1026, "PKCS11: RSA AES Key Wrap/Unwrap tests"); +#ifdef OPENSSL_FOUND static CK_RV test_login_logout_acl_auth(ADBG_Case_t *c, CK_SLOT_ID slot) { CK_FLAGS session_flags = CKF_SERIAL_SESSION | CKF_RW_SESSION; @@ -8658,11 +8667,13 @@ static CK_RV test_login_logout_acl_auth(ADBG_Case_t *c, CK_SLOT_ID slot) Do_ADBG_EndSubCase(c, "Test C_Login()/C_Logout() with ACL based authentication"); return rv; } +#endif /*OPENSSL_FOUND*/ #define GID_STR_LEN 13 static void xtest_pkcs11_test_1027(ADBG_Case_t *c) { +#ifdef OPENSSL_FOUND CK_RV rv = CKR_GENERAL_ERROR; CK_FUNCTION_LIST_PTR ckfunc_list = NULL; CK_SLOT_ID slot = 0; @@ -8734,6 +8745,11 @@ static void xtest_pkcs11_test_1027(ADBG_Case_t *c) out_unsetenv: ADBG_EXPECT_TRUE(c, !unsetenv("CKTEEC_LOGIN_TYPE")); ADBG_EXPECT_TRUE(c, !unsetenv("CKTEEC_LOGIN_GID")); +#else /*!OPENSSL_FOUND*/ + UNUSED(c); + /* xtest_uuid_v5() depends on OpenSSL */ + Do_ADBG_Log("OpenSSL not available, skipping test 1027"); +#endif /*OPENSSL_FOUND*/ } ADBG_CASE_DEFINE(pkcs11, 1027, xtest_pkcs11_test_1027, "PKCS11: Login to PKCS#11 token with ACL based authentication"); From 4f91b9acdf7c1a969c91bda873928f21dd420153 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Sun, 19 Nov 2023 22:19:03 +0900 Subject: [PATCH 18/18] ta: remove useless newline character in *MSG() messages The *MSG() macros take care of printing a newline. Adding a newline character ('\n') is useless. Remove it. Signed-off-by: Vincent Mailhol Reviewed-by: Jerome Forissier --- ta/os_test/include/tb_asserts.h | 34 +++++++++--------- ta/os_test/os_test.c | 62 ++++++++++++++++---------------- ta/rpc_test/ta_rpc.c | 4 +-- ta/sdp_basic/ta_sdp_basic.c | 8 ++--- ta/storage_benchmark/benchmark.c | 2 +- 5 files changed, 55 insertions(+), 55 deletions(-) diff --git a/ta/os_test/include/tb_asserts.h b/ta/os_test/include/tb_asserts.h index 844d0c3b3..e0256e1d2 100644 --- a/ta/os_test/include/tb_asserts.h +++ b/ta/os_test/include/tb_asserts.h @@ -16,9 +16,9 @@ #define TB_ASSERT_MSG(cond, str) \ do { \ if (!(cond)) { \ - EMSG("Assertion failed at line %d in file:\n%s\n", \ + EMSG("Assertion failed at line %d in file:\n%s", \ __LINE__, __FILE__); \ - EMSG("Message: %s\n", str); \ + EMSG("Message: %s", str); \ HALT; \ }; \ } while (0) @@ -29,7 +29,7 @@ do { \ #define TB_ASSERT(cond) \ do { \ if (!(cond)) { \ - EMSG("Assertion failed at line %d in file:\n%s\n", \ + EMSG("Assertion failed at line %d in file:\n%s", \ __LINE__, __FILE__); \ HALT; \ }; \ @@ -41,21 +41,21 @@ do { \ #define TB_ASSERT_EQ_SHORT(src, short) \ do { \ if (((short) == 0) && (__mpanum_size((mpanum)src) != 0)) { \ - EMSG("Assertion failed at line %d in file:\n%s\n", \ + EMSG("Assertion failed at line %d in file:\n%s", \ __LINE__, __FILE__); \ - EMSG("short == 0, but size != 0\n"); \ + EMSG("short == 0, but size != 0"); \ HALT; \ } else if (__mpanum_size((mpanum)src) > 1) { \ - EMSG("Assertion failed at line %d in file:\n%s\n", \ + EMSG("Assertion failed at line %d in file:\n%s", \ __LINE__, __FILE__); \ - EMSG("size > 1, cannot be equal to a short.\n"); \ + EMSG("size > 1, cannot be equal to a short."); \ HALT; \ } else if ( \ (int)(__mpanum_lsw((mpanum)src)*__mpanum_sign((mpanum)src)) != \ (int)(short)) { \ - EMSG("Assertion failed at line %d in file:\n%s\n", \ + EMSG("Assertion failed at line %d in file:\n%s", \ __LINE__, __FILE__); \ - EMSG("short == %d, but src == %d\n", (short), \ + EMSG("short == %d, but src == %d", (short), \ (int)(__mpanum_lsw((mpanum)src) \ *__mpanum_sign((mpanum)src))); \ HALT; \ @@ -68,7 +68,7 @@ do { \ #define TB_ASSERT_STR_EQ(a, b) \ do { \ if (my_strcmp((a), (b)) != 0) { \ - EMSG("Assertion failed %s != %s\n", (a), (b)); \ + EMSG("Assertion failed %s != %s", (a), (b)); \ HALT; \ }; \ } while (0) @@ -79,7 +79,7 @@ do { \ #define TB_ASSERT_POINTER_NULL(p) \ do { \ if ((p) != 0) { \ - EMSG("Assertion failed, pointer was not null.\n"); \ + EMSG("Assertion failed, pointer was not null."); \ HALT; \ }; \ } while (0) @@ -90,7 +90,7 @@ do { \ #define TB_ASSERT_POINTERS_EQ(p, q) \ do { \ if ((p) != (q)) { \ - EMSG("Assertion failed, pointers are not equal.\n"); \ + EMSG("Assertion failed, pointers are not equal."); \ HALT; \ }; \ } while (0) @@ -101,7 +101,7 @@ do { \ #define TB_ASSERT_POINTERS_NEQ(p, q) \ do { \ if ((p) == (q)) { \ - EMSG("Assertion failed, pointers are equal.\n"); \ + EMSG("Assertion failed, pointers are equal."); \ HALT; \ }; \ } while (0) @@ -112,7 +112,7 @@ do { \ #define TB_ASSERT_BIGINT_EQ(a, b) \ do { \ if (TEE_BigIntCmp((a), (b)) != 0) { \ - EMSG("Assertion failed, numbers are not equal.\n"); \ + EMSG("Assertion failed, numbers are not equal."); \ HALT; \ }; \ } while (0) @@ -123,7 +123,7 @@ do { \ #define TB_ASSERT_BIGINT_NEQ(a, b) \ do { \ if (TEE_BigIntCmp((a), (b)) == 0) { \ - EMSG("Assertion failed, numbers are equal.\n"); \ + EMSG("Assertion failed, numbers are equal."); \ HALT; \ }; \ } while (0) @@ -134,7 +134,7 @@ do { \ #define TB_ASSERT_BIGINT_LESS(a, b) \ do { \ if (TEE_BigIntCmp((a), (b)) >= 0) { \ - EMSG("Assertion failed, first is not less than second.\n"); \ + EMSG("Assertion failed, first is not less than second."); \ HALT; \ }; \ } while (0) @@ -145,7 +145,7 @@ do { \ #define TB_ASSERT_INT_EQ(a, b) \ do { \ if ((a) != (b)) { \ - EMSG("Assertion failed, numbers are not equal.\n"); \ + EMSG("Assertion failed, numbers are not equal."); \ HALT; \ }; \ } while (0) diff --git a/ta/os_test/os_test.c b/ta/os_test/os_test.c index e8b549458..74d09180e 100644 --- a/ta/os_test/os_test.c +++ b/ta/os_test/os_test.c @@ -134,7 +134,7 @@ static TEE_Result print_properties(TEE_PropSetHandle h, res = TEE_GetPropertyName(h, nbuf, &nblen); if (res != TEE_SUCCESS) { - EMSG("TEE_GetPropertyName returned 0x%x\n", + EMSG("TEE_GetPropertyName returned 0x%x", (unsigned int)res); return res; } @@ -182,7 +182,7 @@ static TEE_Result print_properties(TEE_PropSetHandle h, return res; if (strcmp(vbuf, vbuf2) != 0) { - EMSG("String of \"%s\" differs\n", nbuf); + EMSG("String of \"%s\" differs", nbuf); return TEE_ERROR_GENERIC; } @@ -215,19 +215,19 @@ static TEE_Result print_properties(TEE_PropSetHandle h, /* check specific myprop.hello property, which is larger than 80 */ if (!strcmp("myprop.hello", nbuf) && vblen2 != 1 + strlen("hello property, larger than 80 characters, so that it checks that it is not truncated by anything in the source code which may be wrong")) { - EMSG("TEE_GetPropertyAsString(\"%s\") is truncated - returned \"%s\"\n", + EMSG("TEE_GetPropertyAsString(\"%s\") is truncated - returned \"%s\"", nbuf, vbuf); return TEE_ERROR_GENERIC; } - DMSG("Found \"%s\" value \"%s\"\n", nbuf, vbuf); + DMSG("Found \"%s\" value \"%s\"", nbuf, vbuf); for (n = 0; n < num_p_attrs; n++) { if (strcmp(nbuf, p_attrs[n].str) != 0) continue; if (p_attrs[n].retrieved) { - EMSG("Value \"%s\" already retrieved\n", + EMSG("Value \"%s\" already retrieved", p_attrs[n].str); return TEE_ERROR_GENERIC; } @@ -242,7 +242,7 @@ static TEE_Result print_properties(TEE_PropSetHandle h, TEE_GetPropertyAsBool(h, NULL, &v); if (res != TEE_SUCCESS) { EMSG( - "TEE_GetPropertyAsBool(\"%s\") returned 0x%x\n", + "TEE_GetPropertyAsBool(\"%s\") returned 0x%x", nbuf, (unsigned int)res); return res; } @@ -256,7 +256,7 @@ static TEE_Result print_properties(TEE_PropSetHandle h, res = TEE_GetPropertyAsU32(h, NULL, &v); if (res != TEE_SUCCESS) { EMSG( - "TEE_GetPropertyAsU32(\"%s\") returned 0x%x\n", + "TEE_GetPropertyAsU32(\"%s\") returned 0x%x", nbuf, (unsigned int)res); return res; } @@ -271,7 +271,7 @@ static TEE_Result print_properties(TEE_PropSetHandle h, TEE_GetPropertyAsUUID(h, NULL, &v); if (res != TEE_SUCCESS) { EMSG( - "TEE_GetPropertyAsUUID(\"%s\") returned 0x%x\n", + "TEE_GetPropertyAsUUID(\"%s\") returned 0x%x", nbuf, (unsigned int)res); return res; } @@ -287,7 +287,7 @@ static TEE_Result print_properties(TEE_PropSetHandle h, &v); if (res != TEE_SUCCESS) { EMSG( - "TEE_GetPropertyAsIdentity(\"%s\") returned 0x%x\n", + "TEE_GetPropertyAsIdentity(\"%s\") returned 0x%x", nbuf, (unsigned int)res); return res; } @@ -351,7 +351,7 @@ static TEE_Result print_properties(TEE_PropSetHandle h, break; default: - EMSG("Unknown type (%d) for \"%s\"\n", + EMSG("Unknown type (%d) for \"%s\"", p_attrs[n].type, p_attrs[n].str); return TEE_ERROR_GENERIC; } @@ -371,7 +371,7 @@ static TEE_Result test_malloc(void) void *p = TEE_Malloc(4, 0); if (p == NULL) { - EMSG("TEE_Malloc failed\n"); + EMSG("TEE_Malloc failed"); return TEE_ERROR_OUT_OF_MEMORY; } TEE_Free(p); @@ -427,7 +427,7 @@ static TEE_Result test_properties(void) res = TEE_AllocatePropertyEnumerator(&h); if (res != TEE_SUCCESS) { - EMSG("TEE_AllocatePropertyEnumerator: returned 0x%x\n", + EMSG("TEE_AllocatePropertyEnumerator: returned 0x%x", (unsigned int)res); return TEE_ERROR_GENERIC; } @@ -451,7 +451,7 @@ static TEE_Result test_properties(void) for (n = 0; n < num_p_attrs; n++) { if (!p_attrs[n].retrieved) { - EMSG("\"%s\" not retrieved\n", p_attrs[n].str); + EMSG("\"%s\" not retrieved", p_attrs[n].str); res = TEE_ERROR_GENERIC; goto cleanup_return; } @@ -534,7 +534,7 @@ static TEE_Result test_mem_access_right(uint32_t param_types, res = TEE_OpenTASession(&test_uuid, TEE_TIMEOUT_INFINITE, 0, NULL, &sess, &ret_orig); if (res != TEE_SUCCESS) { - EMSG("TEE_OpenTASession failed\n"); + EMSG("TEE_OpenTASession failed"); return res; } @@ -548,7 +548,7 @@ static TEE_Result test_mem_access_right(uint32_t param_types, TA_OS_TEST_CMD_PARAMS_ACCESS, l_pts, l_params, &ret_orig); if (res != TEE_SUCCESS) - EMSG("TEE_InvokeTACommand failed\n"); + EMSG("TEE_InvokeTACommand failed"); TEE_CloseTASession(sess); return res; @@ -577,14 +577,14 @@ static TEE_Result test_time(void) (unsigned int)t.millis); break; case TEE_ERROR_OVERFLOW: - EMSG("Stored TA time overflowed %u.%03u\n", + EMSG("Stored TA time overflowed %u.%03u", (unsigned int)t.seconds, (unsigned int)t.millis); break; case TEE_ERROR_TIME_NOT_SET: - EMSG("TA time not stored\n"); + EMSG("TA time not stored"); break; case TEE_ERROR_TIME_NEEDS_RESET: - EMSG("TA time needs reset\n"); + EMSG("TA time needs reset"); break; default: return res; @@ -592,13 +592,13 @@ static TEE_Result test_time(void) res = TEE_SetTAPersistentTime(&null_time); if (res != TEE_SUCCESS) { - EMSG("TEE_SetTAPersistentTime: failed\n"); + EMSG("TEE_SetTAPersistentTime: failed"); return res; } res = TEE_GetTAPersistentTime(&t); if (res != TEE_SUCCESS) { - EMSG("TEE_GetTAPersistentTime null: failed\n"); + EMSG("TEE_GetTAPersistentTime null: failed"); return res; } printf("TA time %u.%03u\n", (unsigned int)t.seconds, @@ -609,31 +609,31 @@ static TEE_Result test_time(void) * it's not even a millisecond. */ if (t.seconds > 1 || t.millis >= 1000) { - EMSG("Unexpected stored TA time %u.%03u\n", + EMSG("Unexpected stored TA time %u.%03u", (unsigned int)t.seconds, (unsigned int)t.millis); return TEE_ERROR_BAD_STATE; } res = TEE_SetTAPersistentTime(&wrap_time); if (res != TEE_SUCCESS) { - EMSG("TEE_SetTAPersistentTime wrap: failed\n"); + EMSG("TEE_SetTAPersistentTime wrap: failed"); return res; } res = TEE_Wait(1000); if (res != TEE_SUCCESS) - EMSG("TEE_Wait wrap: failed\n"); + EMSG("TEE_Wait wrap: failed"); res = TEE_GetTAPersistentTime(&t); if (res != TEE_ERROR_OVERFLOW) { - EMSG("TEE_GetTAPersistentTime: failed\n"); + EMSG("TEE_GetTAPersistentTime: failed"); return TEE_ERROR_BAD_STATE; } printf("TA time %u.%03u\n", (unsigned int)t.seconds, (unsigned int)t.millis); if (t.seconds > 1) { - EMSG("Unexpected wrapped time %u.%03u\n", + EMSG("Unexpected wrapped time %u.%03u", (unsigned int)t.seconds, (unsigned int)t.millis); return TEE_ERROR_BAD_STATE; } @@ -881,14 +881,14 @@ TEE_Result ta_entry_client_with_timeout(uint32_t param_types, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE)) { - EMSG("bad parameters\n"); + EMSG("bad parameters"); return TEE_ERROR_BAD_PARAMETERS; } res = TEE_OpenTASession(&os_test_uuid, TEE_TIMEOUT_INFINITE, 0, NULL, &sess, &ret_orig); if (res != TEE_SUCCESS) { - EMSG("TEE_OpenTASession failed\n"); + EMSG("TEE_OpenTASession failed"); return res; } @@ -898,7 +898,7 @@ TEE_Result ta_entry_client_with_timeout(uint32_t param_types, &ret_orig); if (ret_orig != TEE_ORIGIN_TRUSTED_APP || res != TEE_ERROR_CANCEL) { - EMSG("TEE_InvokeTACommand: res 0x%x ret_orig 0x%x\n", + EMSG("TEE_InvokeTACommand: res 0x%x ret_orig 0x%x", (unsigned int)res, (unsigned int)ret_orig); res = TEE_ERROR_GENERIC; } else @@ -940,7 +940,7 @@ TEE_Result ta_entry_client(uint32_t param_types, TEE_Param params[4]) res = TEE_OpenTASession(&crypt_uuid, TEE_TIMEOUT_INFINITE, 0, NULL, &sess, &ret_orig); if (res != TEE_SUCCESS) { - EMSG("TEE_OpenTASession failed\n"); + EMSG("TEE_OpenTASession failed"); goto cleanup_free; } @@ -955,12 +955,12 @@ TEE_Result ta_entry_client(uint32_t param_types, TEE_Param params[4]) TA_CRYPT_CMD_SHA256, l_pts, l_params, &ret_orig); if (res != TEE_SUCCESS) { - EMSG("TEE_InvokeTACommand failed\n"); + EMSG("TEE_InvokeTACommand failed"); goto cleanup_close_session; } if (TEE_MemCompare(sha256_out, out, sizeof(sha256_out)) != 0) { - EMSG("out parameter failed\n"); + EMSG("out parameter failed"); res = TEE_ERROR_GENERIC; goto cleanup_close_session; } diff --git a/ta/rpc_test/ta_rpc.c b/ta/rpc_test/ta_rpc.c index 15dc092a2..7d9604ee4 100644 --- a/ta/rpc_test/ta_rpc.c +++ b/ta/rpc_test/ta_rpc.c @@ -29,7 +29,7 @@ static TEE_Result rpc_call_cryp(bool sec_mem, uint32_t nParamTypes, params, &cryp_session, &origin); if (res != TEE_SUCCESS) { - EMSG("rpc_sha256 - TEE_OpenTASession returned 0x%x\n", + EMSG("rpc_sha256 - TEE_OpenTASession returned 0x%x", (unsigned int)res); return res; } @@ -69,7 +69,7 @@ static TEE_Result rpc_call_cryp(bool sec_mem, uint32_t nParamTypes, res = TEE_InvokeTACommand(cryp_session, TEE_TIMEOUT_INFINITE, cmd, types, params, &origin); if (res != TEE_SUCCESS) { - EMSG("rpc_call_cryp - TEE_InvokeTACommand returned 0x%x\n", + EMSG("rpc_call_cryp - TEE_InvokeTACommand returned 0x%x", (unsigned int)res); } diff --git a/ta/sdp_basic/ta_sdp_basic.c b/ta/sdp_basic/ta_sdp_basic.c index 1f9485e11..e18d6c49e 100644 --- a/ta/sdp_basic/ta_sdp_basic.c +++ b/ta/sdp_basic/ta_sdp_basic.c @@ -256,7 +256,7 @@ static TEE_Result cmd_invoke(uint32_t nParamTypes, res = TEE_OpenTASession(&uuid, TEE_TIMEOUT_INFINITE, 0, NULL, &sess, &ret_orig); if (res != TEE_SUCCESS) { - EMSG("SDP basic test TA: TEE_OpenTASession() FAILED \n"); + EMSG("SDP basic test TA: TEE_OpenTASession() FAILED"); goto cleanup_return; } @@ -265,7 +265,7 @@ static TEE_Result cmd_invoke(uint32_t nParamTypes, res = TEE_InvokeTACommand(sess, TEE_TIMEOUT_INFINITE, nCommandID, nParamTypes, pParams, &ret_orig); if (res != TEE_SUCCESS) { - EMSG("SDP basic test TA: TEE_OpenTASession() FAILED %x/%d\n", + EMSG("SDP basic test TA: TEE_OpenTASession() FAILED %x/%d", res, ret_orig); } @@ -290,7 +290,7 @@ static TEE_Result cmd_invoke_pta(uint32_t nParamTypes, res = TEE_OpenTASession(&uuid, TEE_TIMEOUT_INFINITE, 0, NULL, &sess, &ret_orig); if (res != TEE_SUCCESS) { - EMSG("SDP basic test TA: TEE_OpenTASession() FAILED \n"); + EMSG("SDP basic test TA: TEE_OpenTASession() FAILED"); goto cleanup_return; } @@ -299,7 +299,7 @@ static TEE_Result cmd_invoke_pta(uint32_t nParamTypes, res = TEE_InvokeTACommand(sess, TEE_TIMEOUT_INFINITE, nCommandID, nParamTypes, pParams, &ret_orig); if (res != TEE_SUCCESS) { - EMSG("SDP basic test TA: TEE_OpenTASession() FAILED %x/%d\n", + EMSG("SDP basic test TA: TEE_OpenTASession() FAILED %x/%d", res, ret_orig); } diff --git a/ta/storage_benchmark/benchmark.c b/ta/storage_benchmark/benchmark.c index 00273092c..21cb8ff86 100644 --- a/ta/storage_benchmark/benchmark.c +++ b/ta/storage_benchmark/benchmark.c @@ -322,7 +322,7 @@ static TEE_Result ta_stroage_benchmark_chunk_access_test(uint32_t nCommandID, if (chunk_size == 0) chunk_size = DEFAULT_CHUNK_SIZE; - IMSG("command id: %u, test data size: %zd, chunk size: %zd\n", + IMSG("command id: %u, test data size: %zd, chunk size: %zd", nCommandID, data_size, chunk_size); chunk_buf = TEE_Malloc(chunk_size, TEE_MALLOC_FILL_ZERO);