Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chaohub
Copy link

@chaohub chaohub commented Apr 18, 2022

CFG_TEE_CLIENT_LOAD_PATH can have multiple paths separated by :

}

tofree = multi_path;
while ((single_path = strsep(&multi_path, ":")) != NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parsing could be done once at startup in order to avoid doing this strdup(), strsep(), free() sequence each time a TA is to be loaded.

@github-actions
Copy link

This pull request has been marked as a stale pull request because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment, otherwise this pull request will automatically be closed in 5 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label May 20, 2022
@etienne-lms
Copy link
Contributor

this P-R could be tags as an enhancement.

@chaohub
Copy link
Author

chaohub commented May 24, 2022

I will address the comments and update the change.

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update.
Please fix commit message to also mention TEEC_LOAD_PATH TEEC_TEST_LOAD_PATH and add your Signed-off-by tag.
(edited)

dev_path, destination, ta, ta_size);
for (int i = 0; i < num_ta_prefix; i++) {
res = try_load_secure_module(ta_prefix[i],
dev_path, destination, ta, ta_size);
Copy link
Contributor

Choose a reason for hiding this comment

The 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);

@@ -31,6 +31,11 @@
#define TA_BINARY_FOUND 0
#define TA_BINARY_NOT_FOUND -1

/* support multiple TA load path */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking: s/support/Support/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix.

@@ -31,6 +31,11 @@
#define TA_BINARY_FOUND 0
#define TA_BINARY_NOT_FOUND -1

/* support multiple TA load path */
#define MAX_TA_PREFIX 8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's likely there will be less than 8 alternate dir paths, however it would be more flexible to remove that limitation and allocated ta_prefix[] dynamically.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-allocate enough entries is efficient if the number of entries is not large. I doubt the practicality for cases with more than 8 paths. Adding code and runt time dynamic allocation for virtually non-exist case, it's kind of over kill.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to not have built-in limitation if not strictly needed (IMHO).
I'll rely on maintainers point of view.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair. Let the maintainers to pick which way to go.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pick a dynamic solution.

@@ -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[MAX_TA_PREFIX] = {0};
int num_ta_prefix = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can (should) remove the initialization value when: global variables are default zero-initialized.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove the values.

CFG_TEE_CLIENT_LOAD_PATH can have multiple paths separated by :
Copy link
Contributor

@jforissier jforissier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many comments from me below 😉 I propose the following instead: #311.

i = 0;
#ifdef TEEC_TEST_LOAD_PATH
test_ta_prefix_multipath = strdup(TEEC_TEST_LOAD_PATH);
if (!test_ta_prefix) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_ta_prefix_multipath

}
while ((temp = strsep(&test_ta_prefix_multipath, ":")) != NULL) {
ta_prefix[i++] = temp;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ta_prefix[i] may be an empty string if multiple colons are found in a row.

@@ -762,30 +769,81 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}

/* Support multiple ta load paths */
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@@ -31,6 +31,8 @@ CFG_TEE_CLIENT_LOG_FILE ?= $(CFG_TEE_FS_PARENT_PATH)/teec.log

# CFG_TEE_CLIENT_LOAD_PATH
# The location of the client library file.
Copy link
Contributor

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.

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],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, the documentation for try_load_secure_module() lacks the description of its first two arguments.

exit:
free(test_ta_prefix_multipath);
free(ta_prefix_multipath);
free(ta_prefix);
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants