From d685a5f6a4ae8f9eaea1d1c5c78171a915f3b16d Mon Sep 17 00:00:00 2001 From: OMOJOLA Date: Thu, 4 May 2023 22:21:04 +0000 Subject: [PATCH] tpm2 PCRs: fix unchecked attempt to set PCR[24] --- src/shared/tpm2-util.c | 2 +- src/test/test-tpm2.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index 530a454c6a..73fd833cc6 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -3152,4 +3152,4 @@ static const char* const pcr_index_table[_PCR_INDEX_MAX_DEFINED] = { [PCR_APPLICATION_SUPPORT] = "application-support", }; -DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_FALLBACK(pcr_index, int, TPM2_PCRS_MAX); +DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_FALLBACK(pcr_index, int, TPM2_PCRS_MAX - 1); diff --git a/src/test/test-tpm2.c b/src/test/test-tpm2.c index 3e989251d8..fb23d4319a 100644 --- a/src/test/test-tpm2.c +++ b/src/test/test-tpm2.c @@ -33,7 +33,7 @@ TEST(tpm2_mask_from_string) { test_tpm2_pcr_mask_from_string_one("sysexts,shim-policy+kernel-boot", 26624, 0); test_tpm2_pcr_mask_from_string_one("sysexts,shim+kernel-boot", 0, -EINVAL); test_tpm2_pcr_mask_from_string_one("sysexts+17+23", 8527872, 0); - test_tpm2_pcr_mask_from_string_one("debug+24", 16842752, 0); + test_tpm2_pcr_mask_from_string_one("debug+24", 0, -EINVAL); } TEST(pcr_index_from_string) { @@ -73,6 +73,7 @@ TEST(pcr_index_from_string) { assert_se(pcr_index_from_string("8") == 8); assert_se(pcr_index_from_string("44") == -EINVAL); assert_se(pcr_index_from_string("-5") == -EINVAL); + assert_se(pcr_index_from_string("24") == -EINVAL); } TEST(tpm2_util_pbkdf2_hmac_sha256) {