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