Skip to contentSkip to conversation

tpm: Enable boot despite unknown firmware failure

PATCH Superseded Michał Grzelak 2 participants 2 messages Jun 14, 2023 – Jun 15, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tpm: Enable boot despite unknown firmware failure

Currently booting the system is prevented when call to EFI firmware hash_log_extend_event() returns unknown error. Solve this by following convention used in commit a4356538d (commands/tpm: Don't propagate measurement failures to the verifiers layer).

Let the system to be bootable by default when unknown TPM error is encountered. Make grub_tpm_is_fail_fatal() global and move its body to efi/tpm.c. Check environment variable tpm_fail_fatal to fallback to previous behaviour.

---
 grub-core/commands/efi/tpm.c | 10 +++++++++-
 grub-core/commands/tpm.c     | 11 ++---------
 include/grub/tpm.h           |  1 +
 3 files changed, 12 insertions(+), 10 deletions(-)
grub-core/commands/efi/tpm.c +9 -1
index c616768f9..05f3064f7 100644
@@ -18,6 +18,7 @@
  *  EFI TPM support code.
  */
 
+#include <grub/env.h>
 #include <grub/err.h>
 #include <grub/i18n.h>
 #include <grub/efi/api.h>
@@ -146,7 +147,8 @@ grub_efi_log_event_status (grub_efi_status_t status)
     case GRUB_EFI_NOT_FOUND:
       return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable"));
     default:
-      return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("unknown TPM error"));
+      return grub_error (grub_tpm_is_fail_fatal () ? GRUB_ERR_UNKNOWN_DEVICE
+                         : GRUB_ERR_NONE, N_("unknown TPM error"));
     }
 }
 
@@ -266,6 +268,12 @@ grub_cc_log_event (unsigned char *buf, grub_size_t size, grub_uint8_t pcr,
     grub_efi_log_event_status (status);
 }
 
+bool
+grub_tpm_is_fail_fatal (void)
+{
+  return grub_env_get_bool ("tpm_fail_fatal", false);
+}
+
 grub_err_t
 grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr,
 		    const char *description)
grub-core/commands/tpm.c +2 -9
index 9f830916d..f86bdc81e 100644
@@ -18,7 +18,6 @@
  *  Core TPM support code.
  */
 
-#include <grub/env.h>
 #include <grub/err.h>
 #include <grub/i18n.h>
 #include <grub/misc.h>
@@ -40,12 +39,6 @@ grub_tpm_verify_init (grub_file_t io,
   return GRUB_ERR_NONE;
 }
 
-static inline bool
-is_tpm_fail_fatal (void)
-{
-  return grub_env_get_bool ("tpm_fail_fatal", false);
-}
-
 static grub_err_t
 grub_tpm_verify_write (void *context, void *buf, grub_size_t size)
 {
@@ -55,7 +48,7 @@ grub_tpm_verify_write (void *context, void *buf, grub_size_t size)
     return GRUB_ERR_NONE;
 
   grub_dprintf ("tpm", "Measuring buffer failed: %d\n", status);
-  return is_tpm_fail_fatal () ? status : GRUB_ERR_NONE;
+  return grub_tpm_is_fail_fatal () ? status : GRUB_ERR_NONE;
 }
 
 static grub_err_t
@@ -91,7 +84,7 @@ grub_tpm_verify_string (char *str, enum grub_verify_string_type type)
     return GRUB_ERR_NONE;
 
   grub_dprintf ("tpm", "Measuring string %s failed: %d\n", str, status);
-  return is_tpm_fail_fatal () ? status : GRUB_ERR_NONE;
+  return grub_tpm_is_fail_fatal () ? status : GRUB_ERR_NONE;
 }
 
 struct grub_file_verifier grub_tpm_verifier = {
include/grub/tpm.h +1 -0
index c19fcbd0a..aea145dd1 100644
@@ -36,5 +36,6 @@
 
 grub_err_t grub_tpm_measure (unsigned char *buf, grub_size_t size,
 			     grub_uint8_t pcr, const char *description);
+bool grub_tpm_is_fail_fatal (void);
 int grub_tpm_present (void);
 #endif
Signature · 1 line
2.37.3
#1 lore raw
Quoted 40 lines · Michał Grzelak

Currently booting the system is prevented when call to EFI firmware hash_log_extend_event() returns unknown error. Solve this by following convention used in commit a4356538d (commands/tpm: Don't propagate measurement failures to the verifiers layer).

Let the system to be bootable by default when unknown TPM error is encountered. Make grub_tpm_is_fail_fatal() global and move its body to efi/tpm.c. Check environment variable tpm_fail_fatal to fallback to previous behaviour.

---
 grub-core/commands/efi/tpm.c | 10 +++++++++-
 grub-core/commands/tpm.c     | 11 ++---------
 include/grub/tpm.h           |  1 +
 3 files changed, 12 insertions(+), 10 deletions(-)
grub-core/commands/efi/tpm.c +3 -1
index c616768f9..05f3064f7 100644
@@ -18,6 +18,7 @@
  *  EFI TPM support code.
  */
 
+#include <grub/env.h>
 #include <grub/err.h>
 #include <grub/i18n.h>
 #include <grub/efi/api.h>
@@ -146,7 +147,8 @@ grub_efi_log_event_status (grub_efi_status_t status)
     case GRUB_EFI_NOT_FOUND:
       return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable"));
     default:
-      return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("unknown TPM error"));
+      return grub_error (grub_tpm_is_fail_fatal () ? GRUB_ERR_UNKNOWN_DEVICE
+                         : GRUB_ERR_NONE, N_("unknown TPM error"));
     }
 }
 

grub-core/commands/efi/tpm.c grub_cc_log_event (unsigned char *buf, grub_size_t size, grub_uint8_t pcr, · line 276

Quoted 9 lines
grub-core/commands/efi/tpm.c +6 -0
@@ -266,6 +268,12 @@ grub_cc_log_event (unsigned char *buf, grub_size_t size, grub_uint8_t pcr,
     grub_efi_log_event_status (status);
 }
 
+bool
+grub_tpm_is_fail_fatal (void)
+{
+  return grub_env_get_bool ("tpm_fail_fatal", false);
+}
+

This function should be defined in the include/grub/tpm.h as

static inline bool
is_tpm_fail_fatal (void)
{
return grub_env_get_bool ("tpm_fail_fatal", false);
}

Of course you should include grub/env.h there too. And probably docs excerpt introduced by commit a4356538d should be generalized a bit too...

Otherwise patch LGTM...

Daniel