From ad95a32cf23117246d810e9398d4e5142652c97a Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Fri, 26 Jun 2020 16:40:27 -0400 Subject: [PATCH] tpm2: fix PCRBelongsTCBGroup for PCClient (bugfix) Fix PCRBelongsTCBGroup by adjusting the set of PCRs that belong to the TCB Group. The effect of this is that PCR changes to PCR 16 (for example) do not change the pcrUpdateCounter anymore. The effect *should not* have any negative side effects when using the TPM. We also need to update the test cases that now show a different pcrUpdateCounter in the responses. Also 'swtpm' test cases need to be fixed to expect the changed result. Signed-off-by: Stefan Berger --- src/tpm2/PCR.c | 7 +++++++ tests/tpm2_pcr_read.c | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/tpm2/PCR.c b/src/tpm2/PCR.c index d49cd332..9699afbc 100644 --- a/src/tpm2/PCR.c +++ b/src/tpm2/PCR.c @@ -163,12 +163,19 @@ PCRBelongsTCBGroup( ) { #if ENABLE_PCR_NO_INCREMENT == YES +#if 0 // Platform specification decides if a PCR belongs to a TCB group. In this // implementation, we assume PCR[20-22] belong to TCB group. If the platform // specification requires differently, the implementation should be // changed accordingly if(handle >= 20 && handle <= 22) return TRUE; +#endif + /* kgold - changed for PC Client, 16, 21-23 no increment */ + if ((handle == 16) || + ((handle >= 21) && (handle <= 23))) { + return TRUE; + } #endif return FALSE; } diff --git a/tests/tpm2_pcr_read.c b/tests/tpm2_pcr_read.c index 6028d7e6..54946e12 100644 --- a/tests/tpm2_pcr_read.c +++ b/tests/tpm2_pcr_read.c @@ -6,6 +6,19 @@ #include #include +static void dump_array(const char *h, const unsigned char *d, size_t dlen) +{ + size_t i; + + fprintf(stderr, "%s\n", h); + for (i = 0; i < dlen; i++) { + fprintf(stderr, "%02x ", d[i]); + if ((i & 0xf) == 0xf) + fprintf(stderr, "\n"); + } + fprintf(stderr, "\n"); +} + int main(void) { unsigned char *rbuffer = NULL; @@ -38,7 +51,7 @@ int main(void) }; const unsigned char tpm2_pcr_read_exp_resp[] = { 0x80, 0x01, 0x00, 0x00, 0x01, 0x86, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x03, 0x01, 0x00, 0x10, 0x00, 0x0b, 0x03, 0x01, 0x00, 0x10, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x10, 0x00, 0x0d, 0x03, 0x01, @@ -118,6 +131,8 @@ int main(void) if (memcmp(rbuffer, tpm2_pcr_read_exp_resp, rlength)) { fprintf(stderr, "Expected response is different than received one.\n"); + dump_array("actual:", rbuffer, rlength); + dump_array("expected:", tpm2_pcr_read_exp_resp, sizeof(tpm2_pcr_read_exp_resp)); goto exit; }