summaryrefslogtreecommitdiff
path: root/src/security/vboot
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2022-08-08 18:08:35 -0700
committerJulius Werner <jwerner@chromium.org>2022-09-02 23:51:29 +0000
commitd96ca2465227f29354b41ce2ea7a17f1c5b8f1c1 (patch)
tree835f9410585448932b2195bfdb7b4066204411f3 /src/security/vboot
parentb45b48de739ebaf52584bc23797869028950a535 (diff)
cbfs/vboot: Adapt to new vb2_digest API
CL:3825558 changes all vb2_digest and vb2_hash functions to take a new hwcrypto_allowed argument, to potentially let them try to call the vb2ex_hwcrypto API for hash calculation. This change will open hardware crypto acceleration up to all hash calculations in coreboot (most notably CBFS verification). As part of this change, the vb2_digest_buffer() function has been removed, so replace existing instances in coreboot with the newer vb2_hash_calculate() API. Due to the circular dependency of these changes with vboot, this patch also needs to update the vboot submodule: Updating from commit id 18cb85b5: 2load_kernel.c: Expose load kernel as vb2_api to commit id b827ddb9: tests: Ensure auxfw sync runs after EC sync This brings in 15 new commits. Signed-off-by: Julius Werner <jwerner@chromium.org> Change-Id: I287d8dac3c49ad7ea3e18a015874ce8d610ec67e Reviewed-on: https://review.coreboot.org/c/coreboot/+/66561 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Jakub Czapiga <jacz@semihalf.com>
Diffstat (limited to 'src/security/vboot')
-rw-r--r--src/security/vboot/misc.h14
-rw-r--r--src/security/vboot/mrc_cache_hash_tpm.c40
-rw-r--r--src/security/vboot/tpm_common.c3
3 files changed, 27 insertions, 30 deletions
diff --git a/src/security/vboot/misc.h b/src/security/vboot/misc.h
index c39af08f1b..8310647760 100644
--- a/src/security/vboot/misc.h
+++ b/src/security/vboot/misc.h
@@ -87,4 +87,18 @@ static inline int vboot_logic_executed(void)
}
}
+static inline bool vboot_hwcrypto_allowed(void)
+{
+ /* When not using vboot firmware verification, HW crypto is always allowed. */
+ if (!CONFIG(VBOOT))
+ return 1;
+
+ /* Before vboot runs we can't check for HW crypto, so err on the side of caution. */
+ if (!vboot_logic_executed())
+ return 0;
+
+ /* Otherwise, vboot can decide. */
+ return vb2api_hwcrypto_allowed(vboot_get_context());
+}
+
#endif /* __VBOOT_MISC_H__ */
diff --git a/src/security/vboot/mrc_cache_hash_tpm.c b/src/security/vboot/mrc_cache_hash_tpm.c
index 77c23f63e4..f67eae48cb 100644
--- a/src/security/vboot/mrc_cache_hash_tpm.c
+++ b/src/security/vboot/mrc_cache_hash_tpm.c
@@ -2,27 +2,16 @@
#include <security/vboot/antirollback.h>
#include <program_loading.h>
-#include <security/vboot/vboot_common.h>
#include <vb2_api.h>
#include <security/tpm/tss.h>
+#include <security/vboot/misc.h>
#include <security/vboot/mrc_cache_hash_tpm.h>
#include <console/console.h>
#include <string.h>
void mrc_cache_update_hash(uint32_t index, const uint8_t *data, size_t size)
{
- uint8_t data_hash[VB2_SHA256_DIGEST_SIZE];
- static const uint8_t dead_hash[VB2_SHA256_DIGEST_SIZE] = {
- 0xba, 0xad, 0xda, 0x1a, /* BAADDA1A */
- 0xde, 0xad, 0xde, 0xad, /* DEADDEAD */
- 0xde, 0xad, 0xda, 0x1a, /* DEADDA1A */
- 0xba, 0xad, 0xba, 0xad, /* BAADBAAD */
- 0xba, 0xad, 0xda, 0x1a, /* BAADDA1A */
- 0xde, 0xad, 0xde, 0xad, /* DEADDEAD */
- 0xde, 0xad, 0xda, 0x1a, /* DEADDA1A */
- 0xba, 0xad, 0xba, 0xad, /* BAADBAAD */
- };
- const uint8_t *hash_ptr = data_hash;
+ struct vb2_hash hash;
/* Initialize TPM driver. */
if (tlcl_lib_init() != VB2_SUCCESS) {
@@ -31,8 +20,8 @@ void mrc_cache_update_hash(uint32_t index, const uint8_t *data, size_t size)
}
/* Calculate hash of data generated by MRC. */
- if (vb2_digest_buffer(data, size, VB2_HASH_SHA256, data_hash,
- sizeof(data_hash))) {
+ if (vb2_hash_calculate(vboot_hwcrypto_allowed(), data, size,
+ VB2_HASH_SHA256, &hash)) {
printk(BIOS_ERR, "MRC: SHA-256 calculation failed for data. "
"Not updating TPM hash space.\n");
/*
@@ -40,13 +29,13 @@ void mrc_cache_update_hash(uint32_t index, const uint8_t *data, size_t size)
* currently stored in TPM hash space is no longer
* valid. If we are not able to calculate hash of the
* data being updated, reset all the bits in TPM hash
- * space to pre-defined hash pattern.
+ * space to zero to invalidate it.
*/
- hash_ptr = dead_hash;
+ memset(hash.raw, 0, VB2_SHA256_DIGEST_SIZE);
}
/* Write hash of data to TPM space. */
- if (antirollback_write_space_mrc_hash(index, hash_ptr, VB2_SHA256_DIGEST_SIZE)
+ if (antirollback_write_space_mrc_hash(index, hash.sha256, sizeof(hash.sha256))
!= TPM_SUCCESS) {
printk(BIOS_ERR, "MRC: Could not save hash to TPM.\n");
return;
@@ -57,15 +46,7 @@ void mrc_cache_update_hash(uint32_t index, const uint8_t *data, size_t size)
int mrc_cache_verify_hash(uint32_t index, const uint8_t *data, size_t size)
{
- uint8_t data_hash[VB2_SHA256_DIGEST_SIZE];
- uint8_t tpm_hash[VB2_SHA256_DIGEST_SIZE];
-
- /* Calculate hash of data read from MRC_CACHE. */
- if (vb2_digest_buffer(data, size, VB2_HASH_SHA256, data_hash,
- sizeof(data_hash))) {
- printk(BIOS_ERR, "MRC: SHA-256 calculation failed for data.\n");
- return 0;
- }
+ struct vb2_hash tpm_hash = { .algo = VB2_HASH_SHA256 };
/* Initialize TPM driver. */
if (tlcl_lib_init() != VB2_SUCCESS) {
@@ -74,13 +55,14 @@ int mrc_cache_verify_hash(uint32_t index, const uint8_t *data, size_t size)
}
/* Read hash of MRC data saved in TPM. */
- if (antirollback_read_space_mrc_hash(index, tpm_hash, sizeof(tpm_hash))
+ if (antirollback_read_space_mrc_hash(index, tpm_hash.sha256, sizeof(tpm_hash.sha256))
!= TPM_SUCCESS) {
printk(BIOS_ERR, "MRC: Could not read hash from TPM.\n");
return 0;
}
- if (memcmp(tpm_hash, data_hash, sizeof(tpm_hash))) {
+ /* Calculate hash of data read from MRC_CACHE and compare. */
+ if (vb2_hash_verify(vboot_hwcrypto_allowed(), data, size, &tpm_hash)) {
printk(BIOS_ERR, "MRC: Hash comparison failed.\n");
return 0;
}
diff --git a/src/security/vboot/tpm_common.c b/src/security/vboot/tpm_common.c
index 7fb2a9d3c5..e67cc01322 100644
--- a/src/security/vboot/tpm_common.c
+++ b/src/security/vboot/tpm_common.c
@@ -1,8 +1,9 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <security/tpm/tspi.h>
-#include <vb2_api.h>
#include <security/vboot/tpm_common.h>
+#include <vb2_api.h>
+#include <vb2_sha.h>
#define TPM_PCR_BOOT_MODE "VBOOT: boot mode"
#define TPM_PCR_GBB_HWID_NAME "VBOOT: GBB HWID"