-
Notifications
You must be signed in to change notification settings - Fork 237
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
Type definitions in tee_client_api.h violate the GlobalPlatform TEE Client API spec #348
Comments
When we implemented this we read " imp;" in |
Cool, thanks for confirming there's not some intentional reason for how we do it that I missed. I probably won't have time to set up an OP-TEE dev environment and make/test a PR any time soon, sadly. I'm already on a bit of a tangent with the Teaclave modifications I'm making, and last night I discovered that the other implementation I'm trying to target actually has the same bug, which means I'd still need to workaround it in Rust even if OP-TEE gets fixed. I'll leave this issue open as documentation and in case anyone else wants to take it on. |
GlobalPlatform TEE Client API Specification v1.0 specifies that the structs TEEC_Context, TEEC_Session, TEEC_SharedMemory, and TEEC_Operation shall have a user defined struct named imp. In OP-TEE the struct is not there and instead the user defined fields are declared directly in the top structs. This commit introduces the imp struct to better support using different implementations. The imp fields now represent the implementation defined parts of the structs that was previously declared directly in the top struct. All previously available parameters are preserved in the imp struct. Link: OP-TEE#348 Reported-by: Tom Hebb <[email protected]> Signed-off-by: Julianus Larson <[email protected]>
GlobalPlatform TEE Client API Specification v1.0 specifies that the structs TEEC_Context, TEEC_Session, TEEC_SharedMemory, and TEEC_Operation shall have a user defined struct named imp. Adding the missing imp struct to the structs in OP-TEE is an ABI breakage which requires a version major update of libteec as explained by Jerome Forissier. Link: OP-TEE#348 Reported-by: Tom Hebb <[email protected]> Signed-off-by: Julianus Larson <[email protected]>
GlobalPlatform TEE Client API Specification v1.0 specifies that the structs TEEC_Context, TEEC_Session, TEEC_SharedMemory, and TEEC_Operation shall have a user defined struct named imp. In OP-TEE the struct is not there and instead the user defined fields are declared directly in the top structs. This commit introduces the imp struct to better support using different implementations. The imp fields now represent the implementation defined parts of the structs that was previously declared directly in the top struct. All previously available parameters are preserved in the imp struct. Adding the missing imp struct to the structs in OP-TEE is an ABI breakage which requires a version major update of libteec as explained by Jerome Forissier. Link: OP-TEE#348 Reported-by: Tom Hebb <[email protected]> Signed-off-by: Julianus Larson <[email protected]>
GlobalPlatform TEE Client API Specification v1.0 specifies that the structs TEEC_Context, TEEC_Session, TEEC_SharedMemory, and TEEC_Operation shall have a user defined struct named imp. In OP-TEE the struct is not there and instead the user defined fields are declared directly in the top structs. This commit introduces the imp struct to better support using different implementations. The imp fields now represent the implementation defined parts of the structs that was previously declared directly in the top struct. All previously available parameters are preserved in the imp struct. Adding the missing imp struct to the structs in OP-TEE is an ABI breakage which requires a version major update of libteec as explained by Jerome Forissier. Link: OP-TEE#348 Reported-by: Tom Hebb <[email protected]> Signed-off-by: Julianus Larson <[email protected]>
GlobalPlatform TEE Client API Specification v1.0 specifies that the structs TEEC_Context, TEEC_Session, TEEC_SharedMemory, and TEEC_Operation shall have a user defined struct named imp. In OP-TEE the struct is not there and instead the user defined fields are declared directly in the top structs. This commit introduces the imp struct to better support using different implementations. The imp fields now represent the implementation defined parts of the structs that was previously declared directly in the top struct. All previously available parameters are preserved in the imp struct. Adding the missing imp struct to the structs in OP-TEE is an ABI breakage which requires a version major update of libteec as explained by Jerome Forissier. Link: OP-TEE#348 Reported-by: Tom Hebb <[email protected]> Signed-off-by: Julianus Larson <[email protected]> Fixed spacing
GlobalPlatform TEE Client API Specification v1.0 specifies that the structs TEEC_Context, TEEC_Session, TEEC_SharedMemory, and TEEC_Operation shall have a user defined struct named imp. In OP-TEE the struct is not there and instead the user defined fields are declared directly in the top structs. This commit introduces the imp struct to better support using different implementations. The imp fields now represent the implementation defined parts of the structs that was previously declared directly in the top struct. All previously available parameters are preserved in the imp struct. The updated version of the imp structure makes it easier to create a binding for Rust. Adding the missing imp struct to the structs in OP-TEE is an ABI breakage which requires a version major update of libteec as explained by Jerome Forissier. Link: OP-TEE#348 Reported-by: Tom Hebb <[email protected]> Signed-off-by: Julianus Larson <[email protected]> Fixed spacing
GlobalPlatform TEE Client API Specification v1.0 specifies that the structs TEEC_Context, TEEC_Session, TEEC_SharedMemory, and TEEC_Operation shall have a user defined struct named imp. In OP-TEE the struct is not there and instead the user defined fields are declared directly in the top structs. This commit introduces the imp struct to better support using different implementations. The imp fields now represent the implementation defined parts of the structs that was previously declared directly in the top struct. All previously available parameters are preserved in the imp struct. The updated version of the imp structure makes it easier to create a binding for Rust. Adding the missing imp struct to the structs in OP-TEE is an ABI breakage which requires a version major update of libteec as explained by Jerome Forissier. Link: OP-TEE#348 Reported-by: Tom Hebb <[email protected]> Signed-off-by: Julianus Larson <[email protected]> Acked-by: Etienne Carriere <[email protected]> Acked-by: Jerome Forissier <[email protected]> Fixed spacing
GlobalPlatform TEE Client API Specification v1.0 specifies that the structs TEEC_Context, TEEC_Session, TEEC_SharedMemory, and TEEC_Operation shall have a user defined struct named imp. In OP-TEE the struct is not there and instead the user defined fields are declared directly in the top structs. This commit introduces the imp struct to better support using different implementations. The imp fields now represent the implementation defined parts of the structs that was previously declared directly in the top struct. All previously available parameters are preserved in the imp struct. The updated version of the imp structure makes it easier to create a binding for Rust. Adding the missing imp struct to the structs in OP-TEE is an ABI breakage which requires a version major update of libteec as explained by Jerome Forissier. Link: OP-TEE#348 Reported-by: Tom Hebb <[email protected]> Signed-off-by: Julianus Larson <[email protected]> Acked-by: Etienne Carriere <[email protected]> Acked-by: Jerome Forissier <[email protected]> Fixed spacing Signed-off-by: Julianus Larson <[email protected]>
GlobalPlatform TEE Client API Specification v1.0 specifies that the structs TEEC_Context, TEEC_Session, TEEC_SharedMemory, and TEEC_Operation shall have a user defined struct named imp. In OP-TEE the struct is not there and instead the user defined fields are declared directly in the top structs. This commit introduces the imp struct to better support using different implementations. The imp fields now represent the implementation defined parts of the structs that was previously declared directly in the top struct. All previously available parameters are preserved in the imp struct. The updated version of the imp structure makes it easier to create a binding for Rust. Adding the missing imp struct to the structs in OP-TEE is an ABI breakage which requires a version major update of libteec as explained by Jerome Forissier. Link: OP-TEE#348 Reported-by: Tom Hebb <[email protected]> Signed-off-by: Julianus Larson <[email protected]> Acked-by: Etienne Carriere <[email protected]> Acked-by: Jerome Forissier <[email protected]> Fixed spacing Signed-off-by: Julianus Larson <[email protected]>
GlobalPlatform TEE Client API Specification v1.0 specifies that the structs TEEC_Context, TEEC_Session, TEEC_SharedMemory, and TEEC_Operation shall have a user defined struct named imp. In OP-TEE the struct is not there and instead the user defined fields are declared directly in the top structs. This commit introduces the imp struct to better support using different implementations. The imp fields now represent the implementation defined parts of the structs that was previously declared directly in the top struct. All previously available parameters are preserved in the imp struct. The updated version of the imp structure makes it easier to create a binding for Rust. Adding the missing imp struct to the structs in OP-TEE is an ABI breakage which requires a version major update of libteec. Link: #348 Reported-by: Tom Hebb <[email protected]> Signed-off-by: Julianus Larson <[email protected]> Acked-by: Etienne Carriere <[email protected]> Acked-by: Jerome Forissier <[email protected]>
Fixed by #349 |
Background
The GlobalPlatform TEE Client API Specification v1.0, which OP-TEE's libteec adheres to, defines API objects as structures visible to and allocated by the user rather than as opaque pointers.
While some of those objects—like
TEEC_UUID
—are fully specified by the spec, others—specificallyTEEC_Context
,TEEC_Session
,TEEC_SharedMemory
, andTEEC_Operation
—end with animp
field of a type defined by the implementation. For example,TEEC_SharedMemory
is specified as follows:And this is what the spec has to say about the
imp
field (emphasis mine):The problem
But here's how we currently define our version of
TEEC_SharedMemory
:optee_client/public/tee_client_api.h
Lines 291 to 306 in 8533e0e
We don't have a field named
imp
at all! We instead put multiple implementation-specific fields right in the struct, in direct violation of the spec. I imagine we did this because it seemed an immaterial distinction, but I've found a case where it makes a difference for me as a user of libteec:Why it matters
I'm currently working on making Apache's Teaclave TrustZone SDK, a Rust abstraction over libteec, work with more implementations than just OP-TEE. Part of that work is making its FFI structure definitions, which currently hardcode OP-TEE's implementation-specific fields, generic over multiple implementations. The obvious way to do that is to use Rust generics, adding a type parameter that defines the concrete type of the
imp
field. But that requires me to split the OP-TEE implementation-specific fields into their own structure, resulting in this concrete type:Unfortunately, in C, that type does not have the same layout as the one from tee_client_api.h shown above. The nested struct changes how padding is calculated: on a 64-bit system, the type shown above has 4 bytes of padding between
flags
andid
that libteec doesn't expect. (Note that I haven't verified the exact layouts empirically, but I'm pretty sure I'm right.)I can work around this, but it means making each implementation-specific struct implement a common trait full of boilerplate getters and setters instead of just being able to access the fields directly from generic code. I'd prefer not to do that if I can avoid it.
Other implementations
There's at least one TEE that does follow my reading of the spec: Trustonic defines
TEEC_SharedMemory
as follows:The text was updated successfully, but these errors were encountered: