Blame SOURCES/2021.patch

44dd2b
From 84556dd39531638ef69c8f1eec7f917de2c88146 Mon Sep 17 00:00:00 2001
44dd2b
From: Trammell hudson <hudson@trmm.net>
44dd2b
Date: Wed, 13 May 2020 12:00:14 +0200
44dd2b
Subject: [PATCH 1/6] tpm2_event_log: parse EV_POST_CODE events according to
44dd2b
 2.3.4.1
44dd2b
44dd2b
Signed-off-by: Trammell hudson <hudson@trmm.net>
44dd2b
---
44dd2b
 lib/tpm2_eventlog.c      |  5 ++++-
44dd2b
 lib/tpm2_eventlog_yaml.c | 24 ++++++++++++++++++++++++
44dd2b
 2 files changed, 28 insertions(+), 1 deletion(-)
44dd2b
44dd2b
diff --git a/lib/tpm2_eventlog.c b/lib/tpm2_eventlog.c
44dd2b
index b44ae10a9..b7bea6124 100644
44dd2b
--- a/lib/tpm2_eventlog.c
44dd2b
+++ b/lib/tpm2_eventlog.c
44dd2b
@@ -88,8 +88,11 @@ bool parse_event2body(TCG_EVENT2 const *event, UINT32 type) {
44dd2b
             }
44dd2b
         }
44dd2b
         break;
44dd2b
-    /* TCG PC Client FPF section 9.2.5 */
44dd2b
+    /* TCG PC Client FPF section 2.3.4.1 and 9.4.1 */
44dd2b
     case EV_POST_CODE:
44dd2b
+        // the event is a string, so there are no length requirements.
44dd2b
+        break;
44dd2b
+    /* TCG PC Client FPF section 9.2.5 */
44dd2b
     case EV_S_CRTM_CONTENTS:
44dd2b
     case EV_EFI_PLATFORM_FIRMWARE_BLOB:
