This is an automated email from the ASF dual-hosted git repository.
yuanz pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/incubator-teaclave-trustzone-sdk.git
The following commit(s) were added to refs/heads/master by this push:
new 7a7d847 optee-teec: update OP-TEE implementation fields (#108)
7a7d847 is described below
commit 7a7d847c8c49e10f0add6cc8fcba3d1b61fc9cc7
Author: Tom Hebb <[email protected]>
AuthorDate: Sat Apr 22 22:41:35 2023 -0400
optee-teec: update OP-TEE implementation fields (#108)
We've been updating our OP-TEE version without updating our Rust
definitions of its API types. Since the GlobalPlatform TEE Client API
uses client-allocated API objects, our code needs to be aware of and
match the implementation-specific fields used by the version of libteec
we link to.
This pulls in two changes that we missed, one of which increases the
space we need to allocate for TEEC_Context and so results in memory
unsafety with our current definitions:
- commit 20b567068a37 ("libutee: flag NULL pointer using invalid shm")
[OP-TEE/optee_client#145]
- commit 4f3d4cbb7824 ("libteec: fix TEEC_RegisterSharedMemory() with a
fallback option") [OP-TEE/optee_client#217]
---
optee-teec/optee-teec-sys/src/tee_client_api.rs | 9 ++++++++-
optee-teec/src/context.rs | 10 +++++++---
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/optee-teec/optee-teec-sys/src/tee_client_api.rs
b/optee-teec/optee-teec-sys/src/tee_client_api.rs
index d647342..0e04ce1 100644
--- a/optee-teec/optee-teec-sys/src/tee_client_api.rs
+++ b/optee-teec/optee-teec-sys/src/tee_client_api.rs
@@ -80,6 +80,7 @@ pub type TEEC_Result = u32;
pub struct TEEC_Context {
pub fd: c_int,
pub reg_mem: bool,
+ pub memref_null: bool,
}
#[repr(C)]
@@ -96,6 +97,12 @@ pub struct TEEC_Session {
pub session_id: u32,
}
+#[repr(C)]
+pub union SharedMemoryFlagsCompat {
+ dummy: bool,
+ flags: u8,
+}
+
#[repr(C)]
pub struct TEEC_SharedMemory {
pub buffer: *mut c_void,
@@ -105,7 +112,7 @@ pub struct TEEC_SharedMemory {
pub alloced_size: size_t,
pub shadow_buffer: *mut c_void,
pub registered_fd: c_int,
- pub buffer_allocated: bool,
+ pub internal: SharedMemoryFlagsCompat,
}
#[derive(Copy, Clone)]
diff --git a/optee-teec/src/context.rs b/optee-teec/src/context.rs
index 3dfdf14..5f79124 100644
--- a/optee-teec/src/context.rs
+++ b/optee-teec/src/context.rs
@@ -36,7 +36,7 @@ impl Context {
/// let ctx = Context::new().unwrap();
/// ```
pub fn new() -> Result<Context> {
- Context::new_raw(0, true).map(|raw| Context { raw })
+ Context::new_raw(0, true, false).map(|raw| Context { raw })
}
/// Creates a raw TEE client context with implementation defined
parameters.
@@ -46,8 +46,12 @@ impl Context {
/// ```
/// let raw_ctx: optee_teec_sys::TEEC_Context = Context::new_raw(0,
true).unwrap();
/// ```
- pub fn new_raw(fd: libc::c_int, reg_mem: bool) ->
Result<raw::TEEC_Context> {
- let mut raw_ctx = raw::TEEC_Context { fd, reg_mem };
+ pub fn new_raw(fd: libc::c_int, reg_mem: bool, memref_null: bool) ->
Result<raw::TEEC_Context> {
+ let mut raw_ctx = raw::TEEC_Context {
+ fd,
+ reg_mem,
+ memref_null,
+ };
unsafe {
match raw::TEEC_InitializeContext(ptr::null_mut() as *mut
libc::c_char, &mut raw_ctx) {
raw::TEEC_SUCCESS => Ok(raw_ctx),
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]