20GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mVarCheckPcdHex[] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' };
50 while (DataSize != 0) {
52 if (Size > DataSize) {
56 for (Index = 0; Index < Size; Index += 1) {
57 TempByte = Data[Index];
58 Val[Index * 3 + 0] = mVarCheckPcdHex[TempByte >> 4];
59 Val[Index * 3 + 1] = mVarCheckPcdHex[TempByte & 0xF];
60 Val[Index * 3 + 2] = (CHAR8)((Index == 7) ?
'-' :
' ');
61 Str[Index] = (CHAR8)((TempByte <
' ' || TempByte >
'z') ?
'.' : TempByte);
66 DEBUG ((DEBUG_INFO,
"%*a%08X: %-48a *%a*\r\n", Indent,
"", Offset, Val, Str));
99 CopyMem (&OneData, (UINT8 *)Data + PcdValidData->VarOffset, PcdValidData->StorageWidth);
101 switch (PcdValidData->Type) {
102 case VarCheckPcdValidList:
104 while ((
UINTN)Ptr < (
UINTN)PcdValidData + PcdValidData->Length) {
106 CopyMem (&OneValue, Ptr, PcdValidData->StorageWidth);
107 if (OneData == OneValue) {
114 Ptr += PcdValidData->StorageWidth;
117 if ((
UINTN)Ptr >= ((
UINTN)PcdValidData + PcdValidData->Length)) {
121 DEBUG ((DEBUG_INFO,
"VarCheckPcdValidData fail: ValidList mismatch (0x%lx)\n", OneData));
130 case VarCheckPcdValidRange:
134 while ((
UINTN)Ptr < (
UINTN)PcdValidData + PcdValidData->Length) {
135 CopyMem (&Minimum, Ptr, PcdValidData->StorageWidth);
136 Ptr += PcdValidData->StorageWidth;
137 CopyMem (&Maximum, Ptr, PcdValidData->StorageWidth);
138 Ptr += PcdValidData->StorageWidth;
140 if ((OneData >= Minimum) && (OneData <= Maximum)) {
145 DEBUG ((DEBUG_INFO,
"VarCheckPcdValidData fail: ValidRange mismatch (0x%lx)\n", OneData));
161UINTN mVarCheckPcdBinSize = 0;
179 IN CHAR16 *VariableName,
181 IN UINT32 Attributes,
189 if (mVarCheckPcdBin ==
NULL) {
193 if ((((Attributes & EFI_VARIABLE_APPEND_WRITE) == 0) && (DataSize == 0)) || (Attributes == 0)) {
204 while ((
UINTN)PcdVariable < ((
UINTN)mVarCheckPcdBin + mVarCheckPcdBinSize)) {
205 if ((
StrCmp ((CHAR16 *)(PcdVariable + 1), VariableName) == 0) &&
211 DEBUG ((DEBUG_INFO,
"VarCheckPcdVariable - %s:%g with Attributes = 0x%08x Size = 0x%x\n", VariableName, VendorGuid, Attributes, DataSize));
212 if ((PcdVariable->Attributes != 0) && (PcdVariable->Attributes != Attributes)) {
213 DEBUG ((DEBUG_INFO,
"VarCheckPcdVariable fail for Attributes - 0x%08x\n", PcdVariable->Attributes));
214 return EFI_SECURITY_VIOLATION;
218 DEBUG ((DEBUG_INFO,
"VarCheckPcdVariable - CHECK PASS with DataSize == 0 !\n"));
227 while ((
UINTN)PcdValidData < ((
UINTN)PcdVariable + PcdVariable->Length)) {
228 if (((
UINTN)PcdValidData->VarOffset + PcdValidData->StorageWidth) <= DataSize) {
230 return EFI_SECURITY_VIOLATION;
240 DEBUG ((DEBUG_INFO,
"VarCheckPcdVariable - ALL CHECK PASS!\n"));
254#ifdef DUMP_VAR_CHECK_PCD
272 DEBUG ((DEBUG_INFO,
" VAR_CHECK_PCD_VALID_DATA_HEADER\n"));
273 DEBUG ((DEBUG_INFO,
" Type - 0x%02x\n", PcdValidData->Type));
274 DEBUG ((DEBUG_INFO,
" Length - 0x%02x\n", PcdValidData->Length));
275 DEBUG ((DEBUG_INFO,
" VarOffset - 0x%04x\n", PcdValidData->VarOffset));
276 DEBUG ((DEBUG_INFO,
" StorageWidth - 0x%02x\n", PcdValidData->StorageWidth));
278 switch (PcdValidData->Type) {
279 case VarCheckPcdValidList:
281 while ((
UINTN)Ptr < ((
UINTN)PcdValidData + PcdValidData->Length)) {
283 CopyMem (&OneValue, Ptr, PcdValidData->StorageWidth);
284 switch (PcdValidData->StorageWidth) {
286 DEBUG ((DEBUG_INFO,
" ValidList - 0x%02x\n", OneValue));
288 case sizeof (UINT16):
289 DEBUG ((DEBUG_INFO,
" ValidList - 0x%04x\n", OneValue));
291 case sizeof (UINT32):
292 DEBUG ((DEBUG_INFO,
" ValidList - 0x%08x\n", OneValue));
294 case sizeof (UINT64):
295 DEBUG ((DEBUG_INFO,
" ValidList - 0x%016lx\n", OneValue));
302 Ptr += PcdValidData->StorageWidth;
307 case VarCheckPcdValidRange:
311 while ((
UINTN)Ptr < (
UINTN)PcdValidData + PcdValidData->Length) {
312 CopyMem (&Minimum, Ptr, PcdValidData->StorageWidth);
313 Ptr += PcdValidData->StorageWidth;
314 CopyMem (&Maximum, Ptr, PcdValidData->StorageWidth);
315 Ptr += PcdValidData->StorageWidth;
317 switch (PcdValidData->StorageWidth) {
319 DEBUG ((DEBUG_INFO,
" Minimum - 0x%02x\n", Minimum));
320 DEBUG ((DEBUG_INFO,
" Maximum - 0x%02x\n", Maximum));
322 case sizeof (UINT16):
323 DEBUG ((DEBUG_INFO,
" Minimum - 0x%04x\n", Minimum));
324 DEBUG ((DEBUG_INFO,
" Maximum - 0x%04x\n", Maximum));
326 case sizeof (UINT32):
327 DEBUG ((DEBUG_INFO,
" Minimum - 0x%08x\n", Minimum));
328 DEBUG ((DEBUG_INFO,
" Maximum - 0x%08x\n", Maximum));
330 case sizeof (UINT64):
331 DEBUG ((DEBUG_INFO,
" Minimum - 0x%016lx\n", Minimum));
332 DEBUG ((DEBUG_INFO,
" Maximum - 0x%016lx\n", Maximum));
361 DEBUG ((DEBUG_INFO,
"VAR_CHECK_PCD_VARIABLE_HEADER\n"));
362 DEBUG ((DEBUG_INFO,
" Revision - 0x%04x\n", PcdVariable->Revision));
363 DEBUG ((DEBUG_INFO,
" HeaderLength - 0x%04x\n", PcdVariable->HeaderLength));
364 DEBUG ((DEBUG_INFO,
" Length - 0x%08x\n", PcdVariable->Length));
365 DEBUG ((DEBUG_INFO,
" Type - 0x%02x\n", PcdVariable->Type));
366 DEBUG ((DEBUG_INFO,
" Attributes - 0x%08x\n", PcdVariable->Attributes));
367 DEBUG ((DEBUG_INFO,
" Guid - %g\n", &PcdVariable->Guid));
368 DEBUG ((DEBUG_INFO,
" Name - %s\n", PcdVariable + 1));
374 while ((
UINTN)PcdValidData < ((
UINTN)PcdVariable + PcdVariable->Length)) {
378 DumpPcdValidData (PcdValidData);
395 IN VOID *VarCheckPcdBin,
401 DEBUG ((DEBUG_INFO,
"DumpVarCheckPcd\n"));
407 while ((
UINTN)PcdVariable < ((
UINTN)VarCheckPcdBin + VarCheckPcdBinSize)) {
408 DumpPcdVariable (PcdVariable);
430 UINTN VarCheckPcdBinSize;
438 (VOID **)&VarCheckPcdBin,
441 if (!EFI_ERROR (Status)) {
447 ASSERT (mVarCheckPcdBin !=
NULL);
452 mVarCheckPcdBinSize = VarCheckPcdBinSize;
455 DEBUG ((DEBUG_INFO,
"VarCheckPcdBin - at 0x%x size = 0x%x\n", mVarCheckPcdBin, mVarCheckPcdBinSize));
457 #ifdef DUMP_VAR_CHECK_PCD
459 DumpVarCheckPcd (mVarCheckPcdBin, mVarCheckPcdBinSize);
463 DEBUG ((DEBUG_INFO,
"[VarCheckPcd] No VarCheckPcdBin found at the first RAW section\n"));
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
EFI_STATUS EFIAPI GetSectionFromFfs(IN EFI_SECTION_TYPE SectionType, IN UINTN SectionInstance, OUT VOID **Buffer, OUT UINTN *Size)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateRuntimeCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define GLOBAL_REMOVE_IF_UNREFERENCED
#define DEBUG(Expression)
#define DEBUG_CODE(Expression)
EFI_STATUS EFIAPI VarCheckLibRegisterAddressPointer(IN VOID **AddressPointer)
EFI_STATUS EFIAPI VarCheckLibRegisterSetVariableCheckHandler(IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler)
EFI_STATUS EFIAPI VarCheckPcdLibNullClassConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI SetVariableCheckHandlerPcd(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
BOOLEAN VarCheckPcdValidData(IN VAR_CHECK_PCD_VALID_DATA_HEADER *PcdValidData, IN VOID *Data, IN UINTN DataSize)
VOID VarCheckPcdInternalDumpHex(IN UINTN Indent, IN UINTN Offset, IN UINTN DataSize, IN VOID *UserData)
VOID EFIAPI LocateVarCheckPcdBin(VOID)