summaryrefslogtreecommitdiff
path: root/lib/tpm_tcg2.c
diff options
context:
space:
mode:
authorIlias Apalodimas <ilias.apalodimas@linaro.org>2024-12-24 08:01:08 -0800
committerIlias Apalodimas <ilias.apalodimas@linaro.org>2025-01-07 15:45:51 +0200
commit8dc886ce314282de9d65fac1e8c68ee40d30f678 (patch)
tree2149d32d6448b69d0a4930d938d7f24912a21d1b /lib/tpm_tcg2.c
parent27891e85f3cb3912c737bf36276f830d9d02d6c8 (diff)
tpm: Don't create an EventLog if algorithms are misconfigured
We already check the active banks vs what U-Boot was compiled with when trying to extend a PCR and we refuse to do so if the TPM active ones don't match the ones U-Boot supports. Do the same thing for the EventLog creation since extending will fail anyway and print a message so the user can figure out the missing algorithms. Co-developed-by: Raymond Mao <raymond.mao@linaro.org> Signed-off-by: Raymond Mao <raymond.mao@linaro.org> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Diffstat (limited to 'lib/tpm_tcg2.c')
-rw-r--r--lib/tpm_tcg2.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/tpm_tcg2.c b/lib/tpm_tcg2.c
index 99671804e3b..e77a9041299 100644
--- a/lib/tpm_tcg2.c
+++ b/lib/tpm_tcg2.c
@@ -567,11 +567,36 @@ int tcg2_log_prepare_buffer(struct udevice *dev, struct tcg2_event_log *elog,
bool ignore_existing_log)
{
struct tcg2_event_log log;
- int rc;
+ int rc, i;
elog->log_position = 0;
elog->found = false;
+ /*
+ * Make sure U-Boot is compiled with all the active PCRs
+ * since we are about to create an EventLog and we won't
+ * measure anything if the PCR banks don't match
+ */
+ if (!tpm2_check_active_banks(dev)) {
+ log_err("Cannot create EventLog\n");
+ log_err("Mismatch between U-Boot and TPM hash algos\n");
+ log_info("TPM:\n");
+ tpm2_print_active_banks(dev);
+ log_info("U-Boot:\n");
+ for (i = 0; i < ARRAY_SIZE(hash_algo_list); i++) {
+ const struct digest_info *algo = &hash_algo_list[i];
+ const char *str;
+
+ if (!algo->supported)
+ continue;
+
+ str = tpm2_algorithm_name(algo->hash_alg);
+ if (str)
+ log_info("%s\n", str);
+ }
+ return -EINVAL;
+ }
+
rc = tcg2_platform_get_log(dev, (void **)&log.log, &log.log_size);
if (!rc) {
log.log_position = 0;