[coreboot-gerrit] Patch set updated for coreboot: tpm2: Fix tlcl and marshaling code for CAR usage

Duncan Laurie (dlaurie@chromium.org) gerrit at coreboot.org
Fri Sep 2 01:22:25 CEST 2016


Duncan Laurie (dlaurie at chromium.org) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16393

-gerrit

commit 6d898be969f1a7ef1f5f65013264310b609548bc
Author: Duncan Laurie <dlaurie at chromium.org>
Date:   Thu Sep 1 16:09:43 2016 -0700

    tpm2: Fix tlcl and marshaling code for CAR usage
    
    Fix a few more instances of global variable usage in the tlcl
    and marshaling code for tpm2.
    
    For the tlcl case this buffer doesn't need to be static as it
    isn't used after this function exits.
    
    Change-Id: Ia739c81d79c6cee9046ae96061045fe4f7fb7c23
    Signed-off-by: Duncan Laurie <dlaurie at chromium.org>
---
 src/lib/tpm2_marshaling.c | 23 ++++++++++++-----------
 src/lib/tpm2_tlcl.c       |  2 +-
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/lib/tpm2_marshaling.c b/src/lib/tpm2_marshaling.c
index f4fd3cb..1edc690 100644
--- a/src/lib/tpm2_marshaling.c
+++ b/src/lib/tpm2_marshaling.c
@@ -546,7 +546,8 @@ struct tpm2_response *tpm_unmarshal_response(TPM_CC command,
 					     void *response_body,
 					     size_t in_size)
 {
-	static struct tpm2_response tpm2_resp;
+	static struct tpm2_response tpm2_static_resp CAR_GLOBAL;
+	struct tpm2_response *tpm2_resp = car_get_var_ptr(&tpm2_static_resp);
 	/*
 	 * Should be 0 when done, positive and negaitive values indicate
 	 * unmarshaling errors.
@@ -556,16 +557,16 @@ struct tpm2_response *tpm_unmarshal_response(TPM_CC command,
 	if ((cr_size < 0) || (in_size < sizeof(struct tpm_header)))
 		return NULL;
 
-	tpm2_resp.hdr.tpm_tag = unmarshal_u16(&response_body, &cr_size);
-	tpm2_resp.hdr.tpm_size = unmarshal_u32(&response_body, &cr_size);
-	tpm2_resp.hdr.tpm_code = unmarshal_TPM_CC(&response_body, &cr_size);
+	tpm2_resp->hdr.tpm_tag = unmarshal_u16(&response_body, &cr_size);
+	tpm2_resp->hdr.tpm_size = unmarshal_u32(&response_body, &cr_size);
+	tpm2_resp->hdr.tpm_code = unmarshal_TPM_CC(&response_body, &cr_size);
 
 	if (!cr_size) {
-		if (tpm2_resp.hdr.tpm_size != sizeof(tpm2_resp.hdr))
+		if (tpm2_resp->hdr.tpm_size != sizeof(tpm2_resp->hdr))
 			printk(BIOS_ERR,
 			       "%s: size mismatch in response to command %#x\n",
 			       __func__, command);
-		return &tpm2_resp;
+		return tpm2_resp;
 	}
 
 	switch (command) {
@@ -574,12 +575,12 @@ struct tpm2_response *tpm_unmarshal_response(TPM_CC command,
 
 	case TPM2_GetCapability:
 		unmarshal_get_capability(&response_body, &cr_size,
-					 &tpm2_resp.gc);
+					 &tpm2_resp->gc);
 		break;
 
 	case TPM2_NV_Read:
 		unmarshal_nv_read(&response_body, &cr_size,
-				  &tpm2_resp.nvr);
+				  &tpm2_resp->nvr);
 		break;
 
 	case TPM2_Clear:
@@ -599,7 +600,7 @@ struct tpm2_response *tpm_unmarshal_response(TPM_CC command,
 			       "Request to unmarshal unexpected command %#x,"
 			       " code %#x",
 			       __func__, __LINE__, command,
-			       tpm2_resp.hdr.tpm_code);
+			       tpm2_resp->hdr.tpm_code);
 
 			for (i = 0; i < cr_size; i++) {
 				if (!(i % 16))
@@ -616,11 +617,11 @@ struct tpm2_response *tpm_unmarshal_response(TPM_CC command,
 		printk(BIOS_INFO,
 		       "%s:%d got %d bytes back in response to %#x,"
 		       " failed to parse (%d)\n",
-		       __func__, __LINE__, tpm2_resp.hdr.tpm_size,
+		       __func__, __LINE__, tpm2_resp->hdr.tpm_size,
 		       command, cr_size);
 		return NULL;
 	}
 
 	/* The entire message have been parsed. */
-	return &tpm2_resp;
+	return tpm2_resp;
 }
diff --git a/src/lib/tpm2_tlcl.c b/src/lib/tpm2_tlcl.c
index 7bfd40d..b6017a2 100644
--- a/src/lib/tpm2_tlcl.c
+++ b/src/lib/tpm2_tlcl.c
@@ -290,7 +290,7 @@ uint32_t tlcl_define_space(uint32_t space_index, size_t space_size)
 	 * This policy digest was obtained using TPM2_PolicyPCR selecting only
 	 * PCR_0 with a value of all zeros.
 	 */
-	static const uint8_t pcr0_unchanged_policy[] = {
+	const uint8_t pcr0_unchanged_policy[] = {
 		0x09, 0x93, 0x3C, 0xCE, 0xEB, 0xB4, 0x41, 0x11,
 		0x18, 0x81, 0x1D, 0xD4, 0x47, 0x78, 0x80, 0x08,
 		0x88, 0x86, 0x62, 0x2D, 0xD7, 0x79, 0x94, 0x46,



More information about the coreboot-gerrit mailing list