44dd2b
         {
44dd2b
diff --git a/lib/tpm2_eventlog_yaml.c b/lib/tpm2_eventlog_yaml.c
44dd2b
index 307c4a09d..ae1406bfe 100644
44dd2b
--- a/lib/tpm2_eventlog_yaml.c
44dd2b
+++ b/lib/tpm2_eventlog_yaml.c
44dd2b
@@ -164,6 +164,29 @@ static bool yaml_uefi_var_data(UEFI_VARIABLE_DATA *data) {
44dd2b
 
44dd2b
     return true;
44dd2b
 }
44dd2b
+/*
44dd2b
+ * TCG PC Client FPF section 2.3.4.1 and 9.4.1:
44dd2b
+ * Usage of the event type EV_POST_CODE:
44dd2b
+ * - If a combined event is measured, the event field SHOULD
44dd2b
+ * be the string "POST CODE" in all caps. ...
44dd2b
+ * - Embedded SMM code and the code that sets it up SHOULD use
44dd2b
+ * the string "SMM CODE" in all caps...
44dd2b
+ * - BIS code (eclusing the BIS Certificate) should use event
44dd2b
+ * field string of "BIS CODE" in all caps. ...
44dd2b
+ * - ACPI flash data prior to any modifications ... should use
44dd2b
+ * event field string of "ACPI DATA" in all caps.
44dd2b
+ */
44dd2b
+static bool yaml_uefi_post_code(const char * data, size_t len)
44dd2b
+{
44dd2b
+    tpm2_tool_output(
44dd2b
+        "  Event:\n"
44dd2b
+        "    - Length: %zu\n"
44dd2b
+        "      String: '%.*s'\n",
44dd2b
+        len,
44dd2b
+        (int) len,
44dd2b
+        data);
44dd2b
+    return true;
44dd2b
+}
44dd2b
 /*
44dd2b
  * TCG PC Client FPF section 9.2.6
44dd2b
  * The tpm2_eventlog module validates the event structure but nothing within
44dd2b
@@ -247,6 +270,7 @@ bool yaml_event2data(TCG_EVENT2 const *event, UINT32 type) {
44dd2b
     case EV_EFI_VARIABLE_AUTHORITY:
44dd2b
         return yaml_uefi_var((UEFI_VARIABLE_DATA*)event->Event);
44dd2b
     case EV_POST_CODE:
44dd2b
+        return yaml_uefi_post_code((const char*)event->Event, event->EventSize);
44dd2b
     case EV_S_CRTM_CONTENTS:
44dd2b
     case EV_EFI_PLATFORM_FIRMWARE_BLOB:
44dd2b
         return yaml_uefi_platfwblob((UEFI_PLATFORM_FIRMWARE_BLOB*)event->Event);
44dd2b
44dd2b
From abfae7af25bdbb41709d09bf99a01132f2f3c24e Mon Sep 17 00:00:00 2001
44dd2b
From: Trammell hudson <hudson@trmm.net>
44dd2b
Date: Wed, 13 May 2020 12:04:49 +0200
44dd2b
Subject: [PATCH 2/6] tpm2_eventlog: rename postcode test to firmware blob test
44dd2b
44dd2b
Signed-off-by: Trammell hudson <hudson@trmm.net>
44dd2b
---
44dd2b
 test/unit/test_tpm2_eventlog.c | 4 ++--
44dd2b
 1 file changed, 2 insertions(+), 2 deletions(-)
44dd2b
44dd2b
diff --git a/test/unit/test_tpm2_eventlog.c b/test/unit/test_tpm2_eventlog.c
44dd2b
index e992ac848..661778506 100644
44dd2b
--- a/test/unit/test_tpm2_eventlog.c
44dd2b
+++ b/test/unit/test_tpm2_eventlog.c
44dd2b
@@ -266,7 +266,7 @@ static void test_parse_event2body_uefivar_badlength(void **state){
44dd2b
 
44dd2b
     assert_false(parse_event2body(event, EV_EFI_VARIABLE_DRIVER_CONFIG));
44dd2b
 }
44dd2b
-static void test_parse_event2body_postcode_badlength(void **state){
44dd2b
+static void test_parse_event2body_firmware_blob_badlength(void **state){
44dd2b
 
44dd2b
     (void)state;
44dd2b
 
44dd2b
@@ -465,7 +465,7 @@ int main(void) {
44dd2b
         cmocka_unit_test(test_foreach_event2_parse_event2body_fail),
44dd2b
         cmocka_unit_test(test_parse_event2body_uefivar_badsize),
44dd2b
         cmocka_unit_test(test_parse_event2body_uefivar_badlength),
44dd2b
-        cmocka_unit_test(test_parse_event2body_postcode_badlength),
44dd2b
+        cmocka_unit_test(test_parse_event2body_firmware_blob_badlength),
44dd2b
         cmocka_unit_test(test_specid_event_nohdr),
44dd2b
         cmocka_unit_test(test_specid_event_badeventtype),
44dd2b
         cmocka_unit_test(test_specid_event_badpcrindex),
44dd2b
44dd2b
From de84d5bd6f89bded62e8dc0ae57619a3758920e5 Mon Sep 17 00:00:00 2001
44dd2b
From: Trammell hudson <hudson@trmm.net>
44dd2b
Date: Wed, 13 May 2020 12:09:45 +0200
44dd2b
Subject: [PATCH 3/6] tpm2_eventlog: pass TCG_EVENT2* to yaml-Uefi_post_code()
44dd2b
44dd2b
Signed-off-by: Trammell hudson <hudson@trmm.net>
44dd2b
---
44dd2b
 lib/tpm2_eventlog_yaml.c | 9 ++++++---
44dd2b
 1 file changed, 6 insertions(+), 3 deletions(-)
44dd2b
44dd2b
diff --git a/lib/tpm2_eventlog_yaml.c b/lib/tpm2_eventlog_yaml.c
44dd2b
index ae1406bfe..e9092769d 100644
44dd2b
--- a/lib/tpm2_eventlog_yaml.c
44dd2b
+++ b/lib/tpm2_eventlog_yaml.c
44dd2b
@@ -171,13 +171,16 @@ static bool yaml_uefi_var_data(UEFI_VARIABLE_DATA *data) {
44dd2b
  * be the string "POST CODE" in all caps. ...
44dd2b
  * - Embedded SMM code and the code that sets it up SHOULD use
44dd2b
  * the string "SMM CODE" in all caps...
44dd2b
- * - BIS code (eclusing the BIS Certificate) should use event
44dd2b
+ * - BIS code (excluding the BIS Certificate) should use event
44dd2b
  * field string of "BIS CODE" in all caps. ...
44dd2b
  * - ACPI flash data prior to any modifications ... should use
44dd2b
  * event field string of "ACPI DATA" in all caps.
44dd2b
  */
44dd2b
-static bool yaml_uefi_post_code(const char * data, size_t len)
44dd2b
+static bool yaml_uefi_post_code(const TCG_EVENT2 * const event)
44dd2b
 {
44dd2b
+    const char * const data = (const char *) event->Event;
44dd2b
+    const size_t len = event->EventSize;
44dd2b
+
44dd2b
     tpm2_tool_output(
44dd2b
         "  Event:\n"
44dd2b
         "    - Length: %zu\n"
44dd2b
@@ -270,7 +273,7 @@ bool yaml_event2data(TCG_EVENT2 const *event, UINT32 type) {
44dd2b
     case EV_EFI_VARIABLE_AUTHORITY:
44dd2b
         return yaml_uefi_var((UEFI_VARIABLE_DATA*)event->Event);
44dd2b
     case EV_POST_CODE:
44dd2b
-        return yaml_uefi_post_code((const char*)event->Event, event->EventSize);
44dd2b
+        return yaml_uefi_post_code(event);
44dd2b
     case EV_S_CRTM_CONTENTS:
44dd2b
     case EV_EFI_PLATFORM_FIRMWARE_BLOB:
44dd2b
         return yaml_uefi_platfwblob((UEFI_PLATFORM_FIRMWARE_BLOB*)event->Event);
44dd2b
44dd2b
From dddeb4d3bc2e4d1eddf143a1ee70de7f7f32fbf3 Mon Sep 17 00:00:00 2001
44dd2b
From: Trammell hudson <hudson@trmm.net>
44dd2b
Date: Wed, 13 May 2020 12:55:14 +0200
44dd2b
Subject: [PATCH 4/6] tpm2_eventlog: use "PCRIndex:" consistently
44dd2b
44dd2b
Signed-off-by: Trammell hudson <hudson@trmm.net>
44dd2b
---
44dd2b
 lib/tpm2_eventlog_yaml.c | 2 +-
44dd2b
 1 file changed, 1 insertion(+), 1 deletion(-)
44dd2b
44dd2b
diff --git a/lib/tpm2_eventlog_yaml.c b/lib/tpm2_eventlog_yaml.c
44dd2b
index e9092769d..d1f308904 100644
44dd2b
--- a/lib/tpm2_eventlog_yaml.c
44dd2b
+++ b/lib/tpm2_eventlog_yaml.c
44dd2b
@@ -329,7 +329,7 @@ void yaml_eventhdr(TCG_EVENT const *event, size_t *count) {
44dd2b
     bytes_to_str(event->digest, sizeof(event->digest), digest_hex, sizeof(digest_hex));
44dd2b
 
44dd2b
     tpm2_tool_output("- Event[%zu]:\n"
44dd2b
-                     "  pcrIndex: %" PRIu32 "\n"
44dd2b
+                     "  PCRIndex: %" PRIu32 "\n"
44dd2b
                      "  eventType: %s\n"
44dd2b
                      "  digest: %s\n"
44dd2b
                      "  eventDataSize: %" PRIu32 "\n", (*count)++, event->pcrIndex,
44dd2b
44dd2b
From c56c70f62af9a4fe884c6efa69eeb36f39d6fe65 Mon Sep 17 00:00:00 2001
44dd2b
From: Trammell hudson <hudson@trmm.net>
44dd2b
Date: Wed, 13 May 2020 12:58:20 +0200
44dd2b
Subject: [PATCH 5/6] tpm2_eventlog: use "Digest:" and "EventSize:"
44dd2b
 consistently
44dd2b
44dd2b
Signed-off-by: Trammell hudson <hudson@trmm.net>
44dd2b
---
44dd2b
 lib/tpm2_eventlog_yaml.c | 6 +++---
44dd2b
 1 file changed, 3 insertions(+), 3 deletions(-)
44dd2b
44dd2b
diff --git a/lib/tpm2_eventlog_yaml.c b/lib/tpm2_eventlog_yaml.c
44dd2b
index d1f308904..50bd2fa6d 100644
44dd2b
--- a/lib/tpm2_eventlog_yaml.c
44dd2b
+++ b/lib/tpm2_eventlog_yaml.c
44dd2b
@@ -330,9 +330,9 @@ void yaml_eventhdr(TCG_EVENT const *event, size_t *count) {
44dd2b
 
44dd2b
     tpm2_tool_output("- Event[%zu]:\n"
44dd2b
                      "  PCRIndex: %" PRIu32 "\n"
44dd2b
-                     "  eventType: %s\n"
44dd2b
-                     "  digest: %s\n"
44dd2b
-                     "  eventDataSize: %" PRIu32 "\n", (*count)++, event->pcrIndex,
44dd2b
+                     "  EventType: %s\n"
44dd2b
+                     "  Digest: %s\n"
44dd2b
+                     "  EventSize: %" PRIu32 "\n", (*count)++, event->pcrIndex,
44dd2b
                      eventtype_to_string(event->eventType), digest_hex,
44dd2b
                      event->eventDataSize);
44dd2b
 }
44dd2b
44dd2b
From 113ab8c213418c6d1c9045bb19069159cc5b594b Mon Sep 17 00:00:00 2001
44dd2b
From: Trammell hudson <hudson@trmm.net>
44dd2b
Date: Wed, 13 May 2020 14:16:39 +0200
44dd2b
Subject: [PATCH 6/6] tpm2_eventlog: use same output format for EV_EFI_ACTION
44dd2b
 and EV_POST_CODE
44dd2b
44dd2b
This also avoids a potential stack smash if the event log
44dd2b
violates the spec and has an action string longer than
44dd2b
permitted.
44dd2b
44dd2b
Signed-off-by: Trammell hudson <hudson@trmm.net>
44dd2b
---
44dd2b
 lib/tpm2_eventlog_yaml.c | 11 ++---------
44dd2b
 1 file changed, 2 insertions(+), 9 deletions(-)
44dd2b
44dd2b
diff --git a/lib/tpm2_eventlog_yaml.c b/lib/tpm2_eventlog_yaml.c
44dd2b
index 50bd2fa6d..8966cae42 100644
44dd2b
--- a/lib/tpm2_eventlog_yaml.c
44dd2b
+++ b/lib/tpm2_eventlog_yaml.c
44dd2b
@@ -182,10 +182,7 @@ static bool yaml_uefi_post_code(const TCG_EVENT2 * const event)
44dd2b
     const size_t len = event->EventSize;
44dd2b
 
44dd2b
     tpm2_tool_output(
44dd2b
-        "  Event:\n"
44dd2b
-        "    - Length: %zu\n"
44dd2b
-        "      String: '%.*s'\n",
44dd2b
-        len,
44dd2b
+        "  Event: '%.*s'\n",
44dd2b
         (int) len,
44dd2b
         data);
44dd2b
     return true;
44dd2b
@@ -225,11 +222,7 @@ bool yaml_uefi_platfwblob(UEFI_PLATFORM_FIRMWARE_BLOB *data) {
44dd2b
 /* TCG PC Client PFP section 9.4.4 */
44dd2b
 bool yaml_uefi_action(UINT8 const *action, size_t size) {
44dd2b
 
44dd2b
-    /* longest string permitted by spec is 47 chars */
44dd2b
-    char buf[50] = { '\0', };
44dd2b
-
44dd2b
-    memcpy (buf, action, size);
44dd2b
-    tpm2_tool_output("  Event: %s\n", buf);
44dd2b
+    tpm2_tool_output("  Event: '%.*s'\n", (int) size, action);
44dd2b
 
44dd2b
     return true;
44dd2b
 }