tpm: OP-TEE transport core for discrete and firmware TPMs
Subsystems (2)
v2 cover tpm: OP-TEE transport core for discrete and firmware TPMs
This adds a driver for a discrete TPM that OP-TEE owns and the normal world cannot reach directly, and factors the shared OP-TEE TEE transport into a small core so the existing fTPM driver uses it too:
- a transport core shared by the OP-TEE TPM front-ends;
- a new discrete TPM front-end;
- the fTPM driver converted onto the core, keeping its name, its platform/OF binding and its shutdown path.
Patch 1 is the feature; patch 2 is the fTPM conversion that justifies the core. Both front-ends were exercised on the Qualcomm Lemans EVK over the shared core: the discrete ST33 TPM (patch 1) and the MS-TPM-20 firmware TPM TA (patch 2), each presenting a working /dev/tpm0 (tpm2_getrandom, PCR read). The fTPM TA is the same MS-TPM-20 reference the existing tpm_ftpm_tee platforms use.
This is the normal-world half. The secure-world OP-TEE support it binds to -- the in-core TPM2 SPI (TIS) driver and the mediator pseudo TA that relays commands to it -- is under review separately:
OP-TEE support: https://github.com/OP-TEE/optee_os/pull/8155
locality 4: https://github.com/OP-TEE/optee_os/issues/8160
(design follow-up: the secure world policing normal-world locality access to the shared chip)
Build and test it on the Qualcomm Lemans EVK (a discrete ST33 TPM on SPI, owned by OP-TEE):
https://qualcomm-linux.github.io/qcom-buildroot/lemans/quick-start.html
v1: https://lore.kernel.org/linux-integrity/[email protected]/
Changes since v1:
- split the shared TEE transport into a core; the discrete chip is now a thin front-end, the tpm_tis_core-style solution that was asked for.
- convert the fTPM driver onto the same core instead of duplicating it.
- use an optee-prefixed name for the new modules; the fTPM driver keeps its name, no module rename.
- rewrite the commit message with a plain description of the components and the rationale for a separate front-end.
- drop the explicit zeroing in favour of initialisers, and reword the module description.
Jorge Ramirez-Ortiz (2):
tpm: add OP-TEE transport core and a discrete TPM driver
tpm_ftpm_tee: use the tpm_optee transport core
MAINTAINERS | 8 + drivers/char/tpm/Kconfig | 28 +++ drivers/char/tpm/Makefile | 2 + drivers/char/tpm/tpm_ftpm_tee.c | 295 ++---------------------------- drivers/char/tpm/tpm_ftpm_tee.h | 35 ---- drivers/char/tpm/tpm_optee.c | 253 +++++++++++++++++++++++++ drivers/char/tpm/tpm_optee.h | 32 ++++ drivers/char/tpm/tpm_optee_dtpm.c | 67 +++++++ 8 files changed, 408 insertions(+), 312 deletions(-) delete mode 100644 drivers/char/tpm/tpm_ftpm_tee.h create mode 100644 drivers/char/tpm/tpm_optee.c create mode 100644 drivers/char/tpm/tpm_optee.h create mode 100644 drivers/char/tpm/tpm_optee_dtpm.c
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
Signature · 1 line
2.55.0
PATCH v2 1/2 tpm: add OP-TEE transport core and a discrete TPM driver
Some platforms place a real (discrete) TPM on a bus that only the secure world can drive. OP-TEE owns that bus, so the normal world cannot reach the chip directly; it instead exposes a mediator trusted application that relays TPM2 commands. Add a driver that talks to that application and presents the chip as a standard TPM2 character device, so the normal-world TPM stack works unchanged.
This is a separate driver from the firmware-TPM one rather than a reuse of it. The TEE transport is the same and is shared through a common core, but the device identity differs: the firmware TPM uses its own application and a public-login session, whereas a discrete chip needs its own application and is restricted to kernel access so that user space and other applications cannot submit raw commands to it. Folding both into one driver would also break on a platform that has both.
--- MAINTAINERS | 8 + drivers/char/tpm/Kconfig | 27 ++++ drivers/char/tpm/Makefile | 2 + drivers/char/tpm/tpm_optee.c | 242 ++++++++++++++++++++++++++++++ drivers/char/tpm/tpm_optee.h | 31 ++++ drivers/char/tpm/tpm_optee_dtpm.c | 67 +++++++++ 6 files changed, 377 insertions(+) create mode 100644 drivers/char/tpm/tpm_optee.c create mode 100644 drivers/char/tpm/tpm_optee.h create mode 100644 drivers/char/tpm/tpm_optee_dtpm.c
MAINTAINERS +8 -0
@@ -27710,6 +27710,14 @@ F: include/linux/tpm*.h F: include/uapi/linux/vtpm_proxy.h F: tools/testing/selftests/tpm2/ +TPM TEE DRIVER FOR DISCRETE TPM +R: Jorge Ramirez-Ortiz <[email protected]> +L: [email protected] +S: Supported +F: drivers/char/tpm/tpm_optee.c +F: drivers/char/tpm/tpm_optee.h +F: drivers/char/tpm/tpm_optee_dtpm.c + TPS546D24 DRIVER M: Duke Du <[email protected]> L: [email protected]
drivers/char/tpm/Kconfig +27 -0
@@ -243,6 +243,33 @@ config TCG_FTPM_TEE help This driver proxies for firmware TPM running in TEE. +config TCG_OPTEE + tristate + depends on TEE && OPTEE + help + Shared transport for TPMs reached through an OP-TEE trusted + application. It is selected by the front-end drivers and is not + meant to be enabled on its own. + +config TCG_OPTEE_DTPM + tristate "OP-TEE based discrete TPM Interface" + depends on TEE && OPTEE + select TCG_OPTEE + help + This driver proxies for a discrete TPM that is owned by OP-TEE and + reachable only from the secure world (for example an SPI TPM behind + OP-TEE's TPM TIS driver). OP-TEE exposes a mediator pseudo TA and + this driver pipes TPM commands through it, presenting a standard + TPM character device to the normal world. + + The secure world is the sole owner of the TPM and of the bus it + sits on. That bus/controller must be disabled in the non-secure + device tree: disabling only the in-kernel TPM driver (e.g. + tpm_tis_spi) is not enough, because the normal-world bus controller + would still drive the engine in parallel with OP-TEE and corrupt + its transfers. With the bus disabled, the TPM is reached only + through this driver. + config TCG_SVSM tristate "SNP SVSM vTPM interface" depends on AMD_MEM_ENCRYPT
drivers/char/tpm/Makefile +2 -0
@@ -45,5 +45,7 @@ obj-$(CONFIG_TCG_CRB) += tpm_crb.o obj-$(CONFIG_TCG_ARM_CRB_FFA) += tpm_crb_ffa.o obj-$(CONFIG_TCG_VTPM_PROXY) += tpm_vtpm_proxy.o obj-$(CONFIG_TCG_FTPM_TEE) += tpm_ftpm_tee.o +obj-$(CONFIG_TCG_OPTEE) += tpm_optee.o +obj-$(CONFIG_TCG_OPTEE_DTPM) += tpm_optee_dtpm.o obj-$(CONFIG_TCG_SVSM) += tpm_svsm.o obj-$(CONFIG_TCG_LOONGSON) += tpm_loongson.o
drivers/char/tpm/tpm_optee.c new file +242 -0
242 lines not on this page · raw message
drivers/char/tpm/tpm_optee.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +* +* Shared transport for TPMs reached through an OP-TEE trusted application. +*/ + +#ifndef __TPM_OPTEE_H__ +#define __TPM_OPTEE_H__ + +#include <linux/types.h> +#include <linux/uuid.h> + +struct device ; + +/** +* struct tpm_optee_config - identity of a TPM reached through an OP-TEE TA +* @ta_uuid: UUID of the trusted application to bind +* @login: TEE_IOCTL_LOGIN_* client login used to open the session +* @cmd_id: TA function ID that submits a TPM command +*/ +struct tpm_optee_config { +uuid_t ta_uuid; +u32 login; +u32 cmd_id; +}; + +int tpm_optee_probe (struct device *dev,const struct tpm_optee_config *cfg); +void tpm_optee_remove (struct device *dev); + +#endif /* __TPM_OPTEE_H__ */
drivers/char/tpm/tpm_optee_dtpm.c new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v2 2/2 tpm_ftpm_tee: use the tpm_optee transport core
In reply to Jorge Ramirez-OrtizThe firmware-TPM driver and the new discrete-TPM driver share the same OP-TEE transport, now factored into a common core. Move the firmware-TPM driver onto it so the transport is not duplicated. The driver keeps its name, its platform/OF binding and its shutdown behaviour; only the transport is shared.
Two functional changes come from sharing the core: a command longer than the caller's buffer is now rejected (it was previously only checked against the application's maximum), and a failed command submission returns -EIO instead of the raw error code from the secure world.
--- drivers/char/tpm/Kconfig | 1 + drivers/char/tpm/tpm_ftpm_tee.c | 295 ++------------------------------ drivers/char/tpm/tpm_ftpm_tee.h | 35 ---- drivers/char/tpm/tpm_optee.c | 11 ++ drivers/char/tpm/tpm_optee.h | 1 + 5 files changed, 31 insertions(+), 312 deletions(-) delete mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
drivers/char/tpm/Kconfig +1 -0
@@ -240,6 +240,7 @@ config TCG_VTPM_PROXY config TCG_FTPM_TEE tristate "TEE based fTPM Interface" depends on TEE && OPTEE + select TCG_OPTEE help This driver proxies for firmware TPM running in TEE.
drivers/char/tpm/tpm_ftpm_tee.c +18 -277
341 lines not on this page · raw message
drivers/char/tpm/tpm_ftpm_tee.h deleted +0 -35
@@ -1,35 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* Copyright (C) Microsoft Corporation -*/ - -#ifndef __TPM_FTPM_TEE_H__ -#define __TPM_FTPM_TEE_H__ - -#include <linux/tee_drv.h> -#include <linux/tpm.h> -#include <linux/uuid.h> - -/* The TAFs ID implemented in this TA */ -#define FTPM_OPTEE_TA_SUBMIT_COMMAND (0) -#define FTPM_OPTEE_TA_EMULATE_PPI (1) - -/* max. buffer size supported by fTPM */ -#define MAX_COMMAND_SIZE 4096 -#define MAX_RESPONSE_SIZE 4096 - -/** -* struct ftpm_tee_private - fTPM's private data -* @chip: struct tpm_chip instance registered with tpm framework. -* @session: fTPM TA session identifier. -* @ctx: TEE context handler. -* @shm: Memory pool shared with fTPM TA in TEE. -*/ -struct ftpm_tee_private { -struct tpm_chip *chip; -u32 session; -struct tee_context *ctx; -struct tee_shm *shm; -}; - -#endif /* __TPM_FTPM_TEE_H__ */
drivers/char/tpm/tpm_optee.c +11 -0
@@ -238,5 +238,16 @@ void tpm_optee_remove(struct device *dev) }EXPORT_SYMBOL_GPL (tpm_optee_remove); +/* Release the TEE resources on shutdown, leaving the chip registered. */ +void tpm_optee_shutdown (struct device *dev) +{ +struct tpm_optee_private *pvt_data =dev_get_drvdata (dev); + +tee_shm_free (pvt_data->shm); +tee_client_close_session (pvt_data->ctx, pvt_data->session); +tee_client_close_context (pvt_data->ctx); +} +EXPORT_SYMBOL_GPL (tpm_optee_shutdown); +MODULE_DESCRIPTION ("OP-TEE TPM transport core" );MODULE_LICENSE ("GPL" );
drivers/char/tpm/tpm_optee.h +1 -0
@@ -27,5 +27,6 @@ struct tpm_optee_config {int tpm_optee_probe (struct device *dev,const struct tpm_optee_config *cfg);void tpm_optee_remove (struct device *dev); +void tpm_optee_shutdown (struct device *dev);#endif /* __TPM_OPTEE_H__ */
Signature · 1 line
2.55.0
Jarkko Sakkinen
maintainerRe: [PATCH v2 1/2] tpm: add OP-TEE transport core and a discrete TPM driver
In reply to Jorge Ramirez-OrtizQuoted 15 lines · Jorge Ramirez-Ortiz
Some platforms place a real (discrete) TPM on a bus that only the secure world can drive. OP-TEE owns that bus, so the normal world cannot reach the chip directly; it instead exposes a mediator trusted application that relays TPM2 commands. Add a driver that talks to that application and presents the chip as a standard TPM2 character device, so the normal-world TPM stack works unchanged.
This is a separate driver from the firmware-TPM one rather than a reuse of it. The TEE transport is the same and is shared through a common core, but the device identity differs: the firmware TPM uses its own application and a public-login session, whereas a discrete chip needs its own application and is restricted to kernel access so that user space and other applications cannot submit raw commands to it. Folding both into one driver would also break on a platform that has both.
Quoted 1 line
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>
Looks pretty good. Did you check the Sashiko remark?
https://sashiko.dev/#/patchset/20261110141923.3100770-1-jorge.ramirez%40oss.qualcomm.com
Br, Jarkko
Re: [PATCH v2 1/2] tpm: add OP-TEE transport core and a discrete TPM driver
Quoted 16 lines · Jarkko Sakkinen
Quoted 15 lines · Jorge Ramirez-Ortiz
Some platforms place a real (discrete) TPM on a bus that only the secure world can drive. OP-TEE owns that bus, so the normal world cannot reach the chip directly; it instead exposes a mediator trusted application that relays TPM2 commands. Add a driver that talks to that application and presents the chip as a standard TPM2 character device, so the normal-world TPM stack works unchanged.
This is a separate driver from the firmware-TPM one rather than a reuse of it. The TEE transport is the same and is shared through a common core, but the device identity differs: the firmware TPM uses its own application and a public-login session, whereas a discrete chip needs its own application and is restricted to kernel access so that user space and other applications cannot submit raw commands to it. Folding both into one driver would also break on a platform that has both.
Quoted 7 lines
Quoted 1 line
Signed-off-by Jorge Ramirez-Ortiz <[email protected]>Looks pretty good. Did you check the Sashiko remark?
https://sashiko.dev/#/patchset/20261110141923.3100770-1-jorge.ramirez%40oss.qualcomm.com
Br, Jarkko
um, right, that is a bug correctly addressed by the ftpm implementation (the shutdown callback needs to go in the core as well)
will post a v3. thanks!
Jarkko Sakkinen
maintainerRe: [PATCH v2 1/2] tpm: add OP-TEE transport core and a discrete TPM driver
Quoted 4 lines · Jorge Ramirez
um, right, that is a bug correctly addressed by the ftpm implementation (the shutdown callback needs to go in the core as well)
will post a v3. thanks!
No worries, we don't have it yet enabled for linux-integrity.
Eric, forwarded just as a supportive argument for the discussion :-)
Br, Jarkko