public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Yao, Jiewen" <jiewen.yao@intel.com>
To: "Gonzalez Del Cueto,
	Rodrigo" <rodrigo.gonzalez.del.cueto@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Wang, Jian J" <jian.j.wang@intel.com>,
	"Zhang, Qi1" <qi1.zhang@intel.com>
Subject: Re: [PATCH] SecurityPkg: Fix GetSupportedAndActivePcrs counter calculation
Date: Thu, 23 Jul 2020 02:12:39 +0000	[thread overview]
Message-ID: <DM5PR11MB20264683F753A5BCCAC7202B8C760@DM5PR11MB2026.namprd11.prod.outlook.com> (raw)
In-Reply-To: <a776afef658b3665c7a79f0ea24dabf0959a692e.1595283971.git.rodrigo.gonzalez.del.cueto@intel.com>

Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>

> -----Original Message-----
> From: Gonzalez Del Cueto, Rodrigo <rodrigo.gonzalez.del.cueto@intel.com>
> Sent: Tuesday, July 21, 2020 6:27 AM
> To: devel@edk2.groups.io
> Cc: Gonzalez Del Cueto, Rodrigo <rodrigo.gonzalez.del.cueto@intel.com>; Yao,
> Jiewen <jiewen.yao@intel.com>; Wang, Jian J <jian.j.wang@intel.com>; Zhang,
> Qi1 <qi1.zhang@intel.com>
> Subject: [PATCH] SecurityPkg: Fix GetSupportedAndActivePcrs counter
> calculation
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2855
> The Tpm2GetCapabilitySupportedAndActivePcrs function prints a
> count number that should reflect the *supported and currently
> active* PCR banks, but the implementation in place displays
> instead the count of the *supported PCR banks* retrieved
> directly from the Tpm2GetCapabilityPcrs()
> TPML_PCR_SELECTION output.
> 
> The counter should only take into account those PCRs banks
> which are active.
> 
> Replaced usage of EFI_D_* for DEBUG_* definitions in debug
> messages.
> 
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Qi Zhang <qi1.zhang@intel.com>
> Signed-off-by: Rodrigo Gonzalez del Cueto
> <rodrigo.gonzalez.del.cueto@intel.com>
> ---
>  .../Library/Tpm2CommandLib/Tpm2Capability.c   | 46 ++++++++++++-------
>  1 file changed, 29 insertions(+), 17 deletions(-)
> 
> diff --git a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c
> b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c
> index 85b11c7715..07cac08c40 100644
> --- a/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c
> +++ b/SecurityPkg/Library/Tpm2CommandLib/Tpm2Capability.c
> @@ -110,7 +110,7 @@ Tpm2GetCapability (
>    // Fail if command failed
> 
>    //
> 
>    if (SwapBytes32(RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {
> 
> -    DEBUG ((EFI_D_ERROR, "Tpm2GetCapability: Response Code error!
> 0x%08x\r\n", SwapBytes32(RecvBuffer.Header.responseCode)));
> 
> +    DEBUG ((DEBUG_ERROR, "Tpm2GetCapability: Response Code error!
> 0x%08x\r\n", SwapBytes32(RecvBuffer.Header.responseCode)));
> 
>      return EFI_DEVICE_ERROR;
> 
>    }
> 
> 
> 
> @@ -522,74 +522,86 @@ Tpm2GetCapabilitySupportedAndActivePcrs (
>    EFI_STATUS            Status;
> 
>    TPML_PCR_SELECTION    Pcrs;
> 
>    UINTN                 Index;
> 
> +  UINT8                 ActivePcrBankCount;
> 
> 
> 
>    //
> 
> -  // Get supported PCR and current Active PCRs.
> 
> +  // Get supported PCR
> 
>    //
> 
>    Status = Tpm2GetCapabilityPcrs (&Pcrs);
> 
> -
> 
> +  DEBUG ((DEBUG_INFO, "Supported PCRs - Count = %08x\n", Pcrs.count));
> 
> +  ActivePcrBankCount = 0;
> 
>    //
> 
>    // If error, assume that we have at least SHA-1 (and return the error.)
> 
>    //
> 
>    if (EFI_ERROR (Status)) {
> 
> -    DEBUG ((EFI_D_ERROR, "GetSupportedAndActivePcrs -
> Tpm2GetCapabilityPcrs fail!\n"));
> 
> +    DEBUG ((DEBUG_ERROR, "GetSupportedAndActivePcrs -
> Tpm2GetCapabilityPcrs fail!\n"));
> 
>      *TpmHashAlgorithmBitmap = HASH_ALG_SHA1;
> 
>      *ActivePcrBanks         = HASH_ALG_SHA1;
> 
> +    ActivePcrBankCount = 1;
> 
>    }
> 
>    //
> 
>    // Otherwise, process the return data to determine what algorithms are
> supported
> 
>    // and currently allocated.
> 
>    //
> 
>    else {
> 
> -    DEBUG ((EFI_D_INFO, "GetSupportedAndActivePcrs - Count = %08x\n",
> Pcrs.count));
> 
>      *TpmHashAlgorithmBitmap = 0;
> 
>      *ActivePcrBanks         = 0;
> 
>      for (Index = 0; Index < Pcrs.count; Index++) {
> 
>        switch (Pcrs.pcrSelections[Index].hash) {
> 
>        case TPM_ALG_SHA1:
> 
> -        DEBUG ((EFI_D_VERBOSE, "GetSupportedAndActivePcrs - HASH_ALG_SHA1
> present.\n"));
> 
> +        DEBUG ((DEBUG_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA1 present.\n"));
> 
>          *TpmHashAlgorithmBitmap |= HASH_ALG_SHA1;
> 
>          if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect,
> Pcrs.pcrSelections[Index].sizeofSelect)) {
> 
> -          DEBUG ((EFI_D_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA1 active.\n"));
> 
> +          DEBUG ((DEBUG_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA1 active.\n"));
> 
>            *ActivePcrBanks |= HASH_ALG_SHA1;
> 
> +          ActivePcrBankCount++;
> 
>          }
> 
>          break;
> 
>        case TPM_ALG_SHA256:
> 
> -        DEBUG ((EFI_D_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA256 present.\n"));
> 
> +        DEBUG ((DEBUG_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA256 present.\n"));
> 
>          *TpmHashAlgorithmBitmap |= HASH_ALG_SHA256;
> 
>          if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect,
> Pcrs.pcrSelections[Index].sizeofSelect)) {
> 
> -          DEBUG ((EFI_D_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA256 active.\n"));
> 
> +          DEBUG ((DEBUG_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA256 active.\n"));
> 
>            *ActivePcrBanks |= HASH_ALG_SHA256;
> 
> +          ActivePcrBankCount++;
> 
>          }
> 
>          break;
> 
>        case TPM_ALG_SHA384:
> 
> -        DEBUG ((EFI_D_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA384 present.\n"));
> 
> +        DEBUG ((DEBUG_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA384 present.\n"));
> 
>          *TpmHashAlgorithmBitmap |= HASH_ALG_SHA384;
> 
>          if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect,
> Pcrs.pcrSelections[Index].sizeofSelect)) {
> 
> -          DEBUG ((EFI_D_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA384 active.\n"));
> 
> +          DEBUG ((DEBUG_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA384 active.\n"));
> 
>            *ActivePcrBanks |= HASH_ALG_SHA384;
> 
> +          ActivePcrBankCount++;
> 
>          }
> 
>          break;
> 
>        case TPM_ALG_SHA512:
> 
> -        DEBUG ((EFI_D_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA512 present.\n"));
> 
> +        DEBUG ((DEBUG_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA512 present.\n"));
> 
>          *TpmHashAlgorithmBitmap |= HASH_ALG_SHA512;
> 
>          if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect,
> Pcrs.pcrSelections[Index].sizeofSelect)) {
> 
> -          DEBUG ((EFI_D_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA512 active.\n"));
> 
> +          DEBUG ((DEBUG_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SHA512 active.\n"));
> 
>            *ActivePcrBanks |= HASH_ALG_SHA512;
> 
> +          ActivePcrBankCount++;
> 
>          }
> 
>          break;
> 
>        case TPM_ALG_SM3_256:
> 
> -        DEBUG ((EFI_D_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SM3_256 present.\n"));
> 
> +        DEBUG ((DEBUG_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SM3_256 present.\n"));
> 
>          *TpmHashAlgorithmBitmap |= HASH_ALG_SM3_256;
> 
>          if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect,
> Pcrs.pcrSelections[Index].sizeofSelect)) {
> 
> -          DEBUG ((EFI_D_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SM3_256 active.\n"));
> 
> +          DEBUG ((DEBUG_VERBOSE, "GetSupportedAndActivePcrs -
> HASH_ALG_SM3_256 active.\n"));
> 
>            *ActivePcrBanks |= HASH_ALG_SM3_256;
> 
> +          ActivePcrBankCount++;
> 
>          }
> 
>          break;
> 
> +      default:
> 
> +        DEBUG ((DEBUG_VERBOSE, "GetSupportedAndActivePcrs - Unsupported
> bank 0x%04x.\n", Pcrs.pcrSelections[Index].hash));
> 
> +        continue;
> 
> +        break;
> 
>        }
> 
>      }
> 
>    }
> 
> 
> 
> +  DEBUG ((DEBUG_INFO, "GetSupportedAndActivePcrs - Count = %08x\n",
> ActivePcrBankCount));
> 
>    return Status;
> 
>  }
> 
> 
> 
> @@ -837,11 +849,11 @@ Tpm2TestParms (
>    }
> 
> 
> 
>    if (RecvBufferSize < sizeof (TPM2_RESPONSE_HEADER)) {
> 
> -    DEBUG ((EFI_D_ERROR, "Tpm2TestParms - RecvBufferSize Error - %x\n",
> RecvBufferSize));
> 
> +    DEBUG ((DEBUG_ERROR, "Tpm2TestParms - RecvBufferSize Error - %x\n",
> RecvBufferSize));
> 
>      return EFI_DEVICE_ERROR;
> 
>    }
> 
>    if (SwapBytes32(RecvBuffer.Header.responseCode) != TPM_RC_SUCCESS) {
> 
> -    DEBUG ((EFI_D_ERROR, "Tpm2TestParms - responseCode - %x\n",
> SwapBytes32(RecvBuffer.Header.responseCode)));
> 
> +    DEBUG ((DEBUG_ERROR, "Tpm2TestParms - responseCode - %x\n",
> SwapBytes32(RecvBuffer.Header.responseCode)));
> 
>      return EFI_UNSUPPORTED;
> 
>    }
> 
> 
> 
> --
> 2.27.0.windows.1


  reply	other threads:[~2020-07-23  2:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-20 22:27 [PATCH] SecurityPkg: Fix GetSupportedAndActivePcrs counter calculation rodrigo.gonzalez.del.cueto
2020-07-23  2:12 ` Yao, Jiewen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-07-20 21:26 Rodrigo Gonzalez del Cueto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DM5PR11MB20264683F753A5BCCAC7202B8C760@DM5PR11MB2026.namprd11.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox