Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for early Trusted Applications
Early TAs are user-mode Trusted Applications that are embedded at link time in the TEE binary. A special read-only data section is used to store them (.rodata.early_ta). A Python script takes care of converting the TAs into a C source file with the proper linker section attribute. The feature is disabled by default. To enable it, the paths to the TA binaries have to be given in $(EARLY_TA_PATHS). They should be ELF files. Typical build steps: $ make ... CFG_EARLY_TA=y ta_dev_kit # (1) $ # ... build the TAs ... # (2) $ make ... EARLY_TA_PATHS=path/to/<uuid>.stripped.elf # (3) Notes: - Setting CFG_EARLY_TA=y during the first step (1) is not necessary, but it will avoid rebuilding libraries during the third step (3) - CFG_EARLY_TA is automatically enabled when EARLY_TA_PATHS is non-empty in step (3) - Several TAs may be given in $(EARLY_TA_PATHS) (3) Early TAs are given a higher load priority than REE FS TAs, since they should be available even before tee-supplicant is ready. Suggested-by: Zeng Tao <prime.zeng@hisilicon.com> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
- Loading branch information
1 parent
23346f1
commit d0c6361
Showing
12 changed files
with
331 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2017, Linaro Limited | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
#ifndef KERNEL_EARLY_TA_H | ||
#define KERNEL_EARLY_TA_H | ||
|
||
#include <compiler.h> | ||
#include <stdint.h> | ||
#include <tee_api_types.h> | ||
|
||
struct early_ta { | ||
TEE_UUID uuid; | ||
uint32_t size; | ||
const uint8_t ta[]; /* @size bytes */ | ||
}; | ||
|
||
#endif /* KERNEL_EARLY_TA_H */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright (c) 2017, Linaro Limited | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
#include <initcall.h> | ||
#include <kernel/early_ta.h> | ||
#include <kernel/linker.h> | ||
#include <kernel/user_ta.h> | ||
#include <string.h> | ||
#include <trace.h> | ||
#include <util.h> | ||
|
||
#include "elf_load.h" | ||
|
||
struct user_ta_store_handle { | ||
const struct early_ta *early_ta; | ||
size_t offs; | ||
}; | ||
|
||
#define for_each_early_ta(_ta) \ | ||
for (_ta = &__rodata_early_ta_start; _ta < &__rodata_early_ta_end; \ | ||
_ta = (const struct early_ta *) \ | ||
ROUNDUP((vaddr_t)_ta + sizeof(*_ta) + _ta->size, \ | ||
__alignof__(struct early_ta))) | ||
|
||
static const struct early_ta *find_early_ta(const TEE_UUID *uuid) | ||
{ | ||
const struct early_ta *ta; | ||
|
||
for_each_early_ta(ta) | ||
if (!memcmp(&ta->uuid, uuid, sizeof(*uuid))) | ||
return ta; | ||
|
||
return NULL; | ||
} | ||
|
||
static TEE_Result early_ta_open(const TEE_UUID *uuid, | ||
struct user_ta_store_handle **h) | ||
{ | ||
const struct early_ta *ta; | ||
struct user_ta_store_handle *handle; | ||
|
||
ta = find_early_ta(uuid); | ||
if (!ta) | ||
return TEE_ERROR_ITEM_NOT_FOUND; | ||
|
||
handle = calloc(1, sizeof(*handle)); | ||
if (!handle) | ||
return TEE_ERROR_OUT_OF_MEMORY; | ||
|
||
handle->early_ta = ta; | ||
*h = handle; | ||
|
||
return TEE_SUCCESS; | ||
} | ||
|
||
static TEE_Result early_ta_get_size(const struct user_ta_store_handle *h, | ||
size_t *size) | ||
{ | ||
*size = h->early_ta->size; | ||
return TEE_SUCCESS; | ||
} | ||
|
||
static TEE_Result early_ta_read(struct user_ta_store_handle *h, void *data, | ||
size_t len) | ||
{ | ||
uint8_t *src = (uint8_t *)h->early_ta->ta + h->offs; | ||
|
||
if (h->offs + len > h->early_ta->size) | ||
return TEE_ERROR_BAD_PARAMETERS; | ||
if (data) | ||
memcpy(data, src, len); | ||
h->offs += len; | ||
|
||
return TEE_SUCCESS; | ||
} | ||
|
||
static void early_ta_close(struct user_ta_store_handle *h) | ||
{ | ||
free(h); | ||
} | ||
|
||
static struct user_ta_store_ops ops = { | ||
.description = "early TA", | ||
.open = early_ta_open, | ||
.get_size = early_ta_get_size, | ||
.read = early_ta_read, | ||
.close = early_ta_close, | ||
.priority = 5, | ||
}; | ||
|
||
static TEE_Result early_ta_init(void) | ||
{ | ||
const struct early_ta *ta; | ||
|
||
for_each_early_ta(ta) | ||
DMSG("Early TA %pUl size %u", (void *)&ta->uuid, ta->size); | ||
|
||
return tee_ta_register_ta_store(&ops); | ||
} | ||
|
||
service_init(early_ta_init); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.