aboutsummaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
2018-11-16lib.mk: centralize profiling flag (-pg)Jerome Forissier
Code cleanup, no functional change. This commit avoids the duplication of the -pg flag in the library makefiles. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-11-15utee: support prehashed RSA sign/ver without ASN.1Gabor Szekely
Add TEE Core Internal API extension TEE_ALG_RSASSA_PKCS1_V1_5 to sign/verify pre-hashed PKCS#1 v1.5 EMSA without ASN.1 around the hash. This relies on libtomcrypt LTC_PKCS_1_V1_5_NA1. The extension can be turned on with CFG_CRYPTO_RSASSA_NA1. Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Gabor Szekely <szvgabor@gmail.com>
2018-11-14core: mbedtls: configure bignum word sizeJens Wiklander
Configures mbedtls bignum word size (mbedtls_mpi_uint and mbedtls_mpi_sint) as 32-bit or 64-bit depending on arm architecture. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-11-14core: switch to mbedtls for bignumJens Wiklander
Adds a mpi_desc.c wrapper to LTC in order to enable usage of bignum (mpi) routines from mbedtls. CFG_MBEDTLS_MPI=y (default y) builds the bignum routines for mbedtls and also enables their usage in LTC and by that replaces libmpa for privileged mode usage. User mode TAs still use libmpa. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-11-14libmbedtls: add mbedtls_mpi_init_mempool()Jens Wiklander
782fddd10ccb ("libmbedtls: add mbedtls_mpi_init_mempool()") from branch import/mbedtls-2.6.1 Adds mbedtls_mpi_init_mempool() which initializes a mbedtls_mpi struct to use the mempool mbedtls_mpi_mempool if configured for memory allocation. All local memory allocation is changed to use mbedtls_mpi_init_mempool() instead of mbedtls_mpi_init(). This will give a stack like alloc/free pattern for which the mempool is optimized. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-11-14libmbedtls: make mbedtls_mpi_mont*() availableJens Wiklander
338738340a8c ("libmbedtls: make mbedtls_mpi_mont*() available") from branch import/mbedtls-2.6.1 Makes mbedtls_mpi_montg_init(), mbedtls_mpi_montmul() and mbedtls_mpi_montred() available for external use. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-11-14libmbedtls: configure mbedTLS for different modesEdison Ai
Split mbedTLS into 3 partitions: CRYPTO, X509 and TLS. CRYPTO is for kernel and user mode. X509 and TLS are mainly for user mode. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Edison Ai <edison.ai@arm.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-11-14mempool: report max memory usageJens Wiklander
Adds CFG_MEMPOOL_REPORT_LAST_OFFSET which if set to y causes mempool to report each time the maximum amount of memory has increased. This helps to determine required size of a mempool. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-11-14mempool: optimize reference countingJens Wiklander
Optimizes reference counting in mempool by using refcount_inc() and refcount_dec() in order to be able to avoid using the mutex in the quick case. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-11-14mempool: add out of memory messageJens Wiklander
Adds a helpful message when a memory allocation with mempool_alloc() fails. If this occurs it's because the memory pool size isn't tuned properly with regards to the user of the pool. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-11-13trace levels: Redefine TRACE_MIN level to 0Ovidiu Mihalachi
The global `trace_level` session-wise indicator which is set by `trace_set_level()` [1], could get a wrong value in case of an input `level` set to 0, meaning that all logs need to be disabled by user define `CFG_TEE_TA_LOG_LEVEL=0` when building TA applications. This inconsistency is caused by a rather wrong value of `TRACE_MIN` low boundary value set to 1. According to [1] `trace level` will be set to `TRACE_MAX` (4) in case input level is smaller than `TRACE_MIN` and larger than `TRACE_MAX`. In the scenario when the needed log level is 0, `trace level` would be set to `TRACE_MAX` and will cause a lot of flow log level information dumped by trace functions/macros that are using `trace_printf()` primitive. This patch sets the `TRACE_MIN` to 0 in order to assure a proper trace level setting and completely disable all logs in case `CFG_TEE_TA_LOG_LEVEL=0`. [1] void trace_set_level(int level) { if (((int)level >= TRACE_MIN) && (level <= TRACE_MAX)) trace_level = level; else trace_level = TRACE_MAX; } Acked-by: Christoph Gellner <cgellner@de.adit-jv.com> Signed-off-by: Ovidiu Mihalachi <ovidiu_mihalachi@mentor.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
2018-11-13Move __early_ta from <compiler.h> to <kernel/early_ta.h>Jerome Forissier
The __early_ta macro is used only in C files generated by scripts/ta_bin_to_c.py. There is no reason to have it defined in a widely used header like <compiler.h>. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
2018-11-13core: force read-only flag on .rodata.* sectionsJerome Forissier
This commit fixes a warning with GCC 8.2 that did not occur with GCC 6.2: $ make out/arm-plat-vexpress/core/arch/arm/kernel/user_ta.o CHK out/arm-plat-vexpress/conf.mk CHK out/arm-plat-vexpress/include/generated/conf.h CHK out/arm-plat-vexpress/core/include/generated/asm-defines.h CC out/arm-plat-vexpress/core/arch/arm/kernel/user_ta.o {standard input}: Assembler messages: {standard input}:4087: Warning: setting incorrect section attributes for .rodata.__unpaged The message is printed as the assembler processes this code fragment, generated by the C compiler: .section .rodata.__unpaged,"aw" The older compiler (GCC 6.2) would generate instead: .section .rodata.__unpaged,"a",%progbits The problem with .rodata.__unpaged,"aw" is that the "w" (writeable) flag is not consistent with the section name (.rodata.*), which by convention is supposed to be read-only. - The section name (".rodata.__unpaged") is given by our macro: __rodata_unpaged. - The "w" flag is added by GCC, not sure why exactly. One reason [1] is when a relocatable binary is being generated and the structure contains relocatable data. But, we are not explicitly asking for a relocatable binary, so this might as well be a bug or counter-intuitive feature of the compiler. Anyway, to avoid the warning, we need to fix the section flags. The section type (%progbits) is optional, it is deduced from the section name by default. %progbits indicates that the section contains data (i.e., is not empty). Link: [1] https://gcc.gnu.org/ml/gcc/2004-05/msg01016.html Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (QEMU) Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (HiKey960) Acked-by: Jens Wiklander <jens.wiklander@linaro.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
2018-11-13libutils: Import strtoul from newlibBryan O'Donoghue
This patch imports strtoul from newlib which the latest version of libfdt depends on. Some modification of the original source is required to do this, specifically: This is an import of the newlib 1.19.0 version of strtoul dropping - Headers and prototypes for re-entrancy - Any reliance on errno Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
2018-11-13libutils: isoc: implement isalpha(), isspace() and isupper()Bryan O'Donoghue
This patch implements isalpha(), isspace() and isupper() which are dependencies for a subsequent patch which brings in strtoul from newlib. Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
2018-11-13libutils: Import strrchr from newlibBryan O'Donoghue
libfdt 1.4.7 depends on strrchr, this patch imports the same from newlib. Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
2018-11-08core: introduce lockdep algorithmJerome Forissier
This commit introduces an algorithm that may be used to detect improper usage of locks at runtime. It can detect two kinds errors: 1. A thread tries to release a lock it does not own, 2. A thread tries to aquire a lock and the operation could *potentially* result in a deadlock. The potential deadlock detection assumes that the code adheres to a strict locking hierarchy, in other word, that there is a partial ordering on the locks so that there can be no situation where circular waits can occur. To put things simply, any two locks should be acquired in the same order in the same thread. This addresses the following case: [Thread #1] [Thread #2] lock(A) lock(B) lock(B) lock(A) <-- deadlock! ... The algorithm builds the lock hierarchy dynamically and reports as soon as a violation is detected. The interface is made of two functions: lockdep_lock_acquire() and lockdep_lock_release(), which are meant to be introduced in the implementation of the actual lock objects. The "acquire" hook tells the algorithm that a particular lock is about to be requested by a particular thread, while the "release" hook is meant to be called before the lock is actually released. If an error is detected, debugging information is sent to the console, and panic() is called. The debugging information includes the lock cycle that was detected (in the above example, {A, B}), as well as the call stacks at the points where the locks were acquired. The good thing with such an instrumentation of the locking code is that there is no need to wait for an actual deadlock to occur in order to detect potential problems. For instance, the timing of execution in the above example could be different but the problem would still be detected: [Thread #1] [Thread #2] lock(A) lock(B) unlock(B) unlock(A) lock(B) lock(A) <-- error! A pseudo-TA is added for testing (pta/core_lockdep_tests.c). This code is based on two sources: - A presentation called "Dl-Check: dynamic potential deadlock detection tool for Java programs" [1], although the somewhat complex MNR algorithm for topological ordering of a DAG was not used; - A depth-first search algorithm [2] was used instead. Link: [1] https://www.slideshare.net/IosifItkin/tmpa2017-dlcheck-dynamic-potential-deadlock-detection-tool-for-java-programs Link: [2] https://en.wikipedia.org/wiki/Topological_sorting#Depth-first_search Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Joakim Bech <joakim.bech@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-11-08libutils: sys/queue.h: add STAILQ_FOREACH_SAFE()Jerome Forissier
Import macro STAILQ_FOREACH_SAFE from FreeBSD. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Joakim Bech <joakim.bech@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-10-08libutee: Fix base64 encoding functionKrzysztof Jackiewicz
Bitwise OR of unsigned int and a signed char is machine dependent and could lead to invalid base64 encoding. This commit makes it use unsigned char instead. Signed-off-by: Krzysztof Jackiewicz <k.jackiewicz@samsung.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-10-03pager: enable BestFit allocation when using the pagerJoakim Bech
When running xtest 6018 we have got panics because of TEE_ERROR_OUT_OF_MEMORY errors when trying to allocate memory (using malloc and calloc). The reason for this seems to be a fragmented heap when running with the pager enabled. By enabling the BestFit algorithm in bget we have seen a much improved use of the heap with a lot less fragmentation. We have been running xtest on QEMU v8 and HiKey 6220 and the performance difference seems to be negligible. Fixes: https://github.com/OP-TEE/optee_os/issues/2580 Signed-off-by: Joakim Bech <joakim.bech@linaro.org> Tested-by: Joakim Bech <joakim.bech@linaro.org> (HiKey 6220, QEMU v8) Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-09-27Allow mixed declaration and codeJens Wiklander
Removes the -Wdeclaration-after-statement compiler flag to allow mixed declaration and code Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-08-01trace: get thread_id right in print_thread_id()Volodymyr Babchuk
Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com> Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
2018-08-01trace: check for CFG_MSG_LONG_PREFIX_MASK only once per messageVolodymyr Babchuk
There is no need for repeated checks for every portion of extended prefix. Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com> Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
2018-08-01trace: print core id if in atomic contextVolodymyr Babchuk
If (D|E|I|F)MSG is called with foreign interrupts masked we can report core ID. "?" will be printed instead, if foreign interrupts aren't masked. With this patch log looks like this: D/TC:2 0 core_mmu_set_user_map:940 0xe181b88 0xeee8003 D/TC:? 0 __wq_rpc:40 wake thread 1 0xe16f028 -3 D/TC:1 thread_handle_std_smc:612 a7: 2 D/TC:3 0 core_mmu_set_user_map:940 0x0 0x0 Where first digit shows core id and second - thread id. Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com> Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
2018-07-04Use inttypes.h over stdint.h on some .h filesJens Wiklander
Uses inttypes.h over stdint.h on some .h files to be nice to U-boot. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-07-04bget: remove unused parameter for bufdump()Volodymyr Babchuk
bufdump() function does not need poolset to work Signed-off-by: Volodymyr Babchuk <vlad.babchuk@gmail.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-06-27libutils: introduce MAX_UNSAFE() and MIN_UNSAFE()Etienne Carriere
This change allows one to use MAX_UNSAFE() and MIN_UNSAFE() macros in particular conditions where MAX()/MIN() macros fail to build from C source file implementation with error traces as below: In file included from core/arch/arm/include/arm.h:8:0, from core/arch/arm/include/kernel/thread.h:11, from core/arch/arm/kernel/asm-defines.c:7: lib/libutils/ext/include/util.h:24:16: error: missing binary operator before token "(" (__extension__({ __typeof__(a) _a = (a); \ ^ core/arch/arm/plat-stm/./platform_config.h:190:25: note: in expansion of macro ‘MAX’ #define STM_SECDDR_END MAX(TZSRAM_BASE + TZSRAM_SIZE, \ ^~~ core/arch/arm/plat-stm/./platform_config.h:204:6: note: in expansion of macro ‘STM_SECDDR_END’ #if (STM_SECDDR_END < 0x80000000ULL) ^~~~~~~~~~~~~~ make: *** [out/core/include/generated/.asm-defines.s] Error 1 Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-06-20benchmark: change the way of timestamp buffer allocation.Igor Opaniuk
In case if timestamp buffer is allocated in userspace and new register user memory API is used for its registering in OP-TEE (introduced in optee_client commit 27888d73d156 ("tee_client_api: register user memory")), there is no possibility to keep this mapping permanent among different TEEC_InvokeCommand invocations, as all SHM are automatically unmapped from OP-TEE VA space after TEEC_InvokeCommand is handled by OP-TEE. Timestamp buffer is now allocated with thread_rpc_alloc_global_payload(). Fixes: https://github.com/OP-TEE/optee_os/issues/1979 Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Joakim Bech <joakim.bech@linaro.org> Signed-off-by: Igor Opaniuk <igor.opaniuk@linaro.org>
2018-06-18libmpa: remove mpa_set_random_generator()Jens Wiklander
MPA is used in two configurations, either in kernel mode or in user mode. In kernel mode random is always drawn with crypto_rng_read() and in user mode utee_cryp_random_number_generate() is used instead. This patch makes the code easier to follow by replacing the call via a function pointer to a normal function call instead. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-06-09libutee: Fix the keepalive condition on last session closeAndrew Gabbasov
Keepalive condition check should involve single instance flag too, since the keepalive flag is meaningless if the TA is not single instance. The same fix was done earlier in the core by commit f9a64f12b542 ("core: fix the keepalive condition in close session"). Fixes: b7ea03ff2963 ("libutee: fix TA_CreateEntryPoint() and TA_DestroyEntryPoint()") Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-06-08mbedtls_config_uta.h: enable check key usageJens Wiklander
Defines MBEDTLS_X509_CHECK_KEY_USAGE to enable checking key usage of a certificate. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-30pta: add system pTAIgor Opaniuk
Add system pTA, which provides misc. auxiliary services, extending existing GlobalPlatform Core API. Add a call for seeding entropy to the default RNG pool. Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Igor Opaniuk <igor.opaniuk@linaro.org>
2018-05-28libmbedtls: refine mbedtls license headerEdison Ai
e0186224bba7 ("libmbedtls: refine mbedtls license header") from branch import/mbedtls-2.6.1 New header format according to this: https://github.com/OP-TEE/optee_os/blob/master/documentation/ copyright_and_license_headers.rst Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Edison Ai <edison.ai@arm.com> [jw: removed the now redundant SPDX-License-Identifier] Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-22libmbedtls: configure and compile mbedtlsJens Wiklander
Configures mbedtls with a minimal user mode TA configuration and makes it compile. Adds dummy include/mbedtls_config_kernel.h to give a good error message in case mbedTLS is compiled in for kernel mode. mbedTLS is enabled for TAs with CFG_TA_MBEDTLS = y Builtin self tests are enabled with CFG_TA_MBEDTLS_SELF_TEST = y Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-22Squashed commit importing mbedtls-2.6.1 sourceJens Wiklander
Squash merging branch import/mbedtls-2.6.1 215609ae4d8c ("mbedtls: configure mbedtls to reach for config") 6916dcd9b9cd ("mbedtls: remove default include/mbedtls/config.h") b60fc42a5cd5 ("Import mbedtls-2.6.1") Acked-by: Joakim Bech <joakim.bech@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-22Add rand() for TA usageJens Wiklander
Adds rand() by declaring it in stdlib.h where it's expected to be found. Implementation is provided in libutee since it depends on TEE_GenerateRandom(). Reviewed-by: Joakim Bech <joakim.bech@linaro.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-22stdint.h: include limits.hJens Wiklander
The define SIZE_MAX uses ULONG_MAX, which is provided in limits.h. Reviewed-by: Joakim Bech <joakim.bech@linaro.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-22libutils: import strcpy() and strncpy()Jens Wiklander
Imports strcpy() and strncpy() from newlib with license added Reviewed-by: Joakim Bech <joakim.bech@linaro.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-22libutils: import strstr() from newlibJens Wiklander
Reviewed-by: Joakim Bech <joakim.bech@linaro.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-22libutils: time.h: typedef time_tJens Wiklander
Typedefs time_t as a int64_t Reviewed-by: Joakim Bech <joakim.bech@linaro.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-16Remove license notice from STMicroelectronics filesEtienne Carriere
Since a while the source files license info are defined by SPDX identifiers. We can safely remove the verbose license text from the files that are owned by either only STMicroelectronics or only both Linaro and STMicroelectronics. Signed-off-by: Etienne Carriere <etienne.carriere@st.com> Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-16util: remove unused macrosJerome Forissier
After commit 9a8117de1263 ("util: update fallback ADD_OVERFLOW() macro") and commit ecdedc94e720 ("util: update fallback SUB_OVERFLOW() macro"), the following macros are not used anymore. Remove them. __INTOF_HALF_MAX_SIGNED(type) __INTOF_MAX_SIGNED(type) __INTOF_MIN_SIGNED(type) __INTOF_MIN(type) __INTOF_MAX(type) Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-15util: update fallback SUB_OVERFLOW() macroJens Wiklander
Updates the fallback SUB_OVERFLOW() macro to better support mixed types in the arguments. Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-15util: update fallback ADD_OVERFLOW() macroJens Wiklander
Updates the fallback ADD_OVERFLOW() macro to better support mixed types in the arguments. Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-15libutils: MIN/MAX macros for assembly codeEtienne Carriere
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
2018-05-09libutils: bget_malloc.c: fix overflow testsJerome Forissier
The overflow tests in raw_calloc(), raw_realloc() and raw_malloc() are wrong. They don't work as expected when hdr_size and ftr_size are both zero. The bug is exposed by commit 96c1d8c56cde ("ta: TEE_Malloc() and friend: skips layers") which causes xtest 8033 to fail because TEE_Malloc(0, TEE_MALLOC_FILL_ZERO) now returns NULL. In addition, the allocation functions in bget.c (bget(), bgetz() and bgetr()) take a parameter of type bufsize for the allocation size. This happens to be a (signed) long. On the other hand, raw_malloc(), raw_calloc() and raw_realloc() take a size_t parameter which is unsigned long. Therefore, large size values are incorrectly interpreted as being negative by the bget code, which then asserts. When run in the context of a TA, this causes a TA panic instead of a TEE_ERROR_OUT_OF_MEMORY error. This bug is also exposed by commit 96c1d8c56cde ("ta: TEE_Malloc() and friend: skips layers") and makes xtest 8034 and 8042 fail. 8034 is TEE_Malloc(0xFFFFFFFE, TEE_MALLOC_FILL_ZERO) while 8042 is TEE_Realloc(ptr, 0xFFFFFFFE). Rework the raw_calloc(), raw_realloc() and raw_malloc() functions to use the MUL_OVERFLOW() and ADD_OVERFLOW() macros instead, operating on the proper types. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Tested-by: Jerome Forissier <jerome.forissier@linaro.org>
2018-05-09util: fix fallback SUB_OVERFLOW() macroJens Wiklander
This only applies when the compiler doesn't provide the __builtin_sub_overflow() function (before GCC 5.1). Fixes problem due to integer promotion in overflow macros when result is a signed type and the subtrahend is an unsigned type with a low value. SUB_OVERFLOW() still doesn't handle all combinations of signed and unsigned types in the parameters. Fixes: ce0d8e2da340 ("util: add macros for arithmetics with overflow checking") Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-09util: fix fallback ADD_OVERFLOW() macroJens Wiklander
This only applies when the compiler doesn't provide the __builtin_add_overflow() function (before GCC 5.1). Fixes problem due to integer promotion in overflow macros when result is a signed type and the second addend is an unsigned type with value 0. ADD_OVERFLOW() still doesn't handle all combinations of signed and unsigned types in the parameters. Fixes: ce0d8e2da340 ("util: add macros for arithmetics with overflow checking") Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-05-04libutils: isoc: implement tolower(), isdigit() and isxdigit()Jerome Forissier
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Acked-by: Joakim Bech <joakim.bech@linaro.org>
2018-05-04Prevent unused warnings in speculation_barrier.hJerome Forissier
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Acked-by: Joakim Bech <joakim.bech@linaro.org>