Revision: 14192
          http://edk2.svn.sourceforge.net/edk2/?rev=14192&view=rev
Author:   oliviermartin
Date:     2013-03-12 01:01:55 +0000 (Tue, 12 Mar 2013)
Log Message:
-----------
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.mar...@arm.com>

Modified Paths:
--------------
    trunk/edk2/ArmPkg/Library/BdsLib/BdsLinuxFdt.c

Modified: trunk/edk2/ArmPkg/Library/BdsLib/BdsLinuxFdt.c
===================================================================
--- trunk/edk2/ArmPkg/Library/BdsLib/BdsLinuxFdt.c      2013-03-12 01:01:11 UTC 
(rev 14191)
+++ trunk/edk2/ArmPkg/Library/BdsLib/BdsLinuxFdt.c      2013-03-12 01:01:55 UTC 
(rev 14192)
@@ -1,15 +1,15 @@
 /** @file
 *
-*  Copyright (c) 2011-2012, 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         
-*  which accompanies this distribution.  The full text of the license may be 
found at        
-*  http://opensource.org/licenses/bsd-license.php                              
              
+*  Copyright (c) 2011-2013, ARM Limited. All rights reserved.
 *
-*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,       
              
-*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.             
+*  This program and the accompanying materials
+*  are licensed and made available under the terms and conditions of the BSD 
License
+*  which accompanies this distribution.  The full text of the license may be 
found at
+*  http://opensource.org/licenses/bsd-license.php
 *
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.
+*
 **/
 
 #include <Library/ArmSmcLib.h>
@@ -243,6 +243,7 @@
   UINTN                 Pages;
   BOOLEAN               PsciSmcSupported;
   UINTN                 Rx;
+  UINTN                 OriginalFdtSize;
 
   //
   // Ensure the Power State Coordination Interface (PSCI) SMCs are there if 
supported
@@ -271,16 +272,28 @@
     }
   }
 
+  //
+  // 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;
@@ -370,10 +383,10 @@
     if (node >= 0) {
       fdt_setprop_string(fdt, node, "name", "memory");
       fdt_setprop_string(fdt, node, "device_type", "memory");
-      
+
       GetSystemMemoryResources (&ResourceList);
       Resource = (BDS_SYSTEM_MEMORY_RESOURCE*)ResourceList.ForwardLink;
-      
+
       if (sizeof(UINTN) == sizeof(UINT32)) {
         Region.Base = cpu_to_fdt32((UINTN)Resource->PhysicalStart);
         Region.Size = cpu_to_fdt32((UINTN)Resource->ResourceLength);
@@ -507,7 +520,7 @@
   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;
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
edk2-commits mailing list
edk2-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to