ldelf: accurate non-legacy TA check
Prior to this patch ldelf relied on e_entry in the ELF header to point
anywhere but at the lowest possible executable address to tell that it's
not a legacy TA. This isn't enough since all TAs can use this entry
address depending on compiler and linker. The only reliable indicator
that the TA is not a legacy TA is that the depr_entry field of the TA
header is UINT64_MAX. Unfortunately this means assuming that the ELF is
not a legacy TA at load time and that the process needs to be restarted
in case it turns out that it was a legacy TA.
With this patch we have reliable detection of non-legacy TAs, but with
increased load time for legacy TAs since the main ELF needs to be loaded
and verified twice due to the TA store interface.
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
diff --git a/ldelf/main.c b/ldelf/main.c
index ecc07ad..b3dac54 100644
--- a/ldelf/main.c
+++ b/ldelf/main.c
@@ -123,8 +123,8 @@
malloc_add_pool((void *)mpool_base, mpool_size);
/* Load the main binary and get a list of dependencies, if any. */
- ta_elf_load_main(&arg->uuid, &arg->is_32bit, &arg->entry_func,
- &arg->stack_ptr, &arg->flags);
+ ta_elf_load_main(&arg->uuid, &arg->is_32bit, &arg->stack_ptr,
+ &arg->flags);
/*
* Load binaries, ta_elf_load() may add external libraries to the
@@ -139,6 +139,8 @@
ta_elf_finalize_mappings(elf);
}
+ ta_elf_finalize_load_main(&arg->entry_func);
+
arg->ftrace_entry = 0;
#ifdef CFG_TA_FTRACE_SUPPORT
if (ftrace_init())