fTPM: firmware TPM running in TEE
Subsystems (3)
v8 cover fTPM: firmware TPM running in TEE
Changes from v7:
- Address Jarkko's comments.
Sasha Levin (2):
fTPM: firmware TPM running in TEE
fTPM: add documentation for ftpm driver
Documentation/security/tpm/index.rst | 1 + Documentation/security/tpm/tpm_ftpm_tee.rst | 27 ++ drivers/char/tpm/Kconfig | 5 + drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_ftpm_tee.c | 350 ++++++++++++++++++++ drivers/char/tpm/tpm_ftpm_tee.h | 40 +++ 6 files changed, 424 insertions(+) create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst create mode 100644 drivers/char/tpm/tpm_ftpm_tee.c create mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
Signature · 1 line
2.20.1
PATCH v8 1/2 fTPM: firmware TPM running in TEE
This patch adds support for a software-only implementation of a TPM running in TEE.
There is extensive documentation of the design here:
https://www.microsoft.com/en-us/research/publication/ftpm-software-implementation-tpm-chip/ .
As well as reference code for the firmware available here:
https://github.com/Microsoft/ms-tpm-20-ref/tree/master/Samples/ARM32-FirmwareTPM
--- drivers/char/tpm/Kconfig | 5 + drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_ftpm_tee.c | 350 ++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm_ftpm_tee.h | 40 ++++ 4 files changed, 396 insertions(+) create mode 100644 drivers/char/tpm/tpm_ftpm_tee.c create mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
drivers/char/tpm/Kconfig +5 -0
@@ -164,6 +164,11 @@ config TCG_VTPM_PROXY /dev/vtpmX and a server-side file descriptor on which the vTPM can receive commands. +config TCG_FTPM_TEE + tristate "TEE based fTPM Interface" + depends on TEE && OPTEE + ---help--- + This driver proxies for firmware TPM running in TEE. source "drivers/char/tpm/st33zp24/Kconfig" endif # TCG_TPM
drivers/char/tpm/Makefile +1 -0
@@ -33,3 +33,4 @@ obj-$(CONFIG_TCG_TIS_ST33ZP24) += st33zp24/ obj-$(CONFIG_TCG_XEN) += xen-tpmfront.o obj-$(CONFIG_TCG_CRB) += tpm_crb.o obj-$(CONFIG_TCG_VTPM_PROXY) += tpm_vtpm_proxy.o +obj-$(CONFIG_TCG_FTPM_TEE) += tpm_ftpm_tee.o
drivers/char/tpm/tpm_ftpm_tee.c new file +350 -0
350 lines not on this page · raw message
drivers/char/tpm/tpm_ftpm_tee.h new file +40 -0
@@ -0,0 +1,40 @@ +/* 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. +* @state: internal state +* @session: fTPM TA session identifier. +* @resp_len: cached response buffer length. +* @resp_buf: cached response buffer. +* @ctx: TEE context handler. +* @shm: Memory pool shared with fTPM TA in TEE. +*/ +struct ftpm_tee_private { +struct tpm_chip *chip; +u32 session; +size_t resp_len; +u8 resp_buf[MAX_RESPONSE_SIZE ]; +struct tee_context *ctx; +struct tee_shm *shm; +}; + +#endif /* __TPM_FTPM_TEE_H__ */
Signature · 1 line
2.20.1
Quoted 6 lines · Sasha Levin
This patch adds support for a software-only implementation of a TPM running in TEE.
There is extensive documentation of the design here:
https://www.microsoft.com/en-us/research/publication/ftpm-software-implementation-tpm-chip/ .
Quoted 7 lines
As well as reference code for the firmware available here:
https://github.com/Microsoft/ms-tpm-20-ref/tree/master/Samples/ARM32-FirmwareTPMSigned-off-by Thirupathaiah Annapureddy <[email protected]>Co-authored-by Sasha Levin <[email protected]>Signed-off-by Sasha Levin <[email protected]>
/Jarkko
PATCH v8 2/2 fTPM: add documentation for ftpm driver
In reply to Sasha LevinThis patch adds basic documentation to describe the new fTPM driver.
--- Documentation/security/tpm/index.rst | 1 + Documentation/security/tpm/tpm_ftpm_tee.rst | 27 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst
Documentation/security/tpm/index.rst +1 -0
@@ -4,4 +4,5 @@ Trusted Platform Module documentation .. toctree:: + tpm_ftpm_tee tpm_vtpm_proxy
Documentation/security/tpm/tpm_ftpm_tee.rst new file +27 -0
@@ -0,0 +1,27 @@ +============================================= +Firmware TPM Driver +============================================= + +This document describes the firmware Trusted Platform Module (fTPM) +device driver. + +Introduction +============ + +This driver is a shim for firmware implemented in ARM's TrustZone +environment. The driver allows programs to interact with the TPM in the same +way they would interact with a hardware TPM. + +Design +====== + +The driver acts as a thin layer that passes commands to and from a TPM +implemented in firmware. The driver itself doesn't contain much logic and is +used more like a dumb pipe between firmware and kernel/userspace. + +The firmware itself is based on the following paper: +https://www.microsoft.com/en-us/research/wp-content/uploads/2017/06/ftpm1.pdf + +When the driver is loaded it will expose ``/dev/tpmX`` character devices to +userspace which will enable userspace to communicate with the firmware TPM +through this device.
Signature · 1 line
2.20.1
Re: [PATCH v8 2/2] fTPM: add documentation for ftpm driver
Quoted 3 lines · Sasha Levin
This patch adds basic documentation to describe the new fTPM driver.
Signed-off-by Sasha Levin <[email protected]>
/Jarkko
Quoted 8 lines · Sasha Levin
Changes from v7:
- Address Jarkko's comments.
Sasha Levin (2):
fTPM: firmware TPM running in TEE
fTPM: add documentation for ftpm driver
Quoted 14 lines
Documentation/security/tpm/index.rst | 1 + Documentation/security/tpm/tpm_ftpm_tee.rst | 27 ++ drivers/char/tpm/Kconfig | 5 + drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_ftpm_tee.c | 350 ++++++++++++++++++++ drivers/char/tpm/tpm_ftpm_tee.h | 40 +++ 6 files changed, 424 insertions(+) create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst create mode 100644 drivers/char/tpm/tpm_ftpm_tee.c create mode 100644 drivers/char/tpm/tpm_ftpm_tee.hSignature · 1 line
2.20.1
I applied the patches now. Appreciate a lot the patience with these. Thank you.
/Jarkko
Quoted 20 lines · Jarkko Sakkinen
Quoted 19 lines · Sasha Levin
Changes from v7:
- Address Jarkko's comments.
Sasha Levin (2):
fTPM: firmware TPM running in TEE
fTPM: add documentation for ftpm driverDocumentation/security/tpm/index.rst | 1 + Documentation/security/tpm/tpm_ftpm_tee.rst | 27 ++ drivers/char/tpm/Kconfig | 5 + drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_ftpm_tee.c | 350 ++++++++++++++++++++ drivers/char/tpm/tpm_ftpm_tee.h | 40 +++ 6 files changed, 424 insertions(+) create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst create mode 100644 drivers/char/tpm/tpm_ftpm_tee.c create mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
Quoted 7 lines
Quoted 3 lines
Signature · 1 line
2.20.1I applied the patches now. Appreciate a lot the patience with these. Thank you.
Will report back any issues when we start using it on real hardware rather than QEMU
Thanks
/Ilias
Quoted 1 line
/Jarkko
Quoted 21 lines · Ilias Apalodimas
Quoted 20 lines · Jarkko Sakkinen
Quoted 19 lines · Sasha Levin
Changes from v7:
- Address Jarkko's comments.
Sasha Levin (2):
fTPM: firmware TPM running in TEE
fTPM: add documentation for ftpm driverDocumentation/security/tpm/index.rst | 1 + Documentation/security/tpm/tpm_ftpm_tee.rst | 27 ++ drivers/char/tpm/Kconfig | 5 + drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_ftpm_tee.c | 350 ++++++++++++++++++++ drivers/char/tpm/tpm_ftpm_tee.h | 40 +++ 6 files changed, 424 insertions(+) create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst create mode 100644 drivers/char/tpm/tpm_ftpm_tee.c create mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
--
2.20.1I applied the patches now. Appreciate a lot the patience with these. Thank you.
Thanks Jarkko!
Quoted 2 lines
Will report back any issues when we start using it on real hardware rather than QEMU
And thank you Ilias, let us know if we can help with the setup.
--
Thanks,
Sasha
Quoted 5 lines · Ilias Apalodimas
Will report back any issues when we start using it on real hardware rather than QEMU
Thanks
/Ilias
That would awesome. PR is far away so there is time to add more tested-by's. Thanks.
/Jarkko
Quoted 10 lines · Jarkko Sakkinen
Quoted 5 lines · Ilias Apalodimas
Will report back any issues when we start using it on real hardware rather than QEMU
Thanks
/IliasThat would awesome. PR is far away so there is time to add more tested-by's. Thanks.
I tested the basic fucntionality on QEMU and with the code only built as a module. You can add my tested-by on this if you want
Quoted 1 line
/Jarkko
Quoted 8 lines · Ilias Apalodimas
Quoted 7 lines · Jarkko Sakkinen
Quoted 5 lines · Ilias Apalodimas
Will report back any issues when we start using it on real hardware rather than QEMU
Thanks
/Ilias
Quoted 6 lines
Quoted 3 lines
That would awesome. PR is far away so there is time to add more tested-by's. Thanks.
I tested the basic fucntionality on QEMU and with the code only built as a module. You can add my tested-by on this if you want
Thank you. Added.
/Jarkko
Quoted 20 lines · Jarkko Sakkinen
Quoted 19 lines · Sasha Levin
Changes from v7:
- Address Jarkko's comments.
Sasha Levin (2):
fTPM: firmware TPM running in TEE
fTPM: add documentation for ftpm driverDocumentation/security/tpm/index.rst | 1 + Documentation/security/tpm/tpm_ftpm_tee.rst | 27 ++ drivers/char/tpm/Kconfig | 5 + drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_ftpm_tee.c | 350 ++++++++++++++++++++ drivers/char/tpm/tpm_ftpm_tee.h | 40 +++ 6 files changed, 424 insertions(+) create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst create mode 100644 drivers/char/tpm/tpm_ftpm_tee.c create mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
Quoted 6 lines
Quoted 3 lines
Signature · 1 line
2.20.1I applied the patches now. Appreciate a lot the patience with these. Thank you.
Hi, can you possibly fix these:
005-tpm-tpm_ftpm_tee-A-driver-for-firmware-TPM-running-i.patch
---------------------------------------------------------------
WARNING: Possible unwrapped commit description (prefer a maximum 75 chars per line) #10:
https://www.microsoft.com/en-us/research/publication/ftpm-software-implementation-tpm-chip/ .
WARNING: Non-standard signature: Co-authored-by:
#18:
WARNING: prefer 'help' over '---help---' for new help texts #39: FILE: drivers/char/tpm/Kconfig:167:
+config TCG_FTPM_TEE
WARNING: please write a paragraph that describes the config symbol fully #39: FILE: drivers/char/tpm/Kconfig:167:
+config TCG_FTPM_TEE
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #57:
new file mode 100644
WARNING: please, no space before tabs
#102: FILE: drivers/char/tpm/tpm_ftpm_tee.c:41:
+ * ^IIn case of success the number of bytes received.$
WARNING: please, no space before tabs
#131: FILE: drivers/char/tpm/tpm_ftpm_tee.c:70:
+ * ^IIn case of success, returns 0.$
WARNING: please, no space before tabs
#276: FILE: drivers/char/tpm/tpm_ftpm_tee.c:215:
+ * ^IOn success, 0. On failure, -errno.$
WARNING: please, no space before tabs
#366: FILE: drivers/char/tpm/tpm_ftpm_tee.c:305:
+ * ^I0 always.$
ERROR: code indent should use tabs where possible
#387: FILE: drivers/char/tpm/tpm_ftpm_tee.c:326:
+ /* memory allocated with devm_kzalloc() is freed automatically */$
WARNING: DT compatible string "microsoft,ftpm" appears un-documented -- check ./Documentation/devicetree/bindings/ #393: FILE: drivers/char/tpm/tpm_ftpm_tee.c:332:
+ { .compatible = "microsoft,ftpm" },
WARNING: DT compatible string vendor "microsoft" appears un-documented -- check ./Documentation/devicetree/bindings/vendor-prefixes.yaml #393: FILE: drivers/char/tpm/tpm_ftpm_tee.c:332:
+ { .compatible = "microsoft,ftpm" },
total: 1 errors, 11 warnings, 405 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
NOTE: Whitespace errors detected.
You may wish to use scripts/cleanpatch or scripts/cleanfile
I temporarily dropped the patches but can apply them once the issues are fixed.
/Jarkko
Quoted 21 lines · Jarkko Sakkinen
Quoted 20 lines · Jarkko Sakkinen
Quoted 19 lines · Sasha Levin
Changes from v7:
- Address Jarkko's comments.
Sasha Levin (2):
fTPM: firmware TPM running in TEE
fTPM: add documentation for ftpm driverDocumentation/security/tpm/index.rst | 1 + Documentation/security/tpm/tpm_ftpm_tee.rst | 27 ++ drivers/char/tpm/Kconfig | 5 + drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_ftpm_tee.c | 350 ++++++++++++++++++++ drivers/char/tpm/tpm_ftpm_tee.h | 40 +++ 6 files changed, 424 insertions(+) create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst create mode 100644 drivers/char/tpm/tpm_ftpm_tee.c create mode 100644 drivers/char/tpm/tpm_ftpm_tee.h
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
--
2.20.1I applied the patches now. Appreciate a lot the patience with these. Thank you.
Hi, can you possibly fix these:
Any objection to sending you a patch on top of your tree instead?
--
Thanks,
Sasha
Quoted 26 lines · Sasha Levin
Quoted 25 lines · Jarkko Sakkinen
Quoted 24 lines · Jarkko Sakkinen
Quoted 22 lines · Sasha Levin
Changes from v7:
- Address Jarkko's comments.
Sasha Levin (2):
fTPM: firmware TPM running in TEE
fTPM: add documentation for ftpm driverDocumentation/security/tpm/index.rst | 1 + Documentation/security/tpm/tpm_ftpm_tee.rst | 27 ++ drivers/char/tpm/Kconfig | 5 + drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_ftpm_tee.c | 350 ++++++++++++++++++++ drivers/char/tpm/tpm_ftpm_tee.h | 40 +++ 6 files changed, 424 insertions(+) create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst create mode 100644 drivers/char/tpm/tpm_ftpm_tee.c create mode 100644 drivers/char/tpm/tpm_ftpm_tee.h--
2.20.1
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
I applied the patches now. Appreciate a lot the patience with these. Thank you.
Hi, can you possibly fix these:
Any objection to sending you a patch on top of your tree instead?
Go ahead. Added the previous patches to my master.
/Jarkko
Quoted 27 lines · Jarkko Sakkinen
Quoted 26 lines · Sasha Levin
Quoted 25 lines · Jarkko Sakkinen
Quoted 24 lines · Jarkko Sakkinen
Quoted 22 lines · Sasha Levin
Changes from v7:
- Address Jarkko's comments.
Sasha Levin (2):
fTPM: firmware TPM running in TEE
fTPM: add documentation for ftpm driverDocumentation/security/tpm/index.rst | 1 + Documentation/security/tpm/tpm_ftpm_tee.rst | 27 ++ drivers/char/tpm/Kconfig | 5 + drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_ftpm_tee.c | 350 ++++++++++++++++++++ drivers/char/tpm/tpm_ftpm_tee.h | 40 +++ 6 files changed, 424 insertions(+) create mode 100644 Documentation/security/tpm/tpm_ftpm_tee.rst create mode 100644 drivers/char/tpm/tpm_ftpm_tee.c create mode 100644 drivers/char/tpm/tpm_ftpm_tee.h--
2.20.1
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
I applied the patches now. Appreciate a lot the patience with these. Thank you.
Hi, can you possibly fix these:
Any objection to sending you a patch on top of your tree instead?
Go ahead. Added the previous patches to my master.
Thanks! I'm getting back home on Monday and I'll send it out right away.
--
Thanks,
Sasha
Hi,
I spent some time with the fTPM module and TA on a Nitrogen6X with the latest OP-TEE master. After stumbling through the "tee_supplicant no persistent storage" problem, my module now issues the following error message on module load:
[ 34.633252] tpm tpm0: ftpm_tee_tpm_op_send: SUBMIT_COMMAND invoke error: 0xffff0006 [ 34.641035] tpm tpm0: tpm_try_transmit: send(): error -65530 [ 34.647008] tpm tpm0: ftpm_tee_tpm_op_send: SUBMIT_COMMAND invoke error: 0xffff0006 [ 34.654788] tpm tpm0: tpm_try_transmit: send(): error -65530 [ 34.660480] ftpm-tee ftpm: ftpm_tee_probe: tpm_chip_register failed with rc=-65530 [ 34.678087] ftpm-tee: probe of ftpm failed with error -65530
To me the TEE_ERROR_BAD_PARAMETERS indicates some ABI issue between the TA and the kernel module. Note that I built the TA from
https://github.com/microsoft/MSRSec.git with commit 6bb57db632c424f87cbaf7ec6f9c89be7682b3c0. Maybe this is not the correct version, I had some problems building the module from the repository mentioned in the Patches
Regards,
Rouven Czerwinski
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | https://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |