plugins: example of using supplicant syslog plugin from TA code - #79
Conversation
|
The example relates to: |
66cacca to
835b031
Compare
etienne-lms
left a comment
There was a problem hiding this comment.
Thanks for the P-R.
Some minor comments.
It would be nice to have a Cmake script. I'll see if I can help.
The supplicant plugin syslog shall be built as a .so and installed in /usr/lib/tee-supplicant/plugins/ right?
| * TA properties: multi-instance TA, no specific attribute | ||
| * TA_FLAG_EXEC_DDR is meaningless but mandated. | ||
| */ | ||
| #define TA_FLAGS TA_FLAG_EXEC_DDR |
There was a problem hiding this comment.
TA_FLAG_EXEC_DDR mandated? maybe by older optee_os. Can you check you still have this dependency. It not, prefer 0 here.
There was a problem hiding this comment.
You are right. TA_FLAG_EXEC_DDR is already deprecated. I will replace to 0.
| case PLUGIN_TA_PING: | ||
| return syslog_plugin_ping(); | ||
| default: | ||
| return TEE_ERROR_BAD_PARAMETERS; |
There was a problem hiding this comment.
TEE_ERROR_NOT_SUPPORTED
| inc_var++); | ||
|
|
||
| params[2].memref.buffer = log_str; | ||
| params[2].memref.size = strlen(log_str); |
There was a problem hiding this comment.
Suggest to add trace here IMSG("Push syslog plugin string \"%s\"", log_str);
| TEE_UUID syslog_uuid = SYSLOG_PLUGIN_UUID; | ||
| TEE_TASessionHandle sess; | ||
| TEE_Param params[4] = { 0 }; | ||
| uint32_t types, orig; |
There was a problem hiding this comment.
Prefer to follow the same codiing rules as optee_os/optee_client.
uint32_t types = 0;
uint32_t orig = 0;| uint32_t d2; | ||
| uint32_t d3; | ||
| uint32_t d4; | ||
| } plug_u; |
|
|
||
| static TEE_Result syslog_plugin_ping(void) | ||
| { | ||
| TEE_Result res; |
There was a problem hiding this comment.
Prefer to follow the same codiing rules as optee_os/optee_client: init all local vars.
| if (param_types != exp_param_types) | ||
| return TEE_ERROR_BAD_PARAMETERS; | ||
|
|
||
| /* If return value != TEE_SUCCESS the session will not be created. */ |
There was a problem hiding this comment.
can remove this comment
| * with a value to be able to identify this session in subsequent calls to the | ||
| * TA. In this function you will normally do the global initialization for the | ||
| * TA. | ||
| */ |
There was a problem hiding this comment.
I suggest to remove these inline comments
| * Copyright (c) 2020, Open Mobile Platform LLC | ||
| */ | ||
|
|
||
| #ifndef TA_PLUGIN_H |
|
|
||
| int main(void) | ||
| { | ||
| int i; |
There was a problem hiding this comment.
default init all loval variables
Do you mean Cmake script to build
Yes, it's right. |
|
All comments have been addressed |
| @@ -0,0 +1,20 @@ | |||
| /* SPDX-License-Identifier: BSD-2-Clause */ | |||
There was a problem hiding this comment.
This file should be made available from optee_client instead to avoid keeping possibly diverging copies.
There was a problem hiding this comment.
I droped this file.
Now we use $(TEEC_EXPORT)/include in syslog Makefile
| /* | ||
| * Interface with syslog tee-supplicant plugin | ||
| */ | ||
| #define SYSLOG_PLUGIN_UUID { 0x96bcf744, 0x4f72, 0x4866, \ |
There was a problem hiding this comment.
Wouldn't it make sense to have a shared .h file with all this?
|
All comments have been addressed |
9d4a5b6 to
ab021b7
Compare
| /* Initialize a context connecting us to the TEE */ | ||
| res = TEEC_InitializeContext(NULL, &ctx); | ||
| if (res != TEEC_SUCCESS) | ||
| errx(1, "TEEC_InitializeContext failed with code 0x%x", res); |
There was a problem hiding this comment.
Please use %#"PRIx32 instead of 0x%x". res is a basically uint32_t.
Same below for the other format strings.
|
|
||
| /* 'sub_cmd' in this case means priority according syslog.h */ | ||
| openlog(NULL, LOG_CONS | LOG_PID, LOG_DAEMON); | ||
| syslog((int)sub_cmd, "%s", (const char *)data); |
There was a problem hiding this comment.
What if data isn't null terminated?
There was a problem hiding this comment.
In this example I use null-terminated strings for the plugin to pass them to syslog().
But actually, data_len stores real size of the data. that's why we can use data and data_len in any other cases of the use of plugins.
There was a problem hiding this comment.
Yes, obviously it works but it isn't robust. Bear in mind that people might copy these examples.
I'd prefer something more safe like:
syslog(sub_cmd, "%*s", (int)data_len, (const char *)data);|
All comments have been addressed |
|
|
TEE clients can add to the tee-supplicant own plugins. This feature makes the supplicant a bit more flexible in terms of providing services. Any external TEE services can be designed as a tee-supplicant plugin. User TAs can interact with the plugins using libutee and the OP-TEE kernel code can use a special plugin PRC for it. This patch adds example of using the plugin framework. 'syslog' plugin is used as an example. It can write log messages from OP-TEE (TAs or kernel) to system log. Also patch adds a new TA, which interacts with the 'syslog' plugin with the help of 'tee_invoke_supp_plugin()'. This TA increments a value and prints some strings to the syslog. Also patch adds a host CA, which calls the TA 'TA_PING_CNT' times. If the example works successfully, we can find the following strings in the log file (for qemu it's '/var/log/messages' file): ``` 21:18:05 buildroot daemon.info tee-supplicant[92]: Hello, plugin! value = 0x0 21:18:07 buildroot daemon.info tee-supplicant[92]: Hello, plugin! value = 0x1 21:18:09 buildroot daemon.info tee-supplicant[92]: Hello, plugin! value = 0x2 21:18:11 buildroot daemon.info tee-supplicant[92]: Hello, plugin! value = 0x3 21:18:13 buildroot daemon.info tee-supplicant[92]: Hello, plugin! value = 0x4 ``` Signed-off-by: Aleksandr Anisimov <a.anisimov@omprussia.ru> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
b7a7c84 to
b4dc6d8
Compare
|
The commit updated, thanks for the review! |
TEE clients can add to the tee-supplicant an own plugin.
This feature makes the supplicant a bit more flexible
in terms of providing services. Any external TEE services
can be designed as a tee-supplicant plugin.
User TAs and also the OP-TEE kernel code can interact
with the plugins with the help of the special PRC.
This patch adds example of using the plugin framework.
By default in tee-supplicant there is 'syslog' plugin.
It can write log messages from OP-TEE (TAs or kernel)
to system log. You can find the implementation of the plugin
in 'tee-supplicant/plugins/syslog/syslog_plugin.c' file.
This example adds a new TA, which interacts with
'syslog' plugin with the help of the plugin-pta.
This TA increments a value and prints some strings
to the syslog. Also patch adds a host CA, which
calls the TA 'TA_PING_CNT' times.
If the example works successfully, we can find the following
strings in the log file (for qemu it's '/var/log/messages' file):
Signed-off-by: Aleksandr Anisimov a.anisimov@omprussia.ru