Skip to content

Commit c54b296

Browse files
tpm2_createpolicy: flush session for trial policy.
The created session is flushed if a trial policy is only used to compute the policy digest. Fixes: #3427 Signed-off-by: Juergen Repp <[email protected]>
1 parent bd832d3 commit c54b296

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tools/tpm2_createpolicy.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ static create_policy_ctx pctx = {
5454

5555
static tool_rc parse_policy_type_specific_command(ESYS_CONTEXT *ectx) {
5656

57+
tool_rc rc;
58+
TSS2_RC rval;
59+
5760
if (!pctx.common_policy_options.policy_type.policy_pcr) {
5861
LOG_ERR("Only PCR policy is currently supported!");
5962
return tool_rc_option_error;
@@ -71,7 +74,7 @@ static tool_rc parse_policy_type_specific_command(ESYS_CONTEXT *ectx) {
7174

7275
tpm2_session **s = &pctx.common_policy_options.policy_session;
7376

74-
tool_rc rc = tpm2_session_open(ectx, session_data, s);
77+
rc = tpm2_session_open(ectx, session_data, s);
7578
if (rc != tool_rc_success) {
7679
return rc;
7780
}
@@ -91,9 +94,19 @@ static tool_rc parse_policy_type_specific_command(ESYS_CONTEXT *ectx) {
9194
return rc;
9295
}
9396

94-
return tpm2_policy_tool_finish(ectx,
95-
pctx.common_policy_options.policy_session,
96-
pctx.common_policy_options.policy_file);
97+
rc = tpm2_policy_tool_finish(ectx,
98+
pctx.common_policy_options.policy_session,
99+
pctx.common_policy_options.policy_file);
100+
if (rc != tool_rc_success) {
101+
return rc;
102+
}
103+
if (pctx.common_policy_options.policy_session_type == TPM2_SE_TRIAL) {
104+
rval = Esys_FlushContext(ectx, tpm2_session_get_handle(*s));
105+
if (rval != TPM2_RC_SUCCESS) {
106+
return tool_rc_general_error;
107+
}
108+
}
109+
return rc;
97110
}
98111

99112
static bool on_option(char key, char *value) {

0 commit comments

Comments
 (0)