-
Notifications
You must be signed in to change notification settings - Fork 365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix use of PCR16 #2879
Open
AndreasFuchsTPM
wants to merge
2
commits into
tpm2-software:master
Choose a base branch
from
AndreasFuchsTPM:test_pcr16
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix use of PCR16 #2879
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
* | ||
* All rights reserved. | ||
***********************************************************************/ | ||
#include "tss2_sys.h" | ||
|
||
#ifdef HAVE_CONFIG_H | ||
#include "config.h" // IWYU pragma: keep | ||
#endif | ||
|
@@ -44,7 +46,7 @@ struct { | |
}; | ||
|
||
struct tpm_state { | ||
TPMS_CAPABILITY_DATA capabilities[7]; | ||
TPMS_CAPABILITY_DATA capabilities[sizeof(capabilities_to_dump) / sizeof(capabilities_to_dump[0])]; | ||
}; | ||
|
||
/** Define a proxy tcti that returns yielded on every second invocation | ||
|
@@ -235,6 +237,40 @@ transient_empty(TSS2_SYS_CONTEXT *sys_ctx) | |
return EXIT_SUCCESS; | ||
} | ||
|
||
int | ||
pcr16_empty(TSS2_SYS_CONTEXT *sys_ctx) | ||
{ | ||
TSS2_RC rc; | ||
TPML_DIGEST pcr_values = { 0 }; | ||
TPML_PCR_SELECTION pcr_selection = { .count=1, .pcrSelections = { { .hash = TPM2_ALG_SHA256, .sizeofSelect = 3, .pcrSelect = { 0 } } } }; | ||
pcr_selection.pcrSelections[0].pcrSelect[(16 / 8)] = 1 << (16 % 8); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we not have a macro for this? |
||
|
||
do { | ||
rc = Tss2_Sys_PCR_Read(sys_ctx, NULL, | ||
&pcr_selection, NULL, NULL, | ||
&pcr_values, | ||
NULL); | ||
} while (rc == TPM2_RC_YIELDED); // TODO also for other cmds? | ||
if (rc != TSS2_RC_SUCCESS) { | ||
LOG_ERROR("TPM2_PCR_Read failed: 0x%" PRIx32, rc); | ||
return EXIT_ERROR; | ||
} | ||
|
||
if (pcr_values.count != 1) { | ||
LOG_ERROR("TPM2_PCR_Read for PCR 16 in SHA256 did not return a value"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you forget a |
||
} | ||
|
||
for (UINT16 i = 0; i < pcr_values.digests[0].size; i++) { | ||
if (pcr_values.digests[0].buffer[i] != 0x00) { | ||
LOGBLOB_ERROR(&pcr_values.digests[0].buffer[0], pcr_values.digests[0].size, | ||
"PCR 16 in SHA256 is not 0x000..000"); | ||
return EXIT_ERROR; | ||
} | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
|
||
int | ||
dumpstate(TSS2_SYS_CONTEXT *sys_ctx, tpm_state *state_first, bool compare) | ||
{ | ||
|
@@ -390,6 +426,13 @@ test_sys_checks_pre(TSS2_TEST_SYS_CONTEXT *test_ctx) | |
return ret; | ||
} | ||
|
||
LOG_DEBUG("Running System API pre-test checks: pcr16 empty"); | ||
ret = pcr16_empty(test_ctx->sys_ctx); | ||
if (ret != EXIT_SUCCESS) { | ||
LOG_ERROR("PCR16 is not empty"); | ||
return ret; | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
|
||
|
@@ -398,13 +441,27 @@ test_sys_checks_post(TSS2_TEST_SYS_CONTEXT *test_ctx) | |
{ | ||
int ret; | ||
|
||
LOG_DEBUG("Running System API pre-test checks: transient handles empty"); | ||
ret = transient_empty(test_ctx->sys_ctx); | ||
if (ret != EXIT_SUCCESS) { | ||
LOG_ERROR("TPM contains transient objects."); | ||
return ret; | ||
} | ||
|
||
LOG_DEBUG("Running System API post-test checks: dump capabilities"); | ||
ret = dumpstate(test_ctx->sys_ctx, test_ctx->tpm_state, 1); | ||
if (ret != EXIT_SUCCESS) { | ||
LOG_ERROR("Error while performing TPM state checks."); | ||
return ret; | ||
} | ||
|
||
LOG_DEBUG("Running System API post-test checks: pcr16 empty"); | ||
ret = pcr16_empty(test_ctx->sys_ctx); | ||
if (ret != EXIT_SUCCESS) { | ||
LOG_ERROR("PCR16 is not empty"); | ||
return ret; | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
|
||
|
@@ -533,6 +590,13 @@ test_esys_checks_pre(TSS2_TEST_ESYS_CONTEXT *test_ctx) | |
return ret; | ||
} | ||
|
||
LOG_DEBUG("Running System API pre-test checks: pcr16 empty"); | ||
ret = pcr16_empty(sys_context); | ||
if (ret != EXIT_SUCCESS) { | ||
LOG_ERROR("PCR16 is not empty"); | ||
return ret; | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
|
||
|
@@ -549,13 +613,27 @@ test_esys_checks_post(TSS2_TEST_ESYS_CONTEXT *test_ctx) | |
return EXIT_ERROR; | ||
} | ||
|
||
LOG_DEBUG("Running System API pre-test checks: transient handles empty"); | ||
ret = transient_empty(sys_context); | ||
if (ret != EXIT_SUCCESS) { | ||
LOG_ERROR("TPM contains transient objects."); | ||
return ret; | ||
} | ||
|
||
LOG_DEBUG("Running System API post-test checks: dump capabilities"); | ||
ret = dumpstate(sys_context, test_ctx->tpm_state, 1); | ||
if (ret != EXIT_SUCCESS) { | ||
LOG_ERROR("Error while performing TPM state checks."); | ||
return ret; | ||
} | ||
|
||
LOG_DEBUG("Running System API pre-test checks: pcr16 empty"); | ||
ret = pcr16_empty(sys_context); | ||
if (ret != EXIT_SUCCESS) { | ||
LOG_ERROR("PCR16 is not empty"); | ||
return ret; | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ARRAY_LEN()
is defined insrc/util/aux_util.h