Skip to content

Commit 25a76db

Browse files
jithu83ij-intel
authored andcommitted
platform/x86/intel/ifs: Validate image size
Perform additional validation prior to loading IFS image. Error out if the size of the file being loaded doesn't match the size specified in the header. Signed-off-by: Jithu Joseph <jithu.joseph@intel.com> Reviewed-by: Tony Luck <tony.luck@intel.com> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Tested-by: Pengfei Xu <pengfei.xu@intel.com> Link: https://lore.kernel.org/r/20231005195137.3117166-6-jithu.joseph@intel.com Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
1 parent 72b96ee commit 25a76db

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • drivers/platform/x86/intel/ifs

drivers/platform/x86/intel/ifs/load.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ int ifs_load_firmware(struct device *dev)
375375
{
376376
const struct ifs_test_caps *test = ifs_get_test_caps(dev);
377377
struct ifs_data *ifsd = ifs_get_data(dev);
378+
unsigned int expected_size;
378379
const struct firmware *fw;
379380
char scan_path[64];
380381
int ret = -EINVAL;
@@ -389,6 +390,13 @@ int ifs_load_firmware(struct device *dev)
389390
goto done;
390391
}
391392

393+
expected_size = ((struct microcode_header_intel *)fw->data)->totalsize;
394+
if (fw->size != expected_size) {
395+
dev_err(dev, "File size mismatch (expected %u, actual %zu). Corrupted IFS image.\n",
396+
expected_size, fw->size);
397+
return -EINVAL;
398+
}
399+
392400
ret = image_sanity_check(dev, (struct microcode_header_intel *)fw->data);
393401
if (ret)
394402
goto release;

0 commit comments

Comments
 (0)