]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
tpm: Enable boot despite unknown firmware failure
authorMichał Grzelak <mchl.grzlk@gmail.com>
Thu, 15 Jun 2023 22:39:47 +0000 (00:39 +0200)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 22 Jun 2023 22:50:38 +0000 (00:50 +0200)
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. Check environment variable tpm_fail_fatal to fallback to
previous behaviour.

Signed-off-by: Michał Grzelak <mchl.grzlk@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
docs/grub.texi
grub-core/commands/efi/tpm.c
grub-core/commands/tpm.c
include/grub/tpm.h

index 9b58886a9086a902c883ec9b63648119ccd81427..fc4e08f2c239792256ba4f2906ea87bae4b3a085 100644 (file)
@@ -3841,6 +3841,11 @@ If this variable is set and true (i.e., not set to ``0'', ``false'',
 fatal. Otherwise, they will merely be debug-logged and boot will
 continue.
 
+Call to EFI firmware, like hash_log_extend_event(), can return an unknown
+error, i.e. due to bug present in firmware. When this variable is set and
+true (same values as with TPM measurements) this situation will be considered
+to be fatal and error-logged as ``unknown TPM error''. If not set, booting
+the OS will be enabled.
 
 @node Environment block
 @section The GRUB environment block
index c616768f9dfa57744aa1bd6b4a355d5b52f62a1f..f250c30dbc3068a9f7b7f7e9ad30910e2756f0dd 100644 (file)
@@ -146,7 +146,7 @@ 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_is_tpm_fail_fatal () ? GRUB_ERR_UNKNOWN_DEVICE : GRUB_ERR_NONE, N_("unknown TPM error"));
     }
 }
 
index 9f830916d67bbcb2b6b6769a0bab508ef64b0da2..324423ef86a1e188dbf7d09821fa3a04e18cc546 100644 (file)
@@ -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_is_tpm_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_is_tpm_fail_fatal () ? status : GRUB_ERR_NONE;
 }
 
 struct grub_file_verifier grub_tpm_verifier = {
index c19fcbd0a60dc1dae95b752bae549db9e4e14b93..d09783dacc0a5a03d60d6baa1b9fe1368ad9ada5 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef GRUB_TPM_HEADER
 #define GRUB_TPM_HEADER 1
 
+#include <grub/env.h>
+
 #define GRUB_STRING_PCR 8
 #define GRUB_BINARY_PCR 9
 
 grub_err_t grub_tpm_measure (unsigned char *buf, grub_size_t size,
                             grub_uint8_t pcr, const char *description);
 int grub_tpm_present (void);
+
+static inline bool
+grub_is_tpm_fail_fatal (void)
+{
+  return grub_env_get_bool ("tpm_fail_fatal", false);
+}
+
 #endif