From 73096907881fcdaba27c128d46a55e6b9ce3cc5e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 15 Aug 2022 11:44:52 +0200 Subject: [PATCH] tpm-util: use trial session where appropriate MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit TPM2 knows two types of policy sessions: "real" ones and "trial" ones. The latter allow you to calculate a policy hash without this enforcing any policy, which the former do. Typically you want to use the "trial" ones when enrolling, and you have to use the "real" ones for unlocking. So far we used "real" ones for both cases. Which works fine – as long as the policy put together matches the current reality (e.g. the PCR values included in the policy are the ones currently in place in the TPM). Let's switch to using trial sessions for enrolling. First of all this is preparation for later work to implement further policy extensions (for example, policies binding to literally specified PCR values, instead of the once currently measured). But from my perspective more importantly it actually is cleaner, as it communicates more clearly what we are actually doing here. No user-visible change in behaviour. --- src/shared/tpm2-util.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index 7ee49bf8dfc..33703c4aa3b 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -661,6 +661,7 @@ static int tpm2_make_pcr_session( ESYS_CONTEXT *c, ESYS_TR primary, ESYS_TR parent_session, + TPM2_SE session_type, uint32_t pcr_mask, uint16_t pcr_bank, /* If UINT16_MAX, pick best bank automatically, otherwise specify bank explicitly. */ bool use_pin, @@ -711,7 +712,7 @@ static int tpm2_make_pcr_session( ESYS_TR_NONE, ESYS_TR_NONE, NULL, - TPM2_SE_POLICY, + session_type, &symmetric, TPM2_ALG_SHA256, &session); @@ -880,8 +881,17 @@ int tpm2_seal( if (r < 0) goto finish; - r = tpm2_make_pcr_session(c.esys_context, primary, session, pcr_mask, UINT16_MAX, !!pin, NULL, - &policy_digest, &pcr_bank); + r = tpm2_make_pcr_session( + c.esys_context, + primary, + session, + TPM2_SE_TRIAL, + pcr_mask, + /* pcr_bank= */ UINT16_MAX, + !!pin, + /* ret_session= */ NULL, + &policy_digest, + &pcr_bank); if (r < 0) goto finish; @@ -1085,8 +1095,17 @@ int tpm2_unseal( if (r < 0) goto finish; - r = tpm2_make_pcr_session(c.esys_context, primary, hmac_session, pcr_mask, pcr_bank, !!pin, &session, - &policy_digest, NULL); + r = tpm2_make_pcr_session( + c.esys_context, + primary, + hmac_session, + TPM2_SE_POLICY, + pcr_mask, + pcr_bank, + !!pin, + &session, + &policy_digest, + /* ret_pcr_bank= */ NULL); if (r < 0) goto finish; -- 2.47.3