TianoCore EDK2 master
Loading...
Searching...
No Matches
TcgMorLockDxe.c
Go to the documentation of this file.
1
13#include <PiDxe.h>
16#include <Library/DebugLib.h>
17#include <Library/BaseLib.h>
19#include "Variable.h"
20
21#include <Protocol/VariablePolicy.h>
22#include <Library/VariablePolicyHelperLib.h>
23
45 IN CHAR16 *VariableName,
46 IN EFI_GUID *VendorGuid,
47 IN UINT32 Attributes,
48 IN UINTN DataSize,
49 IN VOID *Data
50 )
51{
52 //
53 // Just let it pass. No need provide protection for DXE version.
54 //
55 return EFI_SUCCESS;
56}
57
66 VOID
67 )
68{
69 //
70 // Always clear variable to report unsupported to OS.
71 // The reason is that the DXE version is not proper to provide *protection*.
72 // BIOS should use SMM version variable driver to provide such capability.
73 //
75 MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,
76 &gEfiMemoryOverwriteRequestControlLockGuid,
77 0, // Attributes
78 0, // DataSize
79 NULL // Data
80 );
81
82 //
83 // The MOR variable can effectively improve platform security only when the
84 // MorLock variable protects the MOR variable. In turn MorLock cannot be made
85 // secure without SMM support in the platform firmware (see above).
86 //
87 // Thus, delete the MOR variable, should it exist for any reason (some OSes
88 // are known to create MOR unintentionally, in an attempt to set it), then
89 // also lock the MOR variable, in order to prevent other modules from
90 // creating it.
91 //
94 &gEfiMemoryOverwriteControlDataGuid,
95 0, // Attributes
96 0, // DataSize
97 NULL // Data
98 );
99
100 return EFI_SUCCESS;
101}
102
108VOID
110 VOID
111 )
112{
113 EFI_STATUS Status;
114 EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy;
115
116 // First, we obviously need to locate the VariablePolicy protocol.
117 Status = gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid, NULL, (VOID **)&VariablePolicy);
118 if (EFI_ERROR (Status)) {
119 DEBUG ((DEBUG_ERROR, "%a - Could not locate VariablePolicy protocol! %r\n", __func__, Status));
120 return;
121 }
122
123 // If we're successful, go ahead and set the policies to protect the target variables.
124 Status = RegisterBasicVariablePolicy (
125 VariablePolicy,
126 &gEfiMemoryOverwriteRequestControlLockGuid,
127 MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME,
128 VARIABLE_POLICY_NO_MIN_SIZE,
129 VARIABLE_POLICY_NO_MAX_SIZE,
130 VARIABLE_POLICY_NO_MUST_ATTR,
131 VARIABLE_POLICY_NO_CANT_ATTR,
132 VARIABLE_POLICY_TYPE_LOCK_NOW
133 );
134 if (EFI_ERROR (Status)) {
135 DEBUG ((DEBUG_ERROR, "%a - Could not lock variable %s! %r\n", __func__, MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, Status));
136 }
137
138 Status = RegisterBasicVariablePolicy (
139 VariablePolicy,
140 &gEfiMemoryOverwriteControlDataGuid,
142 VARIABLE_POLICY_NO_MIN_SIZE,
143 VARIABLE_POLICY_NO_MAX_SIZE,
144 VARIABLE_POLICY_NO_MUST_ATTR,
145 VARIABLE_POLICY_NO_CANT_ATTR,
146 VARIABLE_POLICY_TYPE_LOCK_NOW
147 );
148 if (EFI_ERROR (Status)) {
149 DEBUG ((DEBUG_ERROR, "%a - Could not lock variable %s! %r\n", __func__, MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, Status));
150 }
151
152 return;
153}
UINT64 UINTN
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME
EFI_STATUS MorLockInit(VOID)
Definition: TcgMorLockDxe.c:65
VOID MorLockInitAtEndOfDxe(VOID)
EFI_STATUS SetVariableCheckHandlerMor(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
Definition: TcgMorLockDxe.c:44
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI VariableServiceSetVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
Definition: Variable.c:2612
Definition: Base.h:213