* [PATCH v2 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt()
@ 2022-05-13 13:41 Stefan Mahnke-Hartmann
2022-05-13 13:41 ` [PATCH v2 2/2] tpm: Add field upgrade mode support for Infineon TPM2 modules Stefan Mahnke-Hartmann
2022-05-16 18:38 ` [PATCH v2 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt() Jarkko Sakkinen
0 siblings, 2 replies; 4+ messages in thread
From: Stefan Mahnke-Hartmann @ 2022-05-13 13:41 UTC (permalink / raw)
To: jarkko, linux-integrity, linux-kernel
Cc: peterhuewe, jgg, jsnitsel, nayna, stefan.mahnke-hartmann,
alexander.steffen, stable
Under certain conditions uninitialized memory will be accessed.
As described by TCG Trusted Platform Module Library Specification,
rev. 1.59 (Part 3: Commands), if a TPM2_GetCapability is received,
requesting a capability, the TPM in field upgrade mode may return a
zero length list.
Check the property count in tpm2_get_tpm_pt().
Fixes: 2ab3241161b3 ("tpm: migrate tpm2_get_tpm_pt() to use struct tpm_buf")
Cc: stable@vger.kernel.org
Signed-off-by: Stefan Mahnke-Hartmann <stefan.mahnke-hartmann@infineon.com>
---
Changelog:
* v2:
* Add inline comment to indicate the root cause to may access unitilized
memory.
* Change 'field upgrade mode' to lower case.
drivers/char/tpm/tpm2-cmd.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 4704fa553098..04a3e23a4afc 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -400,7 +400,16 @@ ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, u32 *value,
if (!rc) {
out = (struct tpm2_get_cap_out *)
&buf.data[TPM_HEADER_SIZE];
- *value = be32_to_cpu(out->value);
+ /*
+ * To prevent failing boot up of some systems, Infineon TPM2.0
+ * returns SUCCESS on TPM2_Startup in field upgrade mode. Also
+ * the TPM2_Getcapability command returns a zero length list
+ * in field upgrade mode.
+ */
+ if (be32_to_cpu(out->property_cnt) > 0)
+ *value = be32_to_cpu(out->value);
+ else
+ rc = -ENODATA;
}
tpm_buf_destroy(&buf);
return rc;
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] tpm: Add field upgrade mode support for Infineon TPM2 modules
2022-05-13 13:41 [PATCH v2 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt() Stefan Mahnke-Hartmann
@ 2022-05-13 13:41 ` Stefan Mahnke-Hartmann
2022-05-16 18:36 ` Jarkko Sakkinen
2022-05-16 18:38 ` [PATCH v2 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt() Jarkko Sakkinen
1 sibling, 1 reply; 4+ messages in thread
From: Stefan Mahnke-Hartmann @ 2022-05-13 13:41 UTC (permalink / raw)
To: jarkko, linux-integrity, linux-kernel
Cc: peterhuewe, jgg, jsnitsel, nayna, stefan.mahnke-hartmann,
alexander.steffen
TPM2_GetCapability with a capability that has the property type value
of TPM_PT_TOTAL_COMMANDS returns a zero length list, when an Infineon
TPM2 is in field upgrade mode.
Since an Infineon TPM2.0 in field upgrade mode returns RC_SUCCESS on
TPM2_Startup, the field upgrade mode has to be detected by
TPM2_GetCapability.
Signed-off-by: Stefan Mahnke-Hartmann <stefan.mahnke-hartmann@infineon.com>
---
Changelog:
* v2:
* Move check of -ENODATA to if condition below.
* Change 'field upgrade mode' to lower case.
drivers/char/tpm/tpm2-cmd.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 04a3e23a4afc..c1eb5d223839 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -754,7 +754,11 @@ int tpm2_auto_startup(struct tpm_chip *chip)
rc = tpm2_get_cc_attrs_tbl(chip);
out:
- if (rc == TPM2_RC_UPGRADE) {
+ /*
+ * Infineon TPM in field upgrade mode will return no data for the number
+ * of supported commands.
+ */
+ if (rc == TPM2_RC_UPGRADE || rc == -ENODATA) {
dev_info(&chip->dev, "TPM in field upgrade mode, requires firmware upgrade\n");
chip->flags |= TPM_CHIP_FLAG_FIRMWARE_UPGRADE;
rc = 0;
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] tpm: Add field upgrade mode support for Infineon TPM2 modules
2022-05-13 13:41 ` [PATCH v2 2/2] tpm: Add field upgrade mode support for Infineon TPM2 modules Stefan Mahnke-Hartmann
@ 2022-05-16 18:36 ` Jarkko Sakkinen
0 siblings, 0 replies; 4+ messages in thread
From: Jarkko Sakkinen @ 2022-05-16 18:36 UTC (permalink / raw)
To: Stefan Mahnke-Hartmann
Cc: linux-integrity, linux-kernel, peterhuewe, jgg, jsnitsel, nayna,
alexander.steffen
On Fri, May 13, 2022 at 03:41:53PM +0200, Stefan Mahnke-Hartmann wrote:
> TPM2_GetCapability with a capability that has the property type value
> of TPM_PT_TOTAL_COMMANDS returns a zero length list, when an Infineon
> TPM2 is in field upgrade mode.
> Since an Infineon TPM2.0 in field upgrade mode returns RC_SUCCESS on
> TPM2_Startup, the field upgrade mode has to be detected by
> TPM2_GetCapability.
>
> Signed-off-by: Stefan Mahnke-Hartmann <stefan.mahnke-hartmann@infineon.com>
> ---
> Changelog:
> * v2:
> * Move check of -ENODATA to if condition below.
> * Change 'field upgrade mode' to lower case.
>
> drivers/char/tpm/tpm2-cmd.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index 04a3e23a4afc..c1eb5d223839 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -754,7 +754,11 @@ int tpm2_auto_startup(struct tpm_chip *chip)
> rc = tpm2_get_cc_attrs_tbl(chip);
>
> out:
> - if (rc == TPM2_RC_UPGRADE) {
> + /*
> + * Infineon TPM in field upgrade mode will return no data for the number
> + * of supported commands.
> + */
> + if (rc == TPM2_RC_UPGRADE || rc == -ENODATA) {
> dev_info(&chip->dev, "TPM in field upgrade mode, requires firmware upgrade\n");
> chip->flags |= TPM_CHIP_FLAG_FIRMWARE_UPGRADE;
> rc = 0;
> --
> 2.25.1
>
Looks good to me.
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
BR, Jarkko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt()
2022-05-13 13:41 [PATCH v2 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt() Stefan Mahnke-Hartmann
2022-05-13 13:41 ` [PATCH v2 2/2] tpm: Add field upgrade mode support for Infineon TPM2 modules Stefan Mahnke-Hartmann
@ 2022-05-16 18:38 ` Jarkko Sakkinen
1 sibling, 0 replies; 4+ messages in thread
From: Jarkko Sakkinen @ 2022-05-16 18:38 UTC (permalink / raw)
To: Stefan Mahnke-Hartmann
Cc: linux-integrity, linux-kernel, peterhuewe, jgg, jsnitsel, nayna,
alexander.steffen, stable
On Fri, May 13, 2022 at 03:41:51PM +0200, Stefan Mahnke-Hartmann wrote:
> Under certain conditions uninitialized memory will be accessed.
> As described by TCG Trusted Platform Module Library Specification,
> rev. 1.59 (Part 3: Commands), if a TPM2_GetCapability is received,
> requesting a capability, the TPM in field upgrade mode may return a
> zero length list.
> Check the property count in tpm2_get_tpm_pt().
>
> Fixes: 2ab3241161b3 ("tpm: migrate tpm2_get_tpm_pt() to use struct tpm_buf")
> Cc: stable@vger.kernel.org
> Signed-off-by: Stefan Mahnke-Hartmann <stefan.mahnke-hartmann@infineon.com>
> ---
> Changelog:
> * v2:
> * Add inline comment to indicate the root cause to may access unitilized
> memory.
> * Change 'field upgrade mode' to lower case.
>
> drivers/char/tpm/tpm2-cmd.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index 4704fa553098..04a3e23a4afc 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -400,7 +400,16 @@ ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, u32 *value,
> if (!rc) {
> out = (struct tpm2_get_cap_out *)
> &buf.data[TPM_HEADER_SIZE];
> - *value = be32_to_cpu(out->value);
> + /*
> + * To prevent failing boot up of some systems, Infineon TPM2.0
> + * returns SUCCESS on TPM2_Startup in field upgrade mode. Also
> + * the TPM2_Getcapability command returns a zero length list
> + * in field upgrade mode.
> + */
> + if (be32_to_cpu(out->property_cnt) > 0)
> + *value = be32_to_cpu(out->value);
> + else
> + rc = -ENODATA;
> }
> tpm_buf_destroy(&buf);
> return rc;
> --
> 2.25.1
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
BR, Jarkko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-05-16 18:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 13:41 [PATCH v2 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt() Stefan Mahnke-Hartmann
2022-05-13 13:41 ` [PATCH v2 2/2] tpm: Add field upgrade mode support for Infineon TPM2 modules Stefan Mahnke-Hartmann
2022-05-16 18:36 ` Jarkko Sakkinen
2022-05-16 18:38 ` [PATCH v2 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt() Jarkko Sakkinen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.