Revision: 14312
          http://edk2.svn.sourceforge.net/edk2/?rev=14312&view=rev
Author:   lzeng14
Date:     2013-04-24 09:33:48 +0000 (Wed, 24 Apr 2013)
Log Message:
-----------
Mallicious code may use SmmFaultTolerantWriteHandler() to update some flash 
area directly, like Variable region, so return EFI_ACCESS_DENIED after End Of 
Dxe in SmmFaultTolerantWriteHandler().
And add code to prevent InfoSize overflow.

Signed-off-by: Star Zeng <[email protected]>
Reviewed-by: Jiewen Yao <[email protected]>

Modified Paths:
--------------
    
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c
    
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
    
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.inf

Modified: 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c
===================================================================
--- 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c 
    2013-04-23 12:48:07 UTC (rev 14311)
+++ 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c 
    2013-04-24 09:33:48 UTC (rev 14312)
@@ -43,7 +43,7 @@
   Caution: This module requires additional review when modified.
   This driver need to make sure the CommBuffer is not in the SMRAM range. 
 
-Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
 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        
@@ -60,12 +60,17 @@
 #include "FaultTolerantWrite.h"
 #include "FaultTolerantWriteSmmCommon.h"
 #include <Protocol/SmmAccess2.h>
+#include <Protocol/SmmEndOfDxe.h>
 
 EFI_EVENT                                 mFvbRegistration = NULL;
 EFI_FTW_DEVICE                            *mFtwDevice      = NULL;
 EFI_SMRAM_DESCRIPTOR                      *mSmramRanges;
 UINTN                                     mSmramRangeCount;
 
+///
+/// The flag to indicate whether the platform has left the DXE phase of 
execution.
+///
+BOOLEAN                                   mEndOfDxe = FALSE;
 
 /**
   This function check if the address is in SMRAM.
@@ -357,6 +362,16 @@
   }
 
   SmmFtwFunctionHeader = (SMM_FTW_COMMUNICATE_FUNCTION_HEADER *)CommBuffer;
+
+  if (mEndOfDxe) {
+    //
+    // It will be not safe to expose the operations after End Of Dxe.
+    //
+    DEBUG ((EFI_D_ERROR, "SmmFtwHandler: Not safe to do the operation: %x 
after End Of Dxe, so access denied!\n", SmmFtwFunctionHeader->Function));
+    SmmFtwFunctionHeader->ReturnStatus = EFI_ACCESS_DENIED;
+    return EFI_SUCCESS;
+  }
+
   switch (SmmFtwFunctionHeader->Function) {
     case FTW_FUNCTION_GET_MAX_BLOCK_SIZE:
       SmmGetMaxBlockSizeHeader = (SMM_FTW_GET_MAX_BLOCK_SIZE_HEADER *) 
SmmFtwFunctionHeader->Data;
@@ -430,6 +445,13 @@
       
     case FTW_FUNCTION_GET_LAST_WRITE:
       SmmFtwGetLastWriteHeader = (SMM_FTW_GET_LAST_WRITE_HEADER *) 
SmmFtwFunctionHeader->Data;
+      if ((UINTN)(~0) - SmmFtwGetLastWriteHeader->PrivateDataSize < OFFSET_OF 
(SMM_FTW_GET_LAST_WRITE_HEADER, Data)){
+        //
+        // Prevent InfoSize overflow
+        //
+        Status = EFI_ACCESS_DENIED;
+        break;
+      }
       InfoSize = OFFSET_OF (SMM_FTW_GET_LAST_WRITE_HEADER, Data) + 
SmmFtwGetLastWriteHeader->PrivateDataSize;
 
       //
@@ -532,7 +554,28 @@
   return EFI_SUCCESS;
 }
 
+/**
+  SMM END_OF_DXE protocol notification event handler.
+ 
+  @param  Protocol   Points to the protocol's unique identifier
+  @param  Interface  Points to the interface instance
+  @param  Handle     The handle on which the interface was installed
 
+  @retval EFI_SUCCESS   SmmEndOfDxeCallback runs successfully
+
+**/
+EFI_STATUS
+EFIAPI
+SmmEndOfDxeCallback (
+  IN CONST EFI_GUID                       *Protocol,
+  IN VOID                                 *Interface,
+  IN EFI_HANDLE                           Handle
+  )
+{
+  mEndOfDxe = TRUE;
+  return EFI_SUCCESS;
+}
+
 /**
   This function is the entry point of the Fault Tolerant Write driver.
 
@@ -555,7 +598,8 @@
   EFI_HANDLE                              FtwHandle;
   EFI_SMM_ACCESS2_PROTOCOL                *SmmAccess;
   UINTN                                   Size;
-  
+  VOID                                    *SmmEndOfDxeRegistration;
+
   //
   // Allocate private data structure for SMM FTW protocol and do some 
initialization
   //
@@ -587,6 +631,16 @@
   mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);
 
   //
+  // Register EFI_SMM_END_OF_DXE_PROTOCOL_GUID notify function.
+  //
+  Status = gSmst->SmmRegisterProtocolNotify (
+                    &gEfiSmmEndOfDxeProtocolGuid,
+                    SmmEndOfDxeCallback,
+                    &SmmEndOfDxeRegistration
+                    );
+  ASSERT_EFI_ERROR (Status);
+
+  //
   // Register FvbNotificationEvent () notify function.
   // 
   Status = gSmst->SmmRegisterProtocolNotify (

Modified: 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
===================================================================
--- 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
   2013-04-23 12:48:07 UTC (rev 14311)
+++ 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
   2013-04-24 09:33:48 UTC (rev 14312)
@@ -4,7 +4,7 @@
 #   depends on the full functionality SMM FVB protocol that support read, 
write/erase 
 #   flash access.
 #
-# Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD 
License
@@ -59,6 +59,7 @@
   gEfiSmmFirmwareVolumeBlockProtocolGuid           ## CONSUMES
   gEfiSmmFaultTolerantWriteProtocolGuid            ## PRODUCES
   gEfiSmmAccess2ProtocolGuid                       ## CONSUMES
+  gEfiSmmEndOfDxeProtocolGuid                      ## CONSUMES
 
 [FeaturePcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable

Modified: 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.inf
===================================================================
--- 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.inf
        2013-04-23 12:48:07 UTC (rev 14311)
+++ 
trunk/edk2/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.inf
        2013-04-24 09:33:48 UTC (rev 14312)
@@ -1,8 +1,11 @@
 ## @file
-# This module is the Runtime DXE part corresponding to SMM Fault Tolerant 
Write (FTW) module. 
+# This module is the DXE part corresponding to SMM Fault Tolerant Write (FTW) 
module.
 # It installs FTW protocol and works with SMM FTW module together.
+# The FTW protocol will not work after End Of Dxe because it will be not safe 
to expose
+# the related operations in SMM handler in SMM FTW module. You can use the FTW 
protocol
+# before End Of Dxe or use FaultTolerantWriteDxe module instead if you really 
want to.
 #
-# Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD 
License

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


------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to