[edk2-devel] [PATCH V2 9/9] MdeModulePkg/VariableSmm: Remove unused SMI handler functions

Kubacki, Michael A michael.a.kubacki at intel.com
Sat Sep 28 01:47:17 UTC 2019


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

Since Runtime Services GetVariable() and GetNextVariableName() no longer
trigger a SW SMI, this change removes the code for handling those requests
from VariableSmm.c.

The following SMM communicate functions are removed from
SmmVariableHandler():

1. SMM_VARIABLE_FUNCTION_GET_VARIABLE
2. SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME

The function numbers are retained so any calls to those functions from
previously built drivers will return EFI_UNSUPPORTED.

Cc: Dandan Bi <dandan.bi at intel.com>
Cc: Ard Biesheuvel <ard.biesheuvel at linaro.org>
Cc: Eric Dong <eric.dong at intel.com>
Cc: Laszlo Ersek <lersek at redhat.com>
Cc: Liming Gao <liming.gao at intel.com>
Cc: Michael D Kinney <michael.d.kinney at intel.com>
Cc: Ray Ni <ray.ni at intel.com>
Cc: Jian J Wang <jian.j.wang at intel.com>
Cc: Hao A Wu <hao.a.wu at intel.com>
Cc: Jiewen Yao <jiewen.yao at intel.com>
Signed-off-by: Michael Kubacki <michael.a.kubacki at intel.com>
---
 MdeModulePkg/Include/Guid/SmmVariableCommon.h            |   4 +-
 MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 101 --------------------
 2 files changed, 1 insertion(+), 104 deletions(-)

diff --git a/MdeModulePkg/Include/Guid/SmmVariableCommon.h b/MdeModulePkg/Include/Guid/SmmVariableCommon.h
index ceef44dfd2..6a73d1e21a 100644
--- a/MdeModulePkg/Include/Guid/SmmVariableCommon.h
+++ b/MdeModulePkg/Include/Guid/SmmVariableCommon.h
@@ -106,7 +106,7 @@ typedef struct {
   EFI_GUID    Guid;
   UINTN       NameSize;     // Return name buffer size
   CHAR16      Name[1];
-} SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME;
+} SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE;
 
 ///
 /// This structure is used to communicate with SMI handler by QueryVariableInfo.
@@ -118,8 +118,6 @@ typedef struct {
   UINT32          Attributes;
 } SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO;
 
