Changeset 58459 in vbox for trunk/src/VBox/Devices/EFI/Firmware/SecurityPkg/Library
- Timestamp:
- Oct 28, 2015 8:17:18 PM (9 years ago)
- Location:
- trunk/src/VBox/Devices/EFI/Firmware
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/Firmware
-
Property svn:mergeinfo
set to (toggle deleted branches)
/vendor/edk2/current 103735-103757
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/Firmware/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.c
r48674 r58459 2 2 Implement defer image load services for user identification in UEFI2.2. 3 3 4 Copyright (c) 2009 - 201 1, Intel Corporation. All rights reserved.<BR>4 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR> 5 5 This program and the accompanying materials 6 6 are licensed and made available under the terms and conditions of the BSD License … … 247 247 while (CheckLen < Info->InfoSize - sizeof (EFI_USER_INFO)) { 248 248 Access = (EFI_USER_INFO_ACCESS_CONTROL *) ((UINT8 *) (Info + 1) + CheckLen); 249 if ( (Access->Type == AccessType)) {249 if (Access->Type == AccessType) { 250 250 *AccessControl = AllocateZeroPool (Access->Size); 251 251 ASSERT (*AccessControl != NULL); … … 264 264 } 265 265 266 267 /** 268 Convert the '/' to '\' in the specified string. 269 270 @param[in, out] Str Points to the string to convert. 271 272 **/ 273 VOID 274 ConvertDPStr ( 275 IN OUT EFI_STRING Str 276 ) 277 { 278 INTN Count; 279 INTN Index; 280 281 Count = StrSize(Str) / 2 - 1; 282 283 if (Count < 4) { 284 return; 285 } 286 287 // 288 // Convert device path string. 289 // 290 Index = Count - 1; 291 while (Index > 0) { 292 // 293 // Find the last '/'. 294 // 295 for (Index = Count - 1; Index > 0; Index--) { 296 if (Str[Index] == L'/') 297 break; 298 } 299 300 // 301 // Check next char. 302 // 303 if (Str[Index + 1] == L'\\') 304 return; 266 /** 267 Get file name from device path. 268 269 The file name may contain one or more device path node. Save the file name in a 270 buffer if file name is found. The caller is responsible to free the buffer. 271 272 @param[in] DevicePath A pointer to a device path. 273 @param[out] FileName The callee allocated buffer to save the file name if file name is found. 274 @param[out] FileNameOffset The offset of file name in device path if file name is found. 275 276 @retval UINTN The file name length. 0 means file name is not found. 277 278 **/ 279 UINTN 280 GetFileName ( 281 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, 282 OUT UINT8 **FileName, 283 OUT UINTN *FileNameOffset 284 ) 285 { 286 UINTN Length; 287 EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; 288 EFI_DEVICE_PATH_PROTOCOL *RootDevicePath; 289 CHAR8 *NodeStr; 290 UINTN NodeStrLength; 291 CHAR16 LastNodeChar; 292 CHAR16 FirstNodeChar; 293 294 // 295 // Get the length of DevicePath before file name. 296 // 297 Length = 0; 298 RootDevicePath = (EFI_DEVICE_PATH_PROTOCOL *)DevicePath; 299 while (!IsDevicePathEnd (RootDevicePath)) { 300 if ((DevicePathType(RootDevicePath) == MEDIA_DEVICE_PATH) && (DevicePathSubType(RootDevicePath) == MEDIA_FILEPATH_DP)) { 301 break; 302 } 303 Length += DevicePathNodeLength (RootDevicePath); 304 RootDevicePath = NextDevicePathNode (RootDevicePath); 305 } 306 307 *FileNameOffset = Length; 308 if (Length == 0) { 309 return 0; 310 } 311 312 // 313 // Get the file name length. 314 // 315 Length = 0; 316 TmpDevicePath = RootDevicePath; 317 while (!IsDevicePathEnd (TmpDevicePath)) { 318 if ((DevicePathType(TmpDevicePath) != MEDIA_DEVICE_PATH) || (DevicePathSubType(TmpDevicePath) != MEDIA_FILEPATH_DP)) { 319 break; 320 } 321 Length += DevicePathNodeLength (TmpDevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL); 322 TmpDevicePath = NextDevicePathNode (TmpDevicePath); 323 } 324 if (Length == 0) { 325 return 0; 326 } 327 328 *FileName = AllocateZeroPool (Length); 329 ASSERT (*FileName != NULL); 330 331 // 332 // Copy the file name to the buffer. 333 // 334 Length = 0; 335 LastNodeChar = '\\'; 336 TmpDevicePath = RootDevicePath; 337 while (!IsDevicePathEnd (TmpDevicePath)) { 338 if ((DevicePathType(TmpDevicePath) != MEDIA_DEVICE_PATH) || (DevicePathSubType(TmpDevicePath) != MEDIA_FILEPATH_DP)) { 339 break; 340 } 341 342 FirstNodeChar = (CHAR16) ReadUnaligned16 ((UINT16 *)((UINT8 *)TmpDevicePath + sizeof (EFI_DEVICE_PATH_PROTOCOL))); 343 NodeStr = (CHAR8 *)TmpDevicePath + sizeof (EFI_DEVICE_PATH_PROTOCOL); 344 NodeStrLength = DevicePathNodeLength (TmpDevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL) - sizeof(CHAR16); 305 345 306 Str[Index] = L'\\'; 346 if ((FirstNodeChar == '\\') && (LastNodeChar == '\\')) { 347 // 348 // Skip separator "\" when there are two separators. 349 // 350 NodeStr += sizeof (CHAR16); 351 NodeStrLength -= sizeof (CHAR16); 352 } else if ((FirstNodeChar != '\\') && (LastNodeChar != '\\')) { 353 // 354 // Add separator "\" when there is no separator. 355 // 356 WriteUnaligned16 ((UINT16 *)(*FileName + Length), '\\'); 357 Length += sizeof (CHAR16); 358 } 359 CopyMem (*FileName + Length, NodeStr, NodeStrLength); 360 Length += NodeStrLength; 307 361 308 // 309 // Check previous char. 310 // 311 if ((Index > 0) && (Str[Index - 1] == L'\\')) { 312 CopyMem (&Str[Index - 1], &Str[Index], (UINTN) ((Count - Index + 1) * sizeof (CHAR16))); 313 return; 314 } 315 Index--; 316 } 362 LastNodeChar = (CHAR16) ReadUnaligned16 ((UINT16 *) (NodeStr + NodeStrLength - sizeof(CHAR16))); 363 TmpDevicePath = NextDevicePathNode (TmpDevicePath); 364 } 365 366 return Length; 317 367 } 318 368 … … 343 393 ) 344 394 { 345 EFI_STATUS Status; 346 EFI_STRING DevicePathStr1; 347 EFI_STRING DevicePathStr2; 348 UINTN StrLen1; 349 UINTN StrLen2; 350 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevicePathText; 351 BOOLEAN DevicePathEqual; 395 UINTN DevicePathSize; 396 UINTN FileNameSize1; 397 UINTN FileNameSize2; 398 UINT8 *FileName1; 399 UINT8 *FileName2; 400 UINTN FileNameOffset1; 401 UINTN FileNameOffset2; 402 BOOLEAN DevicePathEqual; 403 404 FileName1 = NULL; 405 FileName2 = NULL; 406 DevicePathEqual = TRUE; 352 407 353 408 ASSERT (DevicePath1 != NULL); 354 409 ASSERT (DevicePath2 != NULL); 355 356 DevicePathEqual = FALSE; 357 DevicePathText = NULL; 358 Status = gBS->LocateProtocol ( 359 &gEfiDevicePathToTextProtocolGuid, 360 NULL, 361 (VOID **) &DevicePathText 362 ); 363 ASSERT (Status == EFI_SUCCESS); 364 365 // 366 // Get first device path string. 367 // 368 DevicePathStr1 = DevicePathText->ConvertDevicePathToText (DevicePath1, TRUE, TRUE); 369 ConvertDPStr (DevicePathStr1); 370 // 371 // Get second device path string. 372 // 373 DevicePathStr2 = DevicePathText->ConvertDevicePathToText (DevicePath2, TRUE, TRUE); 374 ConvertDPStr (DevicePathStr2); 375 376 // 377 // Compare device path string. 378 // 379 StrLen1 = StrSize (DevicePathStr1); 380 StrLen2 = StrSize (DevicePathStr2); 381 if (StrLen1 > StrLen2) { 410 if (IsDevicePathEnd (DevicePath1)) { 411 return FALSE; 412 } 413 414 // 415 // The file name may contain one or more device path node. 416 // To compare the file name, copy file name to a buffer and compare the buffer. 417 // 418 FileNameSize1 = GetFileName (DevicePath1, &FileName1, &FileNameOffset1); 419 if (FileNameSize1 != 0) { 420 FileNameSize2 = GetFileName (DevicePath2, &FileName2, &FileNameOffset2); 421 if (FileNameOffset1 != FileNameOffset2) { 422 DevicePathEqual = FALSE; 423 goto Done; 424 } 425 if (CompareMem (DevicePath1, DevicePath2, FileNameOffset1) != 0) { 426 DevicePathEqual = FALSE; 427 goto Done; 428 } 429 if (FileNameSize1 > FileNameSize2) { 430 DevicePathEqual = FALSE; 431 goto Done; 432 } 433 if (CompareMem (FileName1, FileName2, FileNameSize1) != 0) { 434 DevicePathEqual = FALSE; 435 goto Done; 436 } 437 DevicePathEqual = TRUE; 438 goto Done; 439 } 440 441 DevicePathSize = GetDevicePathSize (DevicePath1); 442 if (DevicePathSize > GetDevicePathSize (DevicePath2)) { 443 return FALSE; 444 } 445 446 // 447 // Exclude the end of device path node. 448 // 449 DevicePathSize -= sizeof (EFI_DEVICE_PATH_PROTOCOL); 450 if (CompareMem (DevicePath1, DevicePath2, DevicePathSize) != 0) { 382 451 DevicePathEqual = FALSE; 383 goto Done; 384 } 385 386 if (CompareMem (DevicePathStr1, DevicePathStr2, StrLen1) == 0) { 387 DevicePathEqual = TRUE; 388 } 389 390 Done: 391 FreePool (DevicePathStr1); 392 FreePool (DevicePathStr2); 452 } 453 454 Done: 455 if (FileName1 != NULL) { 456 FreePool (FileName1); 457 } 458 if (FileName2 != NULL) { 459 FreePool (FileName2); 460 } 393 461 return DevicePathEqual; 394 462 } … … 533 601 // 534 602 UnicodeSPrint (StrTemp, sizeof (StrTemp), L"Boot%04x", Index); 535 OptionBuffer = GetEfiGlobalVariable (StrTemp);603 GetEfiGlobalVariable2 (StrTemp, (VOID**)&OptionBuffer, NULL); 536 604 if (OptionBuffer == NULL) { 537 605 continue; … … 715 783 @param[in] FileBuffer File buffer matches the input file device path. 716 784 @param[in] FileSize Size of File buffer matches the input file device path. 717 718 @retval EFI_SUCCESS The file specified by File did authenticate, and the 719 platform policy dictates that the DXE Core may use File. 720 @retval EFI_INVALID_PARAMETER File is NULL. 721 @retval EFI_SECURITY_VIOLATION The file specified by File did not authenticate, and 722 the platform policy dictates that File should be placed 723 in the untrusted state. A file may be promoted from 724 the untrusted to the trusted state at a future time 725 with a call to the Trust() DXE Service. 726 @retval EFI_ACCESS_DENIED The file specified by File did not authenticate, and 727 the platform policy dictates that File should not be 728 used for any purpose. 785 @param[in] BootPolicy A boot policy that was used to call LoadImage() UEFI service. 786 787 @retval EFI_SUCCESS FileBuffer is NULL and current user has permission to start 788 UEFI device drivers on the device path specified by DevicePath. 789 @retval EFI_SUCCESS The file specified by DevicePath and non-NULL 790 FileBuffer did authenticate, and the platform policy dictates 791 that the DXE Foundation may use the file. 792 @retval EFI_SECURITY_VIOLATION FileBuffer is NULL and the user has no 793 permission to start UEFI device drivers on the device path specified 794 by DevicePath. 795 @retval EFI_SECURITY_VIOLATION FileBuffer is not NULL and the user has no permission to load 796 drivers from the device path specified by DevicePath. The 797 image has been added into the list of the deferred images. 798 @retval EFI_ACCESS_DENIED The file specified by File and FileBuffer did not 799 authenticate, and the platform policy dictates that the DXE 800 Foundation many not use File. 729 801 730 802 **/ … … 735 807 IN CONST EFI_DEVICE_PATH_PROTOCOL *File, 736 808 IN VOID *FileBuffer, 737 IN UINTN FileSize 738 )739 809 IN UINTN FileSize, 810 IN BOOLEAN BootPolicy 811 ) 740 812 { 741 813 EFI_STATUS Status; … … 744 816 UINT32 FileType; 745 817 818 // 819 // Ignore if File is NULL. 820 // 746 821 if (File == NULL) { 747 return EFI_ INVALID_PARAMETER;822 return EFI_SUCCESS; 748 823 } 749 824 … … 760 835 if (!VerifyDevicePath (File)) { 761 836 DEBUG ((EFI_D_ERROR, "[Security] The image is forbidden to load!\n")); 762 return EFI_ ACCESS_DENIED;837 return EFI_SECURITY_VIOLATION; 763 838 } 764 839 return EFI_SUCCESS; … … 779 854 } 780 855 781 DEBUG ((EFI_D_ ERROR, "[Security] No user identified, the image is deferred to load!\n"));782 PutDefferedImageInfo (File, NULL, 0);856 DEBUG ((EFI_D_INFO, "[Security] No user identified, the image is deferred to load!\n")); 857 PutDefferedImageInfo (File, FileBuffer, FileSize); 783 858 784 859 // … … 850 925 ); 851 926 852 return RegisterSecurity Handler (927 return RegisterSecurity2Handler ( 853 928 DxeDeferImageLoadHandler, 854 929 EFI_AUTH_OPERATION_DEFER_IMAGE_LOAD -
trunk/src/VBox/Devices/EFI/Firmware/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.h
r48674 r58459 3 3 internal structure and functions used by DeferImageLoadLib. 4 4 5 Copyright (c) 2009 - 201 0, Intel Corporation. All rights reserved.<BR>5 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR> 6 6 This program and the accompanying materials 7 7 are licensed and made available under the terms and conditions of the BSD License … … 35 35 #include <Protocol/UserCredential.h> 36 36 #include <Protocol/UserManager.h> 37 #include <Protocol/DevicePathToText.h>38 37 39 38 #include <Guid/GlobalVariable.h> -
trunk/src/VBox/Devices/EFI/Firmware/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.inf
r48674 r58459 1 1 ## @file 2 # The library instance provides security service of deferring image load.2 # Provides security service of deferred image load 3 3 # 4 # Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR> 4 # The platform may need to defer the execution of an image because of security 5 # considerations. These deferred images will be recorded and then reported by 6 # installing an instance of the EFI_DEFERRED_IMAGE_LOAD_PROTOCOL. 7 # 8 # Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR> 5 9 # This program and the accompanying materials 6 10 # are licensed and made available under the terms and conditions of the BSD License … … 14 18 [Defines] 15 19 INF_VERSION = 0x00010005 16 BASE_NAME = DxeDeferImageLoadLib 20 BASE_NAME = DxeDeferImageLoadLib 21 MODULE_UNI_FILE = DxeDeferImageLoadLib.uni 17 22 FILE_GUID = 5E2FAE1F-41DA-4fbd-BC81-603CE5CD8497 18 23 MODULE_TYPE = DXE_DRIVER … … 49 54 50 55 [Protocols] 51 gEfiFirmwareVolume2ProtocolGuid 52 gEfiBlockIoProtocolGuid 53 gEfiSimpleFileSystemProtocolGuid 56 gEfiFirmwareVolume2ProtocolGuid ## SOMETIMES_CONSUMES 57 gEfiBlockIoProtocolGuid ## SOMETIMES_CONSUMES 58 gEfiSimpleFileSystemProtocolGuid ## SOMETIMES_CONSUMES 59 gEfiDeferredImageLoadProtocolGuid ## SOMETIMES_PRODUCES 60 ## SOMETIMES_CONSUMES 61 ## NOTIFY 54 62 gEfiUserManagerProtocolGuid 55 gEfiDeferredImageLoadProtocolGuid 56 gEfiDevicePathToTextProtocolGuid 57 63 58 64 [Guids] 59 gEfiGlobalVariableGuid 65 gEfiGlobalVariableGuid ## SOMETIMES_CONSUMES ## Variable:L"BootOrder" 60 66 61 67 [Pcd] 62 gEfiSecurityPkgTokenSpaceGuid.PcdDeferImageLoadPolicy 68 gEfiSecurityPkgTokenSpaceGuid.PcdDeferImageLoadPolicy ## SOMETIMES_CONSUMES -
trunk/src/VBox/Devices/EFI/Firmware/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
r48674 r58459 2 2 Implement image verification services for secure boot service in UEFI2.3.1. 3 3 4 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR> 4 Caution: This file requires additional review when modified. 5 This library will have external input - PE/COFF image. 6 This external input must be validated carefully to avoid security issue like 7 buffer overflow, integer overflow. 8 9 DxeImageVerificationLibImageRead() function will make sure the PE/COFF image content 10 read is within the image buffer. 11 12 DxeImageVerificationHandler(), HashPeImageByType(), HashPeImage() function will accept 13 untrusted PE/COFF image and validate its data structure within this image buffer before use. 14 15 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR> 5 16 This program and the accompanying materials 6 17 are licensed and made available under the terms and conditions of the BSD License … … 15 26 #include "DxeImageVerificationLib.h" 16 27 28 // 29 // Caution: This is used by a function which may receive untrusted input. 30 // These global variables hold PE/COFF image data, and they should be validated before use. 31 // 17 32 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION mNtHeader; 33 UINT32 mPeCoffHeaderOffset; 34 EFI_GUID mCertType; 35 36 // 37 // Information on current PE/COFF image 38 // 18 39 UINTN mImageSize; 19 UINT 32 mPeCoffHeaderOffset;40 UINT8 *mImageBase = NULL; 20 41 UINT8 mImageDigest[MAX_DIGEST_SIZE]; 21 42 UINTN mImageDigestSize; 22 EFI_IMAGE_DATA_DIRECTORY *mSecDataDir = NULL;23 UINT8 *mImageBase = NULL;24 EFI_GUID mCertType;25 43 26 44 // … … 39 57 // 40 58 UINT8 mHashOidValue[] = { 41 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, // OBJ_md542 59 0x2B, 0x0E, 0x03, 0x02, 0x1A, // OBJ_sha1 43 60 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, // OBJ_sha224 … … 48 65 49 66 HASH_TABLE mHash[] = { 50 { L"SHA1", 20, &mHashOidValue[ 8], 5, Sha1GetContextSize, Sha1Init, Sha1Update, Sha1Final },51 { L"SHA224", 28, &mHashOidValue[ 13],9, NULL, NULL, NULL, NULL },52 { L"SHA256", 32, &mHashOidValue[ 22], 9, Sha256GetContextSize,Sha256Init, Sha256Update, Sha256Final},53 { L"SHA384", 48, &mHashOidValue[ 31], 9, NULL, NULL, NULL, NULL },54 { L"SHA512", 64, &mHashOidValue[ 40], 9, NULL, NULL, NULL, NULL }67 { L"SHA1", 20, &mHashOidValue[0], 5, Sha1GetContextSize, Sha1Init, Sha1Update, Sha1Final }, 68 { L"SHA224", 28, &mHashOidValue[5], 9, NULL, NULL, NULL, NULL }, 69 { L"SHA256", 32, &mHashOidValue[14], 9, Sha256GetContextSize,Sha256Init, Sha256Update, Sha256Final}, 70 { L"SHA384", 48, &mHashOidValue[23], 9, NULL, NULL, NULL, NULL }, 71 { L"SHA512", 64, &mHashOidValue[32], 9, NULL, NULL, NULL, NULL } 55 72 }; 73 74 /** 75 SecureBoot Hook for processing image verification. 76 77 @param[in] VariableName Name of Variable to be found. 78 @param[in] VendorGuid Variable vendor GUID. 79 @param[in] DataSize Size of Data found. If size is less than the 80 data, this value contains the required size. 81 @param[in] Data Data pointer. 82 83 **/ 84 VOID 85 EFIAPI 86 SecureBootHook ( 87 IN CHAR16 *VariableName, 88 IN EFI_GUID *VendorGuid, 89 IN UINTN DataSize, 90 IN VOID *Data 91 ); 56 92 57 93 /** 58 94 Reads contents of a PE/COFF image in memory buffer. 95 96 Caution: This function may receive untrusted input. 97 PE/COFF image is external input, so this function will make sure the PE/COFF image content 98 read is within the image buffer. 59 99 60 100 @param FileHandle Pointer to the file handle to read the PE/COFF image. … … 118 158 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; 119 159 EFI_BLOCK_IO_PROTOCOL *BlockIo; 160 161 if (File == NULL) { 162 return IMAGE_UNKNOWN; 163 } 120 164 121 165 // … … 230 274 PE/COFF Specification 8.0 Appendix A 231 275 276 Caution: This function may receive untrusted input. 277 PE/COFF image is external input, so this function will validate its data structure 278 within this image buffer before use. 279 232 280 @param[in] HashAlg Hash algorithm type. 233 281 … … 298 346 // But CheckSum field and SECURITY data directory (certificate) are excluded 299 347 // 300 Magic = mNtHeader.Pe32->OptionalHeader.Magic; 348 if (mNtHeader.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { 349 // 350 // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value 351 // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the 352 // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC 353 // then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC 354 // 355 Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; 356 } else { 357 // 358 // Get the magic value from the PE/COFF Optional Header 359 // 360 Magic = mNtHeader.Pe32->OptionalHeader.Magic; 361 } 362 301 363 // 302 364 // 3. Calculate the distance from the base of the image header to the image checksum address. … … 537 599 8.0 Appendix A 538 600 601 Caution: This function may receive untrusted input. 602 PE/COFF image is external input, so this function will validate its data structure 603 within this image buffer before use. 604 605 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed image. 606 @param[in] AuthDataSize Size of the Authenticode Signature in bytes. 607 539 608 @retval EFI_UNSUPPORTED Hash algorithm is not supported. 540 609 @retval EFI_SUCCESS Hash successfully. … … 543 612 EFI_STATUS 544 613 HashPeImageByType ( 545 VOID 614 IN UINT8 *AuthData, 615 IN UINTN AuthDataSize 546 616 ) 547 617 { 548 618 UINT8 Index; 549 WIN_CERTIFICATE_EFI_PKCS *PkcsCertData;550 551 PkcsCertData = (WIN_CERTIFICATE_EFI_PKCS *) (mImageBase + mSecDataDir->VirtualAddress);552 553 if (PkcsCertData->Hdr.dwLength < sizeof (WIN_CERTIFICATE_EFI_PKCS) + 32) {554 return EFI_UNSUPPORTED;555 }556 619 557 620 for (Index = 0; Index < HASHALG_MAX; Index++) { … … 568 631 // Fixed offset (+32) is calculated based on two bytes of length encoding. 569 632 // 570 if ((*( PkcsCertData->CertData + 1) & TWO_BYTE_ENCODE) != TWO_BYTE_ENCODE) {633 if ((*(AuthData + 1) & TWO_BYTE_ENCODE) != TWO_BYTE_ENCODE) { 571 634 // 572 635 // Only support two bytes of Long Form of Length Encoding. … … 575 638 } 576 639 577 if ( PkcsCertData->Hdr.dwLength < sizeof (WIN_CERTIFICATE_EFI_PKCS) +32 + mHash[Index].OidLength) {640 if (AuthDataSize < 32 + mHash[Index].OidLength) { 578 641 return EFI_UNSUPPORTED; 579 642 } 580 643 581 if (CompareMem ( PkcsCertData->CertData + 32, mHash[Index].OidValue, mHash[Index].OidLength) == 0) {644 if (CompareMem (AuthData + 32, mHash[Index].OidValue, mHash[Index].OidLength) == 0) { 582 645 break; 583 646 } … … 672 735 if (Name != NULL) { 673 736 NameStringLen = StrSize (Name); 674 } 675 676 ImageExeInfoTable = NULL; 737 } else { 738 NameStringLen = sizeof (CHAR16); 739 } 740 677 741 EfiGetSystemConfigurationTable (&gEfiImageSecurityDatabaseGuid, (VOID **) &ImageExeInfoTable); 678 742 if (ImageExeInfoTable != NULL) { 679 743 // 680 744 // The table has been found! 681 // We must enlarge the table to acc modate the new exe info entry.745 // We must enlarge the table to accomodate the new exe info entry. 682 746 // 683 747 ImageExeInfoTableSize = GetImageExeInfoTableSize (ImageExeInfoTable); … … 691 755 692 756 DevicePathSize = GetDevicePathSize (DevicePath); 693 NewImageExeInfoEntrySize = sizeof (EFI_IMAGE_EXECUTION_INFO) + NameStringLen + DevicePathSize + SignatureSize;757 NewImageExeInfoEntrySize = sizeof (EFI_IMAGE_EXECUTION_INFO) - sizeof (EFI_SIGNATURE_LIST) + NameStringLen + DevicePathSize + SignatureSize; 694 758 NewImageExeInfoTable = (EFI_IMAGE_EXECUTION_INFO_TABLE *) AllocateRuntimePool (ImageExeInfoTableSize + NewImageExeInfoEntrySize); 695 759 if (NewImageExeInfoTable == NULL) { … … 705 769 ImageExeInfoEntry = (EFI_IMAGE_EXECUTION_INFO *) ((UINT8 *) NewImageExeInfoTable + ImageExeInfoTableSize); 706 770 // 707 // Update new item's info mation.708 // 709 WriteUnaligned32 ((UINT32 *) &ImageExeInfoEntry->Action, Action);710 WriteUnaligned32 ((UINT32 *) &ImageExeInfoEntry->InfoSize, (UINT32) NewImageExeInfoEntrySize);771 // Update new item's information. 772 // 773 WriteUnaligned32 ((UINT32 *) ImageExeInfoEntry, Action); 774 WriteUnaligned32 ((UINT32 *) ((UINT8 *) ImageExeInfoEntry + sizeof (EFI_IMAGE_EXECUTION_ACTION)), (UINT32) NewImageExeInfoEntrySize); 711 775 712 776 if (Name != NULL) { 713 CopyMem ((UINT8 *) &ImageExeInfoEntry->InfoSize + sizeof (UINT32), Name, NameStringLen); 777 CopyMem ((UINT8 *) ImageExeInfoEntry + sizeof (EFI_IMAGE_EXECUTION_ACTION) + sizeof (UINT32), Name, NameStringLen); 778 } else { 779 ZeroMem ((UINT8 *) ImageExeInfoEntry + sizeof (EFI_IMAGE_EXECUTION_ACTION) + sizeof (UINT32), sizeof (CHAR16)); 714 780 } 715 781 CopyMem ( 716 (UINT8 *) &ImageExeInfoEntry->InfoSize+ sizeof (UINT32) + NameStringLen,782 (UINT8 *) ImageExeInfoEntry + sizeof (EFI_IMAGE_EXECUTION_ACTION) + sizeof (UINT32) + NameStringLen, 717 783 DevicePath, 718 784 DevicePathSize … … 720 786 if (Signature != NULL) { 721 787 CopyMem ( 722 (UINT8 *) &ImageExeInfoEntry->InfoSize+ sizeof (UINT32) + NameStringLen + DevicePathSize,788 (UINT8 *) ImageExeInfoEntry + sizeof (EFI_IMAGE_EXECUTION_ACTION) + sizeof (UINT32) + NameStringLen + DevicePathSize, 723 789 Signature, 724 790 SignatureSize … … 736 802 FreePool (ImageExeInfoTable); 737 803 } 738 }739 740 /**741 Discover if the UEFI image is authorized by user's policy setting.742 743 @param[in] Policy Specify platform's policy setting.744 745 @retval EFI_ACCESS_DENIED Image is not allowed to run.746 @retval EFI_SECURITY_VIOLATION Image is deferred.747 @retval EFI_SUCCESS Image is authorized to run.748 749 **/750 EFI_STATUS751 ImageAuthorization (752 IN UINT32 Policy753 )754 {755 EFI_STATUS Status;756 EFI_INPUT_KEY Key;757 758 Status = EFI_ACCESS_DENIED;759 760 switch (Policy) {761 762 case QUERY_USER_ON_SECURITY_VIOLATION:763 do {764 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, mNotifyString1, mNotifyString2, NULL);765 if (Key.UnicodeChar == L'Y' || Key.UnicodeChar == L'y') {766 Status = EFI_SUCCESS;767 break;768 } else if (Key.UnicodeChar == L'N' || Key.UnicodeChar == L'n') {769 Status = EFI_ACCESS_DENIED;770 break;771 } else if (Key.UnicodeChar == L'D' || Key.UnicodeChar == L'd') {772 Status = EFI_SECURITY_VIOLATION;773 break;774 }775 } while (TRUE);776 break;777 778 case ALLOW_EXECUTE_ON_SECURITY_VIOLATION:779 Status = EFI_SUCCESS;780 break;781 782 case DEFER_EXECUTE_ON_SECURITY_VIOLATION:783 Status = EFI_SECURITY_VIOLATION;784 break;785 786 case DENY_EXECUTE_ON_SECURITY_VIOLATION:787 Status = EFI_ACCESS_DENIED;788 break;789 }790 791 return Status;792 804 } 793 805 … … 845 857 CertList = (EFI_SIGNATURE_LIST *) Data; 846 858 while ((DataSize > 0) && (DataSize >= CertList->SignatureListSize)) { 847 CertCount = (CertList->SignatureListSize - CertList->SignatureHeaderSize) / CertList->SignatureSize;859 CertCount = (CertList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - CertList->SignatureHeaderSize) / CertList->SignatureSize; 848 860 Cert = (EFI_SIGNATURE_DATA *) ((UINT8 *) CertList + sizeof (EFI_SIGNATURE_LIST) + CertList->SignatureHeaderSize); 849 861 if ((CertList->SignatureSize == sizeof(EFI_SIGNATURE_DATA) - 1 + SignatureSize) && (CompareGuid(&CertList->SignatureType, CertType))) { … … 854 866 // 855 867 IsFound = TRUE; 868 SecureBootHook (VariableName, &gEfiImageSecurityDatabaseGuid, CertList->SignatureSize, Cert); 856 869 break; 857 870 } … … 881 894 as EFI_SIGNATURE_LIST. The Variable may be PK, KEK, DB or DBX. 882 895 883 @param VariableName Name of Variable to search for Certificate. 884 @param VendorGuid Variable vendor GUID. 896 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed image. 897 @param[in] AuthDataSize Size of the Authenticode Signature in bytes. 898 @param[in] VariableName Name of Variable to search for Certificate. 899 @param[in] VendorGuid Variable vendor GUID. 885 900 886 901 @retval TRUE Image pass verification. … … 890 905 BOOLEAN 891 906 IsPkcsSignedDataVerifiedBySignatureList ( 907 IN UINT8 *AuthData, 908 IN UINTN AuthDataSize, 892 909 IN CHAR16 *VariableName, 893 910 IN EFI_GUID *VendorGuid … … 896 913 EFI_STATUS Status; 897 914 BOOLEAN VerifyStatus; 898 WIN_CERTIFICATE_EFI_PKCS *PkcsCertData;899 915 EFI_SIGNATURE_LIST *CertList; 900 916 EFI_SIGNATURE_DATA *Cert; … … 912 928 RootCertSize = 0; 913 929 VerifyStatus = FALSE; 914 PkcsCertData = (WIN_CERTIFICATE_EFI_PKCS *) (mImageBase + mSecDataDir->VirtualAddress);915 930 916 931 DataSize = 0; … … 940 955 // 941 956 RootCert = Cert->SignatureData; 942 RootCertSize = CertList->SignatureSize ;957 RootCertSize = CertList->SignatureSize - sizeof (EFI_GUID); 943 958 944 959 // … … 946 961 // 947 962 VerifyStatus = AuthenticodeVerify ( 948 PkcsCertData->CertData,949 mSecDataDir->Size - sizeof(PkcsCertData->Hdr),963 AuthData, 964 AuthDataSize, 950 965 RootCert, 951 966 RootCertSize, … … 954 969 ); 955 970 if (VerifyStatus) { 971 SecureBootHook (VariableName, VendorGuid, CertList->SignatureSize, Cert); 956 972 goto Done; 957 973 } … … 973 989 974 990 /** 975 Verify certificate in WIN_CERT_TYPE_PKCS_SIGNED_DATA format.976 977 @retval EFI_SUCCESS Image pass verification.978 @retval EFI_SECURITY_VIOLATION Image fail verification.979 980 **/981 EFI_STATUS982 VerifyCertPkcsSignedData (983 VOID984 )985 {986 //987 // 1: Find certificate from DBX forbidden database for revoked certificate.988 //989 if (IsPkcsSignedDataVerifiedBySignatureList (EFI_IMAGE_SECURITY_DATABASE1, &gEfiImageSecurityDatabaseGuid)) {990 //991 // DBX is forbidden database, if Authenticode verification pass with992 // one of the certificate in DBX, this image should be rejected.993 //994 return EFI_SECURITY_VIOLATION;995 }996 997 //998 // 2: Find certificate from KEK database and try to verify authenticode struct.999 //1000 if (IsPkcsSignedDataVerifiedBySignatureList (EFI_KEY_EXCHANGE_KEY_NAME, &gEfiGlobalVariableGuid)) {1001 return EFI_SUCCESS;1002 }1003 1004 //1005 // 3: Find certificate from DB database and try to verify authenticode struct.1006 //1007 if (IsPkcsSignedDataVerifiedBySignatureList (EFI_IMAGE_SECURITY_DATABASE, &gEfiImageSecurityDatabaseGuid)) {1008 return EFI_SUCCESS;1009 } else {1010 return EFI_SECURITY_VIOLATION;1011 }1012 }1013 1014 /**1015 Verify certificate in WIN_CERTIFICATE_UEFI_GUID format.1016 1017 @retval EFI_SUCCESS Image pass verification.1018 @retval EFI_SECURITY_VIOLATION Image fail verification.1019 @retval other error value1020 1021 **/1022 EFI_STATUS1023 VerifyCertUefiGuid (1024 VOID1025 )1026 {1027 BOOLEAN Status;1028 WIN_CERTIFICATE_UEFI_GUID *EfiCert;1029 EFI_SIGNATURE_LIST *KekList;1030 EFI_SIGNATURE_DATA *KekItem;1031 EFI_CERT_BLOCK_RSA_2048_SHA256 *CertBlock;1032 VOID *Rsa;1033 UINTN KekCount;1034 UINTN Index;1035 UINTN KekDataSize;1036 BOOLEAN IsFound;1037 EFI_STATUS Result;1038 1039 EfiCert = NULL;1040 KekList = NULL;1041 KekItem = NULL;1042 CertBlock = NULL;1043 Rsa = NULL;1044 Status = FALSE;1045 IsFound = FALSE;1046 KekDataSize = 0;1047 1048 EfiCert = (WIN_CERTIFICATE_UEFI_GUID *) (mImageBase + mSecDataDir->VirtualAddress);1049 CertBlock = (EFI_CERT_BLOCK_RSA_2048_SHA256 *) EfiCert->CertData;1050 if (!CompareGuid (&EfiCert->CertType, &gEfiCertTypeRsa2048Sha256Guid)) {1051 //1052 // Invalid Certificate Data Type.1053 //1054 return EFI_SECURITY_VIOLATION;1055 }1056 1057 //1058 // Get KEK database variable data size1059 //1060 Result = gRT->GetVariable (EFI_KEY_EXCHANGE_KEY_NAME, &gEfiGlobalVariableGuid, NULL, &KekDataSize, NULL);1061 if (Result != EFI_BUFFER_TOO_SMALL) {1062 return EFI_SECURITY_VIOLATION;1063 }1064 1065 //1066 // Get KEK database variable.1067 //1068 KekList = GetEfiGlobalVariable (EFI_KEY_EXCHANGE_KEY_NAME);1069 if (KekList == NULL) {1070 return EFI_SECURITY_VIOLATION;1071 }1072 1073 //1074 // Enumerate all Kek items in this list to verify the variable certificate data.1075 // If anyone is authenticated successfully, it means the variable is correct!1076 //1077 while ((KekDataSize > 0) && (KekDataSize >= KekList->SignatureListSize)) {1078 if (CompareGuid (&KekList->SignatureType, &gEfiCertRsa2048Guid)) {1079 KekItem = (EFI_SIGNATURE_DATA *) ((UINT8 *) KekList + sizeof (EFI_SIGNATURE_LIST) + KekList->SignatureHeaderSize);1080 KekCount = (KekList->SignatureListSize - sizeof (EFI_SIGNATURE_LIST) - KekList->SignatureHeaderSize) / KekList->SignatureSize;1081 for (Index = 0; Index < KekCount; Index++) {1082 if (CompareMem (KekItem->SignatureData, CertBlock->PublicKey, EFI_CERT_TYPE_RSA2048_SIZE) == 0) {1083 IsFound = TRUE;1084 break;1085 }1086 KekItem = (EFI_SIGNATURE_DATA *) ((UINT8 *) KekItem + KekList->SignatureSize);1087 }1088 }1089 KekDataSize -= KekList->SignatureListSize;1090 KekList = (EFI_SIGNATURE_LIST *) ((UINT8 *) KekList + KekList->SignatureListSize);1091 }1092 1093 if (!IsFound) {1094 //1095 // Signed key is not a trust one.1096 //1097 goto Done;1098 }1099 1100 //1101 // Now, we found the corresponding security policy.1102 // Verify the data payload.1103 //1104 Rsa = RsaNew ();1105 if (Rsa == NULL) {1106 Status = FALSE;1107 goto Done;1108 }1109 1110 //1111 // Set RSA Key Components.1112 // NOTE: Only N and E are needed to be set as RSA public key for signature verification.1113 //1114 Status = RsaSetKey (Rsa, RsaKeyN, CertBlock->PublicKey, EFI_CERT_TYPE_RSA2048_SIZE);1115 if (!Status) {1116 goto Done;1117 }1118 Status = RsaSetKey (Rsa, RsaKeyE, mRsaE, sizeof (mRsaE));1119 if (!Status) {1120 goto Done;1121 }1122 //1123 // Verify the signature.1124 //1125 Status = RsaPkcs1Verify (1126 Rsa,1127 mImageDigest,1128 mImageDigestSize,1129 CertBlock->Signature,1130 EFI_CERT_TYPE_RSA2048_SHA256_SIZE1131 );1132 1133 Done:1134 if (KekList != NULL) {1135 FreePool (KekList);1136 }1137 if (Rsa != NULL ) {1138 RsaFree (Rsa);1139 }1140 if (Status) {1141 return EFI_SUCCESS;1142 } else {1143 return EFI_SECURITY_VIOLATION;1144 }1145 }1146 1147 /**1148 991 Provide verification service for signed images, which include both signature validation 1149 992 and platform policy control. For signature types, both UEFI WIN_CERTIFICATE_UEFI_GUID and … … 1153 996 Executables from FV is bypass, so pass in AuthenticationStatus is ignored. 1154 997 1155 The image verification process is: 1156 Is the Image signed? 1157 If yes, 1158 Does the image verify against a certificate (root or intermediate) in the allowed db? 1159 Run it 1160 Image verification fail 1161 Is the Image's Hash not in forbidden database and the Image's Hash in allowed db? 1162 Run it 1163 If no, 1164 Is the Image's Hash in the forbidden database (DBX)? 1165 if yes, 1166 Error out 1167 Is the Image's Hash in the allowed database (DB)? 1168 If yes, 1169 Run it 1170 If no, 1171 Error out 998 The image verification policy is: 999 If the image is signed, 1000 At least one valid signature or at least one hash value of the image must match a record 1001 in the security database "db", and no valid signature nor any hash value of the image may 1002 be reflected in the security database "dbx". 1003 Otherwise, the image is not signed, 1004 The SHA256 hash value of the image must match a record in the security database "db", and 1005 not be reflected in the security data base "dbx". 1006 1007 Caution: This function may receive untrusted input. 1008 PE/COFF image is external input, so this function will validate its data structure 1009 within this image buffer before use. 1172 1010 1173 1011 @param[in] AuthenticationStatus … … 1178 1016 @param[in] FileBuffer File buffer matches the input file device path. 1179 1017 @param[in] FileSize Size of File buffer matches the input file device path. 1180 1181 @retval EFI_SUCCESS The file specified by File did authenticate, and the 1182 platform policy dictates that the DXE Core may use File. 1183 @retval EFI_INVALID_PARAMETER Input argument is incorrect. 1018 @param[in] BootPolicy A boot policy that was used to call LoadImage() UEFI service. 1019 1020 @retval EFI_SUCCESS The file specified by DevicePath and non-NULL 1021 FileBuffer did authenticate, and the platform policy dictates 1022 that the DXE Foundation may use the file. 1023 @retval EFI_SUCCESS The device path specified by NULL device path DevicePath 1024 and non-NULL FileBuffer did authenticate, and the platform 1025 policy dictates that the DXE Foundation may execute the image in 1026 FileBuffer. 1184 1027 @retval EFI_OUT_RESOURCE Fail to allocate memory. 1185 1028 @retval EFI_SECURITY_VIOLATION The file specified by File did not authenticate, and 1186 1029 the platform policy dictates that File should be placed 1187 in the untrusted state. A file may be promoted from 1188 the untrusted to the trusted state at a future time 1189 with a call to the Trust() DXE Service. 1190 @retval EFI_ACCESS_DENIED The file specified by File did not authenticate, and 1191 the platform policy dictates that File should not be 1192 used for any purpose. 1030 in the untrusted state. The image has been added to the file 1031 execution table. 1032 @retval EFI_ACCESS_DENIED The file specified by File and FileBuffer did not 1033 authenticate, and the platform policy dictates that the DXE 1034 Foundation many not use File. 1193 1035 1194 1036 **/ … … 1199 1041 IN CONST EFI_DEVICE_PATH_PROTOCOL *File, 1200 1042 IN VOID *FileBuffer, 1201 IN UINTN FileSize 1043 IN UINTN FileSize, 1044 IN BOOLEAN BootPolicy 1202 1045 ) 1203 1046 { … … 1206 1049 EFI_IMAGE_DOS_HEADER *DosHdr; 1207 1050 EFI_STATUS VerifyStatus; 1208 UINT8 *SetupMode;1209 1051 EFI_SIGNATURE_LIST *SignatureList; 1210 1052 UINTN SignatureListSize; … … 1213 1055 WIN_CERTIFICATE *WinCertificate; 1214 1056 UINT32 Policy; 1215 UINT8 *SecureBoot Enable;1057 UINT8 *SecureBoot; 1216 1058 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; 1217 1059 UINT32 NumberOfRvaAndSizes; 1218 UINT32 CertSize; 1219 1220 if (File == NULL) { 1221 return EFI_INVALID_PARAMETER; 1222 } 1060 WIN_CERTIFICATE_EFI_PKCS *PkcsCertData; 1061 WIN_CERTIFICATE_UEFI_GUID *WinCertUefiGuid; 1062 UINT8 *AuthData; 1063 UINTN AuthDataSize; 1064 EFI_IMAGE_DATA_DIRECTORY *SecDataDir; 1065 UINT32 OffSet; 1066 CHAR16 *NameStr; 1223 1067 1224 1068 SignatureList = NULL; 1225 1069 SignatureListSize = 0; 1226 1070 WinCertificate = NULL; 1071 SecDataDir = NULL; 1072 PkcsCertData = NULL; 1227 1073 Action = EFI_IMAGE_EXECUTION_AUTH_UNTESTED; 1228 1074 Status = EFI_ACCESS_DENIED; 1075 VerifyStatus = EFI_ACCESS_DENIED; 1076 1229 1077 // 1230 1078 // Check the image type and get policy setting. … … 1261 1109 } 1262 1110 1263 SecureBootEnable = GetVariable (EFI_SECURE_BOOT_ENABLE_NAME, &gEfiSecureBootEnableDisableGuid); 1264 // 1265 // Skip verification if SecureBootEnable variable doesn't exist. 1266 // 1267 if (SecureBootEnable == NULL) { 1111 // 1112 // The policy QUERY_USER_ON_SECURITY_VIOLATION and ALLOW_EXECUTE_ON_SECURITY_VIOLATION 1113 // violates the UEFI spec and has been removed. 1114 // 1115 ASSERT (Policy != QUERY_USER_ON_SECURITY_VIOLATION && Policy != ALLOW_EXECUTE_ON_SECURITY_VIOLATION); 1116 if (Policy == QUERY_USER_ON_SECURITY_VIOLATION || Policy == ALLOW_EXECUTE_ON_SECURITY_VIOLATION) { 1117 CpuDeadLoop (); 1118 } 1119 1120 GetEfiGlobalVariable2 (EFI_SECURE_BOOT_MODE_NAME, (VOID**)&SecureBoot, NULL); 1121 // 1122 // Skip verification if SecureBoot variable doesn't exist. 1123 // 1124 if (SecureBoot == NULL) { 1268 1125 return EFI_SUCCESS; 1269 1126 } 1270 1127 1271 1128 // 1272 // Skip verification if SecureBoot Enableis disabled.1273 // 1274 if (*SecureBoot Enable == SECURE_BOOT_DISABLE) {1275 FreePool (SecureBoot Enable);1129 // Skip verification if SecureBoot is disabled. 1130 // 1131 if (*SecureBoot == SECURE_BOOT_MODE_DISABLE) { 1132 FreePool (SecureBoot); 1276 1133 return EFI_SUCCESS; 1277 1134 } 1278 1279 FreePool (SecureBootEnable); 1280 1281 SetupMode = GetEfiGlobalVariable (EFI_SETUP_MODE_NAME); 1282 1283 // 1284 // SetupMode doesn't exist means no AuthVar driver is dispatched, 1285 // skip verification. 1286 // 1287 if (SetupMode == NULL) { 1288 return EFI_SUCCESS; 1289 } 1290 1291 // 1292 // If platform is in SETUP MODE, skip verification. 1293 // 1294 if (*SetupMode == SETUP_MODE) { 1295 FreePool (SetupMode); 1296 return EFI_SUCCESS; 1297 } 1298 1299 FreePool (SetupMode); 1135 FreePool (SecureBoot); 1300 1136 1301 1137 // … … 1347 1183 } 1348 1184 1349 Magic = mNtHeader.Pe32->OptionalHeader.Magic; 1185 if (mNtHeader.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { 1186 // 1187 // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value 1188 // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the 1189 // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC 1190 // then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC 1191 // 1192 Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; 1193 } else { 1194 // 1195 // Get the magic value from the PE/COFF Optional Header 1196 // 1197 Magic = mNtHeader.Pe32->OptionalHeader.Magic; 1198 } 1199 1350 1200 if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { 1351 1201 // … … 1354 1204 NumberOfRvaAndSizes = mNtHeader.Pe32->OptionalHeader.NumberOfRvaAndSizes; 1355 1205 if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_SECURITY) { 1356 mSecDataDir = (EFI_IMAGE_DATA_DIRECTORY *) &mNtHeader.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY];1206 SecDataDir = (EFI_IMAGE_DATA_DIRECTORY *) &mNtHeader.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]; 1357 1207 } 1358 1208 } else { … … 1362 1212 NumberOfRvaAndSizes = mNtHeader.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes; 1363 1213 if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_SECURITY) { 1364 mSecDataDir = (EFI_IMAGE_DATA_DIRECTORY *) &mNtHeader.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]; 1365 } 1366 } 1367 1368 if ((mSecDataDir == NULL) || ((mSecDataDir != NULL) && (mSecDataDir->Size == 0))) { 1369 // 1370 // This image is not signed. 1214 SecDataDir = (EFI_IMAGE_DATA_DIRECTORY *) &mNtHeader.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]; 1215 } 1216 } 1217 1218 // 1219 // Start Image Validation. 1220 // 1221 if (SecDataDir == NULL || SecDataDir->Size == 0) { 1222 // 1223 // This image is not signed. The SHA256 hash value of the image must match a record in the security database "db", 1224 // and not be reflected in the security data base "dbx". 1371 1225 // 1372 1226 if (!HashPeImage (HASHALG_SHA256)) { … … 1395 1249 1396 1250 // 1397 // Verify signature of executables. 1398 // 1399 WinCertificate = (WIN_CERTIFICATE *) (mImageBase + mSecDataDir->VirtualAddress); 1400 1401 CertSize = sizeof (WIN_CERTIFICATE); 1402 1403 if ((mSecDataDir->Size <= CertSize) || (mSecDataDir->Size < WinCertificate->dwLength)) { 1404 goto Done; 1405 } 1406 1407 switch (WinCertificate->wCertificateType) { 1408 1409 case WIN_CERT_TYPE_EFI_GUID: 1410 CertSize = sizeof (WIN_CERTIFICATE_UEFI_GUID) + sizeof (EFI_CERT_BLOCK_RSA_2048_SHA256) - sizeof (UINT8); 1411 if (WinCertificate->dwLength < CertSize) { 1412 goto Done; 1413 } 1414 1415 // 1416 // Verify UEFI GUID type. 1417 // 1418 if (!HashPeImage (HASHALG_SHA256)) { 1419 goto Done; 1420 } 1421 1422 VerifyStatus = VerifyCertUefiGuid (); 1423 break; 1424 1425 case WIN_CERT_TYPE_PKCS_SIGNED_DATA: 1426 // 1427 // Verify Pkcs signed data type. 1428 // 1429 Status = HashPeImageByType(); 1251 // Verify the signature of the image, multiple signatures are allowed as per PE/COFF Section 4.7 1252 // "Attribute Certificate Table". 1253 // The first certificate starts at offset (SecDataDir->VirtualAddress) from the start of the file. 1254 // 1255 for (OffSet = SecDataDir->VirtualAddress; 1256 OffSet < (SecDataDir->VirtualAddress + SecDataDir->Size); 1257 OffSet += (WinCertificate->dwLength + ALIGN_SIZE (WinCertificate->dwLength))) { 1258 WinCertificate = (WIN_CERTIFICATE *) (mImageBase + OffSet); 1259 if ((SecDataDir->VirtualAddress + SecDataDir->Size - OffSet) <= sizeof (WIN_CERTIFICATE) || 1260 (SecDataDir->VirtualAddress + SecDataDir->Size - OffSet) < WinCertificate->dwLength) { 1261 break; 1262 } 1263 1264 // 1265 // Verify the image's Authenticode signature, only DER-encoded PKCS#7 signed data is supported. 1266 // 1267 if (WinCertificate->wCertificateType == WIN_CERT_TYPE_PKCS_SIGNED_DATA) { 1268 // 1269 // The certificate is formatted as WIN_CERTIFICATE_EFI_PKCS which is described in the 1270 // Authenticode specification. 1271 // 1272 PkcsCertData = (WIN_CERTIFICATE_EFI_PKCS *) WinCertificate; 1273 if (PkcsCertData->Hdr.dwLength <= sizeof (PkcsCertData->Hdr)) { 1274 break; 1275 } 1276 AuthData = PkcsCertData->CertData; 1277 AuthDataSize = PkcsCertData->Hdr.dwLength - sizeof(PkcsCertData->Hdr); 1278 } else if (WinCertificate->wCertificateType == WIN_CERT_TYPE_EFI_GUID) { 1279 // 1280 // The certificate is formatted as WIN_CERTIFICATE_UEFI_GUID which is described in UEFI Spec. 1281 // 1282 WinCertUefiGuid = (WIN_CERTIFICATE_UEFI_GUID *) WinCertificate; 1283 if (WinCertUefiGuid->Hdr.dwLength <= OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID, CertData)) { 1284 break; 1285 } 1286 if (!CompareGuid (&WinCertUefiGuid->CertType, &gEfiCertPkcs7Guid)) { 1287 continue; 1288 } 1289 AuthData = WinCertUefiGuid->CertData; 1290 AuthDataSize = WinCertUefiGuid->Hdr.dwLength - OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID, CertData); 1291 } else { 1292 if (WinCertificate->dwLength < sizeof (WIN_CERTIFICATE)) { 1293 break; 1294 } 1295 continue; 1296 } 1297 1298 Status = HashPeImageByType (AuthData, AuthDataSize); 1430 1299 if (EFI_ERROR (Status)) { 1431 goto Done; 1432 } 1433 1434 VerifyStatus = VerifyCertPkcsSignedData (); 1435 1436 // 1437 // For image verification against enrolled certificate(root or intermediate), 1438 // no need to check image's hash in the allowed database. 1439 // 1440 if (!EFI_ERROR (VerifyStatus)) { 1441 if (!IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE1, mImageDigest, &mCertType, mImageDigestSize)) { 1442 return EFI_SUCCESS; 1443 } 1444 } 1445 break; 1446 1447 default: 1448 goto Done; 1449 } 1450 // 1451 // Get image hash value as executable's signature. 1452 // 1453 SignatureListSize = sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + mImageDigestSize; 1454 SignatureList = (EFI_SIGNATURE_LIST *) AllocateZeroPool (SignatureListSize); 1455 if (SignatureList == NULL) { 1456 Status = EFI_OUT_OF_RESOURCES; 1457 goto Done; 1458 } 1459 SignatureList->SignatureHeaderSize = 0; 1460 SignatureList->SignatureListSize = (UINT32) SignatureListSize; 1461 SignatureList->SignatureSize = (UINT32) mImageDigestSize; 1462 CopyMem (&SignatureList->SignatureType, &mCertType, sizeof (EFI_GUID)); 1463 Signature = (EFI_SIGNATURE_DATA *) ((UINT8 *) SignatureList + sizeof (EFI_SIGNATURE_LIST)); 1464 CopyMem (Signature->SignatureData, mImageDigest, mImageDigestSize); 1465 // 1466 // Signature database check after verification. 1467 // 1468 if (EFI_ERROR (VerifyStatus)) { 1469 // 1470 // Verification failure. 1471 // 1472 if (!IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE1, mImageDigest, &mCertType, mImageDigestSize) && 1473 IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE, mImageDigest, &mCertType, mImageDigestSize)) { 1474 // 1475 // Verification fail, Image Hash is not in forbidden database (DBX), 1476 // and Image Hash is in allowed database (DB). 1477 // 1478 Status = EFI_SUCCESS; 1479 } else { 1300 continue; 1301 } 1302 1303 // 1304 // Check the digital signature against the revoked certificate in forbidden database (dbx). 1305 // 1306 if (IsPkcsSignedDataVerifiedBySignatureList (AuthData, AuthDataSize, EFI_IMAGE_SECURITY_DATABASE1, &gEfiImageSecurityDatabaseGuid)) { 1480 1307 Action = EFI_IMAGE_EXECUTION_AUTH_SIG_FAILED; 1481 Status = EFI_ACCESS_DENIED; 1482 } 1483 } else if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE1, Signature->SignatureData, &mCertType, mImageDigestSize)) { 1484 // 1485 // Executable signature verification passes, but is found in forbidden signature database. 1486 // 1487 Action = EFI_IMAGE_EXECUTION_AUTH_SIG_FOUND; 1308 VerifyStatus = EFI_ACCESS_DENIED; 1309 break; 1310 } 1311 1312 // 1313 // Check the digital signature against the valid certificate in allowed database (db). 1314 // 1315 if (EFI_ERROR (VerifyStatus)) { 1316 if (IsPkcsSignedDataVerifiedBySignatureList (AuthData, AuthDataSize, EFI_IMAGE_SECURITY_DATABASE, &gEfiImageSecurityDatabaseGuid)) { 1317 VerifyStatus = EFI_SUCCESS; 1318 } 1319 } 1320 1321 // 1322 // Check the image's hash value. 1323 // 1324 if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE1, mImageDigest, &mCertType, mImageDigestSize)) { 1325 Action = EFI_IMAGE_EXECUTION_AUTH_SIG_FOUND; 1326 VerifyStatus = EFI_ACCESS_DENIED; 1327 break; 1328 } else if (EFI_ERROR (VerifyStatus)) { 1329 if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE, mImageDigest, &mCertType, mImageDigestSize)) { 1330 VerifyStatus = EFI_SUCCESS; 1331 } 1332 } 1333 } 1334 1335 if (OffSet != (SecDataDir->VirtualAddress + SecDataDir->Size)) { 1336 // 1337 // The Size in Certificate Table or the attribute certicate table is corrupted. 1338 // 1339 VerifyStatus = EFI_ACCESS_DENIED; 1340 } 1341 1342 if (!EFI_ERROR (VerifyStatus)) { 1343 return EFI_SUCCESS; 1344 } else { 1488 1345 Status = EFI_ACCESS_DENIED; 1489 } else if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE, Signature->SignatureData, &mCertType, mImageDigestSize)) { 1490 // 1491 // Executable signature is found in authorized signature database. 1492 // 1493 Status = EFI_SUCCESS; 1494 } else { 1495 // 1496 // Executable signature verification passes, but cannot be found in authorized signature database. 1497 // Get platform policy to determine the action. 1498 // 1499 Action = EFI_IMAGE_EXECUTION_AUTH_SIG_PASSED; 1500 Status = ImageAuthorization (Policy); 1346 if (Action == EFI_IMAGE_EXECUTION_AUTH_SIG_FAILED || Action == EFI_IMAGE_EXECUTION_AUTH_SIG_FOUND) { 1347 // 1348 // Get image hash value as executable's signature. 1349 // 1350 SignatureListSize = sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + mImageDigestSize; 1351 SignatureList = (EFI_SIGNATURE_LIST *) AllocateZeroPool (SignatureListSize); 1352 if (SignatureList == NULL) { 1353 Status = EFI_OUT_OF_RESOURCES; 1354 goto Done; 1355 } 1356 SignatureList->SignatureHeaderSize = 0; 1357 SignatureList->SignatureListSize = (UINT32) SignatureListSize; 1358 SignatureList->SignatureSize = (UINT32) mImageDigestSize; 1359 CopyMem (&SignatureList->SignatureType, &mCertType, sizeof (EFI_GUID)); 1360 Signature = (EFI_SIGNATURE_DATA *) ((UINT8 *) SignatureList + sizeof (EFI_SIGNATURE_LIST)); 1361 CopyMem (Signature->SignatureData, mImageDigest, mImageDigestSize); 1362 } 1501 1363 } 1502 1364 … … 1506 1368 // Policy decides to defer or reject the image; add its information in image executable information table. 1507 1369 // 1508 AddImageExeInfo (Action, NULL, File, SignatureList, SignatureListSize); 1370 NameStr = ConvertDevicePathToText (File, FALSE, TRUE); 1371 AddImageExeInfo (Action, NameStr, File, SignatureList, SignatureListSize); 1372 if (NameStr != NULL) { 1373 DEBUG((EFI_D_INFO, "The image doesn't pass verification: %s\n", NameStr)); 1374 FreePool(NameStr); 1375 } 1376 Status = EFI_SECURITY_VIOLATION; 1509 1377 } 1510 1378 … … 1517 1385 1518 1386 /** 1519 When VariableWriteArchProtocol install, create "SecureBoot" variable. 1520 1521 @param[in] Event Event whose notification function is being invoked. 1522 @param[in] Context Pointer to the notification function's context. 1387 On Ready To Boot Services Event notification handler. 1388 1389 Add the image execution information table if it is not in system configuration table. 1390 1391 @param[in] Event Event whose notification function is being invoked 1392 @param[in] Context Pointer to the notification function's context 1523 1393 1524 1394 **/ 1525 1395 VOID 1526 1396 EFIAPI 1527 VariableWriteCallBack(1528 IN EFI_EVENTEvent,1529 IN VOID*Context1397 OnReadyToBoot ( 1398 IN EFI_EVENT Event, 1399 IN VOID *Context 1530 1400 ) 1531 1401 { 1532 UINT8 SecureBootMode; 1533 UINT8 *SecureBootModePtr; 1534 EFI_STATUS Status; 1535 VOID *ProtocolPointer; 1536 1537 Status = gBS->LocateProtocol (&gEfiVariableWriteArchProtocolGuid, NULL, &ProtocolPointer); 1538 if (EFI_ERROR (Status)) { 1402 EFI_IMAGE_EXECUTION_INFO_TABLE *ImageExeInfoTable; 1403 UINTN ImageExeInfoTableSize; 1404 1405 EfiGetSystemConfigurationTable (&gEfiImageSecurityDatabaseGuid, (VOID **) &ImageExeInfoTable); 1406 if (ImageExeInfoTable != NULL) { 1539 1407 return; 1540 1408 } 1541 1409 1542 // 1543 // Check whether "SecureBoot" variable exists. 1544 // If this library is built-in, it means firmware has capability to perform 1545 // driver signing verification. 1546 // 1547 SecureBootModePtr = GetEfiGlobalVariable (EFI_SECURE_BOOT_MODE_NAME); 1548 if (SecureBootModePtr == NULL) { 1549 SecureBootMode = SECURE_BOOT_MODE_DISABLE; 1550 // 1551 // Authenticated variable driver will update "SecureBoot" depending on SetupMode variable. 1552 // 1553 gRT->SetVariable ( 1554 EFI_SECURE_BOOT_MODE_NAME, 1555 &gEfiGlobalVariableGuid, 1556 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, 1557 sizeof (UINT8), 1558 &SecureBootMode 1559 ); 1560 } else { 1561 FreePool (SecureBootModePtr); 1562 } 1410 ImageExeInfoTableSize = sizeof (EFI_IMAGE_EXECUTION_INFO_TABLE); 1411 ImageExeInfoTable = (EFI_IMAGE_EXECUTION_INFO_TABLE *) AllocateRuntimePool (ImageExeInfoTableSize); 1412 if (ImageExeInfoTable == NULL) { 1413 return ; 1414 } 1415 1416 ImageExeInfoTable->NumberOfImages = 0; 1417 gBS->InstallConfigurationTable (&gEfiImageSecurityDatabaseGuid, (VOID *) ImageExeInfoTable); 1418 1563 1419 } 1564 1420 … … 1578 1434 ) 1579 1435 { 1580 VOID *Registration; 1581 1582 // 1583 // Register callback function upon VariableWriteArchProtocol. 1584 // 1585 EfiCreateProtocolNotifyEvent ( 1586 &gEfiVariableWriteArchProtocolGuid, 1436 EFI_EVENT Event; 1437 1438 // 1439 // Register the event to publish the image execution table. 1440 // 1441 EfiCreateEventReadyToBootEx ( 1587 1442 TPL_CALLBACK, 1588 VariableWriteCallBack,1589 NULL, 1590 & Registration1591 ); 1592 1593 return RegisterSecurity Handler (1443 OnReadyToBoot, 1444 NULL, 1445 &Event 1446 ); 1447 1448 return RegisterSecurity2Handler ( 1594 1449 DxeImageVerificationHandler, 1595 1450 EFI_AUTH_OPERATION_VERIFY_IMAGE | EFI_AUTH_OPERATION_IMAGE_REQUIRED -
trunk/src/VBox/Devices/EFI/Firmware/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.h
r48674 r58459 3 3 internal structure and functions used by ImageVerificationLib. 4 4 5 Copyright (c) 2009 - 201 2, Intel Corporation. All rights reserved.<BR>5 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR> 6 6 This program and the accompanying materials 7 7 are licensed and made available under the terms and conditions of the BSD License … … 44 44 #define TWO_BYTE_ENCODE 0x82 45 45 46 #define ALIGNMENT_SIZE 8 47 #define ALIGN_SIZE(a) (((a) % ALIGNMENT_SIZE) ? ALIGNMENT_SIZE - ((a) % ALIGNMENT_SIZE) : 0) 48 46 49 // 47 50 // Image type definitions -
trunk/src/VBox/Devices/EFI/Firmware/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf
r48674 r58459 1 1 ## @file 2 # The library instance provides security service of image verification. 3 # Image verification Library module supports UEFI2.3.1 2 # Provides security service of image verification 4 3 # 5 # Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR> 4 # This library hooks LoadImage() API to verify every image by the verification policy. 5 # 6 # Caution: This module requires additional review when modified. 7 # This library will have external input - PE/COFF image. 8 # This external input must be validated carefully to avoid security issues such as 9 # buffer overflow or integer overflow. 10 # 11 # Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR> 6 12 # This program and the accompanying materials 7 13 # are licensed and made available under the terms and conditions of the BSD License … … 15 21 [Defines] 16 22 INF_VERSION = 0x00010005 17 BASE_NAME = DxeImageVerificationLib 23 BASE_NAME = DxeImageVerificationLib 24 MODULE_UNI_FILE = DxeImageVerificationLib.uni 18 25 FILE_GUID = 0CA970E1-43FA-4402-BC0A-81AF336BFFD6 19 26 MODULE_TYPE = DXE_DRIVER … … 31 38 DxeImageVerificationLib.c 32 39 DxeImageVerificationLib.h 40 Measurement.c 33 41 34 42 [Packages] … … 50 58 SecurityManagementLib 51 59 PeCoffLib 60 TpmMeasurementLib 52 61 53 62 [Protocols] 54 gEfiFirmwareVolume2ProtocolGuid 55 gEfiBlockIoProtocolGuid 56 gEfiSimpleFileSystemProtocolGuid 57 gEfiVariableWriteArchProtocolGuid 63 gEfiFirmwareVolume2ProtocolGuid ## SOMETIMES_CONSUMES 64 gEfiBlockIoProtocolGuid ## SOMETIMES_CONSUMES 65 gEfiSimpleFileSystemProtocolGuid ## SOMETIMES_CONSUMES 66 67 [Guids] 68 ## SOMETIMES_CONSUMES ## Variable:L"DB" 69 ## SOMETIMES_CONSUMES ## Variable:L"DBX" 70 ## PRODUCES ## SystemTable 71 ## CONSUMES ## SystemTable 72 gEfiImageSecurityDatabaseGuid 73 74 ## SOMETIMES_CONSUMES ## GUID # Unique ID for the type of the signature. 75 ## SOMETIMES_PRODUCES ## GUID # Unique ID for the type of the signature. 76 gEfiCertSha1Guid 58 77 59 [Guids] 60 gEfiCertTypeRsa2048Sha256Guid 61 gEfiImageSecurityDatabaseGuid 62 gEfiCertSha1Guid 78 ## SOMETIMES_CONSUMES ## GUID # Unique ID for the type of the signature. 79 ## SOMETIMES_PRODUCES ## GUID # Unique ID for the type of the signature. 63 80 gEfiCertSha256Guid 64 gEfiCertX509Guid 65 gEfiCert Rsa2048Guid66 gEfi SecureBootEnableDisableGuid81 82 gEfiCertX509Guid ## SOMETIMES_CONSUMES ## GUID # Unique ID for the type of the signature. 83 gEfiCertPkcs7Guid ## SOMETIMES_CONSUMES ## GUID # Unique ID for the type of the certificate. 67 84 68 85 [Pcd] 69 gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy 70 gEfiSecurityPkgTokenSpaceGuid.PcdRemovableMediaImageVerificationPolicy 71 gEfiSecurityPkgTokenSpaceGuid.PcdFixedMediaImageVerificationPolicy 72 86 gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy ## SOMETIMES_CONSUMES 87 gEfiSecurityPkgTokenSpaceGuid.PcdRemovableMediaImageVerificationPolicy ## SOMETIMES_CONSUMES 88 gEfiSecurityPkgTokenSpaceGuid.PcdFixedMediaImageVerificationPolicy ## SOMETIMES_CONSUMES 73 89 74 75 -
trunk/src/VBox/Devices/EFI/Firmware/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c
r48674 r58459 3 3 Execute pending TPM requests from OS or BIOS and Lock TPM. 4 4 5 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR> 5 Caution: This module requires additional review when modified. 6 This driver will have external input - variable. 7 This external input must be validated carefully to avoid security issue. 8 9 ExecutePendingTpmRequest() will receive untrusted input and do validation. 10 11 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR> 6 12 This program and the accompanying materials 7 13 are licensed and made available under the terms and conditions of the BSD License … … 17 23 18 24 #include <Protocol/TcgService.h> 25 #include <Protocol/VariableLock.h> 19 26 #include <Library/DebugLib.h> 20 27 #include <Library/BaseMemoryLib.h> … … 28 35 #include <Guid/EventGroup.h> 29 36 #include <Guid/PhysicalPresenceData.h> 30 31 #define TPM_PP_USER_ABORT ((TPM_RESULT)(-0x10)) 32 #define TPM_PP_BIOS_FAILURE ((TPM_RESULT)(-0x0f)) 37 #include <Library/TcgPpVendorLib.h> 38 33 39 #define CONFIRM_BUFFER_SIZE 4096 34 40 … … 178 184 @param[in] AdditionalParameters Pointer to the Additional paramaters. 179 185 180 @retval T PM_PP_BIOS_FAILUREError occurred during sending command to TPM or181 receiving response from TPM.182 @retval Others Return code from the TPM device after command execution.186 @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Error occurred during sending command to TPM or 187 receiving response from TPM. 188 @retval Others Return code from the TPM device after command execution. 183 189 184 190 **/ 185 TPM_RESULT 191 UINT32 186 192 TpmCommandNoReturnData ( 187 193 IN EFI_TCG_PROTOCOL *TcgProtocol, … … 198 204 TpmRqu = (TPM_RQU_COMMAND_HDR*) AllocatePool (sizeof (*TpmRqu) + AdditionalParameterSize); 199 205 if (TpmRqu == NULL) { 200 return T PM_PP_BIOS_FAILURE;206 return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE; 201 207 } 202 208 … … 216 222 FreePool (TpmRqu); 217 223 if (EFI_ERROR (Status) || (TpmRsp.tag != SwapBytes16 (TPM_TAG_RSP_COMMAND))) { 218 return T PM_PP_BIOS_FAILURE;224 return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE; 219 225 } 220 226 return SwapBytes32 (TpmRsp.returnCode); … … 228 234 @param[in, out] PpiFlags The physical presence interface flags. 229 235 230 @retval T PM_PP_BIOS_FAILUREUnknown physical presence operation.231 @retval T PM_PP_BIOS_FAILUREError occurred during sending command to TPM or232 receiving response from TPM.233 @retval Others Return code from the TPM device after command execution.236 @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Unknown physical presence operation. 237 @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Error occurred during sending command to TPM or 238 receiving response from TPM. 239 @retval Others Return code from the TPM device after command execution. 234 240 235 241 **/ 236 TPM_RESULT 242 UINT32 237 243 ExecutePhysicalPresence ( 238 IN EFI_TCG_PROTOCOL *TcgProtocol,239 IN UINT 8CommandCode,240 IN OUT UINT8*PpiFlags244 IN EFI_TCG_PROTOCOL *TcgProtocol, 245 IN UINT32 CommandCode, 246 IN OUT EFI_PHYSICAL_PRESENCE_FLAGS *PpiFlags 241 247 ) 242 248 { 243 249 BOOLEAN BoolVal; 244 TPM_RESULTTpmResponse;250 UINT32 TpmResponse; 245 251 UINT32 InData[5]; 246 252 … … 325 331 // PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE will be executed after reboot 326 332 // 327 if (( *PpiFlags &FLAG_RESET_TRACK) == 0) {333 if ((PpiFlags->PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) == 0) { 328 334 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_ENABLE_ACTIVATE, PpiFlags); 329 *PpiFlags |=FLAG_RESET_TRACK;335 PpiFlags->PPFlags |= TCG_VENDOR_LIB_FLAG_RESET_TRACK; 330 336 } else { 331 337 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE, PpiFlags); 332 *PpiFlags &= ~FLAG_RESET_TRACK;338 PpiFlags->PPFlags &= ~TCG_VENDOR_LIB_FLAG_RESET_TRACK; 333 339 } 334 340 return TpmResponse; … … 360 366 // Here it is NOT implemented 361 367 // 362 return T PM_PP_BIOS_FAILURE;368 return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE; 363 369 364 370 case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE: … … 370 376 371 377 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE: 372 *PpiFlags &= ~FLAG_NO_PPI_PROVISION;378 PpiFlags->PPFlags &= ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION; 373 379 return 0; 374 380 375 381 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE: 376 *PpiFlags |=FLAG_NO_PPI_PROVISION;382 PpiFlags->PPFlags |= TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION; 377 383 return 0; 378 384 379 385 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE: 380 *PpiFlags &= ~FLAG_NO_PPI_CLEAR;386 PpiFlags->PPFlags &= ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR; 381 387 return 0; 382 388 383 389 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE: 384 *PpiFlags |=FLAG_NO_PPI_CLEAR;390 PpiFlags->PPFlags |= TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR; 385 391 return 0; 386 392 387 393 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE: 388 *PpiFlags &= ~FLAG_NO_PPI_MAINTENANCE;394 PpiFlags->PPFlags &= ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENANCE; 389 395 return 0; 390 396 391 397 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE: 392 *PpiFlags |=FLAG_NO_PPI_MAINTENANCE;398 PpiFlags->PPFlags |= TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENANCE; 393 399 return 0; 394 400 395 401 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR: 396 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_ENABLE_ACTIVATE, PpiFlags); 397 if (TpmResponse == 0) { 402 // 403 // PHYSICAL_PRESENCE_ENABLE_ACTIVATE + PHYSICAL_PRESENCE_CLEAR 404 // PHYSICAL_PRESENCE_CLEAR will be executed after reboot. 405 // 406 if ((PpiFlags->PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) == 0) { 407 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_ENABLE_ACTIVATE, PpiFlags); 408 PpiFlags->PPFlags |= TCG_VENDOR_LIB_FLAG_RESET_TRACK; 409 } else { 398 410 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_CLEAR, PpiFlags); 411 PpiFlags->PPFlags &= ~TCG_VENDOR_LIB_FLAG_RESET_TRACK; 399 412 } 400 413 return TpmResponse; … … 403 416 // 404 417 // PHYSICAL_PRESENCE_ENABLE_ACTIVATE + PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE 405 // PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE will be executed a tfer reboot.406 // 407 if (( *PpiFlags &FLAG_RESET_TRACK) == 0) {418 // PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE will be executed after reboot. 419 // 420 if ((PpiFlags->PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) == 0) { 408 421 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_ENABLE_ACTIVATE, PpiFlags); 409 *PpiFlags |=FLAG_RESET_TRACK;422 PpiFlags->PPFlags |= TCG_VENDOR_LIB_FLAG_RESET_TRACK; 410 423 } else { 411 424 TpmResponse = ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE, PpiFlags); 412 *PpiFlags &= ~FLAG_RESET_TRACK;425 PpiFlags->PPFlags &= ~TCG_VENDOR_LIB_FLAG_RESET_TRACK; 413 426 } 414 427 return TpmResponse; … … 417 430 ; 418 431 } 419 return T PM_PP_BIOS_FAILURE;432 return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE; 420 433 } 421 434 … … 428 441 429 442 @retval TRUE User confirmed the changes by input. 430 @retval FALSE User discarded the changes .443 @retval FALSE User discarded the changes or device error. 431 444 432 445 **/ … … 439 452 EFI_INPUT_KEY Key; 440 453 UINT16 InputKey; 441 454 UINTN Index; 455 442 456 InputKey = 0; 443 457 do { 444 Status = gBS->CheckEvent (gST->ConIn->WaitForKey); 445 if (!EFI_ERROR (Status)) { 446 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); 447 if (Key.ScanCode == SCAN_ESC) { 448 InputKey = Key.ScanCode; 449 } 450 if ((Key.ScanCode == SCAN_F10) && !CautionKey) { 451 InputKey = Key.ScanCode; 452 } 453 if ((Key.ScanCode == SCAN_F12) && CautionKey) { 454 InputKey = Key.ScanCode; 455 } 456 } 458 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); 459 if (Status == EFI_NOT_READY) { 460 gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &Index); 461 continue; 462 } 463 464 if (Status == EFI_DEVICE_ERROR) { 465 return FALSE; 466 } 467 468 if (Key.ScanCode == SCAN_ESC) { 469 InputKey = Key.ScanCode; 470 } 471 if ((Key.ScanCode == SCAN_F10) && !CautionKey) { 472 InputKey = Key.ScanCode; 473 } 474 if ((Key.ScanCode == SCAN_F12) && CautionKey) { 475 InputKey = Key.ScanCode; 476 } 457 477 } while (InputKey == 0); 458 478 … … 499 519 BOOLEAN 500 520 UserConfirm ( 501 IN UINT 8TpmPpCommand521 IN UINT32 TpmPpCommand 502 522 ) 503 523 { … … 525 545 526 546 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY)); 527 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);547 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 528 548 FreePool (TmpStr1); 529 549 break; … … 537 557 538 558 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING)); 539 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);559 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 540 560 FreePool (TmpStr1); 541 561 542 562 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY)); 543 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);563 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 544 564 FreePool (TmpStr1); 545 565 break; … … 553 573 554 574 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY)); 555 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);575 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 556 576 FreePool (TmpStr1); 557 577 break; … … 565 585 566 586 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING)); 567 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);587 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 568 588 FreePool (TmpStr1); 569 589 570 590 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY)); 571 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);591 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 572 592 FreePool (TmpStr1); 573 593 break; … … 582 602 583 603 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR)); 584 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);585 StrnCat (ConfirmText, L" \n\n", (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);604 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 605 StrnCat (ConfirmText, L" \n\n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 586 606 FreePool (TmpStr1); 587 607 588 608 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY)); 589 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);609 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 590 610 FreePool (TmpStr1); 591 611 break; … … 599 619 600 620 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON)); 601 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);621 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 602 622 FreePool (TmpStr1); 603 623 604 624 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY)); 605 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);625 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 606 626 FreePool (TmpStr1); 607 627 break; … … 615 635 616 636 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_OFF)); 617 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);637 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 618 638 FreePool (TmpStr1); 619 639 620 640 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING)); 621 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);641 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 622 642 FreePool (TmpStr1); 623 643 624 644 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY)); 625 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);645 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 626 646 FreePool (TmpStr1); 627 647 break; … … 635 655 636 656 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY)); 637 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);657 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 638 658 FreePool (TmpStr1); 639 659 break; … … 647 667 648 668 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY)); 649 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);669 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 650 670 FreePool (TmpStr1); 651 671 break; … … 659 679 660 680 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON)); 661 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);681 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 662 682 FreePool (TmpStr1); 663 683 664 684 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY)); 665 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);685 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 666 686 FreePool (TmpStr1); 667 687 break; … … 675 695 676 696 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_OFF)); 677 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);697 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 678 698 FreePool (TmpStr1); 679 699 680 700 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING)); 681 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);701 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 682 702 FreePool (TmpStr1); 683 703 684 704 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY)); 685 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);705 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 686 706 FreePool (TmpStr1); 687 707 break; … … 696 716 697 717 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_MAINTAIN)); 698 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);718 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 699 719 FreePool (TmpStr1); 700 720 701 721 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY)); 702 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);722 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 703 723 FreePool (TmpStr1); 704 724 break; … … 721 741 722 742 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON)); 723 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);743 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 724 744 FreePool (TmpStr1); 725 745 726 746 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR)); 727 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);747 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 728 748 FreePool (TmpStr1); 729 749 730 750 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR_CONT)); 731 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);751 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 732 752 FreePool (TmpStr1); 733 753 734 754 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY)); 735 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);755 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 736 756 FreePool (TmpStr1); 737 757 break; … … 745 765 746 766 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_KEY)); 747 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);767 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 748 768 FreePool (TmpStr1); 749 769 750 770 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_INFO)); 751 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);771 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 752 772 FreePool (TmpStr1); 753 773 break; … … 762 782 763 783 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_CLEAR)); 764 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);784 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 765 785 FreePool (TmpStr1); 766 786 767 787 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR)); 768 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);769 StrnCat (ConfirmText, L" \n\n", (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);788 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 789 StrnCat (ConfirmText, L" \n\n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 770 790 FreePool (TmpStr1); 771 791 772 792 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY)); 773 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);793 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 774 794 FreePool (TmpStr1); 775 795 776 796 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_INFO)); 777 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);797 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 778 798 FreePool (TmpStr1); 779 799 break; … … 788 808 789 809 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_MAINTAIN)); 790 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);810 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 791 811 FreePool (TmpStr1); 792 812 793 813 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY)); 794 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);814 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 795 815 FreePool (TmpStr1); 796 816 797 817 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_INFO)); 798 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);818 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 799 819 FreePool (TmpStr1); 800 820 break; … … 809 829 810 830 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR)); 811 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);812 StrnCat (ConfirmText, L" \n\n", (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);831 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 832 StrnCat (ConfirmText, L" \n\n", (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 813 833 FreePool (TmpStr1); 814 834 815 835 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY)); 816 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);836 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 817 837 FreePool (TmpStr1); 818 838 break; … … 827 847 828 848 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON)); 829 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);849 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 830 850 FreePool (TmpStr1); 831 851 832 852 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR)); 833 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);853 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 834 854 FreePool (TmpStr1); 835 855 836 856 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING_CLEAR_CONT)); 837 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);857 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 838 858 FreePool (TmpStr1); 839 859 840 860 TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION_KEY)); 841 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16 *)) - StrLen (ConfirmText) - 1);861 StrnCat (ConfirmText, TmpStr1, (BufSize / sizeof (CHAR16)) - StrLen (ConfirmText) - 1); 842 862 FreePool (TmpStr1); 843 863 break; … … 874 894 875 895 /** 876 Check and execute the requested physical presence command. 877 878 @param[in] TcgProtocol EFI TCG Protocol instance. 879 @param[in] TcgPpData Point to the physical presence NV variable. 896 Check if there is a valid physical presence command request. Also updates parameter value 897 to whether the requested physical presence command already confirmed by user 898 899 @param[in] TcgPpData EFI TCG Physical Presence request data. 900 @param[in] Flags The physical presence interface flags. 901 @param[out] RequestConfirmed If the physical presence operation command required user confirm from UI. 902 True, it indicates the command doesn't require user confirm, or already confirmed 903 in last boot cycle by user. 904 False, it indicates the command need user confirm from UI. 905 906 @retval TRUE Physical Presence operation command is valid. 907 @retval FALSE Physical Presence operation command is invalid. 880 908 881 909 **/ 882 VOID 883 ExecutePendingTpmRequest ( 884 IN EFI_TCG_PROTOCOL *TcgProtocol, 885 IN EFI_PHYSICAL_PRESENCE *TcgPpData 910 BOOLEAN 911 HaveValidTpmRequest ( 912 IN EFI_PHYSICAL_PRESENCE *TcgPpData, 913 IN EFI_PHYSICAL_PRESENCE_FLAGS Flags, 914 OUT BOOLEAN *RequestConfirmed 886 915 ) 887 916 { 888 EFI_STATUS Status; 889 UINTN DataSize; 890 UINT8 Flags; 891 BOOLEAN RequestConfirmed; 892 893 Flags = TcgPpData->Flags; 894 RequestConfirmed = FALSE; 917 BOOLEAN IsRequestValid; 918 919 *RequestConfirmed = FALSE; 920 895 921 switch (TcgPpData->PPRequest) { 896 922 case PHYSICAL_PRESENCE_NO_ACTION: 897 return; 923 *RequestConfirmed = TRUE; 924 return TRUE; 898 925 case PHYSICAL_PRESENCE_ENABLE: 899 926 case PHYSICAL_PRESENCE_DISABLE: … … 907 934 case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE: 908 935 case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH: 909 if ((Flags &FLAG_NO_PPI_PROVISION) != 0) {910 RequestConfirmed = TRUE;936 if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION) != 0) { 937 *RequestConfirmed = TRUE; 911 938 } 912 939 break; … … 914 941 case PHYSICAL_PRESENCE_CLEAR: 915 942 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR: 916 if ((Flags &FLAG_NO_PPI_CLEAR) != 0) {917 RequestConfirmed = TRUE;943 if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR) != 0) { 944 *RequestConfirmed = TRUE; 918 945 } 919 946 break; 920 947 921 948 case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE: 922 if ((Flags &FLAG_NO_PPI_MAINTENANCE) != 0) {923 RequestConfirmed = TRUE;949 if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENANCE) != 0) { 950 *RequestConfirmed = TRUE; 924 951 } 925 952 break; … … 927 954 case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE: 928 955 case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE: 929 if ((Flags & FLAG_NO_PPI_CLEAR) != 0 && (Flags &FLAG_NO_PPI_PROVISION) != 0) {930 RequestConfirmed = TRUE;956 if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR) != 0 && (Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION) != 0) { 957 *RequestConfirmed = TRUE; 931 958 } 932 break; 959 break; 933 960 934 961 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE: 935 962 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE: 936 963 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE: 937 RequestConfirmed = TRUE; 938 break; 939 964 *RequestConfirmed = TRUE; 965 break; 966 967 case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE: 968 case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE: 969 case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE: 970 break; 971 940 972 default: 941 // 942 // Invalid operation request. 943 // 944 TcgPpData->PPResponse = TPM_PP_BIOS_FAILURE; 945 TcgPpData->LastPPRequest = TcgPpData->PPRequest; 946 TcgPpData->PPRequest = PHYSICAL_PRESENCE_NO_ACTION; 947 DataSize = sizeof (EFI_PHYSICAL_PRESENCE); 948 Status = gRT->SetVariable ( 949 PHYSICAL_PRESENCE_VARIABLE, 973 if (TcgPpData->PPRequest >= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) { 974 IsRequestValid = TcgPpVendorLibHasValidRequest (TcgPpData->PPRequest, Flags.PPFlags, RequestConfirmed); 975 if (!IsRequestValid) { 976 return FALSE; 977 } else { 978 break; 979 } 980 } else { 981 // 982 // Wrong Physical Presence command 983 // 984 return FALSE; 985 } 986 } 987 988 if ((Flags.PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) != 0) { 989 // 990 // It had been confirmed in last boot, it doesn't need confirm again. 991 // 992 *RequestConfirmed = TRUE; 993 } 994 995 // 996 // Physical Presence command is correct 997 // 998 return TRUE; 999 } 1000 1001 1002 /** 1003 Check and execute the requested physical presence command. 1004 1005 Caution: This function may receive untrusted input. 1006 TcgPpData variable is external input, so this function will validate 1007 its data structure to be valid value. 1008 1009 @param[in] TcgProtocol EFI TCG Protocol instance. 1010 @param[in] TcgPpData Point to the physical presence NV variable. 1011 @param[in] Flags The physical presence interface flags. 1012 1013 **/ 1014 VOID 1015 ExecutePendingTpmRequest ( 1016 IN EFI_TCG_PROTOCOL *TcgProtocol, 1017 IN EFI_PHYSICAL_PRESENCE *TcgPpData, 1018 IN EFI_PHYSICAL_PRESENCE_FLAGS Flags 1019 ) 1020 { 1021 EFI_STATUS Status; 1022 UINTN DataSize; 1023 BOOLEAN RequestConfirmed; 1024 EFI_PHYSICAL_PRESENCE_FLAGS NewFlags; 1025 BOOLEAN ResetRequired; 1026 UINT32 NewPPFlags; 1027 1028 if (!HaveValidTpmRequest(TcgPpData, Flags, &RequestConfirmed)) { 1029 // 1030 // Invalid operation request. 1031 // 1032 TcgPpData->PPResponse = TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE; 1033 TcgPpData->LastPPRequest = TcgPpData->PPRequest; 1034 TcgPpData->PPRequest = PHYSICAL_PRESENCE_NO_ACTION; 1035 DataSize = sizeof (EFI_PHYSICAL_PRESENCE); 1036 Status = gRT->SetVariable ( 1037 PHYSICAL_PRESENCE_VARIABLE, 1038 &gEfiPhysicalPresenceGuid, 1039 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, 1040 DataSize, 1041 TcgPpData 1042 ); 1043 return; 1044 } 1045 1046 ResetRequired = FALSE; 1047 if (TcgPpData->PPRequest >= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) { 1048 NewFlags = Flags; 1049 NewPPFlags = NewFlags.PPFlags; 1050 TcgPpData->PPResponse = TcgPpVendorLibExecutePendingRequest (TcgPpData->PPRequest, &NewPPFlags, &ResetRequired); 1051 NewFlags.PPFlags = (UINT8)NewPPFlags; 1052 } else { 1053 if (!RequestConfirmed) { 1054 // 1055 // Print confirm text and wait for approval. 1056 // 1057 RequestConfirmed = UserConfirm (TcgPpData->PPRequest); 1058 } 1059 1060 // 1061 // Execute requested physical presence command 1062 // 1063 TcgPpData->PPResponse = TCG_PP_OPERATION_RESPONSE_USER_ABORT; 1064 NewFlags = Flags; 1065 if (RequestConfirmed) { 1066 TcgPpData->PPResponse = ExecutePhysicalPresence (TcgProtocol, TcgPpData->PPRequest, &NewFlags); 1067 } 1068 } 1069 1070 // 1071 // Save the flags if it is updated. 1072 // 1073 if (CompareMem (&Flags, &NewFlags, sizeof(EFI_PHYSICAL_PRESENCE_FLAGS)) != 0) { 1074 Status = gRT->SetVariable ( 1075 PHYSICAL_PRESENCE_FLAGS_VARIABLE, 950 1076 &gEfiPhysicalPresenceGuid, 951 1077 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, 952 DataSize, 953 TcgPpData 954 ); 1078 sizeof (EFI_PHYSICAL_PRESENCE_FLAGS), 1079 &NewFlags 1080 ); 1081 if (EFI_ERROR (Status)) { 955 1082 return; 956 } 957 958 if ((Flags & FLAG_RESET_TRACK) != 0) { 959 // 960 // It had been confirmed in last boot, it doesn't need confirm again. 961 // 962 RequestConfirmed = TRUE; 963 } 964 965 if (!RequestConfirmed) { 966 // 967 // Print confirm text and wait for approval. 968 // 969 RequestConfirmed = UserConfirm (TcgPpData->PPRequest); 970 } 971 972 // 973 // Execute requested physical presence command 974 // 975 TcgPpData->PPResponse = TPM_PP_USER_ABORT; 976 if (RequestConfirmed) { 977 TcgPpData->PPResponse = ExecutePhysicalPresence (TcgProtocol, TcgPpData->PPRequest, &TcgPpData->Flags); 978 } 979 1083 } 1084 } 1085 980 1086 // 981 1087 // Clear request 982 1088 // 983 if (( TcgPpData->Flags &FLAG_RESET_TRACK) == 0) {1089 if ((NewFlags.PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) == 0) { 984 1090 TcgPpData->LastPPRequest = TcgPpData->PPRequest; 985 1091 TcgPpData->PPRequest = PHYSICAL_PRESENCE_NO_ACTION; … … 1001 1107 } 1002 1108 1003 if (TcgPpData->PPResponse == T PM_PP_USER_ABORT) {1109 if (TcgPpData->PPResponse == TCG_PP_OPERATION_RESPONSE_USER_ABORT) { 1004 1110 return; 1005 1111 } … … 1022 1128 break; 1023 1129 default: 1130 if (TcgPpData->LastPPRequest >= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) { 1131 if (ResetRequired) { 1132 break; 1133 } else { 1134 return ; 1135 } 1136 } 1024 1137 if (TcgPpData->PPRequest != PHYSICAL_PRESENCE_NO_ACTION) { 1025 1138 break; … … 1058 1171 EFI_PHYSICAL_PRESENCE TcgPpData; 1059 1172 EFI_TCG_PROTOCOL *TcgProtocol; 1173 EDKII_VARIABLE_LOCK_PROTOCOL *VariableLockProtocol; 1174 EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags; 1060 1175 1061 1176 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&TcgProtocol); 1062 1177 if (EFI_ERROR (Status)) { 1063 1178 return ; 1179 } 1180 1181 // 1182 // Initialize physical presence flags. 1183 // 1184 DataSize = sizeof (EFI_PHYSICAL_PRESENCE_FLAGS); 1185 Status = gRT->GetVariable ( 1186 PHYSICAL_PRESENCE_FLAGS_VARIABLE, 1187 &gEfiPhysicalPresenceGuid, 1188 NULL, 1189 &DataSize, 1190 &PpiFlags 1191 ); 1192 if (EFI_ERROR (Status)) { 1193 PpiFlags.PPFlags = TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION; 1194 Status = gRT->SetVariable ( 1195 PHYSICAL_PRESENCE_FLAGS_VARIABLE, 1196 &gEfiPhysicalPresenceGuid, 1197 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, 1198 sizeof (EFI_PHYSICAL_PRESENCE_FLAGS), 1199 &PpiFlags 1200 ); 1201 if (EFI_ERROR (Status)) { 1202 DEBUG ((EFI_D_ERROR, "[TPM] Set physical presence flag failed, Status = %r\n", Status)); 1203 return ; 1204 } 1205 } 1206 DEBUG ((EFI_D_INFO, "[TPM] PpiFlags = %x\n", PpiFlags.PPFlags)); 1207 1208 // 1209 // This flags variable controls whether physical presence is required for TPM command. 1210 // It should be protected from malicious software. We set it as read-only variable here. 1211 // 1212 Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **)&VariableLockProtocol); 1213 if (!EFI_ERROR (Status)) { 1214 Status = VariableLockProtocol->RequestToLock ( 1215 VariableLockProtocol, 1216 PHYSICAL_PRESENCE_FLAGS_VARIABLE, 1217 &gEfiPhysicalPresenceGuid 1218 ); 1219 if (EFI_ERROR (Status)) { 1220 DEBUG ((EFI_D_ERROR, "[TPM] Error when lock variable %s, Status = %r\n", PHYSICAL_PRESENCE_FLAGS_VARIABLE, Status)); 1221 ASSERT_EFI_ERROR (Status); 1222 } 1064 1223 } 1065 1224 … … 1076 1235 ); 1077 1236 if (EFI_ERROR (Status)) { 1078 if (Status == EFI_NOT_FOUND) { 1079 ZeroMem ((VOID*)&TcgPpData, sizeof (TcgPpData)); 1080 TcgPpData.Flags |= FLAG_NO_PPI_PROVISION; 1081 DataSize = sizeof (EFI_PHYSICAL_PRESENCE); 1082 Status = gRT->SetVariable ( 1083 PHYSICAL_PRESENCE_VARIABLE, 1084 &gEfiPhysicalPresenceGuid, 1085 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, 1086 DataSize, 1087 &TcgPpData 1088 ); 1237 ZeroMem ((VOID*)&TcgPpData, sizeof (TcgPpData)); 1238 DataSize = sizeof (EFI_PHYSICAL_PRESENCE); 1239 Status = gRT->SetVariable ( 1240 PHYSICAL_PRESENCE_VARIABLE, 1241 &gEfiPhysicalPresenceGuid, 1242 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, 1243 DataSize, 1244 &TcgPpData 1245 ); 1246 if (EFI_ERROR (Status)) { 1247 DEBUG ((EFI_D_ERROR, "[TPM] Set physical presence variable failed, Status = %r\n", Status)); 1248 return; 1089 1249 } 1090 ASSERT_EFI_ERROR (Status); 1091 } 1092 1093 DEBUG ((EFI_D_INFO, "[TPM] Flags=%x, PPRequest=%x\n", TcgPpData.Flags, TcgPpData.PPRequest)); 1250 } 1251 1252 DEBUG ((EFI_D_INFO, "[TPM] Flags=%x, PPRequest=%x\n", PpiFlags.PPFlags, TcgPpData.PPRequest)); 1253 1254 if (TcgPpData.PPRequest == PHYSICAL_PRESENCE_NO_ACTION) { 1255 // 1256 // No operation request 1257 // 1258 return; 1259 } 1094 1260 1095 1261 Status = GetTpmCapability (TcgProtocol, &LifetimeLock, &CmdEnable); … … 1119 1285 // Execute pending TPM request. 1120 1286 // 1121 ExecutePendingTpmRequest (TcgProtocol, &TcgPpData );1287 ExecutePendingTpmRequest (TcgProtocol, &TcgPpData, PpiFlags); 1122 1288 DEBUG ((EFI_D_INFO, "[TPM] PPResponse = %x\n", TcgPpData.PPResponse)); 1123 1289 … … 1128 1294 } 1129 1295 1296 /** 1297 Check if the pending TPM request needs user input to confirm. 1298 1299 The TPM request may come from OS. This API will check if TPM request exists and need user 1300 input to confirmation. 1301 1302 @retval TRUE TPM needs input to confirm user physical presence. 1303 @retval FALSE TPM doesn't need input to confirm user physical presence. 1304 1305 **/ 1306 BOOLEAN 1307 EFIAPI 1308 TcgPhysicalPresenceLibNeedUserConfirm( 1309 VOID 1310 ) 1311 { 1312 EFI_STATUS Status; 1313 EFI_PHYSICAL_PRESENCE TcgPpData; 1314 UINTN DataSize; 1315 BOOLEAN RequestConfirmed; 1316 BOOLEAN LifetimeLock; 1317 BOOLEAN CmdEnable; 1318 EFI_TCG_PROTOCOL *TcgProtocol; 1319 EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags; 1320 1321 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&TcgProtocol); 1322 if (EFI_ERROR (Status)) { 1323 return FALSE; 1324 } 1325 1326 // 1327 // Check Tpm requests 1328 // 1329 DataSize = sizeof (EFI_PHYSICAL_PRESENCE); 1330 Status = gRT->GetVariable ( 1331 PHYSICAL_PRESENCE_VARIABLE, 1332 &gEfiPhysicalPresenceGuid, 1333 NULL, 1334 &DataSize, 1335 &TcgPpData 1336 ); 1337 if (EFI_ERROR (Status)) { 1338 return FALSE; 1339 } 1340 1341 DataSize = sizeof (EFI_PHYSICAL_PRESENCE_FLAGS); 1342 Status = gRT->GetVariable ( 1343 PHYSICAL_PRESENCE_FLAGS_VARIABLE, 1344 &gEfiPhysicalPresenceGuid, 1345 NULL, 1346 &DataSize, 1347 &PpiFlags 1348 ); 1349 if (EFI_ERROR (Status)) { 1350 return FALSE; 1351 } 1352 1353 if (TcgPpData.PPRequest == PHYSICAL_PRESENCE_NO_ACTION) { 1354 // 1355 // No operation request 1356 // 1357 return FALSE; 1358 } 1359 1360 if (!HaveValidTpmRequest(&TcgPpData, PpiFlags, &RequestConfirmed)) { 1361 // 1362 // Invalid operation request. 1363 // 1364 return FALSE; 1365 } 1366 1367 // 1368 // Check Tpm Capability 1369 // 1370 Status = GetTpmCapability (TcgProtocol, &LifetimeLock, &CmdEnable); 1371 if (EFI_ERROR (Status)) { 1372 return FALSE; 1373 } 1374 1375 if (!CmdEnable) { 1376 if (LifetimeLock) { 1377 // 1378 // physicalPresenceCMDEnable is locked, can't execute physical presence command. 1379 // 1380 return FALSE; 1381 } 1382 } 1383 1384 if (!RequestConfirmed) { 1385 // 1386 // Need UI to confirm 1387 // 1388 return TRUE; 1389 } 1390 1391 return FALSE; 1392 } 1393 -
trunk/src/VBox/Devices/EFI/Firmware/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.inf
r48674 r58459 1 1 ## @file 2 # TCG physical presence library instance. This library will lock 3 # TPM after executing TPM request. 2 # Executes pending TPM 1.2 requests from OS or BIOS and Locks TPM 4 3 # 5 # Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR> 4 # This library will check and execute TPM 1.2 request from OS or BIOS. The request may 5 # ask for user confirmation before execution. This Library will also lock TPM physical 6 # presence at last. 7 # 8 # Caution: This module requires additional review when modified. 9 # This driver will have external input - variable. 10 # This external input must be validated carefully to avoid security issue. 11 # 12 # Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR> 6 13 # This program and the accompanying materials 7 14 # are licensed and made available under the terms and conditions of the BSD License … … 15 22 [Defines] 16 23 INF_VERSION = 0x00010005 17 BASE_NAME = DxeTcgPhysicalPresenceLib 24 BASE_NAME = DxeTcgPhysicalPresenceLib 25 MODULE_UNI_FILE = DxeTcgPhysicalPresenceLib.uni 18 26 FILE_GUID = EBC43A46-34AC-4F07-A7F5-A5394619361C 19 27 MODULE_TYPE = DXE_DRIVER … … 47 55 PrintLib 48 56 HiiLib 57 TcgPpVendorLib 49 58 50 59 [Protocols] 51 gEfiTcgProtocolGuid 60 gEfiTcgProtocolGuid ## CONSUMES 61 gEdkiiVariableLockProtocolGuid ## CONSUMES 52 62 53 63 [Guids] 64 ## CONSUMES ## HII 65 ## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresence" 66 ## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresence" 67 ## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresenceFlags" 68 ## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresenceFlags" 54 69 gEfiPhysicalPresenceGuid -
trunk/src/VBox/Devices/EFI/Firmware/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.c
r48674 r58459 2 2 The library instance provides security service of TPM measure boot. 3 3 4 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR> 4 Caution: This file requires additional review when modified. 5 This library will have external input - PE/COFF image and GPT partition. 6 This external input must be validated carefully to avoid security issue like 7 buffer overflow, integer overflow. 8 9 DxeTpmMeasureBootLibImageRead() function will make sure the PE/COFF image content 10 read is within the image buffer. 11 12 TcgMeasurePeImage() function will accept untrusted PE/COFF image and validate its 13 data structure within this image buffer before use. 14 15 TcgMeasureGptTable() function will receive untrusted GPT partition table, and parse 16 partition data carefully. 17 18 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR> 5 19 This program and the accompanying materials 6 20 are licensed and made available under the terms and conditions of the BSD License … … 16 30 17 31 #include <Protocol/TcgService.h> 18 #include <Protocol/FirmwareVolume2.h>19 32 #include <Protocol/BlockIo.h> 20 33 #include <Protocol/DiskIo.h> 21 #include <Protocol/DevicePathToText.h> 34 #include <Protocol/FirmwareVolumeBlock.h> 35 36 #include <Guid/MeasuredFvHob.h> 22 37 23 38 #include <Library/BaseLib.h> … … 30 45 #include <Library/PeCoffLib.h> 31 46 #include <Library/SecurityManagementLib.h> 47 #include <Library/HobLib.h> 32 48 33 49 // … … 39 55 VOID *mFileBuffer; 40 56 UINTN mImageSize; 57 // 58 // Measured FV handle cache 59 // 60 EFI_HANDLE mCacheMeasuredHandle = NULL; 61 MEASURED_HOB_DATA *mMeasuredHobData = NULL; 41 62 42 63 /** 43 64 Reads contents of a PE/COFF image in memory buffer. 65 66 Caution: This function may receive untrusted input. 67 PE/COFF image is external input, so this function will make sure the PE/COFF image content 68 read is within the image buffer. 44 69 45 70 @param FileHandle Pointer to the file handle to read the PE/COFF image. … … 86 111 /** 87 112 Measure GPT table data into TPM log. 113 114 Caution: This function may receive untrusted input. 115 The GPT partition table is external input, so this function should parse partition data carefully. 88 116 89 117 @param TcgProtocol Pointer to the located TCG protocol instance. … … 178 206 NumberOfPartition++; 179 207 } 180 PartitionEntry ++;181 } 182 183 // 184 // P arepare Data for Measurement208 PartitionEntry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartitionEntry + PrimaryHeader->SizeOfPartitionEntry); 209 } 210 211 // 212 // Prepare Data for Measurement 185 213 // 186 214 EventSize = (UINT32)(sizeof (EFI_GPT_DATA) - sizeof (GptData->Partitions) 187 215 + NumberOfPartition * PrimaryHeader->SizeOfPartitionEntry); 188 TcgEvent = (TCG_PCR_EVENT *) AllocateZeroPool (EventSize + sizeof (TCG_PCR_EVENT ));216 TcgEvent = (TCG_PCR_EVENT *) AllocateZeroPool (EventSize + sizeof (TCG_PCR_EVENT_HDR)); 189 217 if (TcgEvent == NULL) { 190 218 FreePool (PrimaryHeader); … … 211 239 if (!CompareGuid (&PartitionEntry->PartitionTypeGUID, &mZeroGuid)) { 212 240 CopyMem ( 213 (UINT8 *)&GptData->Partitions + NumberOfPartition * sizeof (EFI_PARTITION_ENTRY),241 (UINT8 *)&GptData->Partitions + NumberOfPartition * PrimaryHeader->SizeOfPartitionEntry, 214 242 (UINT8 *)PartitionEntry, 215 sizeof (EFI_PARTITION_ENTRY)243 PrimaryHeader->SizeOfPartitionEntry 216 244 ); 217 245 NumberOfPartition++; 218 246 } 219 PartitionEntry ++;247 PartitionEntry =(EFI_PARTITION_ENTRY *)((UINT8 *)PartitionEntry + PrimaryHeader->SizeOfPartitionEntry); 220 248 } 221 249 … … 247 275 Measure PE image into TPM log based on the authenticode image hashing in 248 276 PE/COFF Specification 8.0 Appendix A. 277 278 Caution: This function may receive untrusted input. 279 PE/COFF image is external input, so this function will validate its data structure 280 within this image buffer before use. 249 281 250 282 @param[in] TcgProtocol Pointer to the located TCG protocol instance. … … 340 372 ImageLoad->ImageLinkTimeAddress = LinkTimeBase; 341 373 ImageLoad->LengthOfDevicePath = FilePathSize; 342 CopyMem (ImageLoad->DevicePath, FilePath, FilePathSize); 374 if ((FilePath != NULL) && (FilePathSize != 0)) { 375 CopyMem (ImageLoad->DevicePath, FilePath, FilePathSize); 376 } 343 377 344 378 // … … 383 417 // But CheckSum field and SECURITY data directory (certificate) are excluded 384 418 // 385 Magic = Hdr.Pe32->OptionalHeader.Magic; 419 if (Hdr.Pe32->FileHeader.Machine == IMAGE_FILE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { 420 // 421 // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value 422 // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the 423 // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC 424 // then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC 425 // 426 Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; 427 } else { 428 // 429 // Get the magic value from the PE/COFF Optional Header 430 // 431 Magic = Hdr.Pe32->OptionalHeader.Magic; 432 } 386 433 387 434 // … … 619 666 &EventLogLastEntry 620 667 ); 668 if (Status == EFI_OUT_OF_RESOURCES) { 669 // 670 // Out of resource here means the image is hashed and its result is extended to PCR. 671 // But the event log cann't be saved since log area is full. 672 // Just return EFI_SUCCESS in order not to block the image load. 673 // 674 Status = EFI_SUCCESS; 675 } 621 676 622 677 Finish: … … 657 712 returned. 658 713 659 @param[in , out]AuthenticationStatus This is the authentication status returned714 @param[in] AuthenticationStatus This is the authentication status returned 660 715 from the securitymeasurement services for the 661 716 input file. … … 664 719 @param[in] FileBuffer File buffer matches the input file device path. 665 720 @param[in] FileSize Size of File buffer matches the input file device path. 666 667 @retval EFI_SUCCESS The file specified by File did authenticate, and the 668 platform policy dictates that the DXE Core may use File. 669 @retval EFI_INVALID_PARAMETER File is NULL. 670 @retval EFI_SECURITY_VIOLATION The file specified by File did not authenticate, and 671 the platform policy dictates that File should be placed 672 in the untrusted state. A file may be promoted from 673 the untrusted to the trusted state at a future time 674 with a call to the Trust() DXE Service. 675 @retval EFI_ACCESS_DENIED The file specified by File did not authenticate, and 676 the platform policy dictates that File should not be 677 used for any purpose. 678 721 @param[in] BootPolicy A boot policy that was used to call LoadImage() UEFI service. 722 723 @retval EFI_SUCCESS The file specified by DevicePath and non-NULL 724 FileBuffer did authenticate, and the platform policy dictates 725 that the DXE Foundation may use the file. 726 @retval other error value 679 727 **/ 680 728 EFI_STATUS 681 729 EFIAPI 682 730 DxeTpmMeasureBootHandler ( 683 IN OUT UINT32AuthenticationStatus,731 IN UINT32 AuthenticationStatus, 684 732 IN CONST EFI_DEVICE_PATH_PROTOCOL *File, 685 IN VOID *FileBuffer OPTIONAL, 686 IN UINTN FileSize OPTIONAL 733 IN VOID *FileBuffer, 734 IN UINTN FileSize, 735 IN BOOLEAN BootPolicy 687 736 ) 688 737 { 689 EFI_TCG_PROTOCOL *TcgProtocol;690 EFI_STATUS Status;691 TCG_EFI_BOOT_SERVICE_CAPABILITY ProtocolCapability;692 UINT32 TCGFeatureFlags;693 EFI_PHYSICAL_ADDRESS EventLogLocation;694 EFI_PHYSICAL_ADDRESS EventLogLastEntry;695 EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;696 EFI_DEVICE_PATH_PROTOCOL *OrigDevicePathNode;697 EFI_HANDLE Handle;698 BOOLEAN ApplicationRequired;699 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;700 701 if (File == NULL) {702 return EFI_INVALID_PARAMETER;703 }738 EFI_TCG_PROTOCOL *TcgProtocol; 739 EFI_STATUS Status; 740 TCG_EFI_BOOT_SERVICE_CAPABILITY ProtocolCapability; 741 UINT32 TCGFeatureFlags; 742 EFI_PHYSICAL_ADDRESS EventLogLocation; 743 EFI_PHYSICAL_ADDRESS EventLogLastEntry; 744 EFI_DEVICE_PATH_PROTOCOL *DevicePathNode; 745 EFI_DEVICE_PATH_PROTOCOL *OrigDevicePathNode; 746 EFI_HANDLE Handle; 747 EFI_HANDLE TempHandle; 748 BOOLEAN ApplicationRequired; 749 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; 750 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol; 751 EFI_PHYSICAL_ADDRESS FvAddress; 752 UINT32 Index; 704 753 705 754 Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **) &TcgProtocol); … … 720 769 &EventLogLastEntry 721 770 ); 722 if (EFI_ERROR (Status) || ProtocolCapability.TPMDeactivatedFlag ) {771 if (EFI_ERROR (Status) || ProtocolCapability.TPMDeactivatedFlag || (!ProtocolCapability.TPMPresentFlag)) { 723 772 // 724 773 // TPM device doesn't work or activate. … … 731 780 // 732 781 OrigDevicePathNode = DuplicateDevicePath (File); 733 ASSERT (OrigDevicePathNode != NULL);734 782 735 783 // … … 744 792 // 745 793 DevicePathNode = OrigDevicePathNode; 794 ASSERT (DevicePathNode != NULL); 746 795 while (!IsDevicePathEnd (DevicePathNode)) { 747 796 // … … 795 844 796 845 // 797 // Check whether this device path support FV 2protocol.846 // Check whether this device path support FVB protocol. 798 847 // 799 848 DevicePathNode = OrigDevicePathNode; 800 Status = gBS->LocateDevicePath (&gEfiFirmwareVolume 2ProtocolGuid, &DevicePathNode, &Handle);849 Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid, &DevicePathNode, &Handle); 801 850 if (!EFI_ERROR (Status)) { 802 851 // … … 808 857 } 809 858 // 810 // The image from Firmware image will not be mearsured. 811 // Current policy doesn't measure PeImage from Firmware if it is driver 812 // If the got PeImage is application, it will be still be measured. 859 // The PE image from unmeasured Firmware volume need be measured 860 // The PE image from measured Firmware volume will be mearsured according to policy below. 861 // If it is driver, do not measure 862 // If it is application, still measure. 813 863 // 814 864 ApplicationRequired = TRUE; 815 } 816 865 866 if (mCacheMeasuredHandle != Handle && mMeasuredHobData != NULL) { 867 // 868 // Search for Root FV of this PE image 869 // 870 TempHandle = Handle; 871 do { 872 Status = gBS->HandleProtocol( 873 TempHandle, 874 &gEfiFirmwareVolumeBlockProtocolGuid, 875 (VOID**)&FvbProtocol 876 ); 877 TempHandle = FvbProtocol->ParentHandle; 878 } while (!EFI_ERROR(Status) && FvbProtocol->ParentHandle != NULL); 879 880 // 881 // Search in measured FV Hob 882 // 883 Status = FvbProtocol->GetPhysicalAddress(FvbProtocol, &FvAddress); 884 if (EFI_ERROR(Status)){ 885 return Status; 886 } 887 888 ApplicationRequired = FALSE; 889 890 for (Index = 0; Index < mMeasuredHobData->Num; Index++) { 891 if(mMeasuredHobData->MeasuredFvBuf[Index].BlobBase == FvAddress) { 892 // 893 // Cache measured FV for next measurement 894 // 895 mCacheMeasuredHandle = Handle; 896 ApplicationRequired = TRUE; 897 break; 898 } 899 } 900 } 901 } 902 817 903 // 818 904 // File is not found. … … 856 942 DEBUG_CODE_BEGIN (); 857 943 CHAR16 *ToText; 858 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText; 859 Status = gBS->LocateProtocol ( 860 &gEfiDevicePathToTextProtocolGuid, 861 NULL, 862 (VOID **) &DevPathToText 863 ); 864 if (!EFI_ERROR (Status)) { 865 ToText = DevPathToText->ConvertDevicePathToText ( 866 DevicePathNode, 867 FALSE, 868 TRUE 869 ); 870 if (ToText != NULL) { 871 DEBUG ((DEBUG_INFO, "The measured image path is %s.\n", ToText)); 872 } 944 ToText = ConvertDevicePathToText ( 945 DevicePathNode, 946 FALSE, 947 TRUE 948 ); 949 if (ToText != NULL) { 950 DEBUG ((DEBUG_INFO, "The measured image path is %s.\n", ToText)); 951 FreePool (ToText); 873 952 } 874 953 DEBUG_CODE_END (); … … 891 970 // 892 971 Finish: 893 FreePool (OrigDevicePathNode); 972 if (OrigDevicePathNode != NULL) { 973 FreePool (OrigDevicePathNode); 974 } 894 975 895 976 return Status; … … 912 993 ) 913 994 { 914 return RegisterSecurityHandler ( 995 EFI_HOB_GUID_TYPE *GuidHob; 996 997 GuidHob = NULL; 998 999 GuidHob = GetFirstGuidHob (&gMeasuredFvHobGuid); 1000 1001 if (GuidHob != NULL) { 1002 mMeasuredHobData = GET_GUID_HOB_DATA (GuidHob); 1003 } 1004 1005 return RegisterSecurity2Handler ( 915 1006 DxeTpmMeasureBootHandler, 916 1007 EFI_AUTH_OPERATION_MEASURE_IMAGE | EFI_AUTH_OPERATION_IMAGE_REQUIRED -
trunk/src/VBox/Devices/EFI/Firmware/SecurityPkg/Library/DxeTpmMeasureBootLib/DxeTpmMeasureBootLib.inf
r48674 r58459 1 1 ## @file 2 # The library instance provides security service of TPM measure boot.2 # Provides security service for TPM 1.2 measured boot 3 3 # 4 # Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR> 4 # This library instance hooks LoadImage() API to measure every image that 5 # is not measured in PEI phase. And, it will also measure GPT partition. 6 # 7 # Caution: This module requires additional review when modified. 8 # This library will have external input - PE/COFF image and GPT partition. 9 # This external input must be validated carefully to avoid security issues such 10 # as buffer overflow or integer overflow. 11 # 12 # Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR> 5 13 # This program and the accompanying materials 6 14 # are licensed and made available under the terms and conditions of the BSD License … … 15 23 INF_VERSION = 0x00010005 16 24 BASE_NAME = DxeTpmMeasureBootLib 25 MODULE_UNI_FILE = DxeTpmMeasureBootLib.uni 17 26 FILE_GUID = 6C60C7D0-922A-4b7c-87D7-E503EDD73BBF 18 27 MODULE_TYPE = DXE_DRIVER … … 46 55 BaseLib 47 56 SecurityManagementLib 57 HobLib 58 59 [Guids] 60 gMeasuredFvHobGuid ## SOMETIMES_CONSUMES ## HOB 48 61 49 62 [Protocols] 50 gEfiTcgProtocolGuid ## CONSUMES51 gEfiFirmwareVolume 2ProtocolGuid ##CONSUMES52 gEfiBlockIoProtocolGuid ## CONSUMES53 gEfiDiskIoProtocolGuid ## CONSUMES54 gEfiDevicePathToTextProtocolGuid ## SOMETIMES_CONSUMES (Only used in debug mode) 63 gEfiTcgProtocolGuid ## SOMETIMES_CONSUMES 64 gEfiFirmwareVolumeBlockProtocolGuid ## SOMETIMES_CONSUMES 65 gEfiBlockIoProtocolGuid ## SOMETIMES_CONSUMES 66 gEfiDiskIoProtocolGuid ## SOMETIMES_CONSUMES 67 -
trunk/src/VBox/Devices/EFI/Firmware/SecurityPkg/Library/PlatformSecureLibNull/PlatformSecureLibNull.inf
r48674 r58459 1 1 ## @file 2 # NULL platform secure library instance that alway returns TRUE for a user physical present 3 # 2 4 # NULL PlatformSecureLib instance does NOT really detect whether a physical present 3 # user exists but return TRUE directly. This instance can be used to verify security5 # user exists but returns TRUE directly. This instance can be used to verify security 4 6 # related features during platform enabling and development. It should be replaced 5 7 # by a platform-specific method(e.g. Button pressed) in a real platform for product. 6 8 # 7 # Copyright (c) 2011 , Intel Corporation. All rights reserved.<BR>9 # Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR> 8 10 # This program and the accompanying materials 9 11 # are licensed and made available under the terms and conditions of the BSD License … … 18 20 INF_VERSION = 0x00010005 19 21 BASE_NAME = PlatformSecureLibNull 22 MODULE_UNI_FILE = PlatformSecureLibNull.uni 20 23 FILE_GUID = 7FA68D82-10A4-4e71-9524-D3D9500D3CDF 21 24 MODULE_TYPE = DXE_DRIVER -
trunk/src/VBox/Devices/EFI/Firmware/SecurityPkg/Library/TpmCommLib/TisPc.c
r48674 r58459 2 2 Basic TIS (TPM Interface Specification) functions. 3 3 4 Copyright (c) 2005 - 201 1, Intel Corporation. All rights reserved.<BR>4 Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR> 5 5 This program and the accompanying materials 6 6 are licensed and made available under the terms and conditions of the BSD License … … 145 145 /** 146 146 Get the control of TPM chip by sending requestUse command TIS_PC_ACC_RQUUSE 147 to ACCESS Register in the time of default TIS_TIMEOUT_ D.147 to ACCESS Register in the time of default TIS_TIMEOUT_A. 148 148 149 149 @param[in] TisReg Pointer to TIS register. … … 171 171 172 172 MmioWrite8((UINTN)&TisReg->Access, TIS_PC_ACC_RQUUSE); 173 // 174 // No locality set before, ACCESS_X.activeLocality MUST be valid within TIMEOUT_A 175 // 173 176 Status = TisPcWaitRegisterBits ( 174 177 &TisReg->Access, 175 178 (UINT8)(TIS_PC_ACC_ACTIVE |TIS_PC_VALID), 176 179 0, 177 TIS_TIMEOUT_ D180 TIS_TIMEOUT_A 178 181 ); 179 182 return Status; -
trunk/src/VBox/Devices/EFI/Firmware/SecurityPkg/Library/TpmCommLib/TpmCommLib.inf
r48674 r58459 1 1 ## @file 2 # TpmCommLib instance implements basis TPM Interface Specification (TIS) and TPM command functions.2 # Provides some common functions for the TCG feature 3 3 # 4 # Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR> 4 # This instance provides basic TPM Interface Specification (TIS) functions 5 # and TPM hashall function. 6 # 7 # Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR> 5 8 # This program and the accompanying materials 6 9 # are licensed and made available under the terms and conditions of the BSD License … … 15 18 INF_VERSION = 0x00010005 16 19 BASE_NAME = TpmCommLib 20 MODULE_UNI_FILE = TpmCommLib.uni 17 21 FILE_GUID = 7d9fe32e-a6a9-4cdf-abff-10cc7f22e1c9 18 22 MODULE_TYPE = PEIM
Note:
See TracChangeset
for help on using the changeset viewer.