op-tee.rst 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ====================================================
  3. OP-TEE (Open Portable Trusted Execution Environment)
  4. ====================================================
  5. The OP-TEE driver handles OP-TEE [1] based TEEs. Currently it is only the ARM
  6. TrustZone based OP-TEE solution that is supported.
  7. Lowest level of communication with OP-TEE builds on ARM SMC Calling
  8. Convention (SMCCC) [2], which is the foundation for OP-TEE's SMC interface
  9. [3] used internally by the driver. Stacked on top of that is OP-TEE Message
  10. Protocol [4].
  11. OP-TEE SMC interface provides the basic functions required by SMCCC and some
  12. additional functions specific for OP-TEE. The most interesting functions are:
  13. - OPTEE_SMC_FUNCID_CALLS_UID (part of SMCCC) returns the version information
  14. which is then returned by TEE_IOC_VERSION
  15. - OPTEE_SMC_CALL_GET_OS_UUID returns the particular OP-TEE implementation, used
  16. to tell, for instance, a TrustZone OP-TEE apart from an OP-TEE running on a
  17. separate secure co-processor.
  18. - OPTEE_SMC_CALL_WITH_ARG drives the OP-TEE message protocol
  19. - OPTEE_SMC_GET_SHM_CONFIG lets the driver and OP-TEE agree on which memory
  20. range to used for shared memory between Linux and OP-TEE.
  21. The GlobalPlatform TEE Client API [5] is implemented on top of the generic
  22. TEE API.
  23. Picture of the relationship between the different components in the
  24. OP-TEE architecture::
  25. User space Kernel Secure world
  26. ~~~~~~~~~~ ~~~~~~ ~~~~~~~~~~~~
  27. +--------+ +-------------+
  28. | Client | | Trusted |
  29. +--------+ | Application |
  30. /\ +-------------+
  31. || +----------+ /\
  32. || |tee- | ||
  33. || |supplicant| \/
  34. || +----------+ +-------------+
  35. \/ /\ | TEE Internal|
  36. +-------+ || | API |
  37. + TEE | || +--------+--------+ +-------------+
  38. | Client| || | TEE | OP-TEE | | OP-TEE |
  39. | API | \/ | subsys | driver | | Trusted OS |
  40. +-------+----------------+----+-------+----+-----------+-------------+
  41. | Generic TEE API | | OP-TEE MSG |
  42. | IOCTL (TEE_IOC_*) | | SMCCC (OPTEE_SMC_CALL_*) |
  43. +-----------------------------+ +------------------------------+
  44. RPC (Remote Procedure Call) are requests from secure world to kernel driver
  45. or tee-supplicant. An RPC is identified by a special range of SMCCC return
  46. values from OPTEE_SMC_CALL_WITH_ARG. RPC messages which are intended for the
  47. kernel are handled by the kernel driver. Other RPC messages will be forwarded to
  48. tee-supplicant without further involvement of the driver, except switching
  49. shared memory buffer representation.
  50. OP-TEE device enumeration
  51. -------------------------
  52. OP-TEE provides a pseudo Trusted Application: drivers/tee/optee/device.c in
  53. order to support device enumeration. In other words, OP-TEE driver invokes this
  54. application to retrieve a list of Trusted Applications which can be registered
  55. as devices on the TEE bus.
  56. OP-TEE notifications
  57. --------------------
  58. There are two kinds of notifications that secure world can use to make
  59. normal world aware of some event.
  60. 1. Synchronous notifications delivered with ``OPTEE_RPC_CMD_NOTIFICATION``
  61. using the ``OPTEE_RPC_NOTIFICATION_SEND`` parameter.
  62. 2. Asynchronous notifications delivered with a combination of a non-secure
  63. edge-triggered interrupt and a fast call from the non-secure interrupt
  64. handler.
  65. Synchronous notifications are limited by depending on RPC for delivery,
  66. this is only usable when secure world is entered with a yielding call via
  67. ``OPTEE_SMC_CALL_WITH_ARG``. This excludes such notifications from secure
  68. world interrupt handlers.
  69. An asynchronous notification is delivered via a non-secure edge-triggered
  70. interrupt to an interrupt handler registered in the OP-TEE driver. The
  71. actual notification value are retrieved with the fast call
  72. ``OPTEE_SMC_GET_ASYNC_NOTIF_VALUE``. Note that one interrupt can represent
  73. multiple notifications.
  74. One notification value ``OPTEE_SMC_ASYNC_NOTIF_VALUE_DO_BOTTOM_HALF`` has a
  75. special meaning. When this value is received it means that normal world is
  76. supposed to make a yielding call ``OPTEE_MSG_CMD_DO_BOTTOM_HALF``. This
  77. call is done from the thread assisting the interrupt handler. This is a
  78. building block for OP-TEE OS in secure world to implement the top half and
  79. bottom half style of device drivers.
  80. OPTEE_INSECURE_LOAD_IMAGE Kconfig option
  81. ----------------------------------------
  82. The OPTEE_INSECURE_LOAD_IMAGE Kconfig option enables the ability to load the
  83. BL32 OP-TEE image from the kernel after the kernel boots, rather than loading
  84. it from the firmware before the kernel boots. This also requires enabling the
  85. corresponding option in Trusted Firmware for Arm. The Trusted Firmware for Arm
  86. documentation [6] explains the security threat associated with enabling this as
  87. well as mitigations at the firmware and platform level.
  88. There are additional attack vectors/mitigations for the kernel that should be
  89. addressed when using this option.
  90. 1. Boot chain security.
  91. * Attack vector: Replace the OP-TEE OS image in the rootfs to gain control of
  92. the system.
  93. * Mitigation: There must be boot chain security that verifies the kernel and
  94. rootfs, otherwise an attacker can modify the loaded OP-TEE binary by
  95. modifying it in the rootfs.
  96. 2. Alternate boot modes.
  97. * Attack vector: Using an alternate boot mode (i.e. recovery mode), the
  98. OP-TEE driver isn't loaded, leaving the SMC hole open.
  99. * Mitigation: If there are alternate methods of booting the device, such as a
  100. recovery mode, it should be ensured that the same mitigations are applied
  101. in that mode.
  102. 3. Attacks prior to SMC invocation.
  103. * Attack vector: Code that is executed prior to issuing the SMC call to load
  104. OP-TEE can be exploited to then load an alternate OS image.
  105. * Mitigation: The OP-TEE driver must be loaded before any potential attack
  106. vectors are opened up. This should include mounting of any modifiable
  107. filesystems, opening of network ports or communicating with external
  108. devices (e.g. USB).
  109. 4. Blocking SMC call to load OP-TEE.
  110. * Attack vector: Prevent the driver from being probed, so the SMC call to
  111. load OP-TEE isn't executed when desired, leaving it open to being executed
  112. later and loading a modified OS.
  113. * Mitigation: It is recommended to build the OP-TEE driver as builtin driver
  114. rather than as a module to prevent exploits that may cause the module to
  115. not be loaded.
  116. References
  117. ==========
  118. [1] https://github.com/OP-TEE/optee_os
  119. [2] http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
  120. [3] drivers/tee/optee/optee_smc.h
  121. [4] drivers/tee/optee/optee_msg.h
  122. [5] http://www.globalplatform.org/specificationsdevice.asp look for
  123. "TEE Client API Specification v1.0" and click download.
  124. [6] https://trustedfirmware-a.readthedocs.io/en/latest/threat_model/threat_model.html