167 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3====================================================4OP-TEE (Open Portable Trusted Execution Environment)5====================================================6 7The OP-TEE driver handles OP-TEE [1] based TEEs. Currently it is only the ARM8TrustZone based OP-TEE solution that is supported.9 10Lowest level of communication with OP-TEE builds on ARM SMC Calling11Convention (SMCCC) [2], which is the foundation for OP-TEE's SMC interface12[3] used internally by the driver. Stacked on top of that is OP-TEE Message13Protocol [4].14 15OP-TEE SMC interface provides the basic functions required by SMCCC and some16additional functions specific for OP-TEE. The most interesting functions are:17 18- OPTEE_SMC_FUNCID_CALLS_UID (part of SMCCC) returns the version information19 which is then returned by TEE_IOC_VERSION20 21- OPTEE_SMC_CALL_GET_OS_UUID returns the particular OP-TEE implementation, used22 to tell, for instance, a TrustZone OP-TEE apart from an OP-TEE running on a23 separate secure co-processor.24 25- OPTEE_SMC_CALL_WITH_ARG drives the OP-TEE message protocol26 27- OPTEE_SMC_GET_SHM_CONFIG lets the driver and OP-TEE agree on which memory28 range to used for shared memory between Linux and OP-TEE.29 30The GlobalPlatform TEE Client API [5] is implemented on top of the generic31TEE API.32 33Picture of the relationship between the different components in the34OP-TEE architecture::35 36 User space Kernel Secure world37 ~~~~~~~~~~ ~~~~~~ ~~~~~~~~~~~~38 +--------+ +-------------+39 | Client | | Trusted |40 +--------+ | Application |41 /\ +-------------+42 || +----------+ /\43 || |tee- | ||44 || |supplicant| \/45 || +----------+ +-------------+46 \/ /\ | TEE Internal|47 +-------+ || | API |48 + TEE | || +--------+--------+ +-------------+49 | Client| || | TEE | OP-TEE | | OP-TEE |50 | API | \/ | subsys | driver | | Trusted OS |51 +-------+----------------+----+-------+----+-----------+-------------+52 | Generic TEE API | | OP-TEE MSG |53 | IOCTL (TEE_IOC_*) | | SMCCC (OPTEE_SMC_CALL_*) |54 +-----------------------------+ +------------------------------+55 56RPC (Remote Procedure Call) are requests from secure world to kernel driver57or tee-supplicant. An RPC is identified by a special range of SMCCC return58values from OPTEE_SMC_CALL_WITH_ARG. RPC messages which are intended for the59kernel are handled by the kernel driver. Other RPC messages will be forwarded to60tee-supplicant without further involvement of the driver, except switching61shared memory buffer representation.62 63OP-TEE device enumeration64-------------------------65 66OP-TEE provides a pseudo Trusted Application: drivers/tee/optee/device.c in67order to support device enumeration. In other words, OP-TEE driver invokes this68application to retrieve a list of Trusted Applications which can be registered69as devices on the TEE bus.70 71OP-TEE notifications72--------------------73 74There are two kinds of notifications that secure world can use to make75normal world aware of some event.76 771. Synchronous notifications delivered with ``OPTEE_RPC_CMD_NOTIFICATION``78 using the ``OPTEE_RPC_NOTIFICATION_SEND`` parameter.792. Asynchronous notifications delivered with a combination of a non-secure80 edge-triggered interrupt and a fast call from the non-secure interrupt81 handler.82 83Synchronous notifications are limited by depending on RPC for delivery,84this is only usable when secure world is entered with a yielding call via85``OPTEE_SMC_CALL_WITH_ARG``. This excludes such notifications from secure86world interrupt handlers.87 88An asynchronous notification is delivered via a non-secure edge-triggered89interrupt to an interrupt handler registered in the OP-TEE driver. The90actual notification value are retrieved with the fast call91``OPTEE_SMC_GET_ASYNC_NOTIF_VALUE``. Note that one interrupt can represent92multiple notifications.93 94One notification value ``OPTEE_SMC_ASYNC_NOTIF_VALUE_DO_BOTTOM_HALF`` has a95special meaning. When this value is received it means that normal world is96supposed to make a yielding call ``OPTEE_MSG_CMD_DO_BOTTOM_HALF``. This97call is done from the thread assisting the interrupt handler. This is a98building block for OP-TEE OS in secure world to implement the top half and99bottom half style of device drivers.100 101OPTEE_INSECURE_LOAD_IMAGE Kconfig option102----------------------------------------103 104The OPTEE_INSECURE_LOAD_IMAGE Kconfig option enables the ability to load the105BL32 OP-TEE image from the kernel after the kernel boots, rather than loading106it from the firmware before the kernel boots. This also requires enabling the107corresponding option in Trusted Firmware for Arm. The Trusted Firmware for Arm108documentation [6] explains the security threat associated with enabling this as109well as mitigations at the firmware and platform level.110 111There are additional attack vectors/mitigations for the kernel that should be112addressed when using this option.113 1141. Boot chain security.115 116 * Attack vector: Replace the OP-TEE OS image in the rootfs to gain control of117 the system.118 119 * Mitigation: There must be boot chain security that verifies the kernel and120 rootfs, otherwise an attacker can modify the loaded OP-TEE binary by121 modifying it in the rootfs.122 1232. Alternate boot modes.124 125 * Attack vector: Using an alternate boot mode (i.e. recovery mode), the126 OP-TEE driver isn't loaded, leaving the SMC hole open.127 128 * Mitigation: If there are alternate methods of booting the device, such as a129 recovery mode, it should be ensured that the same mitigations are applied130 in that mode.131 1323. Attacks prior to SMC invocation.133 134 * Attack vector: Code that is executed prior to issuing the SMC call to load135 OP-TEE can be exploited to then load an alternate OS image.136 137 * Mitigation: The OP-TEE driver must be loaded before any potential attack138 vectors are opened up. This should include mounting of any modifiable139 filesystems, opening of network ports or communicating with external140 devices (e.g. USB).141 1424. Blocking SMC call to load OP-TEE.143 144 * Attack vector: Prevent the driver from being probed, so the SMC call to145 load OP-TEE isn't executed when desired, leaving it open to being executed146 later and loading a modified OS.147 148 * Mitigation: It is recommended to build the OP-TEE driver as builtin driver149 rather than as a module to prevent exploits that may cause the module to150 not be loaded.151 152References153==========154 155[1] https://github.com/OP-TEE/optee_os156 157[2] http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html158 159[3] drivers/tee/optee/optee_smc.h160 161[4] drivers/tee/optee/optee_msg.h162 163[5] http://www.globalplatform.org/specificationsdevice.asp look for164 "TEE Client API Specification v1.0" and click download.165 166[6] https://trustedfirmware-a.readthedocs.io/en/latest/threat_model/threat_model.html167