Skip to content

Commit

Permalink
tpm2_nv(read|write): use a default buffer size if TPM reports 0.
Browse files Browse the repository at this point in the history
On a NUC5i7RYH, the TPM reports it's max NV buffer size as 0, which
means we can neither read nor write. In this case, default to
512 as that is generally considered a safe size.

Signed-off-by: William Roberts <william.c.roberts@intel.com>
  • Loading branch information
Duncan Palmer authored and William Roberts committed Apr 27, 2018
1 parent 988e1e9 commit b0c6f5b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/tpm2_nv_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
#include "log.h"
#include "tpm2_util.h"

/*
* The default buffer size when one cannot be determined via get capability.
*/
#define NV_DEFAULT_BUFFER_SIZE 512

/**
* Reads the public portion of a Non-Volatile (nv) index.
* @param sapi_context
Expand Down
3 changes: 3 additions & 0 deletions tools/tpm2_nvread.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ static bool nv_read(TSS2_SYS_CONTEXT *sapi_context, tpm2_option_flags flags) {
if (max_data_size > MAX_NV_BUFFER_SIZE) {
max_data_size = MAX_NV_BUFFER_SIZE;
}
else if (max_data_size == 0) {
max_data_size = NV_DEFAULT_BUFFER_SIZE;
}

UINT8 *data_buffer = malloc(data_size);
if (!data_buffer) {
Expand Down
3 changes: 3 additions & 0 deletions tools/tpm2_nvwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ static bool nv_write(TSS2_SYS_CONTEXT *sapi_context) {
if (max_data_size > MAX_NV_BUFFER_SIZE) {
max_data_size = MAX_NV_BUFFER_SIZE;
}
else if (max_data_size == 0) {
max_data_size = NV_DEFAULT_BUFFER_SIZE;
}

UINT16 data_offset = 0;
UINT16 bytes_left = ctx.nv_buffer.t.size;
Expand Down

0 comments on commit b0c6f5b

Please sign in to comment.