diff mbox series

[2/2] tpm: Add Field Upgrade mode support for Infineon TPM2 modules

Message ID 20220506123145.229058-2-stefan.mahnke-hartmann@infineon.com (mailing list archive)
State New
Headers show
Series [1/2] tpm: Fix buffer access in tpm2_get_tpm_pt() | expand

Commit Message

Stefan Mahnke-Hartmann May 6, 2022, 12:31 p.m. UTC
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(+)

Comments

Jarkko Sakkinen May 7, 2022, 7:43 p.m. UTC | #1
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
Stefan Mahnke-Hartmann May 9, 2022, 12:50 p.m. UTC | #2
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
Jarkko Sakkinen May 11, 2022, 3:12 p.m. UTC | #3
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
diff mbox series

Patch

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