Skip to content

Commit

Permalink
[CHERRY-PICK] MdeModulePkg/FaultTolerantWriteDxe: Fix buffer overrun …
Browse files Browse the repository at this point in the history
…issue

- This PR aims to  prevent a buffer overrun issue found in FtwGetLastWriteHeader
function.As per the current code, when there is a malformed blocks (with all bytes as 0s)
then `Offset += FTW_WRITE_TOTAL_SIZE (FtwHeader->NumberOfWrites,
FtwHeader->PrivateDataSize)` would access beyond FtwWorkSpaceSize.

- Also added the signature check to validate work space

Signed-off-by: Sureshkumar Ponnusamy <[email protected]>
  • Loading branch information
Sureshkumar Ponnusamy authored and os-d committed Sep 3, 2024
1 parent 2acf969 commit e37976a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,12 +810,18 @@ FtwGetLastWriteHeader (
FtwHeader = (EFI_FAULT_TOLERANT_WRITE_HEADER *)(FtwWorkSpaceHeader + 1);
Offset = sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER);

if (!CompareGuid (&FtwWorkSpaceHeader->Signature, &gEdkiiWorkingBlockSignatureGuid)) {
*FtwWriteHeader = FtwHeader;
return EFI_ABORTED;
}

while (FtwHeader->Complete == FTW_VALID_STATE) {
Offset += FTW_WRITE_TOTAL_SIZE (FtwHeader->NumberOfWrites, FtwHeader->PrivateDataSize);
//
// If Offset exceed the FTW work space boudary, return error.
//
if (Offset >= FtwWorkSpaceSize) {

if ((Offset + sizeof (EFI_FAULT_TOLERANT_WRITE_HEADER)) >= FtwWorkSpaceSize) {
*FtwWriteHeader = FtwHeader;
return EFI_ABORTED;
}
Expand Down

0 comments on commit e37976a

Please sign in to comment.