]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tpm2-util: dont't find best PCR bank if no PCRs are selected whatsoever
authorLennart Poettering <lennart@poettering.net>
Tue, 24 Oct 2023 20:19:48 +0000 (22:19 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 25 Oct 2023 07:29:20 +0000 (09:29 +0200)
This will otherwise just yield weird log message, complaining that PCRs
were not initialized. But which PCRs if we have none selected?

src/shared/tpm2-util.c

index 8d5097135616cc730b5edcf77c45e907253543a5..4bb17157e276777eb2d7707c053995406a505992 100644 (file)
@@ -2539,6 +2539,12 @@ int tpm2_get_best_pcr_bank(
         assert(c);
         assert(ret);
 
+        if (pcr_mask == 0) {
+                log_debug("Asked to pick best PCR bank but no PCRs selected we could derive this from. Defaulting to SHA256.");
+                *ret = TPM2_ALG_SHA256; /* if no PCRs are selected this doesn't matter anyway... */
+                return 0;
+        }
+
         FOREACH_TPMS_PCR_SELECTION_IN_TPML_PCR_SELECTION(selection, &c->capability_pcrs) {
                 TPMI_ALG_HASH hash = selection->hash;
                 int good;