Add a new module MemoryOverwriteRequestControlLock to register VarCheck handler 
to
 enforce MorLock Policy.
Only SMM version is added because MOR is only supported in SMM variable case. 

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yao, Jiewen <[email protected]>
Reviewed-by: Zhang, Chao <[email protected]>
Cc: Zhang, Chao <[email protected]>
---
 .../MemoryOverwriteRequestControlLock.h            |  43 +++++
 MdePkg/MdePkg.dec                                  |   3 +
 SecurityPkg/SecurityPkg.dsc                        |   2 +
 .../MemoryOverwriteRequestControlLock/TcgMorLock.c | 196 +++++++++++++++++++++
 .../MemoryOverwriteRequestControlLock/TcgMorLock.h | 122 +++++++++++++
 .../TcgMorLock.uni                                 | Bin 0 -> 1964 bytes
 .../TcgMorLockExtra.uni                            | Bin 0 -> 1356 bytes
 .../TcgMorLockSmm.c                                | 153 ++++++++++++++++
 .../TcgMorLockSmm.inf                              |  66 +++++++
 9 files changed, 585 insertions(+)
 create mode 100644 
MdePkg/Include/IndustryStandard/MemoryOverwriteRequestControlLock.h
 create mode 100644 
SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLock.c
 create mode 100644 
SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLock.h
 create mode 100644 
SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLock.uni
 create mode 100644 
SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockExtra.uni
 create mode 100644 
SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockSmm.c
 create mode 100644 
SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockSmm.inf

