summaryrefslogtreecommitdiffstats
path: root/src/commonlib/bsd
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2020-05-06 17:06:35 -0700
committerJulius Werner <jwerner@chromium.org>2020-12-03 00:11:08 +0000
commitfdabf3fcd792e5939445233c74eb8bf3bb73de39 (patch)
tree2e197225a159c20a533e267d728326709711e690 /src/commonlib/bsd
parent0ba16637d8f12fe9ba8388222cfa71fc5206c0f3 (diff)
downloadcoreboot-fdabf3fcd792e5939445233c74eb8bf3bb73de39.tar.gz
coreboot-fdabf3fcd792e5939445233c74eb8bf3bb73de39.tar.bz2
coreboot-fdabf3fcd792e5939445233c74eb8bf3bb73de39.zip
cbfs: Add verification for RO CBFS metadata hash
This patch adds the first stage of the new CONFIG_CBFS_VERIFICATION feature. It's not useful to end-users in this stage so it cannot be selected in menuconfig (and should not be used other than for development) yet. With this patch coreboot can verify the metadata hash of the RO CBFS when it starts booting, but it does not verify individual files yet. Likewise, verifying RW CBFSes with vboot is not yet supported. Verification is bootstrapped from a "metadata hash anchor" structure that is embedded in the bootblock code and marked by a unique magic number. This anchor contains both the CBFS metadata hash and a separate hash for the FMAP which is required to find the primary CBFS. Both are verified on first use in the bootblock (and halt the system on failure). The CONFIG_TOCTOU_SAFETY option is also added for illustrative purposes to show some paths that need to be different when full protection against TOCTOU (time-of-check vs. time-of-use) attacks is desired. For normal verification it is sufficient to check the FMAP and the CBFS metadata hash only once in the bootblock -- for TOCTOU verification we do the same, but we need to be extra careful that we do not re-read the FMAP or any CBFS metadata in later stages. This is mostly achieved by depending on the CBFS metadata cache and FMAP cache features, but we allow for one edge case in case the RW CBFS metadata cache overflows (which may happen during an RW update and could otherwise no longer be fixed because mcache size is defined by RO code). This code is added to demonstrate design intent but won't really matter until RW CBFS verification can be supported. Signed-off-by: Julius Werner <jwerner@chromium.org> Change-Id: I8930434de55eb938b042fdada9aa90218c0b5a34 Reviewed-on: https://review.coreboot.org/c/coreboot/+/41120 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'src/commonlib/bsd')
-rw-r--r--src/commonlib/bsd/include/commonlib/bsd/metadata_hash.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/commonlib/bsd/include/commonlib/bsd/metadata_hash.h b/src/commonlib/bsd/include/commonlib/bsd/metadata_hash.h
new file mode 100644
index 000000000000..d5e54b508edb
--- /dev/null
+++ b/src/commonlib/bsd/include/commonlib/bsd/metadata_hash.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only */
+
+#ifndef _COMMONLIB_BSD_METADATA_HASH_H_
+#define _COMMONLIB_BSD_METADATA_HASH_H_
+
+#include <stdint.h>
+#include <vb2_sha.h>
+
+/* This structure is embedded somewhere in the (uncompressed) bootblock. */
+struct metadata_hash_anchor {
+ uint8_t magic[8];
+ struct vb2_hash cbfs_hash;
+ /* NOTE: This is just reserving space. sizeof(struct vb2_hash) may change between
+ configurations/versions and cannot be relied upon, so the FMAP hash must be placed
+ right after the actual data for the particular CBFS hash algorithm used ends. */
+ uint8_t reserved_space_for_fmap_hash[VB2_MAX_DIGEST_SIZE];
+} __packed;
+
+/* Always use this function to figure out the actual location of the FMAP hash. It always uses
+ the same algorithm as the CBFS hash. */
+static inline uint8_t *metadata_hash_anchor_fmap_hash(struct metadata_hash_anchor *anchor)
+{
+ return anchor->cbfs_hash.raw + vb2_digest_size(anchor->cbfs_hash.algo);
+}
+
+/*
+ * Do not use this constant anywhere else in coreboot code to ensure the bit pattern really only
+ * appears once in the CBFS image. The only coreboot file allowed to use this is
+ * src/lib/metadata_anchor.c to define the actual anchor data structure. It is defined here so
+ * that it can be shared with cbfstool (which may use it freely).
+ */
+#define DO_NOT_USE_METADATA_HASH_ANCHOR_MAGIC_DO_NOT_USE "\xadMdtHsh\x15"
+
+#endif /* _COMMONLIB_BSD_MASTER_HASH_H_ */