]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Tcg/MemoryOverwriteRequestControlLock/TcgMorLockSmm.c
SecurityPkg: Remove Counter Based AuthVariable support
[mirror_edk2.git] / SecurityPkg / Tcg / MemoryOverwriteRequestControlLock / TcgMorLockSmm.c
1 /** @file
2 TCG MOR (Memory Overwrite Request) Lock Control Driver SMM wrapper.
3
4 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <PiSmm.h>
16 #include <Library/SmmServicesTableLib.h>
17 #include <Library/DebugLib.h>
18 #include <Protocol/SmmVarCheck.h>
19 #include <Protocol/SmmVariable.h>
20 #include "TcgMorLock.h"
21
22 EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable;
23
24 /**
25 This service is a wrapper for the UEFI Runtime Service GetVariable().
26
27 @param VariableName the name of the vendor's variable, it's a Null-Terminated Unicode String
28 @param VendorGuid Unify identifier for vendor.
29 @param Attributes Point to memory location to return the attributes of variable. If the point
30 is NULL, the parameter would be ignored.
31 @param DataSize As input, point to the maximum size of return Data-Buffer.
32 As output, point to the actual size of the returned Data-Buffer.
33 @param Data Point to return Data-Buffer.
34
35 @retval EFI_SUCCESS The function completed successfully.
36 @retval EFI_NOT_FOUND The variable was not found.
37 @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. DataSize has
38 been updated with the size needed to complete the request.
39 @retval EFI_INVALID_PARAMETER VariableName is NULL.
40 @retval EFI_INVALID_PARAMETER VendorGuid is NULL.
41 @retval EFI_INVALID_PARAMETER DataSize is NULL.
42 @retval EFI_INVALID_PARAMETER The DataSize is not too small and Data is NULL.
43 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
44 @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due to an authentication failure.
45 **/
46 EFI_STATUS
47 EFIAPI
48 InternalGetVariable (
49 IN CHAR16 *VariableName,
50 IN EFI_GUID *VendorGuid,
51 OUT UINT32 *Attributes OPTIONAL,
52 IN OUT UINTN *DataSize,
53 OUT VOID *Data
54 )
55 {
56 return mSmmVariable->SmmGetVariable (
57 VariableName,
58 VendorGuid,
59 Attributes,
60 DataSize,
61 Data
62 );
63 }
64
65 /**
66 This service is a wrapper for the UEFI Runtime Service SetVariable()
67
68 @param VariableName the name of the vendor's variable, as a
69 Null-Terminated Unicode String
70 @param VendorGuid Unify identifier for vendor.
71 @param Attributes Point to memory location to return the attributes of variable. If the point
72 is NULL, the parameter would be ignored.
73 @param DataSize The size in bytes of Data-Buffer.
74 @param Data Point to the content of the variable.
75
76 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
77 defined by the Attributes.
78 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied, or the
79 DataSize exceeds the maximum allowed.
80 @retval EFI_INVALID_PARAMETER VariableName is an empty Unicode string.
81 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
82 @retval EFI_DEVICE_ERROR The variable could not be saved due to a hardware failure.
83 @retval EFI_WRITE_PROTECTED The variable in question is read-only.
84 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
85 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
86 set but the AuthInfo does NOT pass the validation check carried
87 out by the firmware.
88 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
89
90 **/
91 EFI_STATUS
92 EFIAPI
93 InternalSetVariable (
94 IN CHAR16 *VariableName,
95 IN EFI_GUID *VendorGuid,
96 IN UINT32 Attributes,
97 IN UINTN DataSize,
98 IN VOID *Data
99 )
100 {
101 return mSmmVariable->SmmSetVariable (
102 VariableName,
103 VendorGuid,
104 Attributes,
105 DataSize,
106 Data
107 );
108 }
109
110 /**
111 Entry Point for MOR Lock Control driver.
112
113 @param[in] ImageHandle The firmware allocated handle for the EFI image.
114 @param[in] SystemTable A pointer to the EFI System Table.
115
116 @retval EFI_SUCCESS EntryPoint runs successfully.
117
118 **/
119 EFI_STATUS
120 EFIAPI
121 MorLockDriverEntryPointSmm (
122 IN EFI_HANDLE ImageHandle,
123 IN EFI_SYSTEM_TABLE *SystemTable
124 )
125 {
126 EFI_STATUS Status;
127 EDKII_SMM_VAR_CHECK_PROTOCOL *SmmVarCheck;
128
129 //
130 // This driver link to Smm Variable driver
131 //
132 DEBUG ((EFI_D_INFO, "MorLockDriverEntryPointSmm\n"));
133
134 Status = gSmst->SmmLocateProtocol (
135 &gEfiSmmVariableProtocolGuid,
136 NULL,
137 (VOID **) &mSmmVariable
138 );
139 ASSERT_EFI_ERROR (Status);
140
141 Status = gSmst->SmmLocateProtocol (
142 &gEdkiiSmmVarCheckProtocolGuid,
143 NULL,
144 (VOID **) &SmmVarCheck
145 );
146 ASSERT_EFI_ERROR (Status);
147
148 Status = MorLockDriverInit ();
149 if (EFI_ERROR (Status)) {
150 return Status;
151 }
152
153 Status = SmmVarCheck->SmmRegisterSetVariableCheckHandler (SetVariableCheckHandlerMor);
154 ASSERT_EFI_ERROR (Status);
155
156 return Status;
157 }
158