public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 1/5] MdeModulePkg: avoid SMM pointers being leaked by not using CopyMem()
@ 2020-06-16  9:04 Zhiguang Liu
  2020-06-16  9:04 ` [PATCH 2/5] MdeModulePkg/SmmCore: Remove UEFI LOADED_IMAGE from SMM Zhiguang Liu
                   ` (4 more replies)
  0 siblings, 5 replies; 17+ messages in thread
From: Zhiguang Liu @ 2020-06-16  9:04 UTC (permalink / raw)
  To: devel; +Cc: Star Zeng, Liming Gao, Jian J Wang, Hao A Wu

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2002

This commit will update the logic in function SmmVariableGetStatistics()
so that the pointer fields ('Next' and 'Name') in structure
VARIABLE_INFO_ENTRY will not be copied into the SMM communication buffer.

Doing so will prevent SMM pointers address from being leaked into non-SMM
environment.

Please note that newly introduced internal function CopyVarInfoEntry()
will not use CopyMem() to copy the whole VARIABLE_INFO_ENTRY structure and
then zero out the 'Next' and 'Name' fields. This is for preventing race
conditions where the pointers value might still be read.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Signed-off-by: Hao A Wu <hao.a.wu@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
 MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
index caca5c3241..74e756bc00 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
@@ -315,6 +315,35 @@ GetFvbCountAndBuffer (
 }
 
 
+/**
+  Copy only the meaningful fields of the variable statistics information from
+  source buffer to the destination buffer. Other fields are filled with zero.
+
+  @param[out]  DstInfoEntry    A pointer to the buffer of destination variable
+                               information entry.
+  @param[in]   SrcInfoEntry    A pointer to the buffer of source variable
+                               information entry.
+
+**/
+static
+VOID
+CopyVarInfoEntry (
+  OUT VARIABLE_INFO_ENTRY    *DstInfoEntry,
+  IN  VARIABLE_INFO_ENTRY    *SrcInfoEntry
+  )
+{
+  DstInfoEntry->Next = NULL;
+  DstInfoEntry->Name = NULL;
+
+  CopyGuid (&DstInfoEntry->VendorGuid, &SrcInfoEntry->VendorGuid);
+  DstInfoEntry->Attributes  = SrcInfoEntry->Attributes;
+  DstInfoEntry->ReadCount   = SrcInfoEntry->ReadCount;
+  DstInfoEntry->WriteCount  = SrcInfoEntry->WriteCount;
+  DstInfoEntry->DeleteCount = SrcInfoEntry->DeleteCount;
+  DstInfoEntry->CacheCount  = SrcInfoEntry->CacheCount;
+  DstInfoEntry->Volatile    = SrcInfoEntry->Volatile;
+}
+
 /**
   Get the variable statistics information from the information buffer pointed by gVariableInfo.
 
@@ -377,7 +406,7 @@ SmmVariableGetStatistics (
       *InfoSize = StatisticsInfoSize;
       return EFI_BUFFER_TOO_SMALL;
     }
-    CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY));
+    CopyVarInfoEntry (InfoEntry, VariableInfo);
     CopyMem (InfoName, VariableInfo->Name, NameSize);
     *InfoSize = StatisticsInfoSize;
     return EFI_SUCCESS;
@@ -417,7 +446,7 @@ SmmVariableGetStatistics (
     return EFI_BUFFER_TOO_SMALL;
   }
 
-  CopyMem (InfoEntry, VariableInfo, sizeof (VARIABLE_INFO_ENTRY));
+  CopyVarInfoEntry (InfoEntry, VariableInfo);
   CopyMem (InfoName, VariableInfo->Name, NameSize);
   *InfoSize = StatisticsInfoSize;
 
-- 
2.25.1.windows.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-07-02 13:51 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-16  9:04 [PATCH 1/5] MdeModulePkg: avoid SMM pointers being leaked by not using CopyMem() Zhiguang Liu
2020-06-16  9:04 ` [PATCH 2/5] MdeModulePkg/SmmCore: Remove UEFI LOADED_IMAGE from SMM Zhiguang Liu
2020-06-16 14:45   ` [edk2-devel] " Laszlo Ersek
2020-06-16 22:39   ` Michael D Kinney
2020-06-23  6:12     ` Zhiguang Liu
2020-06-16 22:44   ` Michael D Kinney
2020-06-16  9:04 ` [PATCH 3/5] MdePkg: Remove DXE_SMM_DRIVER support for some libraries Zhiguang Liu
2020-06-16 22:41   ` Michael D Kinney
2020-07-02 13:51   ` Liming Gao
2020-06-16  9:04 ` [PATCH 4/5] SecurityPkg: " Zhiguang Liu
2020-06-16 14:47   ` [edk2-devel] " Laszlo Ersek
2020-06-16  9:04 ` [PATCH 5/5] UefiCpuPkg: Uninstall EFI_SMM_CONFIGURATION_PROTOCOL at end of Dxe Zhiguang Liu
2020-06-16 15:06   ` [edk2-devel] " Laszlo Ersek
2020-06-17  5:30     ` Zhiguang Liu
2020-06-17 12:53       ` Laszlo Ersek
2020-06-16 22:38 ` [edk2-devel] [PATCH 1/5] MdeModulePkg: avoid SMM pointers being leaked by not using CopyMem() Michael D Kinney
2020-06-17  5:25   ` Zhiguang Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox