Skip to contentSkip to conversation

tpm: Enable boot despite unknown firmware failure

PATCH In review Michał Grzelak 2 participants 3 messages Jun 15, 2023 – Jun 21, 2023

lore
Share & tools
lore
#0 lore raw

v2 cover tpm: Enable boot despite unknown firmware failure

Hi all,

This patch fixes small problem with my computer being unbootable under certain circumstances. It also addresses concerns pointed out by Daniel with previous version. If there are any, I would appreciate further comments.

Best regards,
Michał

---
Changelog:
v1->v2:
- change grub_tpm_is_fail_fatal() back to tpm_is_fail_fatal()
- make is_tpm_fail_fatal() static
- move is_tpm_fail_fatal() body to include/grub/tpm.h
- update docs excerpt about tpm_fail_fatal

Michał Grzelak (1):
tpm: Enable boot despite unknown firmware failure

 docs/grub.texi               | 5 +++++
 grub-core/commands/efi/tpm.c | 3 ++-
 grub-core/commands/tpm.c     | 7 -------
 include/grub/tpm.h           | 9 +++++++++
 4 files changed, 16 insertions(+), 8 deletions(-)
Signature · 1 line
2.37.3
#1 lore raw

PATCH v2 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. Check environment variable tpm_fail_fatal to fallback to previous behaviour.

---
 docs/grub.texi               | 5 +++++
 grub-core/commands/efi/tpm.c | 3 ++-
 grub-core/commands/tpm.c     | 7 -------
 include/grub/tpm.h           | 9 +++++++++
 4 files changed, 16 insertions(+), 8 deletions(-)
docs/grub.texi +5 -0
index 9b58886a9..fc4e08f2c 100644
@@ -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
grub-core/commands/efi/tpm.c +2 -1
index c616768f9..508ae8b3a 100644
@@ -146,7 +146,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 (is_tpm_fail_fatal () ? GRUB_ERR_UNKNOWN_DEVICE
+                         : GRUB_ERR_NONE, N_("unknown TPM error"));
     }
 }
 
grub-core/commands/tpm.c +0 -7
index 9f830916d..c7e599170 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)
 {
include/grub/tpm.h +9 -0
index c19fcbd0a..11238da18 100644
@@ -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
 
@@ -37,4 +39,11 @@
 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
+is_tpm_fail_fatal (void)
+{
+  return grub_env_get_bool ("tpm_fail_fatal", false);
+}
+
 #endif
Signature · 1 line
2.37.3
#2 lore raw
In reply to Michał Grzelak
Quoted 7 lines · Michał Grzelak

Hi all,

This patch fixes small problem with my computer being unbootable under certain circumstances. It also addresses concerns pointed out by Daniel with previous version. If there are any, I would appreciate further comments.

Quoted 7 lines

Best regards,
Michał

---
Changelog:
v1->v2:
- change grub_tpm_is_fail_fatal() back to tpm_is_fail_fatal()

Nah, we should not do this because the function is global. However, you did it due to my (wrong) suggestion. Sorry about that. I will fix it before push.

Otherwise Reviewed-by: Daniel Kiper <[email protected]>...

Daniel

Quoted 12 lines

- make is_tpm_fail_fatal() static
- move is_tpm_fail_fatal() body to include/grub/tpm.h
- update docs excerpt about tpm_fail_fatal

Michał Grzelak (1):
tpm: Enable boot despite unknown firmware failure

 docs/grub.texi               | 5 +++++
 grub-core/commands/efi/tpm.c | 3 ++-
 grub-core/commands/tpm.c     | 7 -------
 include/grub/tpm.h           | 9 +++++++++
 4 files changed, 16 insertions(+), 8 deletions(-)