Skip to content

Commit 661e593

Browse files
committed
tee-supplicant: Support multiple ta load paths
CFG_TEE_CLIENT_LOAD_PATH can have multiple paths separated by :
1 parent a5c30b1 commit 661e593

File tree

4 files changed

+75
-13
lines changed

4 files changed

+75
-13
lines changed

config.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ CFG_TEE_CLIENT_LOG_FILE ?= $(CFG_TEE_FS_PARENT_PATH)/teec.log
3131

3232
# CFG_TEE_CLIENT_LOAD_PATH
3333
# The location of the client library file.
34+
# Suport multiple ta load path
35+
# CFG_TEE_CLIENT_LOAD_PATH ?= /lib:/vendor/lib
3436
CFG_TEE_CLIENT_LOAD_PATH ?= /lib
3537

3638
# CFG_TEE_SUPP_PLUGINS

tee-supplicant/src/tee_supplicant.c

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
#define RPC_BUF_SIZE (sizeof(struct tee_iocl_supp_send_arg) + \
6868
RPC_NUM_PARAMS * sizeof(struct tee_ioctl_param))
6969

70+
char **ta_prefix;
71+
int num_ta_prefix;
72+
7073
union tee_rpc_invoke {
7174
uint64_t buf[(RPC_BUF_SIZE - 1) / sizeof(uint64_t) + 1];
7275
struct tee_iocl_supp_recv_arg recv;
@@ -701,6 +704,10 @@ int main(int argc, char *argv[])
701704
int e = 0;
702705
int long_index = 0;
703706
int opt = 0;
707+
char *test_ta_prefix_multipath = NULL;
708+
char *ta_prefix_multipath = NULL;
709+
char *temp;
710+
int i, len;
704711

705712
e = pthread_mutex_init(&arg.mutex, NULL);
706713
if (e) {
@@ -762,30 +769,81 @@ int main(int argc, char *argv[])
762769
exit(EXIT_FAILURE);
763770
}
764771

772+
/* Support multiple ta load paths */
773+
#ifdef TEEC_TEST_LOAD_PATH
774+
if (TEEC_TEST_LOAD_PATH) {
775+
num_ta_prefix++;
776+
len = strlen(TEEC_TEST_LOAD_PATH);
777+
for (i = 0; i < len; i++) {
778+
if (TEEC_TEST_LOAD_PATH[i] == ':') {
779+
num_ta_prefix++;
780+
}
781+
}
782+
}
783+
#endif
784+
if (TEEC_LOAD_PATH) {
785+
num_ta_prefix++;
786+
len = strlen(TEEC_LOAD_PATH);
787+
for (i = 0; i < len; i++) {
788+
if (TEEC_LOAD_PATH[i] == ':') {
789+
num_ta_prefix++;
790+
}
791+
}
792+
}
793+
ta_prefix = (char **)malloc(sizeof(char *) * num_ta_prefix);
794+
if (!ta_prefix) {
795+
EMSG("out of memory");
796+
goto exit;
797+
}
798+
799+
i = 0;
800+
#ifdef TEEC_TEST_LOAD_PATH
801+
test_ta_prefix_multipath = strdup(TEEC_TEST_LOAD_PATH);
802+
if (!test_ta_prefix) {
803+
EMSG("out of memory");
804+
goto exit;
805+
}
806+
while ((temp = strsep(&test_ta_prefix_multipath, ":")) != NULL) {
807+
ta_prefix[i++] = temp;
808+
}
809+
#endif
810+
ta_prefix_multipath = strdup(TEEC_LOAD_PATH);
811+
if (!ta_prefix_multipath) {
812+
EMSG("out of memory");
813+
goto exit;
814+
}
815+
while ((temp = strsep(&ta_prefix_multipath, ":")) != NULL) {
816+
ta_prefix[i++] = temp;
817+
}
818+
765819
if (dev) {
766820
arg.fd = open_dev(dev, &arg.gen_caps);
767821
if (arg.fd < 0) {
768822
EMSG("failed to open \"%s\"", argv[1]);
769-
exit(EXIT_FAILURE);
823+
goto exit;
770824
}
771825
} else {
772826
arg.fd = get_dev_fd(&arg.gen_caps);
773827
if (arg.fd < 0) {
774828
EMSG("failed to find an OP-TEE supplicant device");
775-
exit(EXIT_FAILURE);
829+
goto exit;
776830
}
777831
}
778832

779833
if (plugin_load_all() != 0) {
780834
EMSG("failed to load plugins");
781-
exit(EXIT_FAILURE);
835+
goto exit;
782836
}
783837

784838
while (!arg.abort) {
785839
if (!process_one_request(&arg))
786840
arg.abort = true;
787841
}
788842

843+
exit:
844+
free(test_ta_prefix_multipath);
845+
free(ta_prefix_multipath);
846+
free(ta_prefix);
789847
close(arg.fd);
790848

791849
return EXIT_FAILURE;

tee-supplicant/src/teec_ta_load.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,13 @@ int TEECI_LoadSecureModule(const char* dev_path,
176176
const TEEC_UUID *destination, void *ta,
177177
size_t *ta_size)
178178
{
179-
#ifdef TEEC_TEST_LOAD_PATH
180-
int res = 0;
179+
int res = TA_BINARY_NOT_FOUND;
181180

182-
res = try_load_secure_module(TEEC_TEST_LOAD_PATH,
183-
dev_path, destination, ta, ta_size);
184-
if (res != TA_BINARY_NOT_FOUND)
185-
return res;
186-
#endif
187-
188-
return try_load_secure_module(TEEC_LOAD_PATH,
189-
dev_path, destination, ta, ta_size);
181+
for (int i = 0; i < num_ta_prefix; i++) {
182+
res = try_load_secure_module(ta_prefix[i],
183+
dev_path, destination, ta, ta_size);
184+
if (res == TA_BINARY_FOUND)
185+
break;
186+
}
187+
return res;
190188
}

tee-supplicant/src/teec_ta_load.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#define TA_BINARY_FOUND 0
3232
#define TA_BINARY_NOT_FOUND -1
3333

34+
/* Support multiple TA load paths */
35+
extern char **ta_prefix;
36+
extern int num_ta_prefix;
37+
3438
/**
3539
* Based on the uuid this function will try to find a TA-binary on the
3640
* filesystem and return it back to the caller in the parameter ta.

0 commit comments

Comments
 (0)