]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
commands/efi/tpm: Call get_active_pcr_banks() only with TCG2 1.1 or newer
authorLuca Boccassi <luca.boccassi@gmail.com>
Sat, 20 Sep 2025 01:12:32 +0000 (02:12 +0100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Sat, 11 Oct 2025 13:36:54 +0000 (15:36 +0200)
The call was added in the 1.1 revision of the spec, 1.0 does
not have it, and there are some machines out there with a TPM2
and a UEFI firmware that only supports version 1.0, so the
call fails in those cases. Check the reported version before
calling get_active_pcr_banks().

See Table 4 in section 6.2 of the TCG EFI Protocol Specification:

  https://trustedcomputinggroup.org/wp-content/uploads/EFI-Protocol-Specification-rev13-160330final.pdf

Fixes: f326c5c47 (commands/bli: Set LoaderTpm2ActivePcrBanks runtime variable)
Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
Reviewed-by: Andrew Hamilton <adhamilt@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/commands/efi/tpm.c

index 59d0b67085a1f536c84b26dcf54202f72bf86404..7b493c890b6b0abbcc55acccc39d1dccbf32fd7c 100644 (file)
@@ -39,6 +39,7 @@ static grub_uint8_t grub_tpm_version;
 
 static grub_int8_t tpm1_present = -1;
 static grub_int8_t tpm2_present = -1;
+static grub_int8_t tpm2_pcr_banks_reporting_present = -1;
 
 static grub_efi_boolean_t
 grub_tpm1_present (grub_efi_tpm_protocol_t *tpm)
@@ -89,6 +90,34 @@ grub_tpm2_present (grub_efi_tpm2_protocol_t *tpm)
   return (grub_efi_boolean_t) tpm2_present;
 }
 
+static grub_efi_boolean_t
+grub_tpm2_pcr_banks_reporting_present (grub_efi_tpm2_protocol_t *tpm)
+{
+  grub_efi_status_t status;
+  EFI_TCG2_BOOT_SERVICE_CAPABILITY caps;
+
+  caps.Size = (grub_uint8_t) sizeof (caps);
+
+  if (tpm2_pcr_banks_reporting_present != -1)
+    return (grub_efi_boolean_t) tpm2_pcr_banks_reporting_present;
+
+  if (!grub_tpm2_present (tpm))
+    return (grub_efi_boolean_t) (tpm2_pcr_banks_reporting_present = 0);
+
+  status = tpm->get_capability (tpm, &caps);
+
+  if (status != GRUB_EFI_SUCCESS || caps.StructureVersion.Major < 1
+      || (caps.StructureVersion.Major == 1 && caps.StructureVersion.Minor < 1))
+    tpm2_pcr_banks_reporting_present = 0;
+  else
+    tpm2_pcr_banks_reporting_present = 1;
+
+  grub_dprintf ("tpm", "tpm2 PCR banks reporting%s present\n",
+               tpm2_pcr_banks_reporting_present ? "" : " NOT");
+
+  return (grub_efi_boolean_t) tpm2_pcr_banks_reporting_present;
+}
+
 static grub_efi_boolean_t
 grub_tpm_handle_find (grub_efi_handle_t *tpm_handle,
                      grub_efi_uint8_t *protocol_version)
@@ -355,7 +384,7 @@ grub_tpm2_active_pcr_banks (void)
       return 0;
     }
 
-  if (grub_tpm2_present (tpm))
+  if (grub_tpm2_pcr_banks_reporting_present (tpm))
     {
       grub_efi_status_t status = tpm->get_active_pcr_banks (tpm, &active_pcr_banks);