tee.txt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. TEE subsystem
  2. This document describes the TEE subsystem in Linux.
  3. A TEE (Trusted Execution Environment) is a trusted OS running in some
  4. secure environment, for example, TrustZone on ARM CPUs, or a separate
  5. secure co-processor etc. A TEE driver handles the details needed to
  6. communicate with the TEE.
  7. This subsystem deals with:
  8. - Registration of TEE drivers
  9. - Managing shared memory between Linux and the TEE
  10. - Providing a generic API to the TEE
  11. The TEE interface
  12. =================
  13. include/uapi/linux/tee.h defines the generic interface to a TEE.
  14. User space (the client) connects to the driver by opening /dev/tee[0-9]* or
  15. /dev/teepriv[0-9]*.
  16. - TEE_IOC_SHM_ALLOC allocates shared memory and returns a file descriptor
  17. which user space can mmap. When user space doesn't need the file
  18. descriptor any more, it should be closed. When shared memory isn't needed
  19. any longer it should be unmapped with munmap() to allow the reuse of
  20. memory.
  21. - TEE_IOC_VERSION lets user space know which TEE this driver handles and
  22. the its capabilities.
  23. - TEE_IOC_OPEN_SESSION opens a new session to a Trusted Application.
  24. - TEE_IOC_INVOKE invokes a function in a Trusted Application.
  25. - TEE_IOC_CANCEL may cancel an ongoing TEE_IOC_OPEN_SESSION or TEE_IOC_INVOKE.
  26. - TEE_IOC_CLOSE_SESSION closes a session to a Trusted Application.
  27. There are two classes of clients, normal clients and supplicants. The latter is
  28. a helper process for the TEE to access resources in Linux, for example file
  29. system access. A normal client opens /dev/tee[0-9]* and a supplicant opens
  30. /dev/teepriv[0-9].
  31. Much of the communication between clients and the TEE is opaque to the
  32. driver. The main job for the driver is to receive requests from the
  33. clients, forward them to the TEE and send back the results. In the case of
  34. supplicants the communication goes in the other direction, the TEE sends
  35. requests to the supplicant which then sends back the result.
  36. OP-TEE driver
  37. =============
  38. The OP-TEE driver handles OP-TEE [1] based TEEs. Currently it is only the ARM
  39. TrustZone based OP-TEE solution that is supported.
  40. Lowest level of communication with OP-TEE builds on ARM SMC Calling
  41. Convention (SMCCC) [2], which is the foundation for OP-TEE's SMC interface
  42. [3] used internally by the driver. Stacked on top of that is OP-TEE Message
  43. Protocol [4].
  44. OP-TEE SMC interface provides the basic functions required by SMCCC and some
  45. additional functions specific for OP-TEE. The most interesting functions are:
  46. - OPTEE_SMC_FUNCID_CALLS_UID (part of SMCCC) returns the version information
  47. which is then returned by TEE_IOC_VERSION
  48. - OPTEE_SMC_CALL_GET_OS_UUID returns the particular OP-TEE implementation, used
  49. to tell, for instance, a TrustZone OP-TEE apart from an OP-TEE running on a
  50. separate secure co-processor.
  51. - OPTEE_SMC_CALL_WITH_ARG drives the OP-TEE message protocol
  52. - OPTEE_SMC_GET_SHM_CONFIG lets the driver and OP-TEE agree on which memory
  53. range to used for shared memory between Linux and OP-TEE.
  54. The GlobalPlatform TEE Client API [5] is implemented on top of the generic
  55. TEE API.
  56. Picture of the relationship between the different components in the
  57. OP-TEE architecture.
  58. User space Kernel Secure world
  59. ~~~~~~~~~~ ~~~~~~ ~~~~~~~~~~~~
  60. +--------+ +-------------+
  61. | Client | | Trusted |
  62. +--------+ | Application |
  63. /\ +-------------+
  64. || +----------+ /\
  65. || |tee- | ||
  66. || |supplicant| \/
  67. || +----------+ +-------------+
  68. \/ /\ | TEE Internal|
  69. +-------+ || | API |
  70. + TEE | || +--------+--------+ +-------------+
  71. | Client| || | TEE | OP-TEE | | OP-TEE |
  72. | API | \/ | subsys | driver | | Trusted OS |
  73. +-------+----------------+----+-------+----+-----------+-------------+
  74. | Generic TEE API | | OP-TEE MSG |
  75. | IOCTL (TEE_IOC_*) | | SMCCC (OPTEE_SMC_CALL_*) |
  76. +-----------------------------+ +------------------------------+
  77. RPC (Remote Procedure Call) are requests from secure world to kernel driver
  78. or tee-supplicant. An RPC is identified by a special range of SMCCC return
  79. values from OPTEE_SMC_CALL_WITH_ARG. RPC messages which are intended for the
  80. kernel are handled by the kernel driver. Other RPC messages will be forwarded to
  81. tee-supplicant without further involvement of the driver, except switching
  82. shared memory buffer representation.
  83. References:
  84. [1] https://github.com/OP-TEE/optee_os
  85. [2] http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
  86. [3] drivers/tee/optee/optee_smc.h
  87. [4] drivers/tee/optee/optee_msg.h
  88. [5] http://www.globalplatform.org/specificationsdevice.asp look for
  89. "TEE Client API Specification v1.0" and click download.