Skip to content

New Design for TA-to-TA Invocation #178

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

Merged
merged 1 commit into from
Apr 29, 2025
Merged

Conversation

DemesneGH
Copy link
Contributor

Compared to #177, the Params and TaSession are re-organized and can be used in a more Rust style.
It also addressed some comments from the previous PR #177.

@DemesneGH DemesneGH requested review from ivila and m4sterchain April 8, 2025 10:47
Copy link

@m4sterchain m4sterchain left a comment

Choose a reason for hiding this comment

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

The abstraction looks clear and well-structured. I've added a few minor comments for consideration. Great work overall!

fn update_size_from_raw(&mut self, raw_param: &raw::TEE_Param) {
match &mut self.content {
ParamContent::MemrefOutput { buffer: _, written } => {
*written = unsafe { raw_param.memref.size };
Copy link

@m4sterchain m4sterchain Apr 8, 2025

Choose a reason for hiding this comment

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

I am curious why we consider accessing raw::TEE_Param is unsafe here. Can you add comment about the reason to the code? Or can we provide getter functions for raw::TEE_Param and discuss the safe/unsafe behavior inside the raw module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accessing union should be unsafe in Rust:
error[E0133]: access to union field is unsafe and requires unsafe function or block
--> /teaclave/optee-utee/src/tee_parameter.rs:152:28
|
152 | *written = raw_param.memref.size;
| ^^^^^^^^^^^^^^^^ access to union field
|
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior

Choose a reason for hiding this comment

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

I suggest we follow https://github.com/rust-lang/rust-clippy/issues/9330 to explicitly add comment to unsafe block; and run cargo lint to help automatically enforce available rules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add SAFETY comment for the modules inside this PR. Since cargo clippy infects many other modules, there will be another PR to address all rules.

ParamType::ValueInout => {
param.update_value_from_raw(raw_param);
}
_ => {}
Copy link

@m4sterchain m4sterchain Apr 8, 2025

Choose a reason for hiding this comment

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

Should we check against other param types? We can at least ensure

  1. ValueInput contents are never changed; if not, raise an error;
  2. out size for MemRef Out/InOut types always within the original bound; if not, raise an error;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. ValueInput contents are never changed; if not, raise an error;

For ValueInput, we will not read the TEEParam buffer after invoke, which means if it was changed we will ignore it. It is the same strategy as MemrefInput. Should we add the check for those input?

For 2., agree and will update

fn update_size_from_raw(&mut self, raw_param: &raw::TEE_Param) {
match &mut self.content {
ParamContent::MemrefOutput { buffer: _, written } => {
*written = unsafe { raw_param.memref.size };

Choose a reason for hiding this comment

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

I suggest we follow https://github.com/rust-lang/rust-clippy/issues/9330 to explicitly add comment to unsafe block; and run cargo lint to help automatically enforce available rules.

@DemesneGH DemesneGH force-pushed the param-reorg branch 2 times, most recently from 72434c8 to 297c56f Compare April 9, 2025 09:28
@DemesneGH
Copy link
Contributor Author

Updated for all above comments

@ivila
Copy link
Contributor

ivila commented Apr 10, 2025

Reviewed-by: Zehui Chen <[email protected]>

@ivila
Copy link
Contributor

ivila commented Apr 27, 2025

Should we merge this PR or are we waiting for something?

@DemesneGH
Copy link
Contributor Author

Any other comments? @m4sterchain

@m4sterchain
Copy link

LGTM.

This commit provides the Rust API for GP API TEE_InvokeTACommand(),
which enable the user TA calls another user TA or pseudo TA.

- Add abstraction of TeeParameters and TaSession;
- Add inter-ta example and test scripts.

Signed-off-by: Yuan Zhuang <[email protected]>
Reviewed-by: Zehui Chen <[email protected]>
@DemesneGH DemesneGH merged commit 0a0ab8a into apache:main Apr 29, 2025
14 checks passed
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.

3 participants