Skip to contentSkip to conversation

generic TEE subsystem

PATCH RESEND Superseded Jens Wiklander 4 participants 12 messages Oct 28, 2016 – Nov 3, 2016

Subsystems (4)

v12 of 16 Superseded Latest is v16 →

lore
Share & tools
lore
#0 lore raw

v12 cover generic TEE subsystem

Hi,

This patch set introduces a generic TEE subsystem. The TEE subsystem will contain drivers for various TEE implementations. A TEE (Trusted Execution Environment) is a trusted OS running in some secure environment, for example, TrustZone on ARM CPUs, or a separate secure co-processor etc.

Regarding use cases, TrustZone has traditionally been used for offloading secure tasks to the secure world. Examples include:
- Secure key handling where the OS may or may not have direct access to key material.
- E-commerce and payment technologies. Credentials, credit card numbers etc could be stored in a more secure environment.
- Trusted User Interface (TUI) to ensure that no-one can snoop PIN-codes etc.
- Secure boot to ensure that loaded binaries haven?t been tampered with. It?s not strictly needed for secure boot, but you could enhance security by leveraging a TEE during boot.
- Digital Rights Management (DRM), the studios provides content with different resolution depending on the security of the device. Higher security means higher resolution.

A TEE could also be used in existing and new technologies. For example IMA (Integrity Measurement Architecture) which has been in the kernel for quite a while. Today you can enhance security by using a TPM-chip to sign the IMA measurement list. This is something that you also could do by leveraging a TEE.

