Blame SOURCES/0001-Fix-ESYS_TR-hierarchy-transition.patch

d5d7cb
From e607f78a054acfdbe119499c3608bdb2a44423d9 Mon Sep 17 00:00:00 2001
d5d7cb
From: Andreas Fuchs <andreas.fuchs@sit.fraunhofer.de>
d5d7cb
Date: Thu, 7 May 2020 11:51:17 +0200
d5d7cb
Subject: [PATCH] Fix ESYS_TR hierarchy transition
d5d7cb
d5d7cb
Fix those cases of TPM2_RH_ to ESYS_TR_RH_ translations that were missed in
d5d7cb
780800c0be69a49b9097f8eae653cdb0623d2100
d5d7cb
d5d7cb
Signed-off-by: Andreas Fuchs <andreas.fuchs@sit.fraunhofer.de>
d5d7cb
---
d5d7cb
 lib/tpm2.c | 20 ++++++++++++++------
d5d7cb
 1 file changed, 14 insertions(+), 6 deletions(-)
d5d7cb
d5d7cb
diff --git a/lib/tpm2.c b/lib/tpm2.c
d5d7cb
index e7ff77047bef..909a4422339d 100644
d5d7cb
--- a/lib/tpm2.c
d5d7cb
+++ b/lib/tpm2.c
d5d7cb
@@ -656,6 +656,12 @@ uint32_t fix_esys_hierarchy(TPMI_RH_HIERARCHY hierarchy)
d5d7cb
 {
d5d7cb
 #if defined(ESYS_3_0)
d5d7cb
     switch (hierarchy) {
d5d7cb
+        case ESYS_TR_RH_NULL:
d5d7cb
+        case ESYS_TR_RH_OWNER:
d5d7cb
+        case ESYS_TR_RH_ENDORSEMENT:
d5d7cb
+        case ESYS_TR_RH_PLATFORM:
d5d7cb
+        case ESYS_TR_RH_PLATFORM_NV:
d5d7cb
+            return hierarchy;
d5d7cb
         case TPM2_RH_NULL:
d5d7cb
             return ESYS_TR_RH_NULL;
d5d7cb
         case TPM2_RH_OWNER:
d5d7cb
@@ -664,14 +670,16 @@ uint32_t fix_esys_hierarchy(TPMI_RH_HIERARCHY hierarchy)
d5d7cb
             return ESYS_TR_RH_ENDORSEMENT;
d5d7cb
         case TPM2_RH_PLATFORM:
d5d7cb
             return ESYS_TR_RH_PLATFORM;
d5d7cb
+        case TPM2_RH_PLATFORM_NV:
d5d7cb
+            return ESYS_TR_RH_PLATFORM_NV;
d5d7cb
         default:
d5d7cb
-            return TSS2_ESYS_RC_BAD_VALUE;
d5d7cb
+            LOG_ERR("An unknown hierarchy handle was passed: 0x%08x", hierarchy);
d5d7cb
+            return 0xffffffff;
d5d7cb
     }
d5d7cb
 #elif defined(ESYS_2_3)
d5d7cb
     return hierarchy;
d5d7cb
 #else
d5d7cb
-    UNUSED(hierarchy);
d5d7cb
-    return TSS2_ESYS_RC_BAD_VALUE;
d5d7cb
+#error "Need to define either ESYS_3_0 or ESYS_2_3"
d5d7cb
 #endif
d5d7cb
 }
d5d7cb
 
d5d7cb
@@ -1154,7 +1162,7 @@ tool_rc tpm2_hierarchycontrol(ESYS_CONTEXT *esys_context,
d5d7cb
     }
d5d7cb
 
d5d7cb
     TSS2_RC rval = Esys_HierarchyControl(esys_context, auth_hierarchy->tr_handle,
d5d7cb
-            shandle, ESYS_TR_NONE, ESYS_TR_NONE, enable, state);
d5d7cb
+            shandle, ESYS_TR_NONE, ESYS_TR_NONE, fix_esys_hierarchy(enable), state);
d5d7cb
     if (rval != TPM2_RC_SUCCESS && rval != TPM2_RC_INITIALIZE) {
d5d7cb
         LOG_PERR(Esys_HierarchyControl, rval);
d5d7cb
         return tool_rc_from_tpm(rval);
d5d7cb
@@ -1251,7 +1259,7 @@ tool_rc tpm2_hmac_sequencecomplete(ESYS_CONTEXT *esys_context,
d5d7cb
 
d5d7cb
     TPM2_RC rval = Esys_SequenceComplete(esys_context, sequence_handle,
d5d7cb
             hmac_key_obj_shandle, ESYS_TR_NONE, ESYS_TR_NONE, input_buffer,
d5d7cb
-            TPM2_RH_NULL, result, validation);
d5d7cb
+            fix_esys_hierarchy(TPM2_RH_NULL), result, validation);
d5d7cb
     if (rval != TSS2_RC_SUCCESS) {
d5d7cb
         LOG_PERR(Esys_HMAC, rval);
d5d7cb
         return tool_rc_from_tpm(rval);
d5d7cb
@@ -1907,7 +1915,7 @@ tool_rc tpm2_loadexternal(ESYS_CONTEXT *ectx, const TPM2B_SENSITIVE *private,
d5d7cb
 
d5d7cb
     TSS2_RC rval = Esys_LoadExternal(ectx,
d5d7cb
             ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,
d5d7cb
-            private, public, hierarchy,
d5d7cb
+            private, public, fix_esys_hierarchy(hierarchy),
d5d7cb
             object_handle);
d5d7cb
     if (rval != TSS2_RC_SUCCESS) {
d5d7cb
         LOG_PERR(Esys_LoadExternal, rval);
d5d7cb
-- 
d5d7cb
2.27.0
d5d7cb