ArmPkg/BdsLinuxFdt.c: Check that FDT blob is correctly loaded.

Add some checks in the code loading an FDT blob from a memory-mapped device
so that UEFI will detect and print an error message if the address
range doesn't cover the whole file.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>



git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14192 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
oliviermartin 2013-03-12 01:01:55 +00:00
parent 39f58c9b40
commit 7e91decd13
1 changed files with 25 additions and 12 deletions

View File

@ -1,6 +1,6 @@
/** @file
*
* Copyright (c) 2011-2012, ARM Limited. All rights reserved.
* Copyright (c) 2011-2013, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
@ -243,6 +243,7 @@ PrepareFdt (
UINTN Pages;
BOOLEAN PsciSmcSupported;
UINTN Rx;
UINTN OriginalFdtSize;
//
// Ensure the Power State Coordination Interface (PSCI) SMCs are there if supported
@ -271,16 +272,28 @@ PrepareFdt (
}
}
//
// Sanity checks on the original FDT blob.
//
err = fdt_check_header ((VOID*)(UINTN)(*FdtBlobBase));
if (err != 0) {
Print (L"ERROR: Device Tree header not valid (err:%d)\n", err);
return EFI_INVALID_PARAMETER;
}
// The original FDT blob might have been loaded partially.
// Check that it is not the case.
OriginalFdtSize = (UINTN)fdt_totalsize ((VOID*)(UINTN)(*FdtBlobBase));
if (OriginalFdtSize > *FdtBlobSize) {
Print (L"ERROR: Incomplete FDT. Only %d/%d bytes have been loaded.\n",
*FdtBlobSize, OriginalFdtSize);
return EFI_INVALID_PARAMETER;
}
//
// Allocate memory for the new FDT
//
NewFdtBlobSize = fdt_totalsize((VOID*)(UINTN)(*FdtBlobBase)) + FDT_ADDITIONAL_ENTRIES_SIZE;
NewFdtBlobSize = OriginalFdtSize + FDT_ADDITIONAL_ENTRIES_SIZE;
// Try below a watermark address
Status = EFI_NOT_FOUND;
@ -507,7 +520,7 @@ PrepareFdt (
return EFI_SUCCESS;
FAIL_NEW_FDT:
*FdtBlobSize = (UINTN)fdt_totalsize ((VOID*)(UINTN)(*FdtBlobBase));
*FdtBlobSize = OriginalFdtSize;
// Return success even if we failed to update the FDT blob. The original one is still valid.
return EFI_SUCCESS;
}