From 03328f1087025caa68f410763f87bbb131d377c9 Mon Sep 17 00:00:00 2001 From: Andrey Pronin Date: Wed, 26 Apr 2023 20:08:37 -0700 Subject: cr50: handle unwritten spaces in read_tpm_nvmem This CL checks if the space was defined but not written, and if so, returns TPM_READ_NOT_FOUND from read_tpm_nvmem(). BUG=b:276384456 TEST=with crrev.com/c/2494503, verify that calling chkfwmp prints "read_tpm_nvmem: object at 0x100a not written" and then the following when the space is not written: ``` FWMP read result: 1 ccd unlock allowed: 1 policy update allowed: 1 ``` To create an unwritten space, run tpm_manager_client define_space --index=0x100a --size=40 Change-Id: I8eff2be8da1e28204216d4dbbd54e57e8a8127b3 Signed-off-by: Andrey Pronin Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4483017 Reviewed-by: Mary Ruthven Commit-Queue: Mary Ruthven Auto-Submit: Andrey Pronin Tested-by: Andrey Pronin --- board/cr50/tpm_nvmem_ops.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/board/cr50/tpm_nvmem_ops.c b/board/cr50/tpm_nvmem_ops.c index 92e8721b0a..634a540239 100644 --- a/board/cr50/tpm_nvmem_ops.c +++ b/board/cr50/tpm_nvmem_ops.c @@ -37,6 +37,16 @@ enum tpm_read_rv read_tpm_nvmem(uint16_t obj_index, /* Get properties of this index as stored in nvmem. */ NvReadIndexInfo(object_handle, handle_addr, &nvIndex); + /* + * Check that the index was written to. Otherwise, behave as if the + * index doesn't exist. + */ + if (nvIndex.publicArea.attributes.TPMA_NV_WRITTEN == 0) { + CPRINTF("%s: object at 0x%x not written\n", + __func__, obj_index); + return TPM_READ_NOT_FOUND; + } + /* * We presume it is readable and are not checking the access * limitations. -- cgit v1.2.1