All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt()
@ 2022-05-06 12:31 Stefan Mahnke-Hartmann
  2022-05-06 12:31 ` [PATCH 2/2] tpm: Add Field Upgrade mode support for Infineon TPM2 modules Stefan Mahnke-Hartmann
  2022-05-07 19:43 ` [PATCH 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt() Jarkko Sakkinen
  0 siblings, 2 replies; 8+ messages in thread
From: Stefan Mahnke-Hartmann @ 2022-05-06 12:31 UTC (permalink / raw)
  To: jarkko, linux-integrity, linux-kernel
  Cc: Marten.Lindahl, martenli, jgg, jsnitsel, nayna, johannes.holland,
	peterhuewe, Stefan Mahnke-Hartmann, 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>
---
 drivers/char/tpm/tpm2-cmd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 4704fa553098..e62a644ce26b 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -400,7 +400,10 @@ 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);
+		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] 8+ messages in thread

* [PATCH 2/2] tpm: Add Field Upgrade mode support for Infineon TPM2 modules
  2022-05-06 12:31 [PATCH 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt() Stefan Mahnke-Hartmann
@ 2022-05-06 12:31 ` Stefan Mahnke-Hartmann
  2022-05-07 19:43   ` Jarkko Sakkinen
  2022-05-07 19:43 ` [PATCH 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt() Jarkko Sakkinen
  1 sibling, 1 reply; 8+ messages in thread
From: Stefan Mahnke-Hartmann @ 2022-05-06 12:31 UTC (permalink / raw)
  To: jarkko, linux-integrity, linux-kernel
  Cc: Marten.Lindahl, martenli, jgg, jsnitsel, nayna, johannes.holland,
	peterhuewe, Stefan Mahnke-Hartmann

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>
---
 drivers/char/tpm/tpm2-cmd.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index e62a644ce26b..659130e2936e 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -746,6 +746,12 @@ int tpm2_auto_startup(struct tpm_chip *chip)
 	}
 
 	rc = tpm2_get_cc_attrs_tbl(chip);
+	/*
+	 * Infineon TPM in Field Upgrade mode will return no data for the number
+	 * of supported commands.
+	 */
+	if (rc == -ENODATA)
+		rc = TPM2_RC_UPGRADE;
 
 out:
 	if (rc == TPM2_RC_UPGRADE) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt()
  2022-05-06 12:31 [PATCH 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt() Stefan Mahnke-Hartmann
  2022-05-06 12:31 ` [PATCH 2/2] tpm: Add Field Upgrade mode support for Infineon TPM2 modules Stefan Mahnke-Hartmann
@ 2022-05-07 19:43 ` Jarkko Sakkinen
  2022-05-09 11:48   ` Stefan Mahnke-Hartmann
  1 sibling, 1 reply; 8+ messages in thread
From: Jarkko Sakkinen @ 2022-05-07 19:43 UTC (permalink / raw)
  To: Stefan Mahnke-Hartmann
  Cc: linux-integrity, linux-kernel, Marten.Lindahl, martenli, jgg,
	jsnitsel, nayna, johannes.holland, peterhuewe, stable

On Fri, May 06, 2022 at 02:31:46PM +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
                                      ~~~~~~~~~~~~~~~~~~

Looks like random picks for casing: two words with upper case letter and
one with lowe case.

> 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>

Which section is this in that specification documented?

I looked into section 30.2 but could not find the part that documents this
behaviour, i.e. returning success in FW upgrade mode. Why it wouldn't just
return TPM_RC_UPGRADE?

BR, Jarkko

 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] tpm: Add Field Upgrade mode support for Infineon TPM2 modules
  2022-05-06 12:31 ` [PATCH 2/2] tpm: Add Field Upgrade mode support for Infineon TPM2 modules Stefan Mahnke-Hartmann
@ 2022-05-07 19:43   ` Jarkko Sakkinen
  2022-05-09 12:50     ` Stefan Mahnke-Hartmann
  0 siblings, 1 reply; 8+ messages in thread
From: Jarkko Sakkinen @ 2022-05-07 19:43 UTC (permalink / raw)
  To: Stefan Mahnke-Hartmann
  Cc: linux-integrity, linux-kernel, Marten.Lindahl, martenli, jgg,
	jsnitsel, nayna, johannes.holland, peterhuewe

On Fri, May 06, 2022 at 02:31:48PM +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>
> ---
>  drivers/char/tpm/tpm2-cmd.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> index e62a644ce26b..659130e2936e 100644
> --- a/drivers/char/tpm/tpm2-cmd.c
> +++ b/drivers/char/tpm/tpm2-cmd.c
> @@ -746,6 +746,12 @@ int tpm2_auto_startup(struct tpm_chip *chip)
>  	}
>  
>  	rc = tpm2_get_cc_attrs_tbl(chip);
> +	/*
> +	 * Infineon TPM in Field Upgrade mode will return no data for the number
> +	 * of supported commands.
> +	 */
> +	if (rc == -ENODATA)
> +		rc = TPM2_RC_UPGRADE;

Injecting hardware error codes like this is not considered a great idea.

>  
>  out:
>  	if (rc == TPM2_RC_UPGRADE) {
> -- 
> 2.25.1
> 

BR, Jarkko

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt()
  2022-05-07 19:43 ` [PATCH 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt() Jarkko Sakkinen
@ 2022-05-09 11:48   ` Stefan Mahnke-Hartmann
  2022-05-11 15:11     ` Jarkko Sakkinen
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Mahnke-Hartmann @ 2022-05-09 11:48 UTC (permalink / raw)
  To: jarkko
  Cc: Marten.Lindahl, jgg, johannes.holland, jsnitsel, linux-integrity,
	linux-kernel, martenli, nayna, peterhuewe, stable,
	stefan.mahnke-hartmann

On 07.05.22 21:43, Jarkko Sakkinen wrote:
> On Fri, May 06, 2022 at 02:31:46PM +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
>                                       ~~~~~~~~~~~~~~~~~~
>
> Looks like random picks for casing: two words with upper case letter and
> one with lowe case.

In the TCG specification it is unfortunately also inconsistent.
I will change it to lower case then.

>
>> 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>
>
> Which section is this in that specification documented?

It is described in the TCG Trusted Platform Module Library Specification,
rev. 1.59 (Part 3: Commands) in Chapter 30.2.1, Example 3. This example
describes the behavior in failure mode, but it may occur in other
circumstances, such as field upgrade mode.

>
> I looked into section 30.2 but could not find the part that documents this
> behaviour, i.e. returning success in FW upgrade mode. Why it wouldn't just
> return TPM_RC_UPGRADE?

Since some computer system failed booting up in case the TPM returned
anything else than SUCCESS, therefore Infineon decided to return SUCCESS
when TPM is in field upgrade mode.

BR, Stefan

>
> BR, Jarkko
>
>  


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] tpm: Add Field Upgrade mode support for Infineon TPM2 modules
  2022-05-07 19:43   ` Jarkko Sakkinen
@ 2022-05-09 12:50     ` Stefan Mahnke-Hartmann
  2022-05-11 15:12       ` Jarkko Sakkinen
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Mahnke-Hartmann @ 2022-05-09 12:50 UTC (permalink / raw)
  To: jarkko
  Cc: Marten.Lindahl, jgg, johannes.holland, jsnitsel, linux-integrity,
	linux-kernel, martenli, nayna, peterhuewe,
	stefan.mahnke-hartmann

On 07.05.22 21:43, Jarkko Sakkinen wrote:
> On Fri, May 06, 2022 at 02:31:48PM +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>
>> ---
>>  drivers/char/tpm/tpm2-cmd.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
>> index e62a644ce26b..659130e2936e 100644
>> --- a/drivers/char/tpm/tpm2-cmd.c
>> +++ b/drivers/char/tpm/tpm2-cmd.c
>> @@ -746,6 +746,12 @@ int tpm2_auto_startup(struct tpm_chip *chip)
>>  	}
>>  
>>  	rc = tpm2_get_cc_attrs_tbl(chip);
>> +	/*
>> +	 * Infineon TPM in Field Upgrade mode will return no data for the number
>> +	 * of supported commands.
>> +	 */
>> +	if (rc == -ENODATA)
>> +		rc = TPM2_RC_UPGRADE;
>
> Injecting hardware error codes like this is not considered a great idea.

Resetting the error code was to avoid code duplication, while following the
same rationale as Mårten's patch. I can also add the -ENODATA to the if clause
below or duplicate the code block (similar to Mårten's). Do you have a better
suggestion?

>
>>  
>>  out:
>>  	if (rc == TPM2_RC_UPGRADE) {
>> -- 
>> 2.25.1
>>
>
> BR, Jarkko


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt()
  2022-05-09 11:48   ` Stefan Mahnke-Hartmann
