diff options
author | Nikolai Vyssotski <nikolai.vyssotski@amd.corp-partner.google.com> | 2021-07-09 18:36:27 -0500 |
---|---|---|
committer | Martin Roth <martinroth@google.com> | 2021-07-24 15:18:43 +0000 |
commit | 3c3d2cf77fc96a789d51c58be626a8657d4650ad (patch) | |
tree | 3fd90e05366d11d07d8956c7b2abacf812936957 | |
parent | 9bf4293c3ff5acab0542e73fc31d580446a73398 (diff) |
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 <nikolai.vyssotski@amd.corp-partner.google.com>
Change-Id: Ie8422447b2cff0a6c536e13014905ffa15c70586
Reviewed-on: https://review.coreboot.org/c/coreboot/+/56190
Reviewed-by: Furquan Shaikh <furquan@google.com>
Reviewed-by: Subrata Banik <subrata.banik@intel.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
-rw-r--r-- | src/drivers/intel/fsp2_0/include/fsp/info_header.h | 5 | ||||
-rw-r--r-- | src/drivers/intel/fsp2_0/util.c | 25 |
2 files changed, 22 insertions, 8 deletions
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 <types.h> #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 <fsp/util.h> #include <string.h> #include <types.h> +#include <assert.h> + +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; } |