Another example could be in 2-factor authentication which is becoming increasingly more important. FIDO (https://fidoalliance.org) for example are using public key cryptography in their 2-factor authentication standard (U2F). With FIDO, a private and public key pair will be generated for every site you visit and the private key should never leave the local device. This is an example where you could use secure storage in a TEE for the private key.

Today you will find a quite a few different out of tree implementations of TEE drivers which tends to fragment the TEE ecosystem and development. We think it would be a good idea to have a generic TEE driver integrated in the kernel which would serve as a base for several different TEE solutions, no matter if they are on-chip like TrustZone or if they are on a separate crypto co-processor.

To develop this TEE subsystem we have been using the open source TEE called OP-TEE (https://github.com/OP-TEE/optee_os) and therefore this would be the first TEE solution supported by this new subsystem. OP-TEE is a GlobalPlatform compliant TEE, however this TEE subsystem is not limited to only GlobalPlatform TEEs, instead we have tried to design it so that it should work with other TEE solutions also.

"tee: generic TEE subsystem" brings in the generic TEE subsystem which helps when writing a driver for a specific TEE, for example, OP-TEE.

"tee: add OP-TEE driver" is an OP-TEE driver which uses the subsystem to do its work.

This patch set has been prepared in cooperation with Javier Gonz?lez who proposed "Generic TrustZone Driver in Linux Kernel" patches 28 Nov 2014,
https://lwn.net/Articles/623380/ . We've since then changed the scope to TEE instead of TrustZone.

We have discussed the design on tee-dev at lists.linaro.org (archive at
https://lists.linaro.org/pipermail/tee-dev/) with people from other companies, including Valentin Manea <[email protected]>, Emmanuel MICHEL <[email protected]>,
Jean-michel DELORME <[email protected]>,
and Joakim Bech <[email protected]>. Our main concern has been to agree on something that is generic enough to support many different TEEs while still keeping the interface together.

v12-resend:
* Rebased on v4.9-rc2

v12:
* Rebased on v4.8-rc5
* Addressed review comments from Andrew F. Davis
* Removed Acked-by: Andreas Dannenberg <[email protected]> as the mail bounces
* Bugfix possible null dereference in error cleanup path of optee_probe().
* Bugfix optee_from_msg_param() when calculating offset of memref into a shared memory object

v11:
* Rebased on v4.8-rc3
* Addressed review comments from Nishanth Menon
* Made the TEE framework available as a loadable module.
* Reviewed-by: Javier Gonz?lez <[email protected]>
* Zeroes shared memory on allocation to avoid information leakage
* Links shared memory objects to context to avoid stealing of shared memory object from an unrelated process
* Allow RPC interruption if supplicant is unavailable

v10:
* Rebased on v4.7-rc1
* Addressed private review comments from Nishanth Menon
* Optee driver only accepts one supplicant process on the privileged device
* Optee driver avoids long delayed releases of shm objects
* Added more comments on functions and structs

v9:
* Rebased on v4.6-rc1
* Acked-by: Andreas Dannenberg <[email protected]>
* Addressed comments from Al Viro how file descriptors are passed to user space
* Addressed comments from Randy Dunlap on documentation
* Changed license for include/uapi/linux/tee.h

v8:
* Rebased on v4.5-rc3
* dt/bindings: add bindings for optee

* Fixes build error for X86
* Fixes spell error in "dt/bindings: add bindings for optee"

v7:
* Rebased on v4.5-rc2
* Moved the ARM SMC Calling Convention support into a separate patch set, which is now merged

v6:
* Rebased on v4.3-rc7
* Changed smccc interface to let the compiler marshal most of the parameters
* Added ARCH64 capability for smccc interface
* Changed the PSCI firmware calls (both arm and arm64) to use the new generic smccc interface instead instead of own assembly functions.
* Move optee DT bindings to below arm/firmware
* Defines method for OP-TEE driver to call secure world in DT, smc or hvc
* Exposes implementation id of a TEE driver in sysfs
to easily spawn corresponding tee-supplicant when device is ready
* Update OP-TEE Message Protocol to better cope with fragmented physical memory
* Read time directly from OP-TEE driver instead of forwarding the RPC request to tee-supplicant

v5:
* Replaced kref reference counting for the device with a size_t instead as the counter is always protected by a mutex

v4:
* Rebased on 4.1
* Redesigned the synchronization around entry exit of normal SMC
* Replaced rwsem on the driver instance with kref and completion since rwsem wasn't intended to be used in this way
* Expanded the TEE_IOCTL_PARAM_ATTR_TYPE_MASK to make room for future additional parameter types
* Documents TEE subsystem and OP-TEE driver
* Replaced TEE_IOC_CMD with TEE_IOC_OPEN_SESSION, TEE_IOC_INVOKE, TEE_IOC_CANCEL and TEE_IOC_CLOSE_SESSION
* DT bindings in a separate patch
* Assembly parts moved to arch/arm and arch/arm64 respectively, in a separate patch
* Redefined/clarified the meaning of OPTEE_SMC_SHM_CACHED
* Removed CMA usage to limit the scope of the patch set

v3:
* Rebased on 4.1-rc3 (dma_buf_export() API change)
* A couple of small sparse fixes
* Documents bindings for OP-TEE driver
* Updated MAINTAINERS

v2:
* Replaced the stubbed OP-TEE driver with a real OP-TEE driver
* Removed most APIs not needed by OP-TEE in current state
* Update Documentation/ioctl/ioctl-number.txt with correct path to tee.h
* Rename tee_shm_pool_alloc_cma() to tee_shm_pool_alloc()
* Moved tee.h into include/uapi/linux/
* Redefined tee.h IOCTL macros to be directly based on _IOR and friends
* Removed version info on the API to user space, a data blob which can contain an UUID is left for user space to be able to tell which protocol to use in TEE_IOC_CMD
* Changed user space exposed structures to only have types with __ prefix
* Dropped THIS_MODULE from tee_fops
* Reworked how the driver is registered and ref counted:
- moved from using an embedded struct miscdevice to an embedded struct device.
- uses an struct rw_semaphore as synchronization for driver detachment
- uses alloc/register pattern from TPM

Thanks,
Jens

Jens Wiklander (4):
dt/bindings: add bindings for optee
tee: generic TEE subsystem
tee: add OP-TEE driver
Documentation: tee subsystem and op-tee driver

 Documentation/00-INDEX                             |   2 +
 .../bindings/arm/firmware/linaro,optee-tz.txt      |  31 +
 .../devicetree/bindings/vendor-prefixes.txt        |   1 +
 Documentation/ioctl/ioctl-number.txt               |   1 +
 Documentation/tee.txt                              | 118 +++
 MAINTAINERS                                        |  13 +
 drivers/Kconfig                                    |   2 +
 drivers/Makefile                                   |   1 +
 drivers/tee/Kconfig                                |  18 +
 drivers/tee/Makefile                               |   5 +
 drivers/tee/optee/Kconfig                          |   7 +
 drivers/tee/optee/Makefile                         |   5 +
 drivers/tee/optee/call.c                           | 435 ++++++++++
 drivers/tee/optee/core.c                           | 598 ++++++++++++++
 drivers/tee/optee/optee_msg.h                      | 435 ++++++++++
 drivers/tee/optee/optee_private.h                  | 185 +++++
 drivers/tee/optee/optee_smc.h                      | 446 ++++++++++
 drivers/tee/optee/rpc.c                            | 404 +++++++++
 drivers/tee/optee/supp.c                           | 273 +++++++
 drivers/tee/tee_core.c                             | 901 +++++++++++++++++++++
 drivers/tee/tee_private.h                          | 129 +++
 drivers/tee/tee_shm.c                              | 357 ++++++++
 drivers/tee/tee_shm_pool.c                         | 158 ++++
 include/linux/tee_drv.h                            | 278 +++++++
 include/uapi/linux/tee.h                           | 403 +++++++++
 25 files changed, 5206 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/firmware/linaro,optee-tz.txt
 create mode 100644 Documentation/tee.txt
 create mode 100644 drivers/tee/Kconfig
 create mode 100644 drivers/tee/Makefile
 create mode 100644 drivers/tee/optee/Kconfig
 create mode 100644 drivers/tee/optee/Makefile
 create mode 100644 drivers/tee/optee/call.c
 create mode 100644 drivers/tee/optee/core.c
 create mode 100644 drivers/tee/optee/optee_msg.h
 create mode 100644 drivers/tee/optee/optee_private.h
 create mode 100644 drivers/tee/optee/optee_smc.h
 create mode 100644 drivers/tee/optee/rpc.c
 create mode 100644 drivers/tee/optee/supp.c
 create mode 100644 drivers/tee/tee_core.c
 create mode 100644 drivers/tee/tee_private.h
 create mode 100644 drivers/tee/tee_shm.c
 create mode 100644 drivers/tee/tee_shm_pool.c
 create mode 100644 include/linux/tee_drv.h
 create mode 100644 include/uapi/linux/tee.h
Signature · 1 line
1.9.1
#1 lore raw

PATCH RESEND v12 1/4 dt/bindings: add bindings for optee

Introduces linaro prefix and adds bindings for ARM TrustZone based OP-TEE implementation.

---
 .../bindings/arm/firmware/linaro,optee-tz.txt      | 31 ++++++++++++++++++++++
 .../devicetree/bindings/vendor-prefixes.txt        |  1 +
 2 files changed, 32 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/firmware/linaro,optee-tz.txt
Documentation/devicetree/bindings/arm/firmware/linaro,optee-tz.txt new file +31 -0
new file mode 100644
index 0000000..d38834c
@@ -0,0 +1,31 @@
+OP-TEE Device Tree Bindings
+
+OP-TEE is a piece of software using hardware features to provide a Trusted
+Execution Environment. The security can be provided with ARM TrustZone, but
+also by virtualization or a separate chip.
+
+We're using "linaro" as the first part of the compatible property for
+the reference implementation maintained by Linaro.
+
+* OP-TEE based on ARM TrustZone required properties:
+
+- compatible     : should contain "linaro,optee-tz"
+
+- method         : The method of calling the OP-TEE Trusted OS. Permitted
+                   values are:
+
+                   "smc" : SMC #0, with the register assignments specified
+		           in drivers/tee/optee/optee_smc.h
+
+                   "hvc" : HVC #0, with the register assignments specified
+		           in drivers/tee/optee/optee_smc.h
+
+
+
+Example:
+	firmware {
+		optee {
+			compatible = "linaro,optee-tz";
+			method = "smc";
+		};
+	};
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
index f0a48ea..6ab5d04 100644
@@ -155,6 +155,7 @@ lacie	LaCie
 lantiq	Lantiq Semiconductor
 lenovo	Lenovo Group Ltd.
 lg	LG Corporation
+linaro	Linaro Limited
 linux	Linux-specific binding
 lltc	Linear Technology Corporation
 lsi	LSI Corp. (LSI Logic)
Signature · 1 line
1.9.1
#2 lore raw

PATCH RESEND v12 2/4 tee: generic TEE subsystem

In reply to Jens Wiklander

Initial patch for generic TEE subsystem.
This subsystem provides:
* Registration/un-registration of TEE drivers.
* Shared memory between normal world and secure world.
* Ioctl interface for interaction with user space.
* Sysfs implementation_id of TEE driver

A TEE (Trusted Execution Environment) driver is a driver that interfaces with a trusted OS running in some secure environment, for example, TrustZone on ARM cpus, or a separate secure co-processor etc.

The TEE subsystem can serve a TEE driver for a Global Platform compliant TEE, but it's not limited to only Global Platform TEEs.

This patch builds on other similar implementations trying to solve the same problem:
* "optee_linuxdriver" by among others
Jean-michel DELORME<[email protected]> and Emmanuel MICHEL <[email protected]>
* "Generic TrustZone Driver" by Javier Gonz?lez <[email protected]>

---
 Documentation/ioctl/ioctl-number.txt |   1 +
 MAINTAINERS                          |   7 +
 drivers/Kconfig                      |   2 +
 drivers/Makefile                     |   1 +
 drivers/tee/Kconfig                  |   8 +
 drivers/tee/Makefile                 |   4 +
 drivers/tee/tee_core.c               | 901 +++++++++++++++++++++++++++++++++++
 drivers/tee/tee_private.h            | 129 +++++
 drivers/tee/tee_shm.c                | 357 ++++++++++++++
 drivers/tee/tee_shm_pool.c           | 158 ++++++
 include/linux/tee_drv.h              | 278 +++++++++++
 include/uapi/linux/tee.h             | 403 ++++++++++++++++
 12 files changed, 2249 insertions(+)
 create mode 100644 drivers/tee/Kconfig
 create mode 100644 drivers/tee/Makefile
 create mode 100644 drivers/tee/tee_core.c
 create mode 100644 drivers/tee/tee_private.h
 create mode 100644 drivers/tee/tee_shm.c
 create mode 100644 drivers/tee/tee_shm_pool.c
 create mode 100644 include/linux/tee_drv.h
 create mode 100644 include/uapi/linux/tee.h
Documentation/ioctl/ioctl-number.txt +1 -0
index 81c7f2b..efb38da 100644
@@ -308,6 +308,7 @@ Code  Seq#(hex)	Include File		Comments
 0xA3	80-8F	Port ACL		in development:
 					<mailto:[email protected]>
 0xA3	90-9F	linux/dtlk.h
+0xA4	00-1F	uapi/linux/tee.h	Generic TEE subsystem
 0xAA	00-3F	linux/uapi/linux/userfaultfd.h
 0xAB	00-1F	linux/nbd.h
 0xAC	00-1F	linux/raw.h
MAINTAINERS +7 -0
index c447953..de9cd07 100644
@@ -10634,6 +10634,13 @@ F:	drivers/hwtracing/stm/
 F:	include/linux/stm.h
 F:	include/uapi/linux/stm.h
 
+TEE SUBSYSTEM
+M:	Jens Wiklander <[email protected]>
+S:	Maintained
+F:	include/linux/tee_drv.h
+F:	include/uapi/linux/tee.h
+F:	drivers/tee/
+
 THUNDERBOLT DRIVER
 M:	Andreas Noever <[email protected]>
 S:	Maintained
drivers/Kconfig +2 -0
index e1e2066..de581c1 100644
@@ -202,4 +202,6 @@ source "drivers/hwtracing/intel_th/Kconfig"
 
 source "drivers/fpga/Kconfig"
 
+source "drivers/tee/Kconfig"
+
 endmenu
drivers/Makefile +1 -0
index 194d20b..4d53367 100644
@@ -173,3 +173,4 @@ obj-$(CONFIG_STM)		+= hwtracing/stm/
 obj-$(CONFIG_ANDROID)		+= android/
 obj-$(CONFIG_NVMEM)		+= nvmem/
 obj-$(CONFIG_FPGA)		+= fpga/
+obj-$(CONFIG_TEE)		+= tee/
drivers/tee/Kconfig new file +8 -0
new file mode 100644
index 0000000..50c244e
@@ -0,0 +1,8 @@
+# Generic Trusted Execution Environment Configuration
+config TEE
+	tristate "Trusted Execution Environment support"
+	select DMA_SHARED_BUFFER
+	select GENERIC_ALLOCATOR
+	help
+	  This implements a generic interface towards a Trusted Execution
+	  Environment (TEE).
drivers/tee/Makefile new file +4 -0
new file mode 100644
index 0000000..ec64047
@@ -0,0 +1,4 @@
+obj-$(CONFIG_TEE) += tee.o
+tee-objs += tee_core.o
+tee-objs += tee_shm.o
+tee-objs += tee_shm_pool.o
drivers/tee/tee_core.c new file +901 -0

901 lines not on this page · raw message

drivers/tee/tee_private.h new file +129 -0

129 lines not on this page · raw message

drivers/tee/tee_shm.c new file +357 -0

357 lines not on this page · raw message

drivers/tee/tee_shm_pool.c new file +158 -0

158 lines not on this page · raw message

include/linux/tee_drv.h new file +278 -0

278 lines not on this page · raw message

include/uapi/linux/tee.h new file +403 -0

403 lines not on this page · raw message

Signature · 1 line
1.9.1
#3 lore raw

PATCH RESEND v12 3/4 tee: add OP-TEE driver

In reply to Jens Wiklander

Adds a OP-TEE driver which also can be compiled as a loadable module.

* Targets ARM and ARM64
* Supports using reserved memory from OP-TEE as shared memory
* Probes OP-TEE version using SMCs
* Accepts requests on privileged and unprivileged device
* Uses OPTEE message protocol version 2 to communicate with secure world

---
 MAINTAINERS                       |   5 +
 drivers/tee/Kconfig               |  10 +
 drivers/tee/Makefile              |   1 +
 drivers/tee/optee/Kconfig         |   7 +
 drivers/tee/optee/Makefile        |   5 +
 drivers/tee/optee/call.c          | 435 +++++++++++++++++++++++++++
 drivers/tee/optee/core.c          | 598 ++++++++++++++++++++++++++++++++++++++
 drivers/tee/optee/optee_msg.h     | 435 +++++++++++++++++++++++++++
 drivers/tee/optee/optee_private.h | 185 ++++++++++++
 drivers/tee/optee/optee_smc.h     | 446 ++++++++++++++++++++++++++++
 drivers/tee/optee/rpc.c           | 404 +++++++++++++++++++++++++
 drivers/tee/optee/supp.c          | 273 +++++++++++++++++
 12 files changed, 2804 insertions(+)
 create mode 100644 drivers/tee/optee/Kconfig
 create mode 100644 drivers/tee/optee/Makefile
 create mode 100644 drivers/tee/optee/call.c
 create mode 100644 drivers/tee/optee/core.c
 create mode 100644 drivers/tee/optee/optee_msg.h
 create mode 100644 drivers/tee/optee/optee_private.h
 create mode 100644 drivers/tee/optee/optee_smc.h
 create mode 100644 drivers/tee/optee/rpc.c
 create mode 100644 drivers/tee/optee/supp.c
MAINTAINERS +5 -0
index de9cd07..8130af1 100644
@@ -8984,6 +8984,11 @@ F:	arch/*/oprofile/
 F:	drivers/oprofile/
 F:	include/linux/oprofile.h
 
+OP-TEE DRIVER
+M:	Jens Wiklander <[email protected]>
+S:	Maintained
+F:	drivers/tee/optee/
+
 ORACLE CLUSTER FILESYSTEM 2 (OCFS2)
 M:	Mark Fasheh <[email protected]>
 M:	Joel Becker <[email protected]>
drivers/tee/Kconfig +10 -0
index 50c244e..2330a4e 100644
@@ -6,3 +6,13 @@ config TEE
 	help
 	  This implements a generic interface towards a Trusted Execution
 	  Environment (TEE).
+
+if TEE
+
+menu "TEE drivers"
+
+source "drivers/tee/optee/Kconfig"
+
+endmenu
+
+endif
drivers/tee/Makefile +1 -0
index ec64047..7a4e4a1 100644
@@ -2,3 +2,4 @@ obj-$(CONFIG_TEE) += tee.o
 tee-objs += tee_core.o
 tee-objs += tee_shm.o
 tee-objs += tee_shm_pool.o
+obj-$(CONFIG_OPTEE) += optee/
drivers/tee/optee/Kconfig new file +7 -0
new file mode 100644
index 0000000..0126de8
@@ -0,0 +1,7 @@
+# OP-TEE Trusted Execution Environment Configuration
+config OPTEE
+	tristate "OP-TEE"
+	depends on HAVE_ARM_SMCCC
+	help
+	  This implements the OP-TEE Trusted Execution Environment (TEE)
+	  driver.
drivers/tee/optee/Makefile new file +5 -0
new file mode 100644
index 0000000..92fe578
@@ -0,0 +1,5 @@
+obj-$(CONFIG_OPTEE) += optee.o
+optee-objs += core.o
+optee-objs += call.o
+optee-objs += rpc.o
+optee-objs += supp.o
drivers/tee/optee/call.c new file +435 -0

435 lines not on this page · raw message

drivers/tee/optee/core.c new file +598 -0

598 lines not on this page · raw message

drivers/tee/optee/optee_msg.h new file +435 -0

435 lines not on this page · raw message

drivers/tee/optee/optee_private.h new file +185 -0

185 lines not on this page · raw message

drivers/tee/optee/optee_smc.h new file +446 -0

446 lines not on this page · raw message

drivers/tee/optee/rpc.c new file +404 -0

404 lines not on this page · raw message

drivers/tee/optee/supp.c new file +273 -0

273 lines not on this page · raw message

Signature · 1 line
1.9.1
#4 lore raw

PATCH RESEND v12 4/4 Documentation: tee subsystem and op-tee driver

In reply to Jens Wiklander
---
 Documentation/00-INDEX |   2 +
 Documentation/tee.txt  | 118 +++++++++++++++++++++++++++++++++++++++++++++++++
 MAINTAINERS            |   1 +
 3 files changed, 121 insertions(+)
 create mode 100644 Documentation/tee.txt
Documentation/00-INDEX +2 -0
index 3acc4f1..4a5a887 100644
@@ -436,6 +436,8 @@ sysrq.txt
 	- info on the magic SysRq key.
 target/
 	- directory with info on generating TCM v4 fabric .ko modules
+tee.txt
+	- info on the TEE subsystem and drivers
 this_cpu_ops.txt
 	- List rationale behind and the way to use this_cpu operations.
 thermal/
Documentation/tee.txt new file +118 -0

118 lines not on this page · raw message

MAINTAINERS +1 -0
index 8130af1..76e3a28 100644
@@ -10645,6 +10645,7 @@ S:	Maintained
 F:	include/linux/tee_drv.h
 F:	include/uapi/linux/tee.h
 F:	drivers/tee/
+F:	Documentation/tee.txt
 
 THUNDERBOLT DRIVER
 M:	Andreas Noever <[email protected]>
Signature · 1 line
1.9.1
#5 lore raw
In reply to Jens Wiklander
Quoted 43 lines · Jens Wiklander

Hi,

This patch set introduces a generic TEE subsystem. The TEE subsystem will contain drivers for various TEE implementations. A TEE (Trusted Execution Environment) is a trusted OS running in some secure environment, for example, TrustZone on ARM CPUs, or a separate secure co-processor etc.

Regarding use cases, TrustZone has traditionally been used for offloading secure tasks to the secure world. Examples include:
- Secure key handling where the OS may or may not have direct access to key material.
- E-commerce and payment technologies. Credentials, credit card numbers etc could be stored in a more secure environment.
- Trusted User Interface (TUI) to ensure that no-one can snoop PIN-codes etc.
- Secure boot to ensure that loaded binaries haven?t been tampered with. It?s not strictly needed for secure boot, but you could enhance security by leveraging a TEE during boot.
- Digital Rights Management (DRM), the studios provides content with different resolution depending on the security of the device. Higher security means higher resolution.

A TEE could also be used in existing and new technologies. For example IMA (Integrity Measurement Architecture) which has been in the kernel for quite a while. Today you can enhance security by using a TPM-chip to sign the IMA measurement list. This is something that you also could do by leveraging a TEE.

Another example could be in 2-factor authentication which is becoming increasingly more important. FIDO (https://fidoalliance.org) for example are using public key cryptography in their 2-factor authentication standard (U2F). With FIDO, a private and public key pair will be generated for every site you visit and the private key should never leave the local device. This is an example where you could use secure storage in a TEE for the private key.

Today you will find a quite a few different out of tree implementations of TEE drivers which tends to fragment the TEE ecosystem and development. We think it would be a good idea to have a generic TEE driver integrated in the kernel which would serve as a base for several different TEE solutions, no matter if they are on-chip like TrustZone or if they are on a separate crypto co-processor.

Quoted 7 lines

To develop this TEE subsystem we have been using the open source TEE called OP-TEE (https://github.com/OP-TEE/optee_os) and therefore this would be the first TEE solution supported by this new subsystem. OP-TEE is a GlobalPlatform compliant TEE, however this TEE subsystem is not limited to only GlobalPlatform TEEs, instead we have tried to design it so that it should work with other TEE solutions also.

The above is my biggest concern with this whole subsystem, to me it still feels very OPTEE specific. As much as I would love to believe OPTEE will be the end-all TEE, I'm sure we soon will start to see wider use of vendor TEEs (like TI's own legacy Trustzone thing we are hoping to depreciate with OPTEE moving forward), possibly Google's Trusty TEE, and whatever Intel/AMD are cooking up for x86.

As we all know when things are upstreamed we lose the ability to make radical changes easily, especially to full subsystems. What happens when this framework, built with only one existing TEE, built by the one existing TEE's devs, is not as flexible as we need when other TEEs start rolling out?

Do we see this as a chicken and egg situation, or is there any harm beyond the pains of supporting an out-of-tree driver for a while, to wait until we have at least one other TEE to add to this subsystem before merging?

This may also help with the perceived lack of reviewers for this series.

Thanks,
Andrew

Quoted 185 lines

"tee: generic TEE subsystem" brings in the generic TEE subsystem which helps when writing a driver for a specific TEE, for example, OP-TEE.

"tee: add OP-TEE driver" is an OP-TEE driver which uses the subsystem to do its work.

This patch set has been prepared in cooperation with Javier Gonz?lez who proposed "Generic TrustZone Driver in Linux Kernel" patches 28 Nov 2014,
https://lwn.net/Articles/623380/ . We've since then changed the scope to TEE instead of TrustZone.

We have discussed the design on tee-dev at lists.linaro.org (archive at
https://lists.linaro.org/pipermail/tee-dev/) with people from other companies, including Valentin Manea <[email protected]>, Emmanuel MICHEL <[email protected]>,
Jean-michel DELORME <[email protected]>,
and Joakim Bech <[email protected]>. Our main concern has been to agree on something that is generic enough to support many different TEEs while still keeping the interface together.

v12-resend:
* Rebased on v4.9-rc2

v12:
* Rebased on v4.8-rc5
* Addressed review comments from Andrew F. Davis
* Removed Acked-by: Andreas Dannenberg <[email protected]> as the mail bounces
* Bugfix possible null dereference in error cleanup path of optee_probe().
* Bugfix optee_from_msg_param() when calculating offset of memref into a shared memory object

v11:
* Rebased on v4.8-rc3
* Addressed review comments from Nishanth Menon
* Made the TEE framework available as a loadable module.
* Reviewed-by: Javier Gonz?lez <[email protected]>
* Zeroes shared memory on allocation to avoid information leakage
* Links shared memory objects to context to avoid stealing of shared memory object from an unrelated process
* Allow RPC interruption if supplicant is unavailable

v10:
* Rebased on v4.7-rc1
* Addressed private review comments from Nishanth Menon
* Optee driver only accepts one supplicant process on the privileged device
* Optee driver avoids long delayed releases of shm objects
* Added more comments on functions and structs

v9:
* Rebased on v4.6-rc1
* Acked-by: Andreas Dannenberg <[email protected]>
* Addressed comments from Al Viro how file descriptors are passed to user space
* Addressed comments from Randy Dunlap on documentation
* Changed license for include/uapi/linux/tee.h

v8:
* Rebased on v4.5-rc3
* dt/bindings: add bindings for optee

* Fixes build error for X86
* Fixes spell error in "dt/bindings: add bindings for optee"

v7:
* Rebased on v4.5-rc2
* Moved the ARM SMC Calling Convention support into a separate patch set, which is now merged

v6:
* Rebased on v4.3-rc7
* Changed smccc interface to let the compiler marshal most of the parameters
* Added ARCH64 capability for smccc interface
* Changed the PSCI firmware calls (both arm and arm64) to use the new generic smccc interface instead instead of own assembly functions.
* Move optee DT bindings to below arm/firmware
* Defines method for OP-TEE driver to call secure world in DT, smc or hvc
* Exposes implementation id of a TEE driver in sysfs
to easily spawn corresponding tee-supplicant when device is ready
* Update OP-TEE Message Protocol to better cope with fragmented physical memory
* Read time directly from OP-TEE driver instead of forwarding the RPC request to tee-supplicant

v5:
* Replaced kref reference counting for the device with a size_t instead as the counter is always protected by a mutex

v4:
* Rebased on 4.1
* Redesigned the synchronization around entry exit of normal SMC
* Replaced rwsem on the driver instance with kref and completion since rwsem wasn't intended to be used in this way
* Expanded the TEE_IOCTL_PARAM_ATTR_TYPE_MASK to make room for future additional parameter types
* Documents TEE subsystem and OP-TEE driver
* Replaced TEE_IOC_CMD with TEE_IOC_OPEN_SESSION, TEE_IOC_INVOKE, TEE_IOC_CANCEL and TEE_IOC_CLOSE_SESSION
* DT bindings in a separate patch
* Assembly parts moved to arch/arm and arch/arm64 respectively, in a separate patch
* Redefined/clarified the meaning of OPTEE_SMC_SHM_CACHED
* Removed CMA usage to limit the scope of the patch set

v3:
* Rebased on 4.1-rc3 (dma_buf_export() API change)
* A couple of small sparse fixes
* Documents bindings for OP-TEE driver
* Updated MAINTAINERS

v2:
* Replaced the stubbed OP-TEE driver with a real OP-TEE driver
* Removed most APIs not needed by OP-TEE in current state
* Update Documentation/ioctl/ioctl-number.txt with correct path to tee.h
* Rename tee_shm_pool_alloc_cma() to tee_shm_pool_alloc()
* Moved tee.h into include/uapi/linux/
* Redefined tee.h IOCTL macros to be directly based on _IOR and friends
* Removed version info on the API to user space, a data blob which can contain an UUID is left for user space to be able to tell which protocol to use in TEE_IOC_CMD
* Changed user space exposed structures to only have types with __ prefix
* Dropped THIS_MODULE from tee_fops
* Reworked how the driver is registered and ref counted:
- moved from using an embedded struct miscdevice to an embedded struct device.
- uses an struct rw_semaphore as synchronization for driver detachment
- uses alloc/register pattern from TPM

Thanks,
Jens

Jens Wiklander (4):
dt/bindings: add bindings for optee
tee: generic TEE subsystem
tee: add OP-TEE driver
Documentation: tee subsystem and op-tee driver

 Documentation/00-INDEX                             |   2 +
 .../bindings/arm/firmware/linaro,optee-tz.txt      |  31 +
 .../devicetree/bindings/vendor-prefixes.txt        |   1 +
 Documentation/ioctl/ioctl-number.txt               |   1 +
 Documentation/tee.txt                              | 118 +++
 MAINTAINERS                                        |  13 +
 drivers/Kconfig                                    |   2 +
 drivers/Makefile                                   |   1 +
 drivers/tee/Kconfig                                |  18 +
 drivers/tee/Makefile                               |   5 +
 drivers/tee/optee/Kconfig                          |   7 +
 drivers/tee/optee/Makefile                         |   5 +
 drivers/tee/optee/call.c                           | 435 ++++++++++
 drivers/tee/optee/core.c                           | 598 ++++++++++++++
 drivers/tee/optee/optee_msg.h                      | 435 ++++++++++
 drivers/tee/optee/optee_private.h                  | 185 +++++
 drivers/tee/optee/optee_smc.h                      | 446 ++++++++++
 drivers/tee/optee/rpc.c                            | 404 +++++++++
 drivers/tee/optee/supp.c                           | 273 +++++++
 drivers/tee/tee_core.c                             | 901 +++++++++++++++++++++
 drivers/tee/tee_private.h                          | 129 +++
 drivers/tee/tee_shm.c                              | 357 ++++++++
 drivers/tee/tee_shm_pool.c                         | 158 ++++
 include/linux/tee_drv.h                            | 278 +++++++
 include/uapi/linux/tee.h                           | 403 +++++++++
 25 files changed, 5206 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/firmware/linaro,optee-tz.txt
 create mode 100644 Documentation/tee.txt
 create mode 100644 drivers/tee/Kconfig
 create mode 100644 drivers/tee/Makefile
 create mode 100644 drivers/tee/optee/Kconfig
 create mode 100644 drivers/tee/optee/Makefile
 create mode 100644 drivers/tee/optee/call.c
 create mode 100644 drivers/tee/optee/core.c
 create mode 100644 drivers/tee/optee/optee_msg.h
 create mode 100644 drivers/tee/optee/optee_private.h
 create mode 100644 drivers/tee/optee/optee_smc.h
 create mode 100644 drivers/tee/optee/rpc.c
 create mode 100644 drivers/tee/optee/supp.c
 create mode 100644 drivers/tee/tee_core.c
 create mode 100644 drivers/tee/tee_private.h
 create mode 100644 drivers/tee/tee_shm.c
 create mode 100644 drivers/tee/tee_shm_pool.c
 create mode 100644 include/linux/tee_drv.h
 create mode 100644 include/uapi/linux/tee.h
#6 lore raw
Quoted 4 lines · Andrew F. Davis

Do we see this as a chicken and egg situation, or is there any harm beyond the pains of supporting an out-of-tree driver for a while, to wait until we have at least one other TEE to add to this subsystem before merging?

We haven't been overburneded with TEE vendors wanting to get their
driver code into mainline - do we have any reasonable prospect of other
TEE vendors with an interest in mainline turning up in any kind of
reasonable timeframe?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20161028/3adb9948/attachment.sig>

#7 lore raw
Quoted 7 lines · Mark Brown
Quoted 4 lines · Andrew F. Davis

Do we see this as a chicken and egg situation, or is there any harm beyond the pains of supporting an out-of-tree driver for a while, to wait until we have at least one other TEE to add to this subsystem before merging?

Quoted 5 lines

We haven't been overburneded with TEE vendors wanting to get their driver code into mainline - do we have any reasonable prospect of other TEE vendors with an interest in mainline turning up in any kind of reasonable timeframe?

Doesn't look like anyone has near-term plans for upstreaming non-OPTEE TEEs, we don't at least (TI), so I guess I see no reason right now to delay upstreaming of this TEE's driver on the off-chance it is incompatible with a TEE that may or may not try to get upstreamed later. I'll redact my objection for now.

#8 lore raw
In reply to Andrew F. Davis
Quoted 52 lines · Andrew F. Davis
Quoted 43 lines · Jens Wiklander

Hi,

This patch set introduces a generic TEE subsystem. The TEE subsystem will contain drivers for various TEE implementations. A TEE (Trusted Execution Environment) is a trusted OS running in some secure environment, for example, TrustZone on ARM CPUs, or a separate secure co-processor etc.

Regarding use cases, TrustZone has traditionally been used for offloading secure tasks to the secure world. Examples include:
- Secure key handling where the OS may or may not have direct access to key material.
- E-commerce and payment technologies. Credentials, credit card numbers etc could be stored in a more secure environment.
- Trusted User Interface (TUI) to ensure that no-one can snoop PIN-codes etc.
- Secure boot to ensure that loaded binaries haven?t been tampered with. It?s not strictly needed for secure boot, but you could enhance security by leveraging a TEE during boot.
- Digital Rights Management (DRM), the studios provides content with different resolution depending on the security of the device. Higher security means higher resolution.

A TEE could also be used in existing and new technologies. For example IMA (Integrity Measurement Architecture) which has been in the kernel for quite a while. Today you can enhance security by using a TPM-chip to sign the IMA measurement list. This is something that you also could do by leveraging a TEE.

Another example could be in 2-factor authentication which is becoming increasingly more important. FIDO (https://fidoalliance.org) for example are using public key cryptography in their 2-factor authentication standard (U2F). With FIDO, a private and public key pair will be generated for every site you visit and the private key should never leave the local device. This is an example where you could use secure storage in a TEE for the private key.

Today you will find a quite a few different out of tree implementations of TEE drivers which tends to fragment the TEE ecosystem and development. We think it would be a good idea to have a generic TEE driver integrated in the kernel which would serve as a base for several different TEE solutions, no matter if they are on-chip like TrustZone or if they are on a separate crypto co-processor.

Quoted 7 lines

To develop this TEE subsystem we have been using the open source TEE called OP-TEE (https://github.com/OP-TEE/optee_os) and therefore this would be the first TEE solution supported by this new subsystem. OP-TEE is a GlobalPlatform compliant TEE, however this TEE subsystem is not limited to only GlobalPlatform TEEs, instead we have tried to design it so that it should work with other TEE solutions also.

Quoted 6 lines

The above is my biggest concern with this whole subsystem, to me it still feels very OPTEE specific. As much as I would love to believe OPTEE will be the end-all TEE, I'm sure we soon will start to see wider use of vendor TEEs (like TI's own legacy Trustzone thing we are hoping to depreciate with OPTEE moving forward), possibly Google's Trusty TEE, and whatever Intel/AMD are cooking up for x86.

I'd rather say that it's slightly GlobalPlatform specific, but a bit more flexible.

Quoted 6 lines

As we all know when things are upstreamed we lose the ability to make radical changes easily, especially to full subsystems. What happens when this framework, built with only one existing TEE, built by the one existing TEE's devs, is not as flexible as we need when other TEEs start rolling out?

Initially the TEE subsystem was much more flexible and was criticized for that.

Quoted 5 lines

Do we see this as a chicken and egg situation, or is there any harm beyond the pains of supporting an out-of-tree driver for a while, to wait until we have at least one other TEE to add to this subsystem before merging?

This proposal is the bare minimum to have something useful. On top of this there's more things we'd like to add, for example an in-kernel API for accessing the TEE and secure buffer handling. The way we're dealing with shared memory need to be improved to better support multiple guests communicating with one TEE.

What we can do now with the subsystem now is somewhat limited by the fact that we're trying to upstream it and want to do that it in manageable increments.

Thanks,
Jens

Quoted 191 lines

This may also help with the perceived lack of reviewers for this series.

Thanks,
Andrew

Quoted 185 lines

"tee: generic TEE subsystem" brings in the generic TEE subsystem which helps when writing a driver for a specific TEE, for example, OP-TEE.

"tee: add OP-TEE driver" is an OP-TEE driver which uses the subsystem to do its work.

This patch set has been prepared in cooperation with Javier Gonz?lez who proposed "Generic TrustZone Driver in Linux Kernel" patches 28 Nov 2014,
https://lwn.net/Articles/623380/ . We've since then changed the scope to TEE instead of TrustZone.

We have discussed the design on tee-dev at lists.linaro.org (archive at
https://lists.linaro.org/pipermail/tee-dev/) with people from other companies, including Valentin Manea <[email protected]>, Emmanuel MICHEL <[email protected]>,
Jean-michel DELORME <[email protected]>,
and Joakim Bech <[email protected]>. Our main concern has been to agree on something that is generic enough to support many different TEEs while still keeping the interface together.

v12-resend:
* Rebased on v4.9-rc2

v12:
* Rebased on v4.8-rc5
* Addressed review comments from Andrew F. Davis
* Removed Acked-by: Andreas Dannenberg <[email protected]> as the mail bounces
* Bugfix possible null dereference in error cleanup path of optee_probe().
* Bugfix optee_from_msg_param() when calculating offset of memref into a shared memory object

v11:
* Rebased on v4.8-rc3
* Addressed review comments from Nishanth Menon
* Made the TEE framework available as a loadable module.
* Reviewed-by: Javier Gonz?lez <[email protected]>
* Zeroes shared memory on allocation to avoid information leakage
* Links shared memory objects to context to avoid stealing of shared memory object from an unrelated process
* Allow RPC interruption if supplicant is unavailable

v10:
* Rebased on v4.7-rc1
* Addressed private review comments from Nishanth Menon
* Optee driver only accepts one supplicant process on the privileged device
* Optee driver avoids long delayed releases of shm objects
* Added more comments on functions and structs

v9:
* Rebased on v4.6-rc1
* Acked-by: Andreas Dannenberg <[email protected]>
* Addressed comments from Al Viro how file descriptors are passed to user space
* Addressed comments from Randy Dunlap on documentation
* Changed license for include/uapi/linux/tee.h

v8:
* Rebased on v4.5-rc3
* dt/bindings: add bindings for optee

* Fixes build error for X86
* Fixes spell error in "dt/bindings: add bindings for optee"

v7:
* Rebased on v4.5-rc2
* Moved the ARM SMC Calling Convention support into a separate patch set, which is now merged

v6:
* Rebased on v4.3-rc7
* Changed smccc interface to let the compiler marshal most of the parameters
* Added ARCH64 capability for smccc interface
* Changed the PSCI firmware calls (both arm and arm64) to use the new generic smccc interface instead instead of own assembly functions.
* Move optee DT bindings to below arm/firmware
* Defines method for OP-TEE driver to call secure world in DT, smc or hvc
* Exposes implementation id of a TEE driver in sysfs
to easily spawn corresponding tee-supplicant when device is ready
* Update OP-TEE Message Protocol to better cope with fragmented physical memory
* Read time directly from OP-TEE driver instead of forwarding the RPC request to tee-supplicant

v5:
* Replaced kref reference counting for the device with a size_t instead as the counter is always protected by a mutex

v4:
* Rebased on 4.1
* Redesigned the synchronization around entry exit of normal SMC
* Replaced rwsem on the driver instance with kref and completion since rwsem wasn't intended to be used in this way
* Expanded the TEE_IOCTL_PARAM_ATTR_TYPE_MASK to make room for future additional parameter types
* Documents TEE subsystem and OP-TEE driver
* Replaced TEE_IOC_CMD with TEE_IOC_OPEN_SESSION, TEE_IOC_INVOKE, TEE_IOC_CANCEL and TEE_IOC_CLOSE_SESSION
* DT bindings in a separate patch
* Assembly parts moved to arch/arm and arch/arm64 respectively, in a separate patch
* Redefined/clarified the meaning of OPTEE_SMC_SHM_CACHED
* Removed CMA usage to limit the scope of the patch set

v3:
* Rebased on 4.1-rc3 (dma_buf_export() API change)
* A couple of small sparse fixes
* Documents bindings for OP-TEE driver
* Updated MAINTAINERS

v2:
* Replaced the stubbed OP-TEE driver with a real OP-TEE driver
* Removed most APIs not needed by OP-TEE in current state
* Update Documentation/ioctl/ioctl-number.txt with correct path to tee.h
* Rename tee_shm_pool_alloc_cma() to tee_shm_pool_alloc()
* Moved tee.h into include/uapi/linux/
* Redefined tee.h IOCTL macros to be directly based on _IOR and friends
* Removed version info on the API to user space, a data blob which can contain an UUID is left for user space to be able to tell which protocol to use in TEE_IOC_CMD
* Changed user space exposed structures to only have types with __ prefix
* Dropped THIS_MODULE from tee_fops
* Reworked how the driver is registered and ref counted:
- moved from using an embedded struct miscdevice to an embedded struct device.
- uses an struct rw_semaphore as synchronization for driver detachment
- uses alloc/register pattern from TPM

Thanks,
Jens

Jens Wiklander (4):
dt/bindings: add bindings for optee
tee: generic TEE subsystem
tee: add OP-TEE driver
Documentation: tee subsystem and op-tee driver

 Documentation/00-INDEX                             |   2 +
 .../bindings/arm/firmware/linaro,optee-tz.txt      |  31 +
 .../devicetree/bindings/vendor-prefixes.txt        |   1 +
 Documentation/ioctl/ioctl-number.txt               |   1 +
 Documentation/tee.txt                              | 118 +++
 MAINTAINERS                                        |  13 +
 drivers/Kconfig                                    |   2 +
 drivers/Makefile                                   |   1 +
 drivers/tee/Kconfig                                |  18 +
 drivers/tee/Makefile                               |   5 +
 drivers/tee/optee/Kconfig                          |   7 +
 drivers/tee/optee/Makefile                         |   5 +
 drivers/tee/optee/call.c                           | 435 ++++++++++
 drivers/tee/optee/core.c                           | 598 ++++++++++++++
 drivers/tee/optee/optee_msg.h                      | 435 ++++++++++
 drivers/tee/optee/optee_private.h                  | 185 +++++
 drivers/tee/optee/optee_smc.h                      | 446 ++++++++++
 drivers/tee/optee/rpc.c                            | 404 +++++++++
 drivers/tee/optee/supp.c                           | 273 +++++++
 drivers/tee/tee_core.c                             | 901 +++++++++++++++++++++
 drivers/tee/tee_private.h                          | 129 +++
 drivers/tee/tee_shm.c                              | 357 ++++++++
 drivers/tee/tee_shm_pool.c                         | 158 ++++
 include/linux/tee_drv.h                            | 278 +++++++
 include/uapi/linux/tee.h                           | 403 +++++++++
 25 files changed, 5206 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/firmware/linaro,optee-tz.txt
 create mode 100644 Documentation/tee.txt
 create mode 100644 drivers/tee/Kconfig
 create mode 100644 drivers/tee/Makefile
 create mode 100644 drivers/tee/optee/Kconfig
 create mode 100644 drivers/tee/optee/Makefile
 create mode 100644 drivers/tee/optee/call.c
 create mode 100644 drivers/tee/optee/core.c
 create mode 100644 drivers/tee/optee/optee_msg.h
 create mode 100644 drivers/tee/optee/optee_private.h
 create mode 100644 drivers/tee/optee/optee_smc.h
 create mode 100644 drivers/tee/optee/rpc.c
 create mode 100644 drivers/tee/optee/supp.c
 create mode 100644 drivers/tee/tee_core.c
 create mode 100644 drivers/tee/tee_private.h
 create mode 100644 drivers/tee/tee_shm.c
 create mode 100644 drivers/tee/tee_shm_pool.c
 create mode 100644 include/linux/tee_drv.h
 create mode 100644 include/uapi/linux/tee.h
Tested-by
#9 lore raw
Quoted 64 lines · Jens Wiklander
Quoted 52 lines · Andrew F. Davis
Quoted 43 lines · Jens Wiklander

Hi,

This patch set introduces a generic TEE subsystem. The TEE subsystem will contain drivers for various TEE implementations. A TEE (Trusted Execution Environment) is a trusted OS running in some secure environment, for example, TrustZone on ARM CPUs, or a separate secure co-processor etc.

Regarding use cases, TrustZone has traditionally been used for offloading secure tasks to the secure world. Examples include:
- Secure key handling where the OS may or may not have direct access to key material.
- E-commerce and payment technologies. Credentials, credit card numbers etc could be stored in a more secure environment.
- Trusted User Interface (TUI) to ensure that no-one can snoop PIN-codes etc.
- Secure boot to ensure that loaded binaries haven?t been tampered with. It?s not strictly needed for secure boot, but you could enhance security by leveraging a TEE during boot.
- Digital Rights Management (DRM), the studios provides content with different resolution depending on the security of the device. Higher security means higher resolution.

A TEE could also be used in existing and new technologies. For example IMA (Integrity Measurement Architecture) which has been in the kernel for quite a while. Today you can enhance security by using a TPM-chip to sign the IMA measurement list. This is something that you also could do by leveraging a TEE.

Another example could be in 2-factor authentication which is becoming increasingly more important. FIDO (https://fidoalliance.org) for example are using public key cryptography in their 2-factor authentication standard (U2F). With FIDO, a private and public key pair will be generated for every site you visit and the private key should never leave the local device. This is an example where you could use secure storage in a TEE for the private key.

Today you will find a quite a few different out of tree implementations of TEE drivers which tends to fragment the TEE ecosystem and development. We think it would be a good idea to have a generic TEE driver integrated in the kernel which would serve as a base for several different TEE solutions, no matter if they are on-chip like TrustZone or if they are on a separate crypto co-processor.

Quoted 7 lines

To develop this TEE subsystem we have been using the open source TEE called OP-TEE (https://github.com/OP-TEE/optee_os) and therefore this would be the first TEE solution supported by this new subsystem. OP-TEE is a GlobalPlatform compliant TEE, however this TEE subsystem is not limited to only GlobalPlatform TEEs, instead we have tried to design it so that it should work with other TEE solutions also.

Quoted 6 lines

The above is my biggest concern with this whole subsystem, to me it still feels very OPTEE specific. As much as I would love to believe OPTEE will be the end-all TEE, I'm sure we soon will start to see wider use of vendor TEEs (like TI's own legacy Trustzone thing we are hoping to depreciate with OPTEE moving forward), possibly Google's Trusty TEE, and whatever Intel/AMD are cooking up for x86.

I'd rather say that it's slightly GlobalPlatform specific, but a bit more flexible.

Quoted 1 line
Quoted 9 lines
Quoted 5 lines

As we all know when things are upstreamed we lose the ability to make radical changes easily, especially to full subsystems. What happens when this framework, built with only one existing TEE, built by the one existing TEE's devs, is not as flexible as we need when other TEEs start rolling out?

Initially the TEE subsystem was much more flexible and was criticized for that.

That's rather strange, I haven't been following this from the start so I will just take your word that this is where the community wants this subsystem to go.

Quoted 12 lines
Quoted 5 lines

Do we see this as a chicken and egg situation, or is there any harm beyond the pains of supporting an out-of-tree driver for a while, to wait until we have at least one other TEE to add to this subsystem before merging?

This proposal is the bare minimum to have something useful. On top of this there's more things we'd like to add, for example an in-kernel API for accessing the TEE and secure buffer handling. The way we're dealing with shared memory need to be improved to better support multiple guests communicating with one TEE.

Quoted 4 lines

What we can do now with the subsystem now is somewhat limited by the fact that we're trying to upstream it and want to do that it in manageable increments.

Fair enough.

For now this series is being used in our production SDKs so it has at least some basic testing from us, so for the whole series:

Quoted 194 lines

Thanks,
Jens

Quoted 191 lines

This may also help with the perceived lack of reviewers for this series.

Thanks,
Andrew

Quoted 185 lines

"tee: generic TEE subsystem" brings in the generic TEE subsystem which helps when writing a driver for a specific TEE, for example, OP-TEE.

"tee: add OP-TEE driver" is an OP-TEE driver which uses the subsystem to do its work.

This patch set has been prepared in cooperation with Javier Gonz?lez who proposed "Generic TrustZone Driver in Linux Kernel" patches 28 Nov 2014,
https://lwn.net/Articles/623380/ . We've since then changed the scope to TEE instead of TrustZone.

We have discussed the design on tee-dev at lists.linaro.org (archive at
https://lists.linaro.org/pipermail/tee-dev/) with people from other companies, including Valentin Manea <[email protected]>, Emmanuel MICHEL <[email protected]>,
Jean-michel DELORME <[email protected]>,
and Joakim Bech <[email protected]>. Our main concern has been to agree on something that is generic enough to support many different TEEs while still keeping the interface together.

v12-resend:
* Rebased on v4.9-rc2

v12:
* Rebased on v4.8-rc5
* Addressed review comments from Andrew F. Davis
* Removed Acked-by: Andreas Dannenberg <[email protected]> as the mail bounces
* Bugfix possible null dereference in error cleanup path of optee_probe().
* Bugfix optee_from_msg_param() when calculating offset of memref into a shared memory object

v11:
* Rebased on v4.8-rc3
* Addressed review comments from Nishanth Menon
* Made the TEE framework available as a loadable module.
* Reviewed-by: Javier Gonz?lez <[email protected]>
* Zeroes shared memory on allocation to avoid information leakage
* Links shared memory objects to context to avoid stealing of shared memory object from an unrelated process
* Allow RPC interruption if supplicant is unavailable

v10:
* Rebased on v4.7-rc1
* Addressed private review comments from Nishanth Menon
* Optee driver only accepts one supplicant process on the privileged device
* Optee driver avoids long delayed releases of shm objects
* Added more comments on functions and structs

v9:
* Rebased on v4.6-rc1
* Acked-by: Andreas Dannenberg <[email protected]>
* Addressed comments from Al Viro how file descriptors are passed to user space
* Addressed comments from Randy Dunlap on documentation
* Changed license for include/uapi/linux/tee.h

v8:
* Rebased on v4.5-rc3
* dt/bindings: add bindings for optee

* Fixes build error for X86
* Fixes spell error in "dt/bindings: add bindings for optee"

v7:
* Rebased on v4.5-rc2
* Moved the ARM SMC Calling Convention support into a separate patch set, which is now merged

v6:
* Rebased on v4.3-rc7
* Changed smccc interface to let the compiler marshal most of the parameters
* Added ARCH64 capability for smccc interface
* Changed the PSCI firmware calls (both arm and arm64) to use the new generic smccc interface instead instead of own assembly functions.
* Move optee DT bindings to below arm/firmware
* Defines method for OP-TEE driver to call secure world in DT, smc or hvc
* Exposes implementation id of a TEE driver in sysfs
to easily spawn corresponding tee-supplicant when device is ready
* Update OP-TEE Message Protocol to better cope with fragmented physical memory
* Read time directly from OP-TEE driver instead of forwarding the RPC request to tee-supplicant

v5:
* Replaced kref reference counting for the device with a size_t instead as the counter is always protected by a mutex

v4:
* Rebased on 4.1
* Redesigned the synchronization around entry exit of normal SMC
* Replaced rwsem on the driver instance with kref and completion since rwsem wasn't intended to be used in this way
* Expanded the TEE_IOCTL_PARAM_ATTR_TYPE_MASK to make room for future additional parameter types
* Documents TEE subsystem and OP-TEE driver
* Replaced TEE_IOC_CMD with TEE_IOC_OPEN_SESSION, TEE_IOC_INVOKE, TEE_IOC_CANCEL and TEE_IOC_CLOSE_SESSION
* DT bindings in a separate patch
* Assembly parts moved to arch/arm and arch/arm64 respectively, in a separate patch
* Redefined/clarified the meaning of OPTEE_SMC_SHM_CACHED
* Removed CMA usage to limit the scope of the patch set

v3:
* Rebased on 4.1-rc3 (dma_buf_export() API change)
* A couple of small sparse fixes
* Documents bindings for OP-TEE driver
* Updated MAINTAINERS

v2:
* Replaced the stubbed OP-TEE driver with a real OP-TEE driver
* Removed most APIs not needed by OP-TEE in current state
* Update Documentation/ioctl/ioctl-number.txt with correct path to tee.h
* Rename tee_shm_pool_alloc_cma() to tee_shm_pool_alloc()
* Moved tee.h into include/uapi/linux/
* Redefined tee.h IOCTL macros to be directly based on _IOR and friends
* Removed version info on the API to user space, a data blob which can contain an UUID is left for user space to be able to tell which protocol to use in TEE_IOC_CMD
* Changed user space exposed structures to only have types with __ prefix
* Dropped THIS_MODULE from tee_fops
* Reworked how the driver is registered and ref counted:
- moved from using an embedded struct miscdevice to an embedded struct device.
- uses an struct rw_semaphore as synchronization for driver detachment
- uses alloc/register pattern from TPM

Thanks,
Jens

Jens Wiklander (4):
dt/bindings: add bindings for optee
tee: generic TEE subsystem
tee: add OP-TEE driver
Documentation: tee subsystem and op-tee driver

 Documentation/00-INDEX                             |   2 +
 .../bindings/arm/firmware/linaro,optee-tz.txt      |  31 +
 .../devicetree/bindings/vendor-prefixes.txt        |   1 +
 Documentation/ioctl/ioctl-number.txt               |   1 +
 Documentation/tee.txt                              | 118 +++
 MAINTAINERS                                        |  13 +
 drivers/Kconfig                                    |   2 +
 drivers/Makefile                                   |   1 +
 drivers/tee/Kconfig                                |  18 +
 drivers/tee/Makefile                               |   5 +
 drivers/tee/optee/Kconfig                          |   7 +
 drivers/tee/optee/Makefile                         |   5 +
 drivers/tee/optee/call.c                           | 435 ++++++++++
 drivers/tee/optee/core.c                           | 598 ++++++++++++++
 drivers/tee/optee/optee_msg.h                      | 435 ++++++++++
 drivers/tee/optee/optee_private.h                  | 185 +++++
 drivers/tee/optee/optee_smc.h                      | 446 ++++++++++
 drivers/tee/optee/rpc.c                            | 404 +++++++++
 drivers/tee/optee/supp.c                           | 273 +++++++
 drivers/tee/tee_core.c                             | 901 +++++++++++++++++++++
 drivers/tee/tee_private.h                          | 129 +++
 drivers/tee/tee_shm.c                              | 357 ++++++++
 drivers/tee/tee_shm_pool.c                         | 158 ++++
 include/linux/tee_drv.h                            | 278 +++++++
 include/uapi/linux/tee.h                           | 403 +++++++++
 25 files changed, 5206 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/firmware/linaro,optee-tz.txt
 create mode 100644 Documentation/tee.txt
 create mode 100644 drivers/tee/Kconfig
 create mode 100644 drivers/tee/Makefile
 create mode 100644 drivers/tee/optee/Kconfig
 create mode 100644 drivers/tee/optee/Makefile
 create mode 100644 drivers/tee/optee/call.c
 create mode 100644 drivers/tee/optee/core.c
 create mode 100644 drivers/tee/optee/optee_msg.h
 create mode 100644 drivers/tee/optee/optee_private.h
 create mode 100644 drivers/tee/optee/optee_smc.h
 create mode 100644 drivers/tee/optee/rpc.c
 create mode 100644 drivers/tee/optee/supp.c
 create mode 100644 drivers/tee/tee_core.c
 create mode 100644 drivers/tee/tee_private.h
 create mode 100644 drivers/tee/tee_shm.c
 create mode 100644 drivers/tee/tee_shm_pool.c
 create mode 100644 include/linux/tee_drv.h
 create mode 100644 include/uapi/linux/tee.h
author Tested-by Jerome Forissier Tested-by Volodymyr Babchuk Acked-by Andreas Dannenberg Acked-by Rob Herring
#10 lore raw
Quoted 96 lines · Andrew F. Davis
Quoted 64 lines · Jens Wiklander
Quoted 52 lines · Andrew F. Davis
Quoted 43 lines · Jens Wiklander

Hi,

This patch set introduces a generic TEE subsystem. The TEE subsystem will contain drivers for various TEE implementations. A TEE (Trusted Execution Environment) is a trusted OS running in some secure environment, for example, TrustZone on ARM CPUs, or a separate secure co-processor etc.

Regarding use cases, TrustZone has traditionally been used for offloading secure tasks to the secure world. Examples include:
- Secure key handling where the OS may or may not have direct access to key material.
- E-commerce and payment technologies. Credentials, credit card numbers etc could be stored in a more secure environment.
- Trusted User Interface (TUI) to ensure that no-one can snoop PIN-codes etc.
- Secure boot to ensure that loaded binaries haven?t been tampered with. It?s not strictly needed for secure boot, but you could enhance security by leveraging a TEE during boot.
- Digital Rights Management (DRM), the studios provides content with different resolution depending on the security of the device. Higher security means higher resolution.

A TEE could also be used in existing and new technologies. For example IMA (Integrity Measurement Architecture) which has been in the kernel for quite a while. Today you can enhance security by using a TPM-chip to sign the IMA measurement list. This is something that you also could do by leveraging a TEE.

Another example could be in 2-factor authentication which is becoming increasingly more important. FIDO (https://fidoalliance.org) for example are using public key cryptography in their 2-factor authentication standard (U2F). With FIDO, a private and public key pair will be generated for every site you visit and the private key should never leave the local device. This is an example where you could use secure storage in a TEE for the private key.

Today you will find a quite a few different out of tree implementations of TEE drivers which tends to fragment the TEE ecosystem and development. We think it would be a good idea to have a generic TEE driver integrated in the kernel which would serve as a base for several different TEE solutions, no matter if they are on-chip like TrustZone or if they are on a separate crypto co-processor.

Quoted 7 lines

To develop this TEE subsystem we have been using the open source TEE called OP-TEE (https://github.com/OP-TEE/optee_os) and therefore this would be the first TEE solution supported by this new subsystem. OP-TEE is a GlobalPlatform compliant TEE, however this TEE subsystem is not limited to only GlobalPlatform TEEs, instead we have tried to design it so that it should work with other TEE solutions also.

Quoted 6 lines

The above is my biggest concern with this whole subsystem, to me it still feels very OPTEE specific. As much as I would love to believe OPTEE will be the end-all TEE, I'm sure we soon will start to see wider use of vendor TEEs (like TI's own legacy Trustzone thing we are hoping to depreciate with OPTEE moving forward), possibly Google's Trusty TEE, and whatever Intel/AMD are cooking up for x86.

I'd rather say that it's slightly GlobalPlatform specific, but a bit more flexible.

Quoted 1 line
Quoted 9 lines
Quoted 5 lines

As we all know when things are upstreamed we lose the ability to make radical changes easily, especially to full subsystems. What happens when this framework, built with only one existing TEE, built by the one existing TEE's devs, is not as flexible as we need when other TEEs start rolling out?

Initially the TEE subsystem was much more flexible and was criticized for that.

That's rather strange, I haven't been following this from the start so I will just take your word that this is where the community wants this subsystem to go.

Quoted 12 lines
Quoted 5 lines

Do we see this as a chicken and egg situation, or is there any harm beyond the pains of supporting an out-of-tree driver for a while, to wait until we have at least one other TEE to add to this subsystem before merging?

This proposal is the bare minimum to have something useful. On top of this there's more things we'd like to add, for example an in-kernel API for accessing the TEE and secure buffer handling. The way we're dealing with shared memory need to be improved to better support multiple guests communicating with one TEE.

Quoted 4 lines

What we can do now with the subsystem now is somewhat limited by the fact that we're trying to upstream it and want to do that it in manageable increments.

Quoted 6 lines

Fair enough.

For now this series is being used in our production SDKs so it has at least some basic testing from us, so for the whole series:

Thanks, Andrew. A summary of all tags so far:

When I sent out this patch set I missed including the previous tested-bys:

Then there's also the acked-by from Andreas which should have been included even if the mail now bounces:

The DT patch has (since v8):

Thanks,
Jens

#11 lore raw
Quoted 113 lines · Jens Wiklander
Quoted 96 lines · Andrew F. Davis
Quoted 64 lines · Jens Wiklander
Quoted 52 lines · Andrew F. Davis
Quoted 43 lines · Jens Wiklander

Hi,

This patch set introduces a generic TEE subsystem. The TEE subsystem will contain drivers for various TEE implementations. A TEE (Trusted Execution Environment) is a trusted OS running in some secure environment, for example, TrustZone on ARM CPUs, or a separate secure co-processor etc.

Regarding use cases, TrustZone has traditionally been used for offloading secure tasks to the secure world. Examples include:
- Secure key handling where the OS may or may not have direct access to key material.
- E-commerce and payment technologies. Credentials, credit card numbers etc could be stored in a more secure environment.
- Trusted User Interface (TUI) to ensure that no-one can snoop PIN-codes etc.
- Secure boot to ensure that loaded binaries haven?t been tampered with. It?s not strictly needed for secure boot, but you could enhance security by leveraging a TEE during boot.
- Digital Rights Management (DRM), the studios provides content with different resolution depending on the security of the device. Higher security means higher resolution.

A TEE could also be used in existing and new technologies. For example IMA (Integrity Measurement Architecture) which has been in the kernel for quite a while. Today you can enhance security by using a TPM-chip to sign the IMA measurement list. This is something that you also could do by leveraging a TEE.

Another example could be in 2-factor authentication which is becoming increasingly more important. FIDO (https://fidoalliance.org) for example are using public key cryptography in their 2-factor authentication standard (U2F). With FIDO, a private and public key pair will be generated for every site you visit and the private key should never leave the local device. This is an example where you could use secure storage in a TEE for the private key.

Today you will find a quite a few different out of tree implementations of TEE drivers which tends to fragment the TEE ecosystem and development. We think it would be a good idea to have a generic TEE driver integrated in the kernel which would serve as a base for several different TEE solutions, no matter if they are on-chip like TrustZone or if they are on a separate crypto co-processor.

Quoted 7 lines

To develop this TEE subsystem we have been using the open source TEE called OP-TEE (https://github.com/OP-TEE/optee_os) and therefore this would be the first TEE solution supported by this new subsystem. OP-TEE is a GlobalPlatform compliant TEE, however this TEE subsystem is not limited to only GlobalPlatform TEEs, instead we have tried to design it so that it should work with other TEE solutions also.

Quoted 6 lines

The above is my biggest concern with this whole subsystem, to me it still feels very OPTEE specific. As much as I would love to believe OPTEE will be the end-all TEE, I'm sure we soon will start to see wider use of vendor TEEs (like TI's own legacy Trustzone thing we are hoping to depreciate with OPTEE moving forward), possibly Google's Trusty TEE, and whatever Intel/AMD are cooking up for x86.

I'd rather say that it's slightly GlobalPlatform specific, but a bit more flexible.

Quoted 1 line
Quoted 9 lines
Quoted 5 lines

As we all know when things are upstreamed we lose the ability to make radical changes easily, especially to full subsystems. What happens when this framework, built with only one existing TEE, built by the one existing TEE's devs, is not as flexible as we need when other TEEs start rolling out?

Initially the TEE subsystem was much more flexible and was criticized for that.

That's rather strange, I haven't been following this from the start so I will just take your word that this is where the community wants this subsystem to go.

Quoted 12 lines
Quoted 5 lines

Do we see this as a chicken and egg situation, or is there any harm beyond the pains of supporting an out-of-tree driver for a while, to wait until we have at least one other TEE to add to this subsystem before merging?

This proposal is the bare minimum to have something useful. On top of this there's more things we'd like to add, for example an in-kernel API for accessing the TEE and secure buffer handling. The way we're dealing with shared memory need to be improved to better support multiple guests communicating with one TEE.

Quoted 4 lines

What we can do now with the subsystem now is somewhat limited by the fact that we're trying to upstream it and want to do that it in manageable increments.

Quoted 6 lines

Fair enough.

For now this series is being used in our production SDKs so it has at least some basic testing from us, so for the whole series:

Thanks, Andrew. A summary of all tags so far:

When I sent out this patch set I missed including the previous tested-bys:

Then there's also the acked-by from Andreas which should have been included even if the mail now bounces:

Quoted 7 lines

The DT patch has (since v8):

Thanks,
Jens

Jens,

I want to specify that I tested those patches on Renesas RCAR H3 platform. So my please update my Tested-by:

As far as I know, Renesas plans to use OP-TEE as a driver for cryptographic accelerators and others secure peripherals. So TEE support will be crucial for theirs platform.

Also I suspect that every platform on ARMv8 will include ARM Trusted Firmware (because it now provides PSCI) and some sort of TEE. So we really need generic TEE interface in the kernel.