Skip to content

tpm: Don't propagate measurement failures to the verifiers layer

Robbie Harwood grub-devel 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest3 patches 1 replyIn review
  2. v31 patch 1 replySuperseded

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3types: make bool generally availablegrub-core/commands/parttool.c grub-core/loader/arm64/linux.c grub-core/parttool/msdospart.c +2 more+5 -50 replies
2/3env: add function for retrieving variables as booleansgrub-core/kern/env.c include/grub/env.h+14 -00 replies
3/3tpm: Don't propagate measurement failures to the verifiers layerdocs/grub.texi grub-core/commands/tpm.c+29 -20 replies

Reviews trailers per patch

None of the 3 patches has a Reviewed-by or Acked-by.

PatchJavier Martinez Canillas
1/3
2/3
3/3Also-authored-by

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/3] tpm: Don't propagate measurement failures to the verifiers layer

Address review from Daniel (interdiff attached). I moved the variable parsing into its own function since it has gotten large enough I'd rather it not get rewritten every time we need a variable as a boolean.

Note that I do not have a machine with a broken TPM for testing fallback.

Be well,
--Robbie

Robbie Harwood (3):
types: make bool generally available
env: add function for retrieving variables as booleans
tpm: Don't propagate measurement failures to the verifiers layer

 docs/grub.texi                 | 10 ++++++++++
 grub-core/commands/parttool.c  |  2 +-
 grub-core/commands/tpm.c       | 21 +++++++++++++++++++--
 grub-core/kern/env.c           | 13 +++++++++++++
 grub-core/loader/arm64/linux.c |  1 -
 grub-core/parttool/msdospart.c |  4 ++--
 include/grub/env.h             |  1 +
 include/grub/parttool.h        |  2 +-
 include/grub/types.h           |  1 +
 9 files changed, 48 insertions(+), 7 deletions(-)

Interdiff against v3:

docs/grub.texi +3 -2
index eb43d8970d..4ab5e9b588 100644
@@ -3829,8 +3829,9 @@ displaying the menu.  See the documentation of @samp{GRUB_TIMEOUT_STYLE}
 @node tpm_fail_fatal
 @subsection tpm_fail_fatal
 
-If this variable is enabled, TPM measurements that fail will be treated
-as fatal.  Otherwise, they will merely be debug-logged and boot will
+If this variable is set and true (i.e., not set to ``0'', ``false'',
+``disable'', or ``no''), TPM measurements that fail will be treated as
+fatal.  Otherwise, they will merely be debug-logged and boot will
 continue.
 
 
grub-core/commands/parttool.c +1 -1
index 051e31320e..ff45c65e61 100644
@@ -315,7 +315,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
 		    switch (curarg->type)
 		      {
 		      case GRUB_PARTTOOL_ARG_BOOL:
-			pargs[curarg - ptool->args].bool
+			pargs[curarg - ptool->args].b
 			  = (args[j][grub_strlen (curarg->name)] != '-');
 			break;
 
grub-core/commands/tpm.c +2 -8
index ca088055dd..3437e8e03b 100644
@@ -27,7 +27,6 @@
 #include <grub/term.h>
 #include <grub/verify.h>
 #include <grub/dl.h>
-#include <stdbool.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
@@ -44,12 +43,7 @@ grub_tpm_verify_init (grub_file_t io,
 static inline bool
 is_tpm_fail_fatal (void)
 {
-  const char *val = grub_env_get ("tpm_fail_fatal");
-
-  if (val == NULL || grub_strlen (val) < 1 || grub_strcmp (val, "0") == 0 ||
-      grub_strcmp (val, "false") == 0)
-    return false;
-  return true;
+  return grub_env_get_bool ("tpm_fail_fatal", false);
 }
 
 static grub_err_t
@@ -85,7 +79,7 @@ grub_tpm_verify_string (char *str, enum grub_verify_string_type type)
     }
   description = grub_malloc (grub_strlen (str) + grub_strlen (prefix) + 1);
   if (!description)
-    return GRUB_ERR_NONE;
+    return grub_errno;
   grub_memcpy (description, prefix, grub_strlen (prefix));
   grub_memcpy (description + grub_strlen (prefix), str,
 	       grub_strlen (str) + 1);
grub-core/kern/env.c +13 -0
index 10e08ad76c..7640688963 100644
@@ -144,6 +144,19 @@ grub_env_get (const char *name)
   return var->value;
 }
 
+bool
+grub_env_get_bool (const char *name, bool if_unset)
+{
+  const char *val = grub_env_get (name);
+
+  if (val == NULL || grub_strlen (val) < 1)
+    return if_unset;
+  if (grub_strcmp (val, "0") == 0 || grub_strcmp (val, "false") == 0 ||
+      grub_strcmp (val, "disable") == 0 || grub_strcmp (val, "no") == 0)
+    return false;
+  return true;
+}
+
 void
 grub_env_unset (const char *name)
 {
grub-core/loader/arm64/linux.c +0 -1
index 9d0bacc854..48ab34a256 100644
@@ -33,7 +33,6 @@
 #include <grub/i18n.h>
 #include <grub/lib/cmdline.h>
 #include <grub/verify.h>
-#include <stdbool.h>
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
grub-core/parttool/msdospart.c +2 -2
index 3918caa06e..3a7699e454 100644
@@ -61,7 +61,7 @@ static grub_err_t grub_pcpart_boot (const grub_device_t dev,
       return grub_errno;
     }
 
-  if (args[0].set && args[0].bool)
+  if (args[0].set && args[0].b)
     {
       for (i = 0; i < 4; i++)
 	mbr.entries[i].flag = 0x0;
@@ -116,7 +116,7 @@ static grub_err_t grub_pcpart_type (const grub_device_t dev,
 
   if (args[1].set)
     {
-      if (args[1].bool)
+      if (args[1].b)
 	type |= GRUB_PC_PARTITION_TYPE_HIDDEN_FLAG;
       else
 	type &= ~GRUB_PC_PARTITION_TYPE_HIDDEN_FLAG;
include/grub/env.h +1 -0
index 76f832eb94..6b9379a300 100644
@@ -45,6 +45,7 @@ struct grub_env_var
 
 grub_err_t EXPORT_FUNC(grub_env_set) (const char *name, const char *val);
 const char *EXPORT_FUNC(grub_env_get) (const char *name);
+bool EXPORT_FUNC(grub_env_get_bool) (const char *name, bool if_unset);
 void EXPORT_FUNC(grub_env_unset) (const char *name);
 struct grub_env_var *EXPORT_FUNC(grub_env_update_get_sorted) (void);
 
include/grub/parttool.h +1 -1
index 4e8f8d5e51..4799a22c5d 100644
@@ -32,7 +32,7 @@ struct grub_parttool_args
   int set;
   union
   {
-    int bool;
+    int b;
     char *str;
   };
 };
include/grub/types.h +1 -0
index 5ae0ced388..6d5dc5cdaa 100644
@@ -20,6 +20,7 @@
 #define GRUB_TYPES_HEADER	1
 
 #include <config.h>
+#include <stdbool.h>
 #ifndef GRUB_UTIL
 #include <grub/cpu/types.h>
 #endif
Signature · 1 line
2.35.1