Skip to content

Commit ac83357

Browse files
ronald-cron-armoliviermartin
authored and
oliviermartin
committed
ArmPkg/NorFlashDxe : Fix the check of flash addresses
Fix the check to prevent any reading past the end of the nor flash. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ronald Cron <[email protected]> Reviewed-by: Olivier Martin <[email protected]> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16655 6f19259b-4bc3-4df7-8a09-765794883524
1 parent 2596e61 commit ac83357

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,7 @@ NorFlashRead (
805805
OUT VOID *Buffer
806806
)
807807
{
808-
UINT32 NumBlocks;
809-
UINTN StartAddress;
808+
UINTN StartAddress;
810809

811810
// The buffer must be valid
812811
if (Buffer == NULL) {
@@ -818,15 +817,7 @@ NorFlashRead (
818817
return EFI_SUCCESS;
819818
}
820819

821-
// All blocks must be within the device
822-
NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ;
823-
824-
if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {
825-
DEBUG ((EFI_D_ERROR, "NorFlashRead: ERROR - Read will exceed last block\n"));
826-
return EFI_INVALID_PARAMETER;
827-
}
828-
829-
if (Offset + BufferSizeInBytes >= Instance->Size) {
820+
if (((Lba * Instance->Media.BlockSize) + Offset + BufferSizeInBytes) > Instance->Size) {
830821
DEBUG ((EFI_D_ERROR, "NorFlashRead: ERROR - Read will exceed device size.\n"));
831822
return EFI_INVALID_PARAMETER;
832823
}

0 commit comments

Comments
 (0)