From 3c3d2cf77fc96a789d51c58be626a8657d4650ad Mon Sep 17 00:00:00 2001 From: Nikolai Vyssotski Date: Fri, 9 Jul 2021 18:36:27 -0500 Subject: src/drivers/intel/fsp2_0: allow larger FSP 2.0 header This is in preparation for migrating EDK2 to more recent version(s). In EDK2 repo commit f2cdb268ef appended an additional field to FSP 2.0 header (FspMultiPhaseSiInitEntryOffset). This increases the length of the header from 72 to 76. Instead of checking for exact length check reported header length against known minimum length for a given FSP version. BUG=b:180186886 TEST=build/boot with both header flavors Signed-off-by: Nikolai Vyssotski Change-Id: Ie8422447b2cff0a6c536e13014905ffa15c70586 Reviewed-on: https://review.coreboot.org/c/coreboot/+/56190 Reviewed-by: Furquan Shaikh Reviewed-by: Subrata Banik Tested-by: build bot (Jenkins) --- src/drivers/intel/fsp2_0/include/fsp/info_header.h | 5 ----- src/drivers/intel/fsp2_0/util.c | 25 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'src/drivers/intel/fsp2_0') diff --git a/src/drivers/intel/fsp2_0/include/fsp/info_header.h b/src/drivers/intel/fsp2_0/include/fsp/info_header.h index e08828a1a7..5b6318cb7c 100644 --- a/src/drivers/intel/fsp2_0/include/fsp/info_header.h +++ b/src/drivers/intel/fsp2_0/include/fsp/info_header.h @@ -6,11 +6,6 @@ #include #define FSP_HDR_OFFSET 0x94 -#if CONFIG(PLATFORM_USES_FSP2_2) -#define FSP_HDR_LEN 0x4c -#else -#define FSP_HDR_LEN 0x48 -#endif #define FSP_HDR_SIGNATURE "FSPH" #define FSP_HDR_ATTRIB_FSPT 1 #define FSP_HDR_ATTRIB_FSPM 2 diff --git a/src/drivers/intel/fsp2_0/util.c b/src/drivers/intel/fsp2_0/util.c index e9809e1f01..5045d29448 100644 --- a/src/drivers/intel/fsp2_0/util.c +++ b/src/drivers/intel/fsp2_0/util.c @@ -10,16 +10,35 @@ #include #include #include +#include + +static uint32_t fsp_hdr_get_expected_min_length(void) +{ + if (CONFIG(PLATFORM_USES_FSP2_2)) + return 76; + else if (CONFIG(PLATFORM_USES_FSP2_1)) + return 72; + else if (CONFIG(PLATFORM_USES_FSP2_0)) + return 72; + else + return dead_code_t(uint32_t); +} static bool looks_like_fsp_header(const uint8_t *raw_hdr) { + uint32_t fsp_header_length = read32(raw_hdr + 4); + if (memcmp(raw_hdr, FSP_HDR_SIGNATURE, 4)) { printk(BIOS_ALERT, "Did not find a valid FSP signature\n"); return false; } - if (read32(raw_hdr + 4) != FSP_HDR_LEN) { - printk(BIOS_ALERT, "FSP header has invalid length\n"); + /* It is possible to build FSP with any version of EDK2 which could have introduced new + fields in FSP_INFO_HEADER. The new fields will be ignored based on the reported FSP + version. This check ensures that the reported header length is at least what the + reported FSP version requires so that we do not access any out-of-bound bytes. */ + if (fsp_header_length < fsp_hdr_get_expected_min_length()) { + printk(BIOS_ALERT, "FSP header has invalid length: %d\n", fsp_header_length); return false; } @@ -59,7 +78,7 @@ enum cb_err fsp_validate_component(struct fsp_header *hdr, void *fsp_file, size_ { void *raw_hdr = fsp_file + FSP_HDR_OFFSET; - if (file_size < FSP_HDR_OFFSET + FSP_HDR_LEN) { + if (file_size < FSP_HDR_OFFSET + fsp_hdr_get_expected_min_length()) { printk(BIOS_CRIT, "FSP blob too small.\n"); return CB_ERR; } -- cgit v1.2.3