-typedef SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE;
-
 typedef struct {
   EFI_GUID                      Guid;
   UINTN                         NameSize;
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
index 8d767f75ac..8ba167f889 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
@@ -463,7 +463,6 @@ SmmVariableHandler (
   EFI_STATUS                                              Status;
   SMM_VARIABLE_COMMUNICATE_HEADER                         *SmmVariableFunctionHeader;
   SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE                *SmmVariableHeader;
-  SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME         *GetNextVariableName;
   SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO            *QueryVariableInfo;
   SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE               *GetPayloadSize;
   SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *RuntimeVariableCacheContext;
@@ -474,7 +473,6 @@ SmmVariableHandler (
   VARIABLE_RUNTIME_CACHE_CONTEXT                          *VariableCacheContext;
   VARIABLE_STORE_HEADER                                   *VariableCache;
   UINTN                                                   InfoSize;
-  UINTN                                                   NameBufferSize;
   UINTN                                                   CommBufferPayloadSize;
   UINTN                                                   TempCommBufferSize;
 
@@ -504,105 +502,6 @@ SmmVariableHandler (
 
   SmmVariableFunctionHeader = (SMM_VARIABLE_COMMUNICATE_HEADER *)CommBuffer;
   switch (SmmVariableFunctionHeader->Function) {
-    case SMM_VARIABLE_FUNCTION_GET_VARIABLE:
-      if (CommBufferPayloadSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) {
-        DEBUG ((EFI_D_ERROR, "GetVariable: SMM communication buffer size invalid!\n"));
-        return EFI_SUCCESS;
-      }
-      //
-      // Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.
-      //
-      CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);
-      SmmVariableHeader = (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *) mVariableBufferPayload;
-      if (((UINTN)(~0) - SmmVariableHeader->DataSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) ||
-         ((UINTN)(~0) - SmmVariableHeader->NameSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + SmmVariableHeader->DataSize)) {
-        //
-        // Prevent InfoSize overflow happen
-        //
-        Status = EFI_ACCESS_DENIED;
-        goto EXIT;
-      }
-      InfoSize = OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)
-                 + SmmVariableHeader->DataSize + SmmVariableHeader->NameSize;
-
-      //
-      // SMRAM range check already covered before
-      //
-      if (InfoSize > CommBufferPayloadSize) {
-        DEBUG ((EFI_D_ERROR, "GetVariable: Data size exceed communication buffer size limit!\n"));
-        Status = EFI_ACCESS_DENIED;
-        goto EXIT;
-      }
-
-      //
-      // The VariableSpeculationBarrier() call here is to ensure the previous
-      // range/content checks for the CommBuffer have been completed before the
-      // subsequent consumption of the CommBuffer content.
-      //
-      VariableSpeculationBarrier ();
-      if (SmmVariableHeader->NameSize < sizeof (CHAR16) || SmmVariableHeader->Name[SmmVariableHeader->NameSize/sizeof (CHAR16) - 1] != L'\0') {
-        //
-        // Make sure VariableName is A Null-terminated string.
-        //
-        Status = EFI_ACCESS_DENIED;
-        goto EXIT;
-      }
-
-      Status = VariableServiceGetVariable (
-                 SmmVariableHeader->Name,
-                 &SmmVariableHeader->Guid,
-                 &SmmVariableHeader->Attributes,
-                 &SmmVariableHeader->DataSize,
-                 (UINT8 *)SmmVariableHeader->Name + SmmVariableHeader->NameSize
-                 );
-      CopyMem (SmmVariableFunctionHeader->Data, mVariableBufferPayload, CommBufferPayloadSize);
-      break;
-
-    case SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME:
-      if (CommBufferPayloadSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) {
-        DEBUG ((EFI_D_ERROR, "GetNextVariableName: SMM communication buffer size invalid!\n"));
-        return EFI_SUCCESS;
-      }
-      //
-      // Copy the input communicate buffer payload to pre-allocated SMM variable buffer payload.
-      //
-      CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, CommBufferPayloadSize);
-      GetNextVariableName = (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *) mVariableBufferPayload;
-      if ((UINTN)(~0) - GetNextVariableName->NameSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) {
-        //
-        // Prevent InfoSize overflow happen
-        //
-        Status = EFI_ACCESS_DENIED;
-        goto EXIT;
-      }
-      InfoSize = OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name) + GetNextVariableName->NameSize;
-
-      //
-      // SMRAM range check already covered before
-      //
-      if (InfoSize > CommBufferPayloadSize) {
-        DEBUG ((EFI_D_ERROR, "GetNextVariableName: Data size exceed communication buffer size limit!\n"));
-        Status = EFI_ACCESS_DENIED;
-        goto EXIT;
-      }
-
-      NameBufferSize = CommBufferPayloadSize - OFFSET_OF(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name);
-      if (NameBufferSize < sizeof (CHAR16) || GetNextVariableName->Name[NameBufferSize/sizeof (CHAR16) - 1] != L'\0') {
-        //
-        // Make sure input VariableName is A Null-terminated string.
-        //
-        Status = EFI_ACCESS_DENIED;
-        goto EXIT;
-      }
-
-      Status = VariableServiceGetNextVariableName (
-                 &GetNextVariableName->NameSize,
-                 GetNextVariableName->Name,
-                 &GetNextVariableName->Guid
-                 );
-      CopyMem (SmmVariableFunctionHeader->Data, mVariableBufferPayload, CommBufferPayloadSize);
-      break;
-
     case SMM_VARIABLE_FUNCTION_SET_VARIABLE:
       if (CommBufferPayloadSize < OFFSET_OF(SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name)) {
         DEBUG ((EFI_D_ERROR, "SetVariable: SMM communication buffer size invalid!\n"));
-- 
2.16.2.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#48244): https://edk2.groups.io/g/devel/message/48244
Mute This Topic: https://groups.io/mt/34318595/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list