aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Richter <erichte@linux.ibm.com>2021-11-04 12:03:04 -0500
committerCédric Le Goater <clg@kaod.org>2021-11-04 22:56:56 +0100
commit99a39f93e97ee21f01a1f7179edf3638060645e3 (patch)
tree013cbb62ccb9b2572ca57239c18e0dc0a91738c5
parentbfc543f8c1a77a7b0a4587660262bde4b7cfb8c1 (diff)
downloadskiboot-99a39f93e97ee21f01a1f7179edf3638060645e3.zip
skiboot-99a39f93e97ee21f01a1f7179edf3638060645e3.tar.gz
skiboot-99a39f93e97ee21f01a1f7179edf3638060645e3.tar.bz2
secvar/secboot_tpm: correctly reset the control index on secboot format
When the SECBOOT partition is formatted, the bank hash stored in the control TPM NV index must be updated to match, or else we will immediately fail to load the freshly formatted data at the .load_bank() step. However, while the secboot_format() function does calculate and update the bank hash, it only writes the new hash for bank 0. It does not update the value for bank 1, or set the current active bank. This works as expected if the active bank bit happens to be set to 0. On the other hand, if the active bit is set to 1, the freshly formatted bank 1 will be compared against the unchanged bank hash in bank 1 at the load step, therefore causing an error. This patch fixes this issue by also setting the active bit to 0 to match the freshly calculated hash. Signed-off-by: Eric Richter <erichte@linux.ibm.com> Tested-by: Nick Child <nick.child@ibm.com> Reviewed-by: Daniel Axtens <dja@axtens.net> Signed-off-by: Cédric Le Goater <clg@kaod.org> (cherry picked from commit 5cb28dd14e202b66e95d5420923a157fe9639132) Signed-off-by: Cédric Le Goater <clg@kaod.org>
-rw-r--r--libstb/secvar/storage/secboot_tpm.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/libstb/secvar/storage/secboot_tpm.c b/libstb/secvar/storage/secboot_tpm.c
index 129f674..45373cf 100644
--- a/libstb/secvar/storage/secboot_tpm.c
+++ b/libstb/secvar/storage/secboot_tpm.c
@@ -127,12 +127,15 @@ static int secboot_format(void)
prlog(PR_ERR, "Bank hash failed to calculate somehow\n");
return rc;
}
+ /* Clear bank_hash[1] anyway, to match initial zeroed bank hash state */
+ memset(tpmnv_control_image->bank_hash[1], 0x00, sizeof(tpmnv_control_image->bank_hash[1]));
+
+ tpmnv_control_image->active_bit = 0;
rc = tpmnv_ops.write(SECBOOT_TPMNV_CONTROL_INDEX,
- tpmnv_control_image->bank_hash[0],
- SHA256_DIGEST_SIZE,
- offsetof(struct tpmnv_control,
- bank_hash[0]));
+ tpmnv_control_image,
+ sizeof(struct tpmnv_control),
+ 0);
if (rc) {
prlog(PR_ERR, "Could not write fresh formatted bank hashes to CONTROL index, rc=%d\n", rc);
return rc;