From 89cd8129f72bc2c445839efcddace560bfdfeb8f Mon Sep 17 00:00:00 2001 From: lgao4 Date: Wed, 23 Feb 2011 03:09:55 +0000 Subject: Update PeiCore and DxeCore to verify FFS data checksum. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11332 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Core/Dxe/FwVol/Ffs.c | 15 ++++++++++----- MdeModulePkg/Core/Pei/FwVol/FwVol.c | 11 +++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/FwVol/Ffs.c b/MdeModulePkg/Core/Dxe/FwVol/Ffs.c index aec08b2..5eb22d0 100644 --- a/MdeModulePkg/Core/Dxe/FwVol/Ffs.c +++ b/MdeModulePkg/Core/Dxe/FwVol/Ffs.c @@ -217,6 +217,8 @@ IsValidFfsFile ( ) { EFI_FFS_FILE_STATE FileState; + UINT8 DataCheckSum; + UINT32 FileLength; FileState = GetFileState (ErasePolarity, FfsHeader); switch (FileState) { @@ -224,11 +226,14 @@ IsValidFfsFile ( case EFI_FILE_DELETED: case EFI_FILE_DATA_VALID: case EFI_FILE_MARKED_FOR_UPDATE: - // - // Some other vliadation like file content checksum might be done here. - // For performance issue, Tiano only do FileState check. - // - return TRUE; + DataCheckSum = FFS_FIXED_CHECKSUM; + FileLength = *(UINT32 *)(FfsHeader->Size) & 0x00FFFFFF; + if ((FfsHeader->Attributes & FFS_ATTRIB_CHECKSUM) == FFS_ATTRIB_CHECKSUM) { + DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *)FfsHeader + sizeof(EFI_FFS_FILE_HEADER), FileLength - sizeof(EFI_FFS_FILE_HEADER)); + } + if (FfsHeader->IntegrityCheck.Checksum.File == DataCheckSum) { + return TRUE; + } default: return FALSE; diff --git a/MdeModulePkg/Core/Pei/FwVol/FwVol.c b/MdeModulePkg/Core/Pei/FwVol/FwVol.c index c40f0ea..941657c 100644 --- a/MdeModulePkg/Core/Pei/FwVol/FwVol.c +++ b/MdeModulePkg/Core/Pei/FwVol/FwVol.c @@ -162,6 +162,7 @@ FindFileEx ( UINT64 FvLength; UINT8 ErasePolarity; UINT8 FileState; + UINT8 DataCheckSum; // // Convert the handle of FV to FV header for memory-mapped firmware volume @@ -219,6 +220,16 @@ FindFileEx ( FileLength = *(UINT32 *)(FfsFileHeader->Size) & 0x00FFFFFF; FileOccupiedSize = GET_OCCUPIED_SIZE(FileLength, 8); + DataCheckSum = FFS_FIXED_CHECKSUM; + if ((FfsFileHeader->Attributes & FFS_ATTRIB_CHECKSUM) == FFS_ATTRIB_CHECKSUM) { + DataCheckSum = CalculateCheckSum8 ((CONST UINT8 *)FfsFileHeader + sizeof(EFI_FFS_FILE_HEADER), FileLength - sizeof(EFI_FFS_FILE_HEADER)); + } + if (FfsFileHeader->IntegrityCheck.Checksum.File != DataCheckSum) { + ASSERT (FALSE); + *FileHeader = NULL; + return EFI_NOT_FOUND; + } + if (FileName != NULL) { if (CompareGuid (&FfsFileHeader->Name, (EFI_GUID*)FileName)) { *FileHeader = FfsFileHeader; -- cgit v1.1