Skip to content

Commit

Permalink
Fix issue with reading NV indexes
Browse files Browse the repository at this point in the history
Wrong arguments are used in tpm2_getekcertificate and tpm2_nvdefine when
accessing the list of NV indexes in use. This works fine on
little-endian systems, but on big-endian systems this will not find any
NV indexes, causing issues when using these functions without an
argument. Also, use the same argument in tpm2_nvreadpublic.

Signed-off-by: Štěpán Horáček <[email protected]>
  • Loading branch information
shoracek committed Mar 26, 2024
1 parent 1be8d63 commit 941e995
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tools/tpm2_getekcertificate.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ tool_rc get_tpm_properties(ESYS_CONTEXT *ectx) {

free(capability_data);
rc = tpm2_getcap(ectx, TPM2_CAP_HANDLES,
tpm2_util_hton_32(TPM2_HT_NV_INDEX), TPM2_PT_NV_INDEX_MAX, NULL,
TPM2_NV_INDEX_FIRST, TPM2_PT_NV_INDEX_MAX, NULL,
&capability_data);
if (rc != tool_rc_success) {
LOG_ERR("Failed to read capability data for NV indices.");
Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_nvdefine.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static tool_rc handle_no_index_specified(ESYS_CONTEXT *ectx, TPM2_NV_INDEX *chos
capabilities = NULL;

/* now find what NV indexes are in use */
rc = tpm2_getcap(ectx, TPM2_CAP_HANDLES, tpm2_util_hton_32(TPM2_HT_NV_INDEX),
rc = tpm2_getcap(ectx, TPM2_CAP_HANDLES, TPM2_NV_INDEX_FIRST,
TPM2_PT_NV_INDEX_MAX, NULL, &capabilities);
if (rc != tool_rc_success) {
goto out;
Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_nvreadpublic.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static tool_rc process_inputs(ESYS_CONTEXT *ectx) {
*/
if (ctx.nv_index == 0 && ctx.is_command_dispatch) {
rc = tpm2_getcap(ectx, TPM2_CAP_HANDLES,
TPM2_HT_NV_INDEX << 24, TPM2_PT_NV_INDEX_MAX, NULL,
TPM2_NV_INDEX_FIRST, TPM2_PT_NV_INDEX_MAX, NULL,
&ctx.capability_data);
if (rc != tool_rc_success) {
return rc;
Expand Down

0 comments on commit 941e995

Please sign in to comment.