@ 2022-05-11 15:11     ` Jarkko Sakkinen
  0 siblings, 0 replies; 8+ messages in thread
From: Jarkko Sakkinen @ 2022-05-11 15:11 UTC (permalink / raw)
  To: Stefan Mahnke-Hartmann
  Cc: Marten.Lindahl, jgg, johannes.holland, jsnitsel, linux-integrity,
	linux-kernel, martenli, nayna, peterhuewe, stable

On Mon, May 09, 2022 at 01:48:09PM +0200, Stefan Mahnke-Hartmann wrote:
> On 07.05.22 21:43, Jarkko Sakkinen wrote:
> > On Fri, May 06, 2022 at 02:31:46PM +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
> >                                       ~~~~~~~~~~~~~~~~~~
> >
> > Looks like random picks for casing: two words with upper case letter and
> > one with lowe case.
> 
> In the TCG specification it is unfortunately also inconsistent.
> I will change it to lower case then.
> 
> >
> >> 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>
> >
> > Which section is this in that specification documented?
> 
> It is described in the TCG Trusted Platform Module Library Specification,
> rev. 1.59 (Part 3: Commands) in Chapter 30.2.1, Example 3. This example
> describes the behavior in failure mode, but it may occur in other
> circumstances, such as field upgrade mode.
> 
> >
> > I looked into section 30.2 but could not find the part that documents this
> > behaviour, i.e. returning success in FW upgrade mode. Why it wouldn't just
> > return TPM_RC_UPGRADE?
> 
> Since some computer system failed booting up in case the TPM returned
> anything else than SUCCESS, therefore Infineon decided to return SUCCESS
> when TPM is in field upgrade mode.

OK, fair enough. This would be a place for inline comment though, given
that it is not obvious by intuition.

BR, Jarkko

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] tpm: Add Field Upgrade mode support for Infineon TPM2 modules
  2022-05-09 12:50     ` Stefan Mahnke-Hartmann
