Skip to content

Commit bf071e5

Browse files
author
Hernan Gatta
committed
libteec: implement OCALL support during function invocation
OCALLs allow a TA to invoke functions on their CA with parameters, if desired. The flow begins when a CA calls TEEC_InvokeFunction. If the TEE context was initialized with the OCALL setting, libteec includes an additional parameter, the OCALL parameter, in the function invocation IOCTL. The presence of the OCALL parameter lets the kernel driver know that an OCALL may result from the invocation. If an OCALL does arrive from the TA, the OCALL parameter includes information about the OCALL, including the ID of the function that libteec must handle. These are: allocate shared memory, free shared memory, and invoke a function on the CA. If either of the first two functions arrive at libteec, the library handles these on behalf of the CA, allocating and freeing shared memory as necessary. When the third function arrives, libteec processes the OCALL's parameters. These will have temporarily replaced the parameters of the original function invocation. Additionally, the 'func' element of the IOCTL parameters will have been modified to carry the command ID that the TA requests that the CA execute on its behalf. The library passes this ID along with the parameters and arbitrary data pointers configured via the settings API to the CA-provided OCALL handler. After the handler is finished processing the request, libteec performs minor post-processing on the parameters and calls back into the driver to let it know that the OCALL has been handled. It is possible for a TA to invoke multiple OCALLs in the same originating function invocation. Signed-off-by: Hernan Gatta <hegatta@microsoft.com>
1 parent dacd6a3 commit bf071e5

File tree

3 files changed

+370
-11
lines changed

3 files changed

+370
-11
lines changed

libteec/include/linux/tee.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
/* Flags relating to shared memory */
4646
#define TEE_IOCTL_SHM_MAPPED 0x1 /* memory mapped in normal world */
4747
#define TEE_IOCTL_SHM_DMA_BUF 0x2 /* dma-buf handle on shared memory */
48+
#define TEE_IOCTL_SHM_OCALL 0x4 /* memory used for an OCALL */
4849

4950
#define TEE_MAX_ARG_SIZE 1024
5051

@@ -168,9 +169,14 @@ struct tee_ioctl_shm_register_fd_data {
168169
/* Meta parameter carrying extra information about the message. */
169170
#define TEE_IOCTL_PARAM_ATTR_META 0x100
170171

172+
/* Parameter carrying information about an OCALL reply or request. */
173+
#define TEE_IOCTL_PARAM_ATTR_OCALL 0x200
174+
171175
/* Mask of all known attr bits */
172176
#define TEE_IOCTL_PARAM_ATTR_MASK \
173-
(TEE_IOCTL_PARAM_ATTR_TYPE_MASK | TEE_IOCTL_PARAM_ATTR_META)
177+
(TEE_IOCTL_PARAM_ATTR_TYPE_MASK | \
178+
TEE_IOCTL_PARAM_ATTR_META | \
179+
TEE_IOCTL_PARAM_ATTR_OCALL)
174180

175181
/*
176182
* Matches TEEC_LOGIN_* in GP TEE Client API
@@ -244,6 +250,33 @@ struct tee_ioctl_open_session_arg {
244250
#define TEE_IOC_OPEN_SESSION _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 2, \
245251
struct tee_ioctl_buf_data)
246252

253+
/*
254+
* Command sent to the CA to request allocation of shared memory to carry the
255+
* parameters of an OCALL
256+
*
257+
* [out] param[0].u.value.a SHM ID
258+
* [in] param[0].u.value.b requested memory size
259+
*
260+
* Note: [in] means from driver to CA, [out], from CA to driver.
261+
*/
262+
#define TEE_IOCTL_OCALL_CMD_SHM_ALLOC 1
263+
264+
/*
265+
* Command sent to the CA to free previously allocated shared memory.
266+
*
267+
* [in] param[0].u.value.a SHM ID
268+
*
269+
* Note: [in] means from driver to CA.
270+
*/
271+
#define TEE_IOCTL_OCALL_CMD_SHM_FREE 2
272+
273+
/*
274+
* Command sent to the CA to execute an OCALL by Id.
275+
*
276+
* [any] param[0..3].u.* carry OCALL parameters
277+
*/
278+
#define TEE_IOCTL_OCALL_CMD_INVOKE 3
279+
247280
/**
248281
* struct tee_ioctl_invoke_func_arg - Invokes a function in a Trusted
249282
* Application

0 commit comments

Comments
 (0)