ftpm: dt-binding: add dts documentation for fTPM driver
Subsystems (3)
PATCH 1/2 ftpm: dt-binding: add dts documentation for fTPM driver
--- .../bindings/security/tpm/tpm_ftpm_tee.txt | 13 +++++++++++++ .../devicetree/bindings/vendor-prefixes.txt | 1 + 2 files changed, 14 insertions(+) create mode 100644 Documentation/devicetree/bindings/security/tpm/tpm_ftpm_tee.txt
Documentation/devicetree/bindings/security/tpm/tpm_ftpm_tee.txt new file +13 -0
@@ -0,0 +1,13 @@ +Required properties: +- compatible: should be "microsoft,ftpm" +- linux,sml-base: 64-bit base address of the reserved memory allocated + for the firmware event log +- linux,sml-size: size of the memory allocated for the firmware event log + +Example: + +tpm@0 { + compatible = "microsoft,ftpm"; + linux,sml-base = <0x0 0xC0000000>; + linux,sml-size = <0x10000>; +};
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
@@ -249,6 +249,7 @@ micrel Micrel Inc. microchip Microchip Technology Inc. microcrystal Micro Crystal AG micron Micron Technology Inc. +microsoft Microsoft Corporation mikroe MikroElektronika d.o.o. minix MINIX Technology Ltd. miramems MiraMEMS Sensing Technology Co., Ltd.
Signature · 1 line
2.19.1
PATCH 2/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 | 353 ++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm_ftpm_tee.h | 61 ++++++ 4 files changed, 420 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 + ---help--- + This driver proxies for fTPM 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 +353 -0
353 lines not on this page · raw message
drivers/char/tpm/tpm_ftpm_tee.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
2.19.1
Quoted 2 lines · Sasha Levin
Signed-off-by Sasha Levin <[email protected]>---
I know I don't take patches without any changelog text :)
Quoted 5 lines · Greg KH
Quoted 2 lines · Sasha Levin
Signed-off-by Sasha Levin <[email protected]>---
I know I don't take patches without any changelog text :)
I honestly don't have anything meaningful to add in the changelog, and looking at similar commits under Documentation/devicetree/bindings/ that just add a new binding, they have a very similar changelog as well (see 204d94e63e22, 772bf73ed4dc, and b805c403c859 for example).
While I could add meaningless text which basically copies the subject line, I don't think it will solve the concern you're pointing out here.
There is a lot of documentation for the fTPM driver which is listed in the following patch, but it's not relevant to this patch at all.
--
Thanks,
Sasha
Re: [PATCH 2/2] ftpm: firmware TPM running in TEE
In reply to Sasha LevinQuoted 9 lines · On Tue, 2 Apr 2019 12:33:16 -0700 "Sasha Levin" <[email protected]> wrote:
+/*
+ *ftpm_tee_tpm_op_recvretrieve fTPM response.
+ * @param: chip, thetpm_chipdescription as specified indriver/char/tpm/tpm.h.
+ * @param: buf, the buffer to store data.
+ * @param: count, the number of bytes to read.
+ * @return: In case of success the number of bytes received.
+ * In other case, a < 0 value describing the issue.
+ */
You are using a docbook style comment but it doesn't start with docbook prefix.
/**
* ftpm_tee_tpm_op_recv retrieve fTPM response.
*
* @param: chip, the tpm_chip description as specified in driver/char/tpm/tpm.h.
* @param: buf, the buffer to store data.
* @param: count, the number of bytes to read.
* @return: In case of success the number of bytes received.
* In other case, a < 0 value describing the issue.
*/
Jason Gunthorpe
reviewerRe: [PATCH 2/2] ftpm: firmware TPM running in TEE
In reply to Sasha LevinQuoted 13 lines · Sasha Levin
drivers/char/tpm/tpm_ftpm_tee.c new file +13
-0+/* +* Undo what has been done in ftpm_tee_probe +*/ +static void ftpm_tee_deinit (struct ftpm_tee_private *pvt_data) +{ +/* Release the chip */ +if (pvt_data->state &STATE_REGISTERED_FLAG ) +tpm_chip_unregister (pvt_data->chip); + +if (pvt_data->ctx !=NULL ) { + +/* Free the shared memory pool */ +if (pvt_data->state &STATE_TEE_SHMALLOC_FLAG )
drivers/char/tpm/tpm_ftpm_tee.c line 228
Quoted 10 lines
drivers/char/tpm/tpm_ftpm_tee.c new file +10
-0+tee_shm_free (pvt_data->shm); + +/* close the existing session with fTPM TA*/ +if (pvt_data->state &STATE_TEE_OPENED_FLAG ) +tee_client_close_session (pvt_data->ctx, + pvt_data->session); + +/* close the context with TEE driver */ +tee_client_close_context (pvt_data->ctx); + }
all these flags are ugly, just use a normal goto unwind during probe please
Quoted 9 lines
drivers/char/tpm/tpm_ftpm_tee.c new file +9
-0+ +/* memory allocated with devm_kzalloc() is freed automatically */ +} + +/* +* ftpm_tee_probe initialize the fTPM +* @param: pdev, the platform_device description. +* @return: 0 in case of success. +* or a negative value describing the error.
drivers/char/tpm/tpm_ftpm_tee.c line 247
Quoted 10 lines
drivers/char/tpm/tpm_ftpm_tee.c new file +10
-0+*/ +static int ftpm_tee_probe (struct platform_device *pdev) +{ +int rc; +struct tpm_chip *chip; +struct device *dev = &pdev->dev; +struct ftpm_tee_private *pvt_data =NULL ; +struct tee_ioctl_open_session_arg sess_arg; + +dev_dbg (dev,"%s++\n" , __func__);
Please don't push tracing like this to the upstream kernel, we have ftrace and what not to do this generally :(
Quoted 34 lines
drivers/char/tpm/tpm_ftpm_tee.c new file +34
-0+ pvt_data =devm_kzalloc (dev,sizeof (struct ftpm_tee_private ), +GFP_KERNEL ); +if (!pvt_data) +return -ENOMEM ; + +dev_set_drvdata (dev, pvt_data); + +/* Open context with TEE driver */ + pvt_data->ctx =tee_client_open_context (NULL , ftpm_tee_match,NULL , +NULL ); +if (IS_ERR (pvt_data->ctx)) { +dev_err (dev,"%s:tee_client_open_context failed\n" , __func__); +return -EPROBE_DEFER ; + } + +/* Open a session with fTPM TA*/ +memset (&sess_arg,0 ,sizeof (sess_arg)); +memcpy (sess_arg.uuid, ftpm_ta_uuid.b,TEE_IOCTL_UUID_LEN ); + sess_arg.clnt_login =TEE_IOCTL_LOGIN_PUBLIC ; + sess_arg.num_params =0 ; + + rc =tee_client_open_session (pvt_data->ctx, &sess_arg,NULL ); +if ((rc <0 ) || (sess_arg.ret !=0 )) { +dev_err (dev,"%s:tee_client_open_session failed, err=%x\n" , + __func__, sess_arg.ret); + rc = -EINVAL ; + goto out; + } + pvt_data->session = sess_arg.session; + pvt_data->state |=STATE_TEE_OPENED_FLAG ; + +/* Allocate dynamic shared memory with fTPM TA */ + pvt_data->shm = tee_shm_alloc(pvt_data->ctx, + (MAX_COMMAND_SIZE + MAX_RESPONSE_SIZE),
drivers/char/tpm/tpm_ftpm_tee.c line 292
Quoted 10 lines
drivers/char/tpm/tpm_ftpm_tee.c new file +10
-0+ TEE_SHM_MAPPED | TEE_SHM_DMA_BUF); +if (IS_ERR (pvt_data->shm)) { +dev_err (dev,"%s:tee_shm_alloc failed\n" , __func__); + rc = -ENOMEM ; + goto out; + } + pvt_data->state |=STATE_TEE_SHMALLOC_FLAG ; + +/* Allocate new struct tpm_chip instance */ + chip =tpm_chip_alloc (dev, &ftpm_tee_tpm_ops);
Why not tpmm_chip_alloc ? Using devm in other places
Doesn't this leak memory? I don't see a put_device cleanup for chip_alloc?
drivers/char/tpm/tpm_ftpm_tee.c line 303
Quoted 11 lines
drivers/char/tpm/tpm_ftpm_tee.c new file +11
-0+if (IS_ERR (chip)) { +dev_err (dev,"%s:tpm_chip_alloc failed\n" , __func__); + rc =PTR_ERR (chip); + goto out; + } + + pvt_data->chip = chip; + pvt_data->chip->flags |=TPM_CHIP_FLAG_TPM2 ; + +/* Create a character device for the fTPM */ + rc =tpm_chip_register (pvt_data->chip);
It is a bad idea to do things after tpm_chip_register, it should be the last thing done during probe except for error cleanup via a goto unwind.
Jason
Quoted 2 lines · Sasha Levin
Signed-off-by Sasha Levin <[email protected]>---
/Jarkko
Re: [PATCH 2/2] ftpm: firmware TPM running in TEE
In reply to Sasha LevinQuoted 11 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/ .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]>Signed-off-by Sasha Levin <[email protected]>
What is the context anyway? I mean tpm_crb already supports fTPM running in TZ.
/Jarkko
Re: [PATCH 2/2] ftpm: firmware TPM running in TEE
In reply to Stephen HemmingerQuoted 16 lines · Stephen Hemminger
Quoted 9 lines · On Tue, 2 Apr 2019 12:33:16 -0700 "Sasha Levin" <[email protected]> wrote:
+/*
+ *ftpm_tee_tpm_op_recvretrieve fTPM response.
+ * @param: chip, thetpm_chipdescription as specified indriver/char/tpm/tpm.h.
+ * @param: buf, the buffer to store data.
+ * @param: count, the number of bytes to read.
+ * @return: In case of success the number of bytes received.
+ * In other case, a < 0 value describing the issue.
+ */You are using a docbook style comment but it doesn't start with docbook prefix.
Quoted 9 lines
/**
*ftpm_tee_tpm_op_recvretrieve fTPM response.
*
* @param: chip, thetpm_chipdescription as specified indriver/char/tpm/tpm.h.
* @param: buf, the buffer to store data.
* @param: count, the number of bytes to read.
* @return: In case of success the number of bytes received.
* In other case, a < 0 value describing the issue.
*/
This is different commenting style that we use on anything else under drivers/char/tpm.
/Jarkko
Re: [PATCH 2/2] ftpm: firmware TPM running in TEE
In reply to Jarkko SakkinenQuoted 7 lines · Jarkko Sakkinen
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 8 lines
Quoted 5 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]>Signed-off-by Sasha Levin <[email protected]>What is the context anyway? I mean
tpm_crbalready supports fTPM running in TZ.
Might take 2-3 weeks before I have time to go through ftpm1.pdf with full concentration. I did search through the PDF for CRB and found zero hits.
The commit message should absolutely better explain what is going on and preferably there should be some more broad documentation in Documentation/security/tpm.
Now this is just a random code dump and nothing else.
Also, I have zero idea how to test this. Any recommendations on ARM board that can be easily used to test custom TZ applications would be nice.
/Jarkko
Re: [PATCH 2/2] ftpm: firmware TPM running in TEE
Quoted 14 lines · Jarkko Sakkinen
Quoted 13 lines · Jarkko Sakkinen
Quoted 11 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/ .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]>Signed-off-by Sasha Levin <[email protected]>
Quoted 6 lines
Quoted 2 lines
What is the context anyway? I mean
tpm_crbalready supports fTPM running in TZ.Might take 2-3 weeks before I have time to go through ftpm1.pdf with full concentration. I did search through the PDF for CRB and found zero hits.
The fTPM as described in that paper and implemented in practice does not use the CRB interface, thus we can't use tpm_crb to interface with the firmware TPM.
Quoted 3 lines
The commit message should absolutely better explain what is going on and preferably there should be some more broad documentation in
Documentation/security/tpm.
The code itself is just a small shim between the firmware TPM and the kernel's TPM interface. There's really not much else to expand on in the commit log.
I'll add some background to Documentation/security/tpm.
Quoted 1 line
Now this is just a random code dump and nothing else.
It pretty much is, but that's because this is just a "stupid" shim, there heavy lifting is done outside of the kernel.
Quoted 3 lines
Also, I have zero idea how to test this. Any recommendations on ARM board that can be easily used to test custom TZ applications would be nice.
We are testing this on a Broadcom's Stingray SST100 board, and if you have one we can help out with setting up a test environment. Otherwise, we haven't really tried it on other boards.
--
Thanks,
Sasha
Re: [PATCH 2/2] ftpm: firmware TPM running in TEE
Quoted 18 lines · Sasha Levin
Quoted 17 lines · Jarkko Sakkinen
Quoted 15 lines · Jarkko Sakkinen
Quoted 11 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/ .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]>Signed-off-by Sasha Levin <[email protected]>What is the context anyway? I mean
tpm_crbalready supports fTPM running in TZ.
Quoted 7 lines
Quoted 3 lines
Might take 2-3 weeks before I have time to go through ftpm1.pdf with full concentration. I did search through the PDF for CRB and found zero hits.
The fTPM as described in that paper and implemented in practice does not use the CRB interface, thus we can't use
tpm_crbto interface with the firmware TPM.
Obviously not but what is the reason of not implementing CRB but instead making yet another interface? I mean CRB supports SMC call.
For me this is taking steps back as to the early days when there was proprietary intefaces to TPM before TCG came along and stardized.
I'm sure that the TPM implementation itself could be reworked to inteface using CRB. It would also be good for ARM as a platform as now this new made up interface causes unwanted divergence. I thought that throwing ad hoc intefaces everywhere is something that ARM Linux community tries to reduce, not increase.
/Jarkko
Re: [PATCH 2/2] ftpm: firmware TPM running in TEE
Quoted 30 lines · Jarkko Sakkinen
Quoted 18 lines · Sasha Levin
Quoted 17 lines · Jarkko Sakkinen
Quoted 15 lines · Jarkko Sakkinen
Quoted 11 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/ .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]>Signed-off-by Sasha Levin <[email protected]>What is the context anyway? I mean
tpm_crbalready supports fTPM running in TZ.Quoted 7 lines
Quoted 3 lines
Might take 2-3 weeks before I have time to go through ftpm1.pdf with full concentration. I did search through the PDF for CRB and found zero hits.
The fTPM as described in that paper and implemented in practice does not use the CRB interface, thus we can't use
tpm_crbto interface with the firmware TPM.Obviously not but what is the reason of not implementing CRB but instead making yet another interface? I mean CRB supports SMC call.
Quoted 8 lines
For me this is taking steps back as to the early days when there was proprietary intefaces to TPM before TCG came along and stardized.
I'm sure that the TPM implementation itself could be reworked to inteface using CRB. It would also be good for ARM as a platform as now this new made up interface causes unwanted divergence. I thought that throwing ad hoc intefaces everywhere is something that ARM Linux community tries to reduce, not increase.
I'm not sure what the original reasons were for not using the CRB interface. Note that the paper is from a few years ago, and implementations of this fTPM existed before the paper, so it's very possible that it just predates CRB.
Either way, there is existing hardware that runs this TPM and I'm trying to get it out of Microsoft's tree and get it upstream. There's not much I could do about existing hardware at this point.
--
Thanks,
Sasha
Re: [PATCH 2/2] ftpm: firmware TPM running in TEE
Quoted 40 lines · Sasha Levin
Quoted 30 lines · Jarkko Sakkinen
Quoted 18 lines · Sasha Levin
Quoted 17 lines · Jarkko Sakkinen
Quoted 15 lines · Jarkko Sakkinen
Quoted 11 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/ .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]>Signed-off-by Sasha Levin <[email protected]>What is the context anyway? I mean
tpm_crbalready supports fTPM running in TZ.Quoted 7 lines
Quoted 3 lines
Might take 2-3 weeks before I have time to go through ftpm1.pdf with full concentration. I did search through the PDF for CRB and found zero hits.
The fTPM as described in that paper and implemented in practice does not use the CRB interface, thus we can't use
tpm_crbto interface with the firmware TPM.Obviously not but what is the reason of not implementing CRB but instead making yet another interface? I mean CRB supports SMC call.
Quoted 8 lines
For me this is taking steps back as to the early days when there was proprietary intefaces to TPM before TCG came along and stardized.
I'm sure that the TPM implementation itself could be reworked to inteface using CRB. It would also be good for ARM as a platform as now this new made up interface causes unwanted divergence. I thought that throwing ad hoc intefaces everywhere is something that ARM Linux community tries to reduce, not increase.
Quoted 8 lines
I'm not sure what the original reasons were for not using the CRB interface. Note that the paper is from a few years ago, and implementations of this fTPM existed before the paper, so it's very possible that it just predates CRB.
Either way, there is existing hardware that runs this TPM and I'm trying to get it out of Microsoft's tree and get it upstream. There's not much I could do about existing hardware at this point.
OK, the 2nd paragraph kind of is enough reason to pull it. Thanks for elaborating this. Just wanted to get a clearer picture where this sits in the universe. I'll do detailed review as soon as I have time.
I don't need to have the hardware as long as *someone* could give tested-by for this.
/Jarkko