From e1465e21570dc4344c25371fc213dcd01a807b25 Mon Sep 17 00:00:00 2001 From: Jeremy Compostella Date: Thu, 8 Sep 2022 10:11:53 -0700 Subject: util/ifittool: Error out if microcodes do not fit the FIT table parse_microcode_blob() returns success when it reaches max_fit_entries microcode. It makes the FIT table size verification in fit_add_microcode_file() useless. This patch makes parse_microcode_blob() error out if max_fit_entries is reached. Note that this size verification is critical as a FIT table only partially listing the microcode patches can lead to boot failures as recently observed on Raptor Lake-P. BRANCH=firmware-brya-14505.B BUG=b:245380705 TEST=compilation errors out when trying to stitch more than CONFIG_CPU_INTEL_NUM_FIT_ENTRIES microcode patches. Signed-off-by: Jeremy Compostella Change-Id: Id9c5fb6c1e264f3f5137d29201b9021c72d78fde Reviewed-on: https://review.coreboot.org/c/coreboot/+/67454 Reviewed-by: Selma Bensaid Tested-by: build bot (Jenkins) Reviewed-by: Tim Wawrzynczak Reviewed-by: Zhixing Ma --- util/cbfstool/fit.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'util') diff --git a/util/cbfstool/fit.c b/util/cbfstool/fit.c index 7f8218a745..8ed24943b8 100644 --- a/util/cbfstool/fit.c +++ b/util/cbfstool/fit.c @@ -275,8 +275,10 @@ parse_microcode_blob(struct cbfs_image *image, struct cbfs_file *mcode_file; mcode_file = cbfs_get_entry(image, blob_name); - if (!mcode_file) + if (!mcode_file) { + ERROR("Couldn't find microcode blob.\n"); return 1; + } fit_location_from_cbfs_header(¤t_offset, &file_length, mcode_file); @@ -301,6 +303,11 @@ parse_microcode_blob(struct cbfs_image *image, total_size > file_length) break; + if (num_mcus == max_fit_entries) { + ERROR("Maximum of FIT entries reached.\n"); + return 1; + } + /* FIXME: Should the checksum be validated? */ mcus[num_mcus].offset = current_offset; mcus[num_mcus].size = total_size; @@ -309,9 +316,6 @@ parse_microcode_blob(struct cbfs_image *image, current_offset += mcus[num_mcus].size; file_length -= mcus[num_mcus].size; num_mcus++; - /* Reached limit of FIT entries. */ - if (num_mcus == max_fit_entries) - break; if (file_length < sizeof(struct microcode_header)) break; } @@ -492,13 +496,6 @@ int fit_add_microcode_file(struct fit_table *fit, if (parse_microcode_blob(image, blob_name, &mcus_found, mcus, max_fit_entries)) { - ERROR("Couldn't parse microcode blob.\n"); - free(mcus); - return 1; - } - - if (mcus_found > fit_free_space(fit, max_fit_entries)) { - ERROR("Maximum of FIT entries reached.\n"); free(mcus); return 1; } -- cgit v1.2.3