nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0268-TPM-Print-messages-if-measuraments-fail-as-debug-ins.patch

eefaf6
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
eefaf6
From: Javier Martinez Canillas <javierm@redhat.com>
eefaf6
Date: Wed, 16 Oct 2019 15:32:04 +0200
eefaf6
Subject: [PATCH] TPM: Print messages if measuraments fail as debug instead of
eefaf6
 error
eefaf6
eefaf6
If the calls to EFI services to do TPM measuraments fail, currently error
eefaf6
messages are printed. But this is not a fatal error and just pollutes the
eefaf6
output, so instead just print them as debug messages.
eefaf6
eefaf6
Resolves: rhbz#1761811
eefaf6
eefaf6
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
eefaf6
---
eefaf6
 grub-core/kern/efi/tpm.c | 58 +++++++++++++++++++++++++-----------------------
eefaf6
 1 file changed, 30 insertions(+), 28 deletions(-)
eefaf6
eefaf6
diff --git a/grub-core/kern/efi/tpm.c b/grub-core/kern/efi/tpm.c
f6e916
index 0d3ebe22e..5dc908652 100644
eefaf6
--- a/grub-core/kern/efi/tpm.c
eefaf6
+++ b/grub-core/kern/efi/tpm.c
eefaf6
@@ -161,6 +161,34 @@ grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf,
eefaf6
   }
eefaf6
 }
eefaf6
 
eefaf6
+static inline grub_err_t grub_tpm_dprintf(grub_efi_status_t status)
eefaf6
+{
eefaf6
+  switch (status) {
eefaf6
+  case GRUB_EFI_SUCCESS:
eefaf6
+    return 0;
eefaf6
+  case GRUB_EFI_DEVICE_ERROR:
eefaf6
+    grub_dprintf ("tpm", "Command failed: 0x%"PRIxGRUB_EFI_STATUS"\n",
eefaf6
+                  status);
eefaf6
+    return GRUB_ERR_IO;
eefaf6
+  case GRUB_EFI_INVALID_PARAMETER:
eefaf6
+    grub_dprintf ("tpm", "Invalid parameter: 0x%"PRIxGRUB_EFI_STATUS"\n",
eefaf6
+                  status);
eefaf6
+    return GRUB_ERR_BAD_ARGUMENT;
eefaf6
+  case GRUB_EFI_BUFFER_TOO_SMALL:
eefaf6
+    grub_dprintf ("tpm", "Output buffer too small: 0x%"PRIxGRUB_EFI_STATUS"\n",
eefaf6
+                  status);
eefaf6
+    return GRUB_ERR_BAD_ARGUMENT;
eefaf6
+  case GRUB_EFI_NOT_FOUND:
eefaf6
+    grub_dprintf ("tpm", "TPM unavailable: 0x%"PRIxGRUB_EFI_STATUS"\n",
eefaf6
+                  status);
eefaf6
+    return GRUB_ERR_UNKNOWN_DEVICE;
eefaf6
+  default:
eefaf6
+    grub_dprintf ("tpm", "Unknown TPM error: 0x%"PRIxGRUB_EFI_STATUS"\n",
eefaf6
+                  status);
eefaf6
+    return GRUB_ERR_UNKNOWN_DEVICE;
eefaf6
+  }
eefaf6
+}
eefaf6
+
eefaf6
 static grub_err_t
eefaf6
 grub_tpm1_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf,
eefaf6
 		    grub_size_t size, grub_uint8_t pcr,
eefaf6
@@ -194,20 +222,7 @@ grub_tpm1_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf,
eefaf6
                        (unsigned long) buf, (grub_uint64_t) size,
eefaf6
 		       algorithm, event, &eventnum, &lastevent);
eefaf6
 
eefaf6
-  switch (status) {
eefaf6
-  case GRUB_EFI_SUCCESS:
eefaf6
-    return 0;
eefaf6
-  case GRUB_EFI_DEVICE_ERROR:
eefaf6
-    return grub_error (GRUB_ERR_IO, N_("Command failed"));
eefaf6
-  case GRUB_EFI_INVALID_PARAMETER:
eefaf6
-    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter"));
eefaf6
-  case GRUB_EFI_BUFFER_TOO_SMALL:
eefaf6
-    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Output buffer too small"));
eefaf6
-  case GRUB_EFI_NOT_FOUND:
eefaf6
-    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable"));
eefaf6
-  default:
eefaf6
-    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error"));
eefaf6
-  }
eefaf6
+  return grub_tpm_dprintf(status);
eefaf6
 }
eefaf6
 
eefaf6
 static grub_err_t
eefaf6
@@ -240,20 +255,7 @@ grub_tpm2_log_event(grub_efi_handle_t tpm_handle, unsigned char *buf,
eefaf6
   status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, (unsigned long) buf,
eefaf6
 		       (grub_uint64_t) size, event);
eefaf6
 
eefaf6
-  switch (status) {
eefaf6
-  case GRUB_EFI_SUCCESS:
eefaf6
-    return 0;
eefaf6
-  case GRUB_EFI_DEVICE_ERROR:
eefaf6
-    return grub_error (GRUB_ERR_IO, N_("Command failed"));
eefaf6
-  case GRUB_EFI_INVALID_PARAMETER:
eefaf6
-    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Invalid parameter"));
eefaf6
-  case GRUB_EFI_BUFFER_TOO_SMALL:
eefaf6
-    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Output buffer too small"));
eefaf6
-  case GRUB_EFI_NOT_FOUND:
eefaf6
-    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("TPM unavailable"));
eefaf6
-  default:
eefaf6
-    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, N_("Unknown TPM error"));
eefaf6
-  }
eefaf6
+  return grub_tpm_dprintf(status);
eefaf6
 }
eefaf6
 
eefaf6
 grub_err_t