]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockSmm.c
Add Secure MOR implementation.
[mirror_edk2.git] / SecurityPkg / Tcg / MemoryOverwriteRequestControlLock / TcgMorLockSmm.c
diff --git a/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockSmm.c b/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockSmm.c
new file mode 100644 (file)
index 0000000..019cb8b
--- /dev/null
@@ -0,0 +1,158 @@
+/** @file\r
+   TCG MOR (Memory Overwrite Request) Lock Control Driver SMM wrapper.\r
+   \r
+Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials \r
+are licensed and made available under the terms and conditions of the BSD License \r
+which accompanies this distribution.  The full text of the license may be found at \r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiSmm.h>\r
+#include <Library/SmmServicesTableLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Protocol/SmmVarCheck.h>\r
+#include <Protocol/SmmVariable.h>\r
+#include "TcgMorLock.h"\r
+\r
+EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable;\r
+\r
+/**\r
+  This service is a wrapper for the UEFI Runtime Service GetVariable().\r
+\r
+  @param  VariableName the name of the vendor's variable, it's a Null-Terminated Unicode String\r
+  @param  VendorGuid   Unify identifier for vendor.\r
+  @param  Attributes   Point to memory location to return the attributes of variable. If the point\r
+                       is NULL, the parameter would be ignored.\r
+  @param  DataSize     As input, point to the maximum size of return Data-Buffer.\r
+                       As output, point to the actual size of the returned Data-Buffer.\r
+  @param  Data         Point to return Data-Buffer.\r
+\r
+  @retval  EFI_SUCCESS            The function completed successfully.\r
+  @retval  EFI_NOT_FOUND          The variable was not found.\r
+  @retval  EFI_BUFFER_TOO_SMALL   The DataSize is too small for the result. DataSize has\r
+                                  been updated with the size needed to complete the request.\r
+  @retval  EFI_INVALID_PARAMETER  VariableName is NULL.\r
+  @retval  EFI_INVALID_PARAMETER  VendorGuid is NULL.\r
+  @retval  EFI_INVALID_PARAMETER  DataSize is NULL.\r
+  @retval  EFI_INVALID_PARAMETER  The DataSize is not too small and Data is NULL.\r
+  @retval  EFI_DEVICE_ERROR       The variable could not be retrieved due to a hardware error.\r
+  @retval  EFI_SECURITY_VIOLATION The variable could not be retrieved due to an authentication failure.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InternalGetVariable (\r
+  IN      CHAR16                   *VariableName,\r
+  IN      EFI_GUID                 *VendorGuid,\r
+  OUT     UINT32                   *Attributes OPTIONAL,\r
+  IN OUT  UINTN                    *DataSize,\r
+  OUT     VOID                     *Data\r
+  )\r
+{\r
+  return mSmmVariable->SmmGetVariable (\r
+                         VariableName,\r
+                         VendorGuid,\r
+                         Attributes,\r
+                         DataSize,\r
+                         Data\r
+                         );\r
+}\r
+\r
+/**\r
+  This service is a wrapper for the UEFI Runtime Service SetVariable()\r
+\r
+  @param  VariableName the name of the vendor's variable, as a\r
+                       Null-Terminated Unicode String\r
+  @param  VendorGuid   Unify identifier for vendor.\r
+  @param  Attributes   Point to memory location to return the attributes of variable. If the point\r
+                       is NULL, the parameter would be ignored.\r
+  @param  DataSize     The size in bytes of Data-Buffer.\r
+  @param  Data         Point to the content of the variable.\r
+\r
+  @retval  EFI_SUCCESS            The firmware has successfully stored the variable and its data as\r
+                                  defined by the Attributes.\r
+  @retval  EFI_INVALID_PARAMETER  An invalid combination of attribute bits was supplied, or the\r
+                                  DataSize exceeds the maximum allowed.\r
+  @retval  EFI_INVALID_PARAMETER  VariableName is an empty Unicode string.\r
+  @retval  EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the variable and its data.\r
+  @retval  EFI_DEVICE_ERROR       The variable could not be saved due to a hardware failure.\r
+  @retval  EFI_WRITE_PROTECTED    The variable in question is read-only.\r
+  @retval  EFI_WRITE_PROTECTED    The variable in question cannot be deleted.\r
+  @retval  EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS\r
+                                  set but the AuthInfo does NOT pass the validation check carried\r
+                                  out by the firmware.\r
+  @retval  EFI_NOT_FOUND          The variable trying to be updated or deleted was not found.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InternalSetVariable (\r
+  IN CHAR16                       *VariableName,\r
+  IN EFI_GUID                     *VendorGuid,\r
+  IN UINT32                       Attributes,\r
+  IN UINTN                        DataSize,\r
+  IN VOID                         *Data\r
+  )\r
+{\r
+  return mSmmVariable->SmmSetVariable (\r
+                         VariableName,\r
+                         VendorGuid,\r
+                         Attributes,\r
+                         DataSize,\r
+                         Data\r
+                         );\r
+}\r
+\r
+/**\r
+  Entry Point for MOR Lock Control driver.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS       EntryPoint runs successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MorLockDriverEntryPointSmm (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EDKII_SMM_VAR_CHECK_PROTOCOL  *SmmVarCheck;\r
+\r
+  //\r
+  // This driver link to Smm Variable driver\r
+  //\r
+  DEBUG ((EFI_D_INFO, "MorLockDriverEntryPointSmm\n"));\r
+  \r
+  Status = gSmst->SmmLocateProtocol (\r
+                  &gEfiSmmVariableProtocolGuid,\r
+                  NULL,\r
+                  (VOID **) &mSmmVariable\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = gSmst->SmmLocateProtocol (\r
+                  &gEdkiiSmmVarCheckProtocolGuid,\r
+                  NULL,\r
+                  (VOID **) &SmmVarCheck\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = MorLockDriverInit ();\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = SmmVarCheck->SmmRegisterSetVariableCheckHandler (SetVariableCheckHandlerMor);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
+\r