]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/SmmCore: Fix hang due to already-freed memory deference
authorRuiyu Ni <ruiyu.ni@intel.com>
Thu, 1 Feb 2018 10:14:24 +0000 (18:14 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Sat, 3 Feb 2018 06:48:58 +0000 (14:48 +0800)
SmiHandlerUnRegister() validates the DispatchHandle by checking
whether the first 32bit matches to a certain signature
(SMI_HANDLER_SIGNATURE).
But if a caller calls *UnRegister() twice and the memory freed by
first call still contains the signature, the second call may hang.

The patch fixes this issue by locating the DispatchHandle
in all SMI handlers, instead of checking the signature.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Core/PiSmmCore/Smi.c

index ad483a1877ce129d71d3440a73bfb75841a32727..0c09e7fa102fb0e943629a2fdd9a35c897eac578 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SMI management.\r
 \r
 /** @file\r
   SMI management.\r
 \r
-  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available \r
   under the terms and conditions of the BSD License which accompanies this \r
   distribution.  The full text of the license may be found at        \r
   This program and the accompanying materials are licensed and made available \r
   under the terms and conditions of the BSD License which accompanies this \r
   distribution.  The full text of the license may be found at        \r
@@ -276,14 +276,41 @@ SmiHandlerUnRegister (
 {\r
   SMI_HANDLER  *SmiHandler;\r
   SMI_ENTRY    *SmiEntry;\r
 {\r
   SMI_HANDLER  *SmiHandler;\r
   SMI_ENTRY    *SmiEntry;\r
+  LIST_ENTRY   *EntryLink;\r
+  LIST_ENTRY   *HandlerLink;\r
 \r
 \r
-  SmiHandler = (SMI_HANDLER *) DispatchHandle;\r
-\r
-  if (SmiHandler == NULL) {\r
+  if (DispatchHandle == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  if (SmiHandler->Signature != SMI_HANDLER_SIGNATURE) {\r
+  //\r
+  // Look for it in root SMI handlers\r
+  //\r
+  SmiHandler = NULL;\r
+  for ( HandlerLink = GetFirstNode (&mRootSmiEntry.SmiHandlers)\r
+      ; !IsNull (&mRootSmiEntry.SmiHandlers, HandlerLink) && (SmiHandler != DispatchHandle)\r
+      ; HandlerLink = GetNextNode (&mRootSmiEntry.SmiHandlers, HandlerLink)\r
+      ) {\r
+    SmiHandler = CR (HandlerLink, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);\r
+  }\r
+\r
+  //\r
+  // Look for it in non-root SMI handlers\r
+  //\r
+  for ( EntryLink = GetFirstNode (&mSmiEntryList)\r
+      ; !IsNull (&mSmiEntryList, EntryLink) && (SmiHandler != DispatchHandle)\r
+      ; EntryLink = GetNextNode (&mSmiEntryList, EntryLink)\r
+      ) {\r
+    SmiEntry = CR (EntryLink, SMI_ENTRY, AllEntries, SMI_ENTRY_SIGNATURE);\r
+    for ( HandlerLink = GetFirstNode (&SmiEntry->SmiHandlers)\r
+        ; !IsNull (&SmiEntry->SmiHandlers, HandlerLink) && (SmiHandler != DispatchHandle)\r
+        ; HandlerLink = GetNextNode (&SmiEntry->SmiHandlers, HandlerLink)\r
+        ) {\r
+      SmiHandler = CR (HandlerLink, SMI_HANDLER, Link, SMI_HANDLER_SIGNATURE);\r
+    }\r
+  }\r
+\r
+  if (SmiHandler != DispatchHandle) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r