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>
This commit is contained in:
Nikolai Vyssotski 2021-07-09 18:36:27 -05:00 committed by Martin Roth
parent 9bf4293c3f
commit 3c3d2cf77f
2 changed files with 22 additions and 8 deletions

View File

@ -6,11 +6,6 @@
#include <types.h> #include <types.h>
#define FSP_HDR_OFFSET 0x94 #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_SIGNATURE "FSPH"
#define FSP_HDR_ATTRIB_FSPT 1 #define FSP_HDR_ATTRIB_FSPT 1
#define FSP_HDR_ATTRIB_FSPM 2 #define FSP_HDR_ATTRIB_FSPM 2

View File

@ -10,16 +10,35 @@
#include <fsp/util.h> #include <fsp/util.h>
#include <string.h> #include <string.h>
#include <types.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) 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)) { if (memcmp(raw_hdr, FSP_HDR_SIGNATURE, 4)) {
printk(BIOS_ALERT, "Did not find a valid FSP signature\n"); printk(BIOS_ALERT, "Did not find a valid FSP signature\n");
return false; return false;
} }
if (read32(raw_hdr + 4) != FSP_HDR_LEN) { /* It is possible to build FSP with any version of EDK2 which could have introduced new
printk(BIOS_ALERT, "FSP header has invalid length\n"); 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; 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; 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"); printk(BIOS_CRIT, "FSP blob too small.\n");
return CB_ERR; return CB_ERR;
} }