Skip to content

Commit

Permalink
MdeModulePkg/IntelFrameworkModulePkg FwVol:
Browse files Browse the repository at this point in the history
  Move the check of FV Header signature and file system to
  GetFwVolHeader() to avoid reading the whole unexpected FvHeader.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <[email protected]>
Reviewed-by: Liming Gao <[email protected]>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16255 6f19259b-4bc3-4df7-8a09-765794883524
  • Loading branch information
lzeng14 authored and lzeng14 committed Oct 29, 2014
1 parent 24903bc commit 4888d15
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 50 deletions.
29 changes: 19 additions & 10 deletions IntelFrameworkModulePkg/Universal/FirmwareVolume/FwVolDxe/FwVol.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Layers on top of Firmware Block protocol to produce a file abstraction
of FV based files.
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions
Expand Down Expand Up @@ -34,6 +34,8 @@
@retval EFI_SUCCESS Successfully read volume header to the allocated
buffer.
@retval EFI_ACCESS_DENIED Read status of FV is not enabled.
@retval EFI_INVALID_PARAMETER The FV Header signature is not as expected or
the file system could not be understood.
**/
EFI_STATUS
GetFwVolHeader (
Expand Down Expand Up @@ -90,6 +92,22 @@ GetFwVolHeader (
);
}

//
// Validate FV Header signature, if not as expected, continue.
//
if (TempFvh.Signature != EFI_FVH_SIGNATURE) {
return EFI_INVALID_PARAMETER;
}

//
// Check to see that the file system is indeed formatted in a way we can
// understand it...
//
if ((!CompareGuid (&TempFvh.FileSystemGuid, &gEfiFirmwareFileSystem2Guid)) &&
(!CompareGuid (&TempFvh.FileSystemGuid, &gEfiFirmwareFileSystem3Guid))) {
return EFI_INVALID_PARAMETER;
}

*FwVolHeader = AllocatePool (TempFvh.HeaderLength);
if (*FwVolHeader == NULL) {
return EFI_OUT_OF_RESOURCES;
Expand Down Expand Up @@ -669,15 +687,6 @@ FwVolDriverInit (
continue;
}
ASSERT (FwVolHeader != NULL);
//
// Check to see that the file system is indeed formatted in a way we can
// understand it...
//
if ((!CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem2Guid)) &&
(!CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem3Guid))) {
FreePool (FwVolHeader);
continue;
}
FreePool (FwVolHeader);

Reinstall = FALSE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file
Common defines and definitions for a FwVolDxe driver.
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions
Expand Down Expand Up @@ -484,6 +484,8 @@ IsValidFFSFile (
@retval EFI_SUCCESS Successfully read volume header to the allocated
buffer.
@retval EFI_ACCESS_DENIED Read status of FV is not enabled.
@retval EFI_INVALID_PARAMETER The FV Header signature is not as expected or
the file system could not be understood.
**/
EFI_STATUS
GetFwVolHeader (
Expand Down
2 changes: 2 additions & 0 deletions MdeModulePkg/Core/Dxe/DxeMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -2595,6 +2595,8 @@ ReadFvbData (
@retval EFI_OUT_OF_RESOURCES No enough buffer could be allocated.
@retval EFI_SUCCESS Successfully read volume header to the allocated
buffer.
@retval EFI_INVALID_PARAMETER The FV Header signature is not as expected or
the file system could not be understood.
**/
EFI_STATUS
Expand Down
36 changes: 18 additions & 18 deletions MdeModulePkg/Core/Dxe/FwVol/FwVol.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ ReadFvbData (
@retval EFI_OUT_OF_RESOURCES No enough buffer could be allocated.
@retval EFI_SUCCESS Successfully read volume header to the allocated
buffer.
@retval EFI_INVALID_PARAMETER The FV Header signature is not as expected or
the file system could not be understood.
**/
EFI_STATUS
Expand All @@ -199,6 +201,22 @@ GetFwVolHeader (
return Status;
}

//
// Validate FV Header signature, if not as expected, continue.
//
if (TempFvh.Signature != EFI_FVH_SIGNATURE) {
return EFI_INVALID_PARAMETER;
}

//
// Check to see that the file system is indeed formatted in a way we can
// understand it...
//
if ((!CompareGuid (&TempFvh.FileSystemGuid, &gEfiFirmwareFileSystem2Guid)) &&
(!CompareGuid (&TempFvh.FileSystemGuid, &gEfiFirmwareFileSystem3Guid))) {
return EFI_INVALID_PARAMETER;
}

//
// Allocate a buffer for the caller
//
Expand Down Expand Up @@ -658,29 +676,11 @@ NotifyFwVolBlock (
}
ASSERT (FwVolHeader != NULL);

//
// Validate FV Header signature, if not as expected, continue.
//
if (FwVolHeader->Signature != EFI_FVH_SIGNATURE) {
CoreFreePool (FwVolHeader);
continue;
}

if (!VerifyFvHeaderChecksum (FwVolHeader)) {
CoreFreePool (FwVolHeader);
continue;
}


//
// Check to see that the file system is indeed formatted in a way we can
// understand it...
//
if ((!CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem2Guid)) &&
(!CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiFirmwareFileSystem3Guid))) {
continue;
}

//
// Check if there is an FV protocol already installed in that handle
//
Expand Down
21 changes: 0 additions & 21 deletions MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,25 +405,4 @@ IsValidFfsFile (
IN EFI_FFS_FILE_HEADER *FfsHeader
);


/**
given the supplied FW_VOL_BLOCK_PROTOCOL, allocate a buffer for output and
copy the volume header into it.
@param Fvb The FW_VOL_BLOCK_PROTOCOL instance from which to
read the volume header
@param FwVolHeader Pointer to pointer to allocated buffer in which
the volume header is returned.
@retval EFI_OUT_OF_RESOURCES No enough buffer could be allocated.
@retval EFI_SUCCESS Successfully read volume header to the allocated
buffer.
**/
EFI_STATUS
GetFwVolHeader (
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb,
OUT EFI_FIRMWARE_VOLUME_HEADER **FwVolHeader
);

#endif

0 comments on commit 4888d15

Please sign in to comment.