Revision: 14139
          http://edk2.svn.sourceforge.net/edk2/?rev=14139&view=rev
Author:   sfu5
Date:     2013-02-21 01:35:22 +0000 (Thu, 21 Feb 2013)
Log Message:
-----------
Add error handling code to prevent variable store corruption in release build.
Signed-off-by: Fu Siyuan <siyuan...@intel.com>
Reviewed-by: Ye Ting  <ting...@intel.com>
Reviewed-by: Dong Guo <guo.d...@intel.com>

Modified Paths:
--------------
    trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/AuthService.c
    trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c
    trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h

Modified: trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/AuthService.c
===================================================================
--- trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/AuthService.c       
2013-02-20 18:21:14 UTC (rev 14138)
+++ trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/AuthService.c       
2013-02-21 01:35:22 UTC (rev 14139)
@@ -445,6 +445,10 @@
              FALSE
              );
   ASSERT_EFI_ERROR (Status);
+  if (EFI_ERROR (Status)) {
+    return 0;
+  }
+
   //
   // Check whether the public key entry does exist.
   //
@@ -492,6 +496,9 @@
                  FALSE
                  );
       ASSERT_EFI_ERROR (Status);
+      if (EFI_ERROR (Status)) {
+        return 0;
+      }
 
       DataSize  = DataSizeOfVariable (Variable.CurrPtr);
       Data      = GetVariableDataPtr (Variable.CurrPtr);

Modified: trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c
===================================================================
--- trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c  
2013-02-20 18:21:14 UTC (rev 14138)
+++ trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.c  
2013-02-21 01:35:22 UTC (rev 14139)
@@ -651,27 +651,28 @@
   If ReclaimPubKeyStore is TRUE, reclaim invalid key in public key database 
and update the PubKeyIndex
   for all the count-based authenticate variable in NV storage.
 
-  @param[in]   VariableBase            Base address of variable store.
-  @param[out]  LastVariableOffset      Offset of last variable.
-  @param[in]   IsVolatile              The variable store is volatile or not;
-                                       if it is non-volatile, need FTW.
-  @param[in, out] UpdatingPtrTrack     Pointer to updating variable pointer 
track structure.
-  @param[in]   ReclaimPubKeyStore      Reclaim for public key database or not.
-  @param[in]   ReclaimAnyway           If TRUE, do reclaim anyway.
+  @param[in]      VariableBase            Base address of variable store.
+  @param[out]     LastVariableOffset      Offset of last variable.
+  @param[in]      IsVolatile              The variable store is volatile or 
not;
+                                          if it is non-volatile, need FTW.
+  @param[in, out] UpdatingPtrTrack        Pointer to updating variable pointer 
track structure.
+  @param[in]      ReclaimPubKeyStore      Reclaim for public key database or 
not.
+  @param[in]      ReclaimAnyway           If TRUE, do reclaim anyway.
   
+  @return EFI_SUCCESS                  Reclaim operation has finished 
successfully.
   @return EFI_OUT_OF_RESOURCES         No enough memory resources.
-  @return EFI_SUCCESS                  Reclaim operation has finished 
successfully.
+  @return EFI_DEVICE_ERROR             The public key database doesn't exist.
   @return Others                       Unexpect error happened during reclaim 
operation.
 
 **/
 EFI_STATUS
 Reclaim (
-  IN  EFI_PHYSICAL_ADDRESS  VariableBase,
-  OUT UINTN                 *LastVariableOffset,
-  IN  BOOLEAN               IsVolatile,
-  IN OUT VARIABLE_POINTER_TRACK *UpdatingPtrTrack,
-  IN  BOOLEAN               ReclaimPubKeyStore,
-  IN  BOOLEAN               ReclaimAnyway
+  IN     EFI_PHYSICAL_ADDRESS         VariableBase,
+  OUT    UINTN                        *LastVariableOffset,
+  IN     BOOLEAN                      IsVolatile,
+  IN OUT VARIABLE_POINTER_TRACK       *UpdatingPtrTrack,
+  IN     BOOLEAN                      ReclaimPubKeyStore,
+  IN     BOOLEAN                      ReclaimAnyway
   )
 {
   VARIABLE_HEADER       *Variable;
@@ -809,6 +810,12 @@
     // Reinstall the new public key database.
     //
     ASSERT (PubKeyHeader != NULL);
+    if (PubKeyHeader == NULL) {
+      FreePool (ValidBuffer);
+      FreePool (NewPubKeyIndex);
+      FreePool (NewPubKeyStore);
+      return EFI_DEVICE_ERROR;
+    }
     CopyMem (CurrPtr, (UINT8*) PubKeyHeader, sizeof (VARIABLE_HEADER));
     Variable = (VARIABLE_HEADER*) CurrPtr;
     Variable->DataSize = NewPubKeySize;

Modified: trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h
===================================================================
--- trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h  
2013-02-20 18:21:14 UTC (rev 14138)
+++ trunk/edk2/SecurityPkg/VariableAuthenticated/RuntimeDxe/Variable.h  
2013-02-21 01:35:22 UTC (rev 14139)
@@ -381,27 +381,28 @@
   If ReclaimPubKeyStore is TRUE, reclaim invalid key in public key database 
and update the PubKeyIndex
   for all the count-based authenticate variable in NV storage.
 
-  @param[in]   VariableBase            Base address of variable store.
-  @param[out]  LastVariableOffset      Offset of last variable.
-  @param[in]   IsVolatile              The variable store is volatile or not;
-                                       if it is non-volatile, need FTW.
-  @param[in, out] UpdatingPtrTrack     Pointer to updating variable pointer 
track structure.
-  @param[in]   ReclaimPubKeyStore      Reclaim for public key database or not.
-  @param[in]   ReclaimAnyway           If TRUE, do reclaim anyway.
+  @param[in]      VariableBase            Base address of variable store.
+  @param[out]     LastVariableOffset      Offset of last variable.
+  @param[in]      IsVolatile              The variable store is volatile or 
not;
+                                          if it is non-volatile, need FTW.
+  @param[in, out] UpdatingPtrTrack        Pointer to updating variable pointer 
track structure.
+  @param[in]      ReclaimPubKeyStore      Reclaim for public key database or 
not.
+  @param[in]      ReclaimAnyway           If TRUE, do reclaim anyway.
   
+  @return EFI_SUCCESS                  Reclaim operation has finished 
successfully.
   @return EFI_OUT_OF_RESOURCES         No enough memory resources.
-  @return EFI_SUCCESS                  Reclaim operation has finished 
successfully.
+  @return EFI_DEVICE_ERROR             The public key database doesn't exist.
   @return Others                       Unexpect error happened during reclaim 
operation.
 
 **/
 EFI_STATUS
 Reclaim (
-  IN  EFI_PHYSICAL_ADDRESS  VariableBase,
-  OUT UINTN                 *LastVariableOffset,
-  IN  BOOLEAN               IsVolatile,
-  IN OUT VARIABLE_POINTER_TRACK *UpdatingPtrTrack,
-  IN  BOOLEAN               ReclaimPubKeyStore,
-  IN  BOOLEAN               ReclaimAnyway
+  IN     EFI_PHYSICAL_ADDRESS         VariableBase,
+  OUT    UINTN                        *LastVariableOffset,
+  IN     BOOLEAN                      IsVolatile,
+  IN OUT VARIABLE_POINTER_TRACK       *UpdatingPtrTrack,
+  IN     BOOLEAN                      ReclaimPubKeyStore,
+  IN     BOOLEAN                      ReclaimAnyway
   );
 
 /**

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


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
edk2-commits mailing list
edk2-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to