@ 2022-05-11 15:12       ` Jarkko Sakkinen
  0 siblings, 0 replies; 8+ messages in thread
From: Jarkko Sakkinen @ 2022-05-11 15:12 UTC (permalink / raw)
  To: Stefan Mahnke-Hartmann
  Cc: Marten.Lindahl, jgg, johannes.holland, jsnitsel, linux-integrity,
	linux-kernel, martenli, nayna, peterhuewe

On Mon, May 09, 2022 at 02:50:18PM +0200, Stefan Mahnke-Hartmann wrote:
> On 07.05.22 21:43, Jarkko Sakkinen wrote:
> > On Fri, May 06, 2022 at 02:31:48PM +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>
> >> ---
> >>  drivers/char/tpm/tpm2-cmd.c | 6 ++++++
> >>  1 file changed, 6 insertions(+)
> >>
> >> diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
> >> index e62a644ce26b..659130e2936e 100644
> >> --- a/drivers/char/tpm/tpm2-cmd.c
> >> +++ b/drivers/char/tpm/tpm2-cmd.c
> >> @@ -746,6 +746,12 @@ int tpm2_auto_startup(struct tpm_chip *chip)
> >>  	}
> >>  
> >>  	rc = tpm2_get_cc_attrs_tbl(chip);
> >> +	/*
> >> +	 * Infineon TPM in Field Upgrade mode will return no data for the number
> >> +	 * of supported commands.
> >> +	 */
> >> +	if (rc == -ENODATA)
> >> +		rc = TPM2_RC_UPGRADE;
> >
> > Injecting hardware error codes like this is not considered a great idea.
> 
> Resetting the error code was to avoid code duplication, while following the
> same rationale as Mårten's patch. I can also add the -ENODATA to the if clause
> below or duplicate the code block (similar to Mårten's). Do you have a better
> suggestion?

I'd do that instead. It documents better the conditions.

BR, Jarkko

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-05-11 15:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06 12:31 [PATCH 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt() Stefan Mahnke-Hartmann
2022-05-06 12:31 ` [PATCH 2/2] tpm: Add Field Upgrade mode support for Infineon TPM2 modules Stefan Mahnke-Hartmann
2022-05-07 19:43   ` Jarkko Sakkinen
2022-05-09 12:50     ` Stefan Mahnke-Hartmann
2022-05-11 15:12       ` Jarkko Sakkinen
2022-05-07 19:43 ` [PATCH 1/2] tpm: Fix buffer access in tpm2_get_tpm_pt() Jarkko Sakkinen
2022-05-09 11:48   ` Stefan Mahnke-Hartmann
2022-05-11 15:11     ` 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.