diff --git 
a/MdePkg/Include/IndustryStandard/MemoryOverwriteRequestControlLock.h 
b/MdePkg/Include/IndustryStandard/MemoryOverwriteRequestControlLock.h
new file mode 100644
index 0000000..771306b
--- /dev/null
+++ b/MdePkg/Include/IndustryStandard/MemoryOverwriteRequestControlLock.h
@@ -0,0 +1,43 @@
+/** @file
+  Support for Microsoft Secure MOR implementation, defined at 
+  Microsoft Secure MOR implementation.
+  
https://msdn.microsoft.com/en-us/library/windows/hardware/mt270973(v=vs.85).aspx
+
+  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD 
License
+  which accompanies this distribution.  The full text of the license may be 
found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef __MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_H__
+#define __MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_H__
+
+#define MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_GUID \
+  { \
+    0xBB983CCF, 0x151D, 0x40E1, {0xA0, 0x7B, 0x4A, 0x17, 0xBE, 0x16, 0x82, 
0x92} \
+  }
+
+#define MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME 
L"MemoryOverwriteRequestControlLock"
+
+//
+// VendorGuid: {BB983CCF-151D-40E1-A07B-4A17BE168292}
+// Name:       MemoryOverwriteRequestControlLock
+// Attributes: NV+BS+RT
+// Size:       0x1 byte
+//
+// The BIOS initializes MemoryOverwriteRequestControlLock to a value of 0x00
+// before BDS (BOOT#### processing). When the OS loader calls SetVariable by
+// specifying 0x01, the access mode for both MemoryOverwriteRequestControlLock
+// and MemoryOverwriteRequestControl is changed to read-only. If any other
+// value is specified in the SetVariable call, it fails with the 
+// EFI_INVALID_PARAMETER error code.
+//
+
+extern EFI_GUID gEfiMemoryOverwriteRequestControlLockGuid;
+
+#endif
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index 598a6d0..7d74b69 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -388,6 +388,9 @@
 
   ## Include/Guid/MemoryOverwriteControl.h
   gEfiMemoryOverwriteControlDataGuid = { 0xe20939be, 0x32d4, 0x41be, {0xa1, 
0x50, 0x89, 0x7f, 0x85, 0xd4, 0x98, 0x29 }}
+  
+  ## Include/IndustryStandard/MemoryOverwriteRequestControlLock.h
+  gEfiMemoryOverwriteRequestControlLockGuid = { 0xBB983CCF, 0x151D, 0x40E1, 
{0xA0, 0x7B, 0x4A, 0x17, 0xBE, 0x16, 0x82, 0x92}}
 
   ## Include/Guid/WinCertificate.h
   gEfiCertTypeRsa2048Sha256Guid = { 0xa7717414, 0xc616, 0x4977, {0x94, 0x20, 
0x84, 0x47, 0x12, 0xa7, 0x35, 0xbf }}
diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
index fa94d90..2d464a0 100644
--- a/SecurityPkg/SecurityPkg.dsc
+++ b/SecurityPkg/SecurityPkg.dsc
@@ -234,6 +234,8 @@
   SecurityPkg/Pkcs7Verify/Pkcs7VerifyDxe/Pkcs7VerifyDxe.inf
 
 [Components.IA32, Components.X64]
+
+  SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockSmm.inf
   SecurityPkg/Tcg/TcgSmm/TcgSmm.inf
   SecurityPkg/Tcg/TrEESmm/TrEESmm.inf
   #
diff --git a/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLock.c 
b/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLock.c
new file mode 100644
index 0000000..7ca7079
--- /dev/null
+++ b/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLock.c
@@ -0,0 +1,196 @@
+/** @file
+  TCG MOR (Memory Overwrite Request) Lock Control Driver.
+
+  This driver initilize MemoryOverwriteRequestControlLock variable.
+  This module will add Variable Hook and allow 
MemoryOverwriteRequestControlLock variable set only once.
+
+Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials 
+are licensed and made available under the terms and conditions of the BSD 
License 
+which accompanies this distribution.  The full text of the license may be 
found at 
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <PiDxe.h>
+#include <Guid/MemoryOverwriteControl.h>
+#include <IndustryStandard/MemoryOverwriteRequestControlLock.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include "TcgMorLock.h"
+
+typedef struct {
+  CHAR16                                 *VariableName;
+  EFI_GUID                               *VendorGuid;
+} VARIABLE_TYPE;
+
+VARIABLE_TYPE  mMorVariableType[] = {
+  {MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,      
&gEfiMemoryOverwriteControlDataGuid},
+  {MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,  
&gEfiMemoryOverwriteRequestControlLockGuid},
+};
+
+/**
+  Returns if this is MOR related variable.
+
+  @param  VariableName the name of the vendor's variable, it's a 
Null-Terminated Unicode String
+  @param  VendorGuid   Unify identifier for vendor.
+
+  @retval  TRUE            The variable is MOR related.
+  @retval  FALSE           The variable is NOT MOR related.
+**/
+BOOLEAN
+IsAnyMorVariable (
+  IN CHAR16                                 *VariableName,
+  IN EFI_GUID                               *VendorGuid
+  )
+{
+  UINTN   Index;
+
+  for (Index = 0; Index < 
sizeof(mMorVariableType)/sizeof(mMorVariableType[0]); Index++) {
+    if ((StrCmp (VariableName, mMorVariableType[Index].VariableName) == 0) && 
+        (CompareGuid (VendorGuid, mMorVariableType[Index].VendorGuid))) {
+      return TRUE;
+    }
+  }
+  return FALSE;
+}
+
+/**
+  Returns if this is MOR lock variable.
+
+  @param  VariableName the name of the vendor's variable, it's a 
Null-Terminated Unicode String
+  @param  VendorGuid   Unify identifier for vendor.
+
+  @retval  TRUE            The variable is MOR lock variable.
+  @retval  FALSE           The variable is NOT MOR lock variable.
+**/
+BOOLEAN
+IsMorLockVariable (
+  IN CHAR16                                 *VariableName,
+  IN EFI_GUID                               *VendorGuid
+  )
+{
+  if ((StrCmp (VariableName, MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME) == 0) 
&& 
+      (CompareGuid (VendorGuid, &gEfiMemoryOverwriteRequestControlLockGuid))) {
+    return TRUE;
+  }
+  return FALSE;
+}
+
+/**
+  This service is a checker handler for the UEFI Runtime Service SetVariable()
+
+  @param  VariableName the name of the vendor's variable, as a
+                       Null-Terminated Unicode String
+  @param  VendorGuid   Unify identifier for vendor.
+  @param  Attributes   Point to memory location to return the attributes of 
variable. If the point
+                       is NULL, the parameter would be ignored.
+  @param  DataSize     The size in bytes of Data-Buffer.
+  @param  Data         Point to the content of the variable.
+
+  @retval  EFI_SUCCESS            The firmware has successfully stored the 
variable and its data as
+                                  defined by the Attributes.
+  @retval  EFI_INVALID_PARAMETER  An invalid combination of attribute bits was 
supplied, or the
+                                  DataSize exceeds the maximum allowed.
+  @retval  EFI_INVALID_PARAMETER  VariableName is an empty Unicode string.
+  @retval  EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the 
variable and its data.
+  @retval  EFI_DEVICE_ERROR       The variable could not be saved due to a 
hardware failure.
+  @retval  EFI_WRITE_PROTECTED    The variable in question is read-only.
+  @retval  EFI_WRITE_PROTECTED    The variable in question cannot be deleted.
+  @retval  EFI_SECURITY_VIOLATION The variable could not be written due to 
EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
+                                  set but the AuthInfo does NOT pass the 
validation check carried
+                                  out by the firmware.
+  @retval  EFI_NOT_FOUND          The variable trying to be updated or deleted 
was not found.
+
+**/
+EFI_STATUS
+EFIAPI
+SetVariableCheckHandlerMor (
+  IN CHAR16     *VariableName,
+  IN EFI_GUID   *VendorGuid,
+  IN UINT32     Attributes,
+  IN UINTN      DataSize,
+  IN VOID       *Data
+  )
+{
+  UINTN       MorLockDataSize;
+  BOOLEAN     MorLock;
+  EFI_STATUS  Status;
+
+  //
+  // do not handle non-MOR variable
+  //
+  if (!IsAnyMorVariable (VariableName, VendorGuid)) {
+    return EFI_SUCCESS;
+  }
+
+  MorLockDataSize = sizeof(MorLock);
+  Status = InternalGetVariable (
+             MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,
+             &gEfiMemoryOverwriteRequestControlLockGuid,
+             NULL,
+             &MorLockDataSize,
+             &MorLock
+             );
+  if (!EFI_ERROR (Status) && MorLock) {
+    //
+    // If lock, deny access
+    //
+    return EFI_INVALID_PARAMETER;
+  }
+  
+  //
+  // check format
+  //
+  if (IsMorLockVariable(VariableName, VendorGuid)) {
+    //
+    // Delete not OK
+    //
+    if ((DataSize == 0) || (Data == NULL) || (Attributes == 0)) {
+      return EFI_INVALID_PARAMETER;
+    }
+    //
+    // set to any other value not OK
+    //
+    if ((DataSize != sizeof(UINT8)) || ((*(UINT8 *)Data != 1) && (*(UINT8 
*)Data != 0))) {
+      return EFI_INVALID_PARAMETER;
+    }
+  }
+  //
+  // Or grant access
+  //
+  return EFI_SUCCESS;
+}
+
+/**
+  Entry Point for MOR Lock Control driver.
+
+  @param[in] ImageHandle  Image handle of this driver.
+  @param[in] SystemTable  A Pointer to the EFI System Table.
+
+  @retval EFI_SUCEESS     
+  @return Others          Some error occurs.
+**/
+EFI_STATUS
+EFIAPI
+MorLockDriverInit (
+  VOID
+  )
+{
+  EFI_STATUS  Status;
+  UINT8       Data;
+
+  Data = 0;
+  Status = InternalSetVariable (
+             MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,
+             &gEfiMemoryOverwriteRequestControlLockGuid,
+             EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS,
+             1,
+             &Data
+             );
+  return Status;
+}
diff --git a/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLock.h 
b/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLock.h
new file mode 100644
index 0000000..dbae913
--- /dev/null
+++ b/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLock.h
@@ -0,0 +1,122 @@
+/** @file
+   TCG MOR (Memory Overwrite Request) Lock Control Driver header file.
+   
+Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials 
+are licensed and made available under the terms and conditions of the BSD 
License 
+which accompanies this distribution.  The full text of the license may be 
found at 
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _EFI_TCG_MOR_LOCK_H_
+#define _EFI_TCG_MOR_LOCK_H_
+
+/**
+  This service is a wrapper for the UEFI Runtime Service GetVariable().
+
+  @param  VariableName the name of the vendor's variable, it's a 
Null-Terminated Unicode String
+  @param  VendorGuid   Unify identifier for vendor.
+  @param  Attributes   Point to memory location to return the attributes of 
variable. If the point
+                       is NULL, the parameter would be ignored.
+  @param  DataSize     As input, point to the maximum size of return 
Data-Buffer.
+                       As output, point to the actual size of the returned 
Data-Buffer.
+  @param  Data         Point to return Data-Buffer.
+
+  @retval  EFI_SUCCESS            The function completed successfully.
+  @retval  EFI_NOT_FOUND          The variable was not found.
+  @retval  EFI_BUFFER_TOO_SMALL   The DataSize is too small for the result. 
DataSize has
+                                  been updated with the size needed to 
complete the request.
+  @retval  EFI_INVALID_PARAMETER  VariableName is NULL.
+  @retval  EFI_INVALID_PARAMETER  VendorGuid is NULL.
+  @retval  EFI_INVALID_PARAMETER  DataSize is NULL.
+  @retval  EFI_INVALID_PARAMETER  The DataSize is not too small and Data is 
NULL.
+  @retval  EFI_DEVICE_ERROR       The variable could not be retrieved due to a 
hardware error.
+  @retval  EFI_SECURITY_VIOLATION The variable could not be retrieved due to 
an authentication failure.
+**/
+EFI_STATUS
+EFIAPI
+InternalGetVariable (
+  IN      CHAR16                   *VariableName,
+  IN      EFI_GUID                 *VendorGuid,
+  OUT     UINT32                   *Attributes OPTIONAL,
+  IN OUT  UINTN                    *DataSize,
+  OUT     VOID                     *Data
+  );
+
+/**
+  This service is a wrapper for the UEFI Runtime Service SetVariable()
+
+  @param  VariableName the name of the vendor's variable, as a
+                       Null-Terminated Unicode String
+  @param  VendorGuid   Unify identifier for vendor.
+  @param  Attributes   Point to memory location to return the attributes of 
variable. If the point
+                       is NULL, the parameter would be ignored.
+  @param  DataSize     The size in bytes of Data-Buffer.
+  @param  Data         Point to the content of the variable.
+
+  @retval  EFI_SUCCESS            The firmware has successfully stored the 
variable and its data as
+                                  defined by the Attributes.
+  @retval  EFI_INVALID_PARAMETER  An invalid combination of attribute bits was 
supplied, or the
+                                  DataSize exceeds the maximum allowed.
+  @retval  EFI_INVALID_PARAMETER  VariableName is an empty Unicode string.
+  @retval  EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the 
variable and its data.
+  @retval  EFI_DEVICE_ERROR       The variable could not be saved due to a 
hardware failure.
+  @retval  EFI_WRITE_PROTECTED    The variable in question is read-only.
+  @retval  EFI_WRITE_PROTECTED    The variable in question cannot be deleted.
+  @retval  EFI_SECURITY_VIOLATION The variable could not be written due to 
EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
+                                  set but the AuthInfo does NOT pass the 
validation check carried
+                                  out by the firmware.
+  @retval  EFI_NOT_FOUND          The variable trying to be updated or deleted 
was not found.
+
+**/
+EFI_STATUS
+EFIAPI
+InternalSetVariable (
+  IN CHAR16                       *VariableName,
+  IN EFI_GUID                     *VendorGuid,
+  IN UINT32                       Attributes,
+  IN UINTN                        DataSize,
+  IN VOID                         *Data
+  );
+
+/**
+  This service is a checker handler for the UEFI Runtime Service SetVariable()
+
+  @param  VariableName the name of the vendor's variable, as a
+                       Null-Terminated Unicode String
+  @param  VendorGuid   Unify identifier for vendor.
+  @param  Attributes   Point to memory location to return the attributes of 
variable. If the point
+                       is NULL, the parameter would be ignored.
+  @param  DataSize     The size in bytes of Data-Buffer.
+  @param  Data         Point to the content of the variable.
+
+  @retval  EFI_SUCCESS            The firmware has successfully stored the 
variable and its data as
+                                  defined by the Attributes.
+  @retval  EFI_INVALID_PARAMETER  An invalid combination of attribute bits was 
supplied, or the
+                                  DataSize exceeds the maximum allowed.
+  @retval  EFI_INVALID_PARAMETER  VariableName is an empty Unicode string.
+  @retval  EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the 
variable and its data.
+  @retval  EFI_DEVICE_ERROR       The variable could not be saved due to a 
hardware failure.
+  @retval  EFI_WRITE_PROTECTED    The variable in question is read-only.
+  @retval  EFI_WRITE_PROTECTED    The variable in question cannot be deleted.
+  @retval  EFI_SECURITY_VIOLATION The variable could not be written due to 
EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
+                                  set but the AuthInfo does NOT pass the 
validation check carried
+                                  out by the firmware.
+  @retval  EFI_NOT_FOUND          The variable trying to be updated or deleted 
was not found.
+
+**/
+EFI_STATUS
+EFIAPI
+SetVariableCheckHandlerMor (
+  IN CHAR16     *VariableName,
+  IN EFI_GUID   *VendorGuid,
+  IN UINT32     Attributes,
+  IN UINTN      DataSize,
+  IN VOID       *Data
+  );
+
+#endif
diff --git a/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLock.uni 
b/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLock.uni
new file mode 100644
index 
0000000000000000000000000000000000000000..2e549379cfbd78bf4a1c45d71755b1eaac0cdf46
GIT binary patch
literal 1964
zcmds&UvCmY6vgkeiQi#DU(~dqCcYSB1X-2Xb_pz2pUm>7EfLtdrLFkk)!&(+3?N2d
z^udsw*|~G)+;h*pvwZ(nvzj@c2mGA9uu~h`#71`4?qJnk%VyZ--afXk>|J6#VxC%I
zr7bMAYgVP*@W^vy9iGp2#dyj3C4MvJl6hi>j05`w#<k`CL~i|!m@#%{=O8McVhuqQ
zH%BC~obZ-o9WuY$!gBV86NQhH6J0*JKT~k}@9=jp9g(La?u=NA<=X&jb){&`PP$y+
zCDqQzR44DD&3)#__Rt>L6Wixq6_BdRS7%C2Y0R;XeXJ@wb)TJELz8YL=ftY?H5$U>
znKh`-^BsJm+86j2a8isZD7OmEVJZD{SPt-*!bE!uc+Buuoy1D<#=K349rIPSb$Y^{
zG?{s3p)#RDIz3!QP<N=xx832WzPyC(h!L2CSW}Q9OEHsY=vuvNx1hJ<xrTME$@*}E
zOXPavJ8!`FbGBnR2vHnDcPf@TU0L_xxn38ks;p0a_o{~C{DpCw)21##OZ8BHdA?XG
zAV%{wUDY{rD)H3cSoKuUR{o_|x=QvX^{H)Xe~G0J^PwGV?NmWI=ZT7B+^7ULZMrA5
z*Nk<(0_x5#W7E$W))xKMvkYJ9+p}Zl1iQl)5Tf=i`Z>X)>ycC5)W;et%)%9Vg}LF^
zTJ5iKI$>X^sgLOF1h0-~c8t9RsxVR?y~9e}WmC)yU->9%@Op)>qJLn1%Z`}q{w2#O
zA&bP`uW%xI3oY7olVUb^-gbRqYo5C_)w8$inQ(Wy@afn`kWw&upe3y8<Q{hFsFlIz
zSHC@fTZDB*hn)GYQ70ULC8ibF{i|<zWtHilWvL$NlArpgy{gNuOn;xHZruO!uMu_p
E0koGsKL7v#

literal 0
HcmV?d00001

diff --git 
a/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockExtra.uni 
b/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockExtra.uni
new file mode 100644
index 
0000000000000000000000000000000000000000..ea7896b273ca7448bcc10720fa322c03e3e9ab7a
GIT binary patch
literal 1356
zcmZ9M-ER_65XI-&#Q%ZN7d0)Yi7&<&OIa(i1p-T|PtEdCx{(4|Xe<8l>hH|m4<Lm5
zF?a5nGiPS+zrRguT8;l3el`1Icb3}1X7<uvVAWY{6Pw$$tt_)E#)<vH8deFusr|u!
zifw3Hd{SHDzhR%SlKp~POU`CK7RbdM&eyi{yK}q8vu3Y|^P2g+y|s7t!A@Csa+F1m
znc3P|CEQ3oMuU@cILSjy0-CsFMBnhw?8(_S?31-@V4urOD?TwCQqN$G{|c0hTpmCv
zGTP!X^Zf*#E6&z_w#&1xVG%3EOIa;ItMC)7x-IP{td`D9N)`CJJ<TILu~tnI8#C(O
zBR6!Ku`ZZ|SP#y+KoK)}rlmeoVnvOsdo8NgW`A|SrQ-VRT1*(l?l9XF4nh=%pqFB8
z*emNXJooD&RmJ`ed#I2&|HkK-)1fXw%N<_h{QfFeK#aC~x~g-wRN|v|?uu2=R{ohQ
z-5~pndNz-=-(VTTd}?P$Ck;^U`B#d>_RS*L^y!|ST{52Yb*MXsjBTG|tR4Dm#McwK
zz9Z{0N7(g61%yib4&O+G$Iy{`tklOE>&(IxdY!rDd+kp5INfkA)SgGI*$rL;XV%5u
z0aX}1k3L{0?y@OnjIVqYHF$l+SJ8hmf9FKZ_5DS8l#oSaKT4bmy@M8gx=AtH)+jkv
z`st-<x?Q%DvS0LS=nau}x4F7~PzGfNw_x``9f2R=(}m?VtD2*oP&sw}oN6bG>NVB>
x41e)cv^rQ9)J*S7OeZ{g^zeG=mC|<{x;C)6#7Et;_P0pURlnjDte05``#-v1(n|mU

literal 0
HcmV?d00001

diff --git a/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockSmm.c 
b/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockSmm.c
new file mode 100644
index 0000000..4159d84
--- /dev/null
+++ b/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockSmm.c
@@ -0,0 +1,153 @@
+/** @file
+   TCG MOR (Memory Overwrite Request) Lock Control Driver SMM wrapper.
+   
+Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials 
+are licensed and made available under the terms and conditions of the BSD 
License 
+which accompanies this distribution.  The full text of the license may be 
found at 
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <PiSmm.h>
+#include <Library/SmmServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Protocol/SmmVarCheck.h>
+#include <Protocol/SmmVariable.h>
+#include "TcgMorLock.h"
+
+EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable;
+
+/**
+  This service is a wrapper for the UEFI Runtime Service GetVariable().
+
+  @param  VariableName the name of the vendor's variable, it's a 
Null-Terminated Unicode String
+  @param  VendorGuid   Unify identifier for vendor.
+  @param  Attributes   Point to memory location to return the attributes of 
variable. If the point
+                       is NULL, the parameter would be ignored.
+  @param  DataSize     As input, point to the maximum size of return 
Data-Buffer.
+                       As output, point to the actual size of the returned 
Data-Buffer.
+  @param  Data         Point to return Data-Buffer.
+
+  @retval  EFI_SUCCESS            The function completed successfully.
+  @retval  EFI_NOT_FOUND          The variable was not found.
+  @retval  EFI_BUFFER_TOO_SMALL   The DataSize is too small for the result. 
DataSize has
+                                  been updated with the size needed to 
complete the request.
+  @retval  EFI_INVALID_PARAMETER  VariableName is NULL.
+  @retval  EFI_INVALID_PARAMETER  VendorGuid is NULL.
+  @retval  EFI_INVALID_PARAMETER  DataSize is NULL.
+  @retval  EFI_INVALID_PARAMETER  The DataSize is not too small and Data is 
NULL.
+  @retval  EFI_DEVICE_ERROR       The variable could not be retrieved due to a 
hardware error.
+  @retval  EFI_SECURITY_VIOLATION The variable could not be retrieved due to 
an authentication failure.
+**/
+EFI_STATUS
+EFIAPI
+InternalGetVariable (
+  IN      CHAR16                   *VariableName,
+  IN      EFI_GUID                 *VendorGuid,
+  OUT     UINT32                   *Attributes OPTIONAL,
+  IN OUT  UINTN                    *DataSize,
+  OUT     VOID                     *Data
+  )
+{
+  return mSmmVariable->SmmGetVariable (
+                         VariableName,
+                         VendorGuid,
+                         Attributes,
+                         DataSize,
+                         Data
+                         );
+}
+
+/**
+  This service is a wrapper for the UEFI Runtime Service SetVariable()
+
+  @param  VariableName the name of the vendor's variable, as a
+                       Null-Terminated Unicode String
+  @param  VendorGuid   Unify identifier for vendor.
+  @param  Attributes   Point to memory location to return the attributes of 
variable. If the point
+                       is NULL, the parameter would be ignored.
+  @param  DataSize     The size in bytes of Data-Buffer.
+  @param  Data         Point to the content of the variable.
+
+  @retval  EFI_SUCCESS            The firmware has successfully stored the 
variable and its data as
+                                  defined by the Attributes.
+  @retval  EFI_INVALID_PARAMETER  An invalid combination of attribute bits was 
supplied, or the
+                                  DataSize exceeds the maximum allowed.
+  @retval  EFI_INVALID_PARAMETER  VariableName is an empty Unicode string.
+  @retval  EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the 
variable and its data.
+  @retval  EFI_DEVICE_ERROR       The variable could not be saved due to a 
hardware failure.
+  @retval  EFI_WRITE_PROTECTED    The variable in question is read-only.
+  @retval  EFI_WRITE_PROTECTED    The variable in question cannot be deleted.
+  @retval  EFI_SECURITY_VIOLATION The variable could not be written due to 
EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
+                                  set but the AuthInfo does NOT pass the 
validation check carried
+                                  out by the firmware.
+  @retval  EFI_NOT_FOUND          The variable trying to be updated or deleted 
was not found.
+
+**/
+EFI_STATUS
+EFIAPI
+InternalSetVariable (
+  IN CHAR16                       *VariableName,
+  IN EFI_GUID                     *VendorGuid,
+  IN UINT32                       Attributes,
+  IN UINTN                        DataSize,
+  IN VOID                         *Data
+  )
+{
+  return mSmmVariable->SmmSetVariable (
+                         VariableName,
+                         VendorGuid,
+                         Attributes,
+                         DataSize,
+                         Data
+                         );
+}
+
+/**
+  Entry Point for MOR Lock Control driver.
+
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.
+  @param[in] SystemTable    A pointer to the EFI System Table.
+
+  @retval EFI_SUCCESS       EntryPoint runs successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+MorLockDriverEntryPointSmm (
+  IN EFI_HANDLE         ImageHandle,
+  IN EFI_SYSTEM_TABLE   *SystemTable
+  )
+{
+  EFI_STATUS                    Status;
+  EDKII_SMM_VAR_CHECK_PROTOCOL  *SmmVarCheck;
+
+  //
+  // This driver link to Smm Variable driver
+  //
+  DEBUG ((EFI_D_INFO, "MorLockDriverEntryPointSmm\n"));
+  
+  Status = gSmst->SmmLocateProtocol (
+                  &gEfiSmmVariableProtocolGuid,
+                  NULL,
+                  (VOID **) &mSmmVariable
+                  );
+  ASSERT_EFI_ERROR (Status);
+
+  Status = gSmst->SmmLocateProtocol (
+                  &gEdkiiSmmVarCheckProtocolGuid,
+                  NULL,
+                  (VOID **) &SmmVarCheck
+                  );
+  ASSERT_EFI_ERROR (Status);
+  Status = SmmVarCheck->SmmRegisterSetVariableCheckHandler 
(SetVariableCheckHandlerMor);
+  ASSERT_EFI_ERROR (Status);
+
+  Status = MorLockDriverInit ();
+  return Status;
+}
+
diff --git 
a/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockSmm.inf 
b/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockSmm.inf
new file mode 100644
index 0000000..19d9f3e
--- /dev/null
+++ b/SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockSmm.inf
@@ -0,0 +1,66 @@
+## @file
+#  Initilizes MemoryOverwriteRequestControlLock variable
+#
+#  This module will add Variable Hook and allow 
MemoryOverwriteRequestControlLock variable set only once.
+#
+# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD 
License
+# which accompanies this distribution. The full text of the license may be 
found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = TcgMorLockSmm
+  MODULE_UNI_FILE                = TcgMorLock.uni
+  FILE_GUID                      = E2EA6F47-E678-47FA-8C1B-02A03E825C6E
+  MODULE_TYPE                    = DXE_SMM_DRIVER
+  VERSION_STRING                 = 1.0
+  PI_SPECIFICATION_VERSION       = 0x0001000A
+  ENTRY_POINT                    = MorLockDriverEntryPointSmm
+
+#
+# The following information is for reference only and not required by the 
build tools.
+#
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
+#
+
+[Sources]
+  TcgMorLock.c
+  TcgMorLockSmm.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  SecurityPkg/SecurityPkg.dec
+
+[LibraryClasses]
+  UefiDriverEntryPoint
+  SmmServicesTableLib
+  DebugLib
+  BaseLib
+  BaseMemoryLib
+
+[Guids]
+  ## SOMETIMES_CONSUMES      ## Variable:L"MemoryOverwriteRequestControl"
+  gEfiMemoryOverwriteControlDataGuid
+
+  ## SOMETIMES_CONSUMES      ## Variable:L"MemoryOverwriteRequestControlLock"
+  ## PRODUCES                ## Variable:L"MemoryOverwriteRequestControlLock"
+  gEfiMemoryOverwriteRequestControlLockGuid
+
+[Protocols]
+  gEdkiiSmmVarCheckProtocolGuid           ## CONSUMES
+  gEfiSmmVariableProtocolGuid             ## CONSUMES
+
+[Depex]
+  gEfiSmmVariableProtocolGuid AND
+  gSmmVariableWriteGuid AND
+  ( gEfiTcgProtocolGuid OR gEfiTrEEProtocolGuid )
+
+[UserExtensions.TianoCore."ExtraFiles"]
+  TcgMorLockExtra.uni
-- 
1.9.5.msysgit.0

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to