Skip to content

Commit 76dde66

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 76dde66

File tree

4 files changed

+58
-13
lines changed

4 files changed

+58
-13
lines changed

config.mk

+2
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

+43-3
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[MAX_TA_PREFIX] = {0};
71+
int num_ta_prefix = 0;
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,9 @@ 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;
704710

705711
e = pthread_mutex_init(&arg.mutex, NULL);
706712
if (e) {
@@ -762,30 +768,64 @@ int main(int argc, char *argv[])
762768
exit(EXIT_FAILURE);
763769
}
764770

771+
#ifdef TEEC_TEST_LOAD_PATH
772+
test_ta_prefix_multipath = strdup(TEEC_TEST_LOAD_PATH);
773+
if (!test_ta_prefix) {
774+
EMSG("out of memory");
775+
goto exit;
776+
}
777+
while ((temp = strsep(&test_ta_prefix_multipath, ":")) != NULL) {
778+
if (num_ta_prefix < MAX_TA_PREFIX) {
779+
ta_prefix[num_ta_prefix++] = temp;
780+
}
781+
else {
782+
EMSG("Too many ta load paths");
783+
goto exit;
784+
}
785+
}
786+
#endif
787+
ta_prefix_multipath = strdup(TEEC_LOAD_PATH);
788+
if (!ta_prefix_multipath) {
789+
EMSG("out of memory");
790+
goto exit;
791+
}
792+
while ((temp = strsep(&ta_prefix_multipath, ":")) != NULL) {
793+
if (num_ta_prefix < MAX_TA_PREFIX) {
794+
ta_prefix[num_ta_prefix++] = temp;
795+
}
796+
else {
797+
EMSG("Too many ta load paths");
798+
goto exit;
799+
}
800+
}
801+
765802
if (dev) {
766803
arg.fd = open_dev(dev, &arg.gen_caps);
767804
if (arg.fd < 0) {
768805
EMSG("failed to open \"%s\"", argv[1]);
769-
exit(EXIT_FAILURE);
806+
goto exit;
770807
}
771808
} else {
772809
arg.fd = get_dev_fd(&arg.gen_caps);
773810
if (arg.fd < 0) {
774811
EMSG("failed to find an OP-TEE supplicant device");
775-
exit(EXIT_FAILURE);
812+
goto exit;
776813
}
777814
}
778815

779816
if (plugin_load_all() != 0) {
780817
EMSG("failed to load plugins");
781-
exit(EXIT_FAILURE);
818+
goto exit;
782819
}
783820

784821
while (!arg.abort) {
785822
if (!process_one_request(&arg))
786823
arg.abort = true;
787824
}
788825

826+
exit:
827+
free(test_ta_prefix_multipath);
828+
free(ta_prefix_multipath);
789829
close(arg.fd);
790830

791831
return EXIT_FAILURE;

tee-supplicant/src/teec_ta_load.c

+8-10
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

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
#define TA_BINARY_FOUND 0
3232
#define TA_BINARY_NOT_FOUND -1
3333

34+
/* support multiple TA load path */
35+
#define MAX_TA_PREFIX 8
36+
extern char *ta_prefix[MAX_TA_PREFIX];
37+
extern int num_ta_prefix;
38+
3439
/**
3540
* Based on the uuid this function will try to find a TA-binary on the
3641
* filesystem and return it back to the caller in the parameter ta.

0 commit comments

Comments
 (0)