TianoCore EDK2 master
Loading...
Searching...
No Matches
TcgMorLock.c
Go to the documentation of this file.
1
12#include <PiDxe.h>
15#include <Library/DebugLib.h>
16#include <Library/BaseLib.h>
18#include "TcgMorLock.h"
19
20typedef struct {
21 CHAR16 *VariableName;
22 EFI_GUID *VendorGuid;
24
25VARIABLE_TYPE mMorVariableType[] = {
26 { MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, &gEfiMemoryOverwriteControlDataGuid },
27 { MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid },
28};
29
39BOOLEAN
41 IN CHAR16 *VariableName,
42 IN EFI_GUID *VendorGuid
43 )
44{
45 UINTN Index;
46
47 for (Index = 0; Index < sizeof (mMorVariableType)/sizeof (mMorVariableType[0]); Index++) {
48 if ((StrCmp (VariableName, mMorVariableType[Index].VariableName) == 0) &&
49 (CompareGuid (VendorGuid, mMorVariableType[Index].VendorGuid)))
50 {
51 return TRUE;
52 }
53 }
54
55 return FALSE;
56}
57
67BOOLEAN
69 IN CHAR16 *VariableName,
70 IN EFI_GUID *VendorGuid
71 )
72{
73 if ((StrCmp (VariableName, MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME) == 0) &&
74 (CompareGuid (VendorGuid, &gEfiMemoryOverwriteRequestControlLockGuid)))
75 {
76 return TRUE;
77 }
78
79 return FALSE;
80}
81
109EFIAPI
111 IN CHAR16 *VariableName,
112 IN EFI_GUID *VendorGuid,
113 IN UINT32 Attributes,
114 IN UINTN DataSize,
115 IN VOID *Data
116 )
117{
118 UINTN MorLockDataSize;
119 BOOLEAN MorLock;
120 EFI_STATUS Status;
121
122 //
123 // do not handle non-MOR variable
124 //
125 if (!IsAnyMorVariable (VariableName, VendorGuid)) {
126 return EFI_SUCCESS;
127 }
128
129 MorLockDataSize = sizeof (MorLock);
130 Status = InternalGetVariable (
131 MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,
132 &gEfiMemoryOverwriteRequestControlLockGuid,
133 NULL,
134 &MorLockDataSize,
135 &MorLock
136 );
137 if (!EFI_ERROR (Status) && MorLock) {
138 //
139 // If lock, deny access
140 //
141 return EFI_INVALID_PARAMETER;
142 }
143
144 //
145 // Delete not OK
146 //
147 if ((DataSize != sizeof (UINT8)) || (Data == NULL) || (Attributes == 0)) {
148 return EFI_INVALID_PARAMETER;
149 }
150
151 //
152 // check format
153 //
154 if (IsMorLockVariable (VariableName, VendorGuid)) {
155 //
156 // set to any other value not OK
157 //
158 if ((*(UINT8 *)Data != 1) && (*(UINT8 *)Data != 0)) {
159 return EFI_INVALID_PARAMETER;
160 }
161 }
162
163 //
164 // Or grant access
165 //
166 return EFI_SUCCESS;
167}
168
179EFIAPI
181 VOID
182 )
183{
184 EFI_STATUS Status;
185 UINT8 Data;
186
187 Data = 0;
188 Status = InternalSetVariable (
189 MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,
190 &gEfiMemoryOverwriteRequestControlLockGuid,
191 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
192 1,
193 &Data
194 );
195 return Status;
196}
UINT64 UINTN
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
EFI_STATUS InternalGetVariable(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size)
Definition: Measurement.c:178
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
EFI_STATUS EFIAPI SetVariableCheckHandlerMor(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
Definition: TcgMorLock.c:110
BOOLEAN IsMorLockVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid)
Definition: TcgMorLock.c:68
BOOLEAN IsAnyMorVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid)
Definition: TcgMorLock.c:40
EFI_STATUS EFIAPI MorLockDriverInit(VOID)
Definition: TcgMorLock.c:180
EFI_STATUS EFIAPI InternalSetVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
Definition: TcgMorLockSmm.c:87
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
#define EFI_VARIABLE_NON_VOLATILE
Definition: Base.h:213