-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tee-supplicant: Support multiple ta load paths #306
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,9 @@ | |
#define RPC_BUF_SIZE (sizeof(struct tee_iocl_supp_send_arg) + \ | ||
RPC_NUM_PARAMS * sizeof(struct tee_ioctl_param)) | ||
|
||
char **ta_prefix; | ||
int num_ta_prefix; | ||
|
||
union tee_rpc_invoke { | ||
uint64_t buf[(RPC_BUF_SIZE - 1) / sizeof(uint64_t) + 1]; | ||
struct tee_iocl_supp_recv_arg recv; | ||
|
@@ -701,6 +704,10 @@ int main(int argc, char *argv[]) | |
int e = 0; | ||
int long_index = 0; | ||
int opt = 0; | ||
char *test_ta_prefix_multipath = NULL; | ||
char *ta_prefix_multipath = NULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The purpose of the variables is a bit hard to figure out from their names IMO. |
||
char *temp; | ||
int i, len; | ||
|
||
e = pthread_mutex_init(&arg.mutex, NULL); | ||
if (e) { | ||
|
@@ -762,30 +769,81 @@ int main(int argc, char *argv[]) | |
exit(EXIT_FAILURE); | ||
} | ||
|
||
/* Support multiple ta load paths */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather have a helper function to parse the paths. There is duplication. |
||
#ifdef TEEC_TEST_LOAD_PATH | ||
if (TEEC_TEST_LOAD_PATH) { | ||
num_ta_prefix++; | ||
len = strlen(TEEC_TEST_LOAD_PATH); | ||
for (i = 0; i < len; i++) { | ||
if (TEEC_TEST_LOAD_PATH[i] == ':') { | ||
num_ta_prefix++; | ||
} | ||
} | ||
} | ||
#endif | ||
if (TEEC_LOAD_PATH) { | ||
num_ta_prefix++; | ||
len = strlen(TEEC_LOAD_PATH); | ||
for (i = 0; i < len; i++) { | ||
if (TEEC_LOAD_PATH[i] == ':') { | ||
num_ta_prefix++; | ||
} | ||
} | ||
} | ||
ta_prefix = (char **)malloc(sizeof(char *) * num_ta_prefix); | ||
if (!ta_prefix) { | ||
EMSG("out of memory"); | ||
goto exit; | ||
} | ||
|
||
i = 0; | ||
#ifdef TEEC_TEST_LOAD_PATH | ||
test_ta_prefix_multipath = strdup(TEEC_TEST_LOAD_PATH); | ||
if (!test_ta_prefix) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
EMSG("out of memory"); | ||
goto exit; | ||
} | ||
while ((temp = strsep(&test_ta_prefix_multipath, ":")) != NULL) { | ||
ta_prefix[i++] = temp; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
#endif | ||
ta_prefix_multipath = strdup(TEEC_LOAD_PATH); | ||
if (!ta_prefix_multipath) { | ||
EMSG("out of memory"); | ||
goto exit; | ||
} | ||
while ((temp = strsep(&ta_prefix_multipath, ":")) != NULL) { | ||
ta_prefix[i++] = temp; | ||
} | ||
|
||
if (dev) { | ||
arg.fd = open_dev(dev, &arg.gen_caps); | ||
if (arg.fd < 0) { | ||
EMSG("failed to open \"%s\"", argv[1]); | ||
exit(EXIT_FAILURE); | ||
goto exit; | ||
} | ||
} else { | ||
arg.fd = get_dev_fd(&arg.gen_caps); | ||
if (arg.fd < 0) { | ||
EMSG("failed to find an OP-TEE supplicant device"); | ||
exit(EXIT_FAILURE); | ||
goto exit; | ||
} | ||
} | ||
|
||
if (plugin_load_all() != 0) { | ||
EMSG("failed to load plugins"); | ||
exit(EXIT_FAILURE); | ||
goto exit; | ||
} | ||
|
||
while (!arg.abort) { | ||
if (!process_one_request(&arg)) | ||
arg.abort = true; | ||
} | ||
|
||
exit: | ||
free(test_ta_prefix_multipath); | ||
free(ta_prefix_multipath); | ||
free(ta_prefix); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not convinced this kind of cleanup is desirable immediately before exiting. |
||
close(arg.fd); | ||
|
||
return EXIT_FAILURE; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,15 +176,13 @@ int TEECI_LoadSecureModule(const char* dev_path, | |
const TEEC_UUID *destination, void *ta, | ||
size_t *ta_size) | ||
{ | ||
#ifdef TEEC_TEST_LOAD_PATH | ||
int res = 0; | ||
int res = TA_BINARY_NOT_FOUND; | ||
|
||
res = try_load_secure_module(TEEC_TEST_LOAD_PATH, | ||
dev_path, destination, ta, ta_size); | ||
if (res != TA_BINARY_NOT_FOUND) | ||
return res; | ||
#endif | ||
|
||
return try_load_secure_module(TEEC_LOAD_PATH, | ||
dev_path, destination, ta, ta_size); | ||
for (int i = 0; i < num_ta_prefix; i++) { | ||
res = try_load_secure_module(ta_prefix[i], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, the documentation for |
||
dev_path, destination, ta, ta_size); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix indentation res = try_load_secure_module(ta_prefix[i], dev_path,
destination, ta, ta_size); |
||
if (res == TA_BINARY_FOUND) | ||
break; | ||
} | ||
return res; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is just wrong, it should be removed. The same error is present in
CMakeLists.mk
.