2 Implement image verification services for secure boot service in UEFI2.3.1.
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.
9 DxeImageVerificationLibImageRead() function will make sure the PE/COFF image content
10 read is within the image buffer.
12 DxeImageVerificationHandler(), HashPeImageByType(), HashPeImage() function will accept
13 untrusted PE/COFF image and validate its data structure within this image buffer before use.
15 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
16 This program and the accompanying materials
17 are licensed and made available under the terms and conditions of the BSD License
18 which accompanies this distribution. The full text of the license may be found at
19 http://opensource.org/licenses/bsd-license.php
21 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
22 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
26 #include "DxeImageVerificationLib.h"
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.
32 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION mNtHeader
;
33 UINT32 mPeCoffHeaderOffset
;
37 // Information on current PE/COFF image
40 UINT8
*mImageBase
= NULL
;
41 UINT8 mImageDigest
[MAX_DIGEST_SIZE
];
42 UINTN mImageDigestSize
;
45 // Notify string for authorization UI.
47 CHAR16 mNotifyString1
[MAX_NOTIFY_STRING_LEN
] = L
"Image verification pass but not found in authorized database!";
48 CHAR16 mNotifyString2
[MAX_NOTIFY_STRING_LEN
] = L
"Launch this image anyway? (Yes/Defer/No)";
50 // Public Exponent of RSA Key.
52 CONST UINT8 mRsaE
[] = { 0x01, 0x00, 0x01 };
56 // OID ASN.1 Value for Hash Algorithms
58 UINT8 mHashOidValue
[] = {
59 0x2B, 0x0E, 0x03, 0x02, 0x1A, // OBJ_sha1
60 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, // OBJ_sha224
61 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, // OBJ_sha256
62 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, // OBJ_sha384
63 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, // OBJ_sha512
66 HASH_TABLE mHash
[] = {
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
}
75 SecureBoot Hook for processing image verification.
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.
87 IN CHAR16
*VariableName
,
88 IN EFI_GUID
*VendorGuid
,
94 Reads contents of a PE/COFF image in memory buffer.
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.
100 @param FileHandle Pointer to the file handle to read the PE/COFF image.
101 @param FileOffset Offset into the PE/COFF image to begin the read operation.
102 @param ReadSize On input, the size in bytes of the requested read operation.
103 On output, the number of bytes actually read.
104 @param Buffer Output buffer that contains the data read from the PE/COFF image.
106 @retval EFI_SUCCESS The specified portion of the PE/COFF image was read and the size
110 DxeImageVerificationLibImageRead (
113 IN OUT UINTN
*ReadSize
,
119 if (FileHandle
== NULL
|| ReadSize
== NULL
|| Buffer
== NULL
) {
120 return EFI_INVALID_PARAMETER
;
123 if (MAX_ADDRESS
- FileOffset
< *ReadSize
) {
124 return EFI_INVALID_PARAMETER
;
127 EndPosition
= FileOffset
+ *ReadSize
;
128 if (EndPosition
> mImageSize
) {
129 *ReadSize
= (UINT32
)(mImageSize
- FileOffset
);
132 if (FileOffset
>= mImageSize
) {
136 CopyMem (Buffer
, (UINT8
*)((UINTN
) FileHandle
+ FileOffset
), *ReadSize
);
145 @param[in] File This is a pointer to the device path of the file that is
148 @return UINT32 Image Type
153 IN CONST EFI_DEVICE_PATH_PROTOCOL
*File
157 EFI_HANDLE DeviceHandle
;
158 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
159 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
162 return IMAGE_UNKNOWN
;
166 // First check to see if File is from a Firmware Volume
169 TempDevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) File
;
170 Status
= gBS
->LocateDevicePath (
171 &gEfiFirmwareVolume2ProtocolGuid
,
175 if (!EFI_ERROR (Status
)) {
176 Status
= gBS
->OpenProtocol (
178 &gEfiFirmwareVolume2ProtocolGuid
,
182 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
184 if (!EFI_ERROR (Status
)) {
185 return IMAGE_FROM_FV
;
190 // Next check to see if File is from a Block I/O device
193 TempDevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) File
;
194 Status
= gBS
->LocateDevicePath (
195 &gEfiBlockIoProtocolGuid
,
199 if (!EFI_ERROR (Status
)) {
201 Status
= gBS
->OpenProtocol (
203 &gEfiBlockIoProtocolGuid
,
207 EFI_OPEN_PROTOCOL_GET_PROTOCOL
209 if (!EFI_ERROR (Status
) && BlockIo
!= NULL
) {
210 if (BlockIo
->Media
!= NULL
) {
211 if (BlockIo
->Media
->RemovableMedia
) {
213 // Block I/O is present and specifies the media is removable
215 return IMAGE_FROM_REMOVABLE_MEDIA
;
218 // Block I/O is present and specifies the media is not removable
220 return IMAGE_FROM_FIXED_MEDIA
;
227 // File is not in a Firmware Volume or on a Block I/O device, so check to see if
228 // the device path supports the Simple File System Protocol.
231 TempDevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) File
;
232 Status
= gBS
->LocateDevicePath (
233 &gEfiSimpleFileSystemProtocolGuid
,
237 if (!EFI_ERROR (Status
)) {
239 // Simple File System is present without Block I/O, so assume media is fixed.
241 return IMAGE_FROM_FIXED_MEDIA
;
245 // File is not from an FV, Block I/O or Simple File System, so the only options
246 // left are a PCI Option ROM and a Load File Protocol such as a PXE Boot from a NIC.
248 TempDevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) File
;
249 while (!IsDevicePathEndType (TempDevicePath
)) {
250 switch (DevicePathType (TempDevicePath
)) {
252 case MEDIA_DEVICE_PATH
:
253 if (DevicePathSubType (TempDevicePath
) == MEDIA_RELATIVE_OFFSET_RANGE_DP
) {
254 return IMAGE_FROM_OPTION_ROM
;
258 case MESSAGING_DEVICE_PATH
:
259 if (DevicePathSubType(TempDevicePath
) == MSG_MAC_ADDR_DP
) {
260 return IMAGE_FROM_REMOVABLE_MEDIA
;
267 TempDevicePath
= NextDevicePathNode (TempDevicePath
);
269 return IMAGE_UNKNOWN
;
273 Caculate hash of Pe/Coff image based on the authenticode image hashing in
274 PE/COFF Specification 8.0 Appendix A
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.
280 @param[in] HashAlg Hash algorithm type.
282 @retval TRUE Successfully hash image.
283 @retval FALSE Fail in hash image.
293 EFI_IMAGE_SECTION_HEADER
*Section
;
298 UINTN SumOfBytesHashed
;
299 EFI_IMAGE_SECTION_HEADER
*SectionHeader
;
303 UINT32 NumberOfRvaAndSizes
;
306 SectionHeader
= NULL
;
309 if ((HashAlg
!= HASHALG_SHA1
) && (HashAlg
!= HASHALG_SHA256
)) {
314 // Initialize context of hash.
316 ZeroMem (mImageDigest
, MAX_DIGEST_SIZE
);
318 if (HashAlg
== HASHALG_SHA1
) {
319 mImageDigestSize
= SHA1_DIGEST_SIZE
;
320 mCertType
= gEfiCertSha1Guid
;
321 } else if (HashAlg
== HASHALG_SHA256
) {
322 mImageDigestSize
= SHA256_DIGEST_SIZE
;
323 mCertType
= gEfiCertSha256Guid
;
328 CtxSize
= mHash
[HashAlg
].GetContextSize();
330 HashCtx
= AllocatePool (CtxSize
);
331 if (HashCtx
== NULL
) {
335 // 1. Load the image header into memory.
337 // 2. Initialize a SHA hash context.
338 Status
= mHash
[HashAlg
].HashInit(HashCtx
);
345 // Measuring PE/COFF Image Header;
346 // But CheckSum field and SECURITY data directory (certificate) are excluded
348 if (mNtHeader
.Pe32
->FileHeader
.Machine
== IMAGE_FILE_MACHINE_IA64
&& mNtHeader
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
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
355 Magic
= EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
;
358 // Get the magic value from the PE/COFF Optional Header
360 Magic
= mNtHeader
.Pe32
->OptionalHeader
.Magic
;
364 // 3. Calculate the distance from the base of the image header to the image checksum address.
365 // 4. Hash the image header from its base to beginning of the image checksum.
367 HashBase
= mImageBase
;
368 if (Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
372 HashSize
= (UINTN
) ((UINT8
*) (&mNtHeader
.Pe32
->OptionalHeader
.CheckSum
) - HashBase
);
373 NumberOfRvaAndSizes
= mNtHeader
.Pe32
->OptionalHeader
.NumberOfRvaAndSizes
;
374 } else if (Magic
== EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
) {
378 HashSize
= (UINTN
) ((UINT8
*) (&mNtHeader
.Pe32Plus
->OptionalHeader
.CheckSum
) - HashBase
);
379 NumberOfRvaAndSizes
= mNtHeader
.Pe32Plus
->OptionalHeader
.NumberOfRvaAndSizes
;
382 // Invalid header magic number.
388 Status
= mHash
[HashAlg
].HashUpdate(HashCtx
, HashBase
, HashSize
);
394 // 5. Skip over the image checksum (it occupies a single ULONG).
396 if (NumberOfRvaAndSizes
<= EFI_IMAGE_DIRECTORY_ENTRY_SECURITY
) {
398 // 6. Since there is no Cert Directory in optional header, hash everything
399 // from the end of the checksum to the end of image header.
401 if (Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
405 HashBase
= (UINT8
*) &mNtHeader
.Pe32
->OptionalHeader
.CheckSum
+ sizeof (UINT32
);
406 HashSize
= mNtHeader
.Pe32
->OptionalHeader
.SizeOfHeaders
- (UINTN
) (HashBase
- mImageBase
);
411 HashBase
= (UINT8
*) &mNtHeader
.Pe32Plus
->OptionalHeader
.CheckSum
+ sizeof (UINT32
);
412 HashSize
= mNtHeader
.Pe32Plus
->OptionalHeader
.SizeOfHeaders
- (UINTN
) (HashBase
- mImageBase
);
416 Status
= mHash
[HashAlg
].HashUpdate(HashCtx
, HashBase
, HashSize
);
423 // 7. Hash everything from the end of the checksum to the start of the Cert Directory.
425 if (Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
429 HashBase
= (UINT8
*) &mNtHeader
.Pe32
->OptionalHeader
.CheckSum
+ sizeof (UINT32
);
430 HashSize
= (UINTN
) ((UINT8
*) (&mNtHeader
.Pe32
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY
]) - HashBase
);
435 HashBase
= (UINT8
*) &mNtHeader
.Pe32Plus
->OptionalHeader
.CheckSum
+ sizeof (UINT32
);
436 HashSize
= (UINTN
) ((UINT8
*) (&mNtHeader
.Pe32Plus
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY
]) - HashBase
);
440 Status
= mHash
[HashAlg
].HashUpdate(HashCtx
, HashBase
, HashSize
);
447 // 8. Skip over the Cert Directory. (It is sizeof(IMAGE_DATA_DIRECTORY) bytes.)
448 // 9. Hash everything from the end of the Cert Directory to the end of image header.
450 if (Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
454 HashBase
= (UINT8
*) &mNtHeader
.Pe32
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY
+ 1];
455 HashSize
= mNtHeader
.Pe32
->OptionalHeader
.SizeOfHeaders
- (UINTN
) (HashBase
- mImageBase
);
460 HashBase
= (UINT8
*) &mNtHeader
.Pe32Plus
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY
+ 1];
461 HashSize
= mNtHeader
.Pe32Plus
->OptionalHeader
.SizeOfHeaders
- (UINTN
) (HashBase
- mImageBase
);
465 Status
= mHash
[HashAlg
].HashUpdate(HashCtx
, HashBase
, HashSize
);
473 // 10. Set the SUM_OF_BYTES_HASHED to the size of the header.
475 if (Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
479 SumOfBytesHashed
= mNtHeader
.Pe32
->OptionalHeader
.SizeOfHeaders
;
484 SumOfBytesHashed
= mNtHeader
.Pe32Plus
->OptionalHeader
.SizeOfHeaders
;
488 Section
= (EFI_IMAGE_SECTION_HEADER
*) (
490 mPeCoffHeaderOffset
+
492 sizeof (EFI_IMAGE_FILE_HEADER
) +
493 mNtHeader
.Pe32
->FileHeader
.SizeOfOptionalHeader
497 // 11. Build a temporary table of pointers to all the IMAGE_SECTION_HEADER
498 // structures in the image. The 'NumberOfSections' field of the image
499 // header indicates how big the table should be. Do not include any
500 // IMAGE_SECTION_HEADERs in the table whose 'SizeOfRawData' field is zero.
502 SectionHeader
= (EFI_IMAGE_SECTION_HEADER
*) AllocateZeroPool (sizeof (EFI_IMAGE_SECTION_HEADER
) * mNtHeader
.Pe32
->FileHeader
.NumberOfSections
);
503 if (SectionHeader
== NULL
) {
508 // 12. Using the 'PointerToRawData' in the referenced section headers as
509 // a key, arrange the elements in the table in ascending order. In other
510 // words, sort the section headers according to the disk-file offset of
513 for (Index
= 0; Index
< mNtHeader
.Pe32
->FileHeader
.NumberOfSections
; Index
++) {
515 while ((Pos
> 0) && (Section
->PointerToRawData
< SectionHeader
[Pos
- 1].PointerToRawData
)) {
516 CopyMem (&SectionHeader
[Pos
], &SectionHeader
[Pos
- 1], sizeof (EFI_IMAGE_SECTION_HEADER
));
519 CopyMem (&SectionHeader
[Pos
], Section
, sizeof (EFI_IMAGE_SECTION_HEADER
));
524 // 13. Walk through the sorted table, bring the corresponding section
525 // into memory, and hash the entire section (using the 'SizeOfRawData'
526 // field in the section header to determine the amount of data to hash).
527 // 14. Add the section's 'SizeOfRawData' to SUM_OF_BYTES_HASHED .
528 // 15. Repeat steps 13 and 14 for all the sections in the sorted table.
530 for (Index
= 0; Index
< mNtHeader
.Pe32
->FileHeader
.NumberOfSections
; Index
++) {
531 Section
= &SectionHeader
[Index
];
532 if (Section
->SizeOfRawData
== 0) {
535 HashBase
= mImageBase
+ Section
->PointerToRawData
;
536 HashSize
= (UINTN
) Section
->SizeOfRawData
;
538 Status
= mHash
[HashAlg
].HashUpdate(HashCtx
, HashBase
, HashSize
);
543 SumOfBytesHashed
+= HashSize
;
547 // 16. If the file size is greater than SUM_OF_BYTES_HASHED, there is extra
548 // data in the file that needs to be added to the hash. This data begins
549 // at file offset SUM_OF_BYTES_HASHED and its length is:
550 // FileSize - (CertDirectory->Size)
552 if (mImageSize
> SumOfBytesHashed
) {
553 HashBase
= mImageBase
+ SumOfBytesHashed
;
555 if (NumberOfRvaAndSizes
<= EFI_IMAGE_DIRECTORY_ENTRY_SECURITY
) {
558 if (Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
562 CertSize
= mNtHeader
.Pe32
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY
].Size
;
567 CertSize
= mNtHeader
.Pe32Plus
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY
].Size
;
571 if (mImageSize
> CertSize
+ SumOfBytesHashed
) {
572 HashSize
= (UINTN
) (mImageSize
- CertSize
- SumOfBytesHashed
);
574 Status
= mHash
[HashAlg
].HashUpdate(HashCtx
, HashBase
, HashSize
);
578 } else if (mImageSize
< CertSize
+ SumOfBytesHashed
) {
584 Status
= mHash
[HashAlg
].HashFinal(HashCtx
, mImageDigest
);
587 if (HashCtx
!= NULL
) {
590 if (SectionHeader
!= NULL
) {
591 FreePool (SectionHeader
);
597 Recognize the Hash algorithm in PE/COFF Authenticode and caculate hash of
598 Pe/Coff image based on the authenticode image hashing in PE/COFF Specification
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.
605 @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed image.
606 @param[in] AuthDataSize Size of the Authenticode Signature in bytes.
608 @retval EFI_UNSUPPORTED Hash algorithm is not supported.
609 @retval EFI_SUCCESS Hash successfully.
615 IN UINTN AuthDataSize
620 for (Index
= 0; Index
< HASHALG_MAX
; Index
++) {
622 // Check the Hash algorithm in PE/COFF Authenticode.
623 // According to PKCS#7 Definition:
624 // SignedData ::= SEQUENCE {
626 // digestAlgorithms DigestAlgorithmIdentifiers,
627 // contentInfo ContentInfo,
629 // The DigestAlgorithmIdentifiers can be used to determine the hash algorithm in PE/COFF hashing
630 // This field has the fixed offset (+32) in final Authenticode ASN.1 data.
631 // Fixed offset (+32) is calculated based on two bytes of length encoding.
633 if ((*(AuthData
+ 1) & TWO_BYTE_ENCODE
) != TWO_BYTE_ENCODE
) {
635 // Only support two bytes of Long Form of Length Encoding.
640 if (AuthDataSize
< 32 + mHash
[Index
].OidLength
) {
641 return EFI_UNSUPPORTED
;
644 if (CompareMem (AuthData
+ 32, mHash
[Index
].OidValue
, mHash
[Index
].OidLength
) == 0) {
649 if (Index
== HASHALG_MAX
) {
650 return EFI_UNSUPPORTED
;
654 // HASH PE Image based on Hash algorithm in PE/COFF Authenticode.
656 if (!HashPeImage(Index
)) {
657 return EFI_UNSUPPORTED
;
665 Returns the size of a given image execution info table in bytes.
667 This function returns the size, in bytes, of the image execution info table specified by
668 ImageExeInfoTable. If ImageExeInfoTable is NULL, then 0 is returned.
670 @param ImageExeInfoTable A pointer to a image execution info table structure.
672 @retval 0 If ImageExeInfoTable is NULL.
673 @retval Others The size of a image execution info table in bytes.
677 GetImageExeInfoTableSize (
678 EFI_IMAGE_EXECUTION_INFO_TABLE
*ImageExeInfoTable
682 EFI_IMAGE_EXECUTION_INFO
*ImageExeInfoItem
;
685 if (ImageExeInfoTable
== NULL
) {
689 ImageExeInfoItem
= (EFI_IMAGE_EXECUTION_INFO
*) ((UINT8
*) ImageExeInfoTable
+ sizeof (EFI_IMAGE_EXECUTION_INFO_TABLE
));
690 TotalSize
= sizeof (EFI_IMAGE_EXECUTION_INFO_TABLE
);
691 for (Index
= 0; Index
< ImageExeInfoTable
->NumberOfImages
; Index
++) {
692 TotalSize
+= ReadUnaligned32 ((UINT32
*) &ImageExeInfoItem
->InfoSize
);
693 ImageExeInfoItem
= (EFI_IMAGE_EXECUTION_INFO
*) ((UINT8
*) ImageExeInfoItem
+ ReadUnaligned32 ((UINT32
*) &ImageExeInfoItem
->InfoSize
));
700 Create an Image Execution Information Table entry and add it to system configuration table.
702 @param[in] Action Describes the action taken by the firmware regarding this image.
703 @param[in] Name Input a null-terminated, user-friendly name.
704 @param[in] DevicePath Input device path pointer.
705 @param[in] Signature Input signature info in EFI_SIGNATURE_LIST data structure.
706 @param[in] SignatureSize Size of signature.
711 IN EFI_IMAGE_EXECUTION_ACTION Action
,
712 IN CHAR16
*Name OPTIONAL
,
713 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
714 IN EFI_SIGNATURE_LIST
*Signature OPTIONAL
,
715 IN UINTN SignatureSize
718 EFI_IMAGE_EXECUTION_INFO_TABLE
*ImageExeInfoTable
;
719 EFI_IMAGE_EXECUTION_INFO_TABLE
*NewImageExeInfoTable
;
720 EFI_IMAGE_EXECUTION_INFO
*ImageExeInfoEntry
;
721 UINTN ImageExeInfoTableSize
;
722 UINTN NewImageExeInfoEntrySize
;
724 UINTN DevicePathSize
;
726 ImageExeInfoTable
= NULL
;
727 NewImageExeInfoTable
= NULL
;
728 ImageExeInfoEntry
= NULL
;
731 if (DevicePath
== NULL
) {
736 NameStringLen
= StrSize (Name
);
738 NameStringLen
= sizeof (CHAR16
);
741 EfiGetSystemConfigurationTable (&gEfiImageSecurityDatabaseGuid
, (VOID
**) &ImageExeInfoTable
);
742 if (ImageExeInfoTable
!= NULL
) {
744 // The table has been found!
745 // We must enlarge the table to accomodate the new exe info entry.
747 ImageExeInfoTableSize
= GetImageExeInfoTableSize (ImageExeInfoTable
);
751 // We should create a new table to append to the configuration table.
753 ImageExeInfoTableSize
= sizeof (EFI_IMAGE_EXECUTION_INFO_TABLE
);
756 DevicePathSize
= GetDevicePathSize (DevicePath
);
757 NewImageExeInfoEntrySize
= sizeof (EFI_IMAGE_EXECUTION_INFO
) + NameStringLen
+ DevicePathSize
+ SignatureSize
;
758 NewImageExeInfoTable
= (EFI_IMAGE_EXECUTION_INFO_TABLE
*) AllocateRuntimePool (ImageExeInfoTableSize
+ NewImageExeInfoEntrySize
);
759 if (NewImageExeInfoTable
== NULL
) {
763 if (ImageExeInfoTable
!= NULL
) {
764 CopyMem (NewImageExeInfoTable
, ImageExeInfoTable
, ImageExeInfoTableSize
);
766 NewImageExeInfoTable
->NumberOfImages
= 0;
768 NewImageExeInfoTable
->NumberOfImages
++;
769 ImageExeInfoEntry
= (EFI_IMAGE_EXECUTION_INFO
*) ((UINT8
*) NewImageExeInfoTable
+ ImageExeInfoTableSize
);
771 // Update new item's infomation.
773 WriteUnaligned32 ((UINT32
*) &ImageExeInfoEntry
->Action
, Action
);
774 WriteUnaligned32 ((UINT32
*) &ImageExeInfoEntry
->InfoSize
, (UINT32
) NewImageExeInfoEntrySize
);
777 CopyMem ((UINT8
*) &ImageExeInfoEntry
->InfoSize
+ sizeof (UINT32
), Name
, NameStringLen
);
779 ZeroMem ((UINT8
*) &ImageExeInfoEntry
->InfoSize
+ sizeof (UINT32
), sizeof (CHAR16
));
782 (UINT8
*) &ImageExeInfoEntry
->InfoSize
+ sizeof (UINT32
) + NameStringLen
,
786 if (Signature
!= NULL
) {
788 (UINT8
*) &ImageExeInfoEntry
->InfoSize
+ sizeof (UINT32
) + NameStringLen
+ DevicePathSize
,
794 // Update/replace the image execution table.
796 gBS
->InstallConfigurationTable (&gEfiImageSecurityDatabaseGuid
, (VOID
*) NewImageExeInfoTable
);
799 // Free Old table data!
801 if (ImageExeInfoTable
!= NULL
) {
802 FreePool (ImageExeInfoTable
);
807 Check whether signature is in specified database.
809 @param[in] VariableName Name of database variable that is searched in.
810 @param[in] Signature Pointer to signature that is searched for.
811 @param[in] CertType Pointer to hash algrithom.
812 @param[in] SignatureSize Size of Signature.
814 @return TRUE Found the signature in the variable database.
815 @return FALSE Not found the signature in the variable database.
819 IsSignatureFoundInDatabase (
820 IN CHAR16
*VariableName
,
822 IN EFI_GUID
*CertType
,
823 IN UINTN SignatureSize
827 EFI_SIGNATURE_LIST
*CertList
;
828 EFI_SIGNATURE_DATA
*Cert
;
835 // Read signature database variable.
840 Status
= gRT
->GetVariable (VariableName
, &gEfiImageSecurityDatabaseGuid
, NULL
, &DataSize
, NULL
);
841 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
845 Data
= (UINT8
*) AllocateZeroPool (DataSize
);
850 Status
= gRT
->GetVariable (VariableName
, &gEfiImageSecurityDatabaseGuid
, NULL
, &DataSize
, Data
);
851 if (EFI_ERROR (Status
)) {
855 // Enumerate all signature data in SigDB to check if executable's signature exists.
857 CertList
= (EFI_SIGNATURE_LIST
*) Data
;
858 while ((DataSize
> 0) && (DataSize
>= CertList
->SignatureListSize
)) {
859 CertCount
= (CertList
->SignatureListSize
- sizeof (EFI_SIGNATURE_LIST
) - CertList
->SignatureHeaderSize
) / CertList
->SignatureSize
;
860 Cert
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) CertList
+ sizeof (EFI_SIGNATURE_LIST
) + CertList
->SignatureHeaderSize
);
861 if ((CertList
->SignatureSize
== sizeof(EFI_SIGNATURE_DATA
) - 1 + SignatureSize
) && (CompareGuid(&CertList
->SignatureType
, CertType
))) {
862 for (Index
= 0; Index
< CertCount
; Index
++) {
863 if (CompareMem (Cert
->SignatureData
, Signature
, SignatureSize
) == 0) {
865 // Find the signature in database.
868 SecureBootHook (VariableName
, &gEfiImageSecurityDatabaseGuid
, CertList
->SignatureSize
, Cert
);
872 Cert
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) Cert
+ CertList
->SignatureSize
);
880 DataSize
-= CertList
->SignatureListSize
;
881 CertList
= (EFI_SIGNATURE_LIST
*) ((UINT8
*) CertList
+ CertList
->SignatureListSize
);
893 Verify PKCS#7 SignedData using certificate found in Variable which formatted
894 as EFI_SIGNATURE_LIST. The Variable may be PK, KEK, DB or DBX.
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.
901 @retval TRUE Image pass verification.
902 @retval FALSE Image fail verification.
906 IsPkcsSignedDataVerifiedBySignatureList (
908 IN UINTN AuthDataSize
,
909 IN CHAR16
*VariableName
,
910 IN EFI_GUID
*VendorGuid
914 BOOLEAN VerifyStatus
;
915 EFI_SIGNATURE_LIST
*CertList
;
916 EFI_SIGNATURE_DATA
*Cert
;
929 VerifyStatus
= FALSE
;
932 Status
= gRT
->GetVariable (VariableName
, VendorGuid
, NULL
, &DataSize
, NULL
);
933 if (Status
== EFI_BUFFER_TOO_SMALL
) {
934 Data
= (UINT8
*) AllocateZeroPool (DataSize
);
939 Status
= gRT
->GetVariable (VariableName
, VendorGuid
, NULL
, &DataSize
, (VOID
*) Data
);
940 if (EFI_ERROR (Status
)) {
945 // Find X509 certificate in Signature List to verify the signature in pkcs7 signed data.
947 CertList
= (EFI_SIGNATURE_LIST
*) Data
;
948 while ((DataSize
> 0) && (DataSize
>= CertList
->SignatureListSize
)) {
949 if (CompareGuid (&CertList
->SignatureType
, &gEfiCertX509Guid
)) {
950 Cert
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) CertList
+ sizeof (EFI_SIGNATURE_LIST
) + CertList
->SignatureHeaderSize
);
951 CertCount
= (CertList
->SignatureListSize
- sizeof (EFI_SIGNATURE_LIST
) - CertList
->SignatureHeaderSize
) / CertList
->SignatureSize
;
952 for (Index
= 0; Index
< CertCount
; Index
++) {
954 // Iterate each Signature Data Node within this CertList for verify.
956 RootCert
= Cert
->SignatureData
;
957 RootCertSize
= CertList
->SignatureSize
- sizeof (EFI_GUID
);
960 // Call AuthenticodeVerify library to Verify Authenticode struct.
962 VerifyStatus
= AuthenticodeVerify (
971 SecureBootHook (VariableName
, VendorGuid
, CertList
->SignatureSize
, Cert
);
974 Cert
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) Cert
+ CertList
->SignatureSize
);
977 DataSize
-= CertList
->SignatureListSize
;
978 CertList
= (EFI_SIGNATURE_LIST
*) ((UINT8
*) CertList
+ CertList
->SignatureListSize
);
991 Provide verification service for signed images, which include both signature validation
992 and platform policy control. For signature types, both UEFI WIN_CERTIFICATE_UEFI_GUID and
993 MSFT Authenticode type signatures are supported.
995 In this implementation, only verify external executables when in USER MODE.
996 Executables from FV is bypass, so pass in AuthenticationStatus is ignored.
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".
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.
1011 @param[in] AuthenticationStatus
1012 This is the authentication status returned from the security
1013 measurement services for the input file.
1014 @param[in] File This is a pointer to the device path of the file that is
1015 being dispatched. This will optionally be used for logging.
1016 @param[in] FileBuffer File buffer matches the input file device path.
1017 @param[in] FileSize Size of File buffer matches the input file device path.
1018 @param[in] BootPolicy A boot policy that was used to call LoadImage() UEFI service.
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
1027 @retval EFI_OUT_RESOURCE Fail to allocate memory.
1028 @retval EFI_SECURITY_VIOLATION The file specified by File did not authenticate, and
1029 the platform policy dictates that File should be placed
1030 in the untrusted state. The image has been added to the file
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.
1039 DxeImageVerificationHandler (
1040 IN UINT32 AuthenticationStatus
,
1041 IN CONST EFI_DEVICE_PATH_PROTOCOL
*File
,
1042 IN VOID
*FileBuffer
,
1044 IN BOOLEAN BootPolicy
1049 EFI_IMAGE_DOS_HEADER
*DosHdr
;
1050 EFI_STATUS VerifyStatus
;
1051 EFI_SIGNATURE_LIST
*SignatureList
;
1052 UINTN SignatureListSize
;
1053 EFI_SIGNATURE_DATA
*Signature
;
1054 EFI_IMAGE_EXECUTION_ACTION Action
;
1055 WIN_CERTIFICATE
*WinCertificate
;
1058 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
1059 UINT32 NumberOfRvaAndSizes
;
1060 WIN_CERTIFICATE_EFI_PKCS
*PkcsCertData
;
1061 WIN_CERTIFICATE_UEFI_GUID
*WinCertUefiGuid
;
1064 EFI_IMAGE_DATA_DIRECTORY
*SecDataDir
;
1067 SignatureList
= NULL
;
1068 SignatureListSize
= 0;
1069 WinCertificate
= NULL
;
1071 PkcsCertData
= NULL
;
1072 Action
= EFI_IMAGE_EXECUTION_AUTH_UNTESTED
;
1073 Status
= EFI_ACCESS_DENIED
;
1074 VerifyStatus
= EFI_ACCESS_DENIED
;
1077 // Check the image type and get policy setting.
1079 switch (GetImageType (File
)) {
1082 Policy
= ALWAYS_EXECUTE
;
1085 case IMAGE_FROM_OPTION_ROM
:
1086 Policy
= PcdGet32 (PcdOptionRomImageVerificationPolicy
);
1089 case IMAGE_FROM_REMOVABLE_MEDIA
:
1090 Policy
= PcdGet32 (PcdRemovableMediaImageVerificationPolicy
);
1093 case IMAGE_FROM_FIXED_MEDIA
:
1094 Policy
= PcdGet32 (PcdFixedMediaImageVerificationPolicy
);
1098 Policy
= DENY_EXECUTE_ON_SECURITY_VIOLATION
;
1102 // If policy is always/never execute, return directly.
1104 if (Policy
== ALWAYS_EXECUTE
) {
1106 } else if (Policy
== NEVER_EXECUTE
) {
1107 return EFI_ACCESS_DENIED
;
1111 // The policy QUERY_USER_ON_SECURITY_VIOLATION violates the UEFI spec and has been removed.
1113 ASSERT (Policy
!= QUERY_USER_ON_SECURITY_VIOLATION
);
1114 if (Policy
== QUERY_USER_ON_SECURITY_VIOLATION
) {
1118 GetEfiGlobalVariable2 (EFI_SECURE_BOOT_MODE_NAME
, (VOID
**)&SecureBoot
, NULL
);
1120 // Skip verification if SecureBoot variable doesn't exist.
1122 if (SecureBoot
== NULL
) {
1127 // Skip verification if SecureBoot is disabled.
1129 if (*SecureBoot
== SECURE_BOOT_MODE_DISABLE
) {
1130 FreePool (SecureBoot
);
1133 FreePool (SecureBoot
);
1136 // Read the Dos header.
1138 if (FileBuffer
== NULL
) {
1139 return EFI_INVALID_PARAMETER
;
1142 mImageBase
= (UINT8
*) FileBuffer
;
1143 mImageSize
= FileSize
;
1145 ZeroMem (&ImageContext
, sizeof (ImageContext
));
1146 ImageContext
.Handle
= (VOID
*) FileBuffer
;
1147 ImageContext
.ImageRead
= (PE_COFF_LOADER_READ_FILE
) DxeImageVerificationLibImageRead
;
1150 // Get information about the image being loaded
1152 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
1153 if (EFI_ERROR (Status
)) {
1155 // The information can't be got from the invalid PeImage
1160 Status
= EFI_ACCESS_DENIED
;
1162 DosHdr
= (EFI_IMAGE_DOS_HEADER
*) mImageBase
;
1163 if (DosHdr
->e_magic
== EFI_IMAGE_DOS_SIGNATURE
) {
1165 // DOS image header is present,
1166 // so read the PE header after the DOS image header.
1168 mPeCoffHeaderOffset
= DosHdr
->e_lfanew
;
1170 mPeCoffHeaderOffset
= 0;
1173 // Check PE/COFF image.
1175 mNtHeader
.Pe32
= (EFI_IMAGE_NT_HEADERS32
*) (mImageBase
+ mPeCoffHeaderOffset
);
1176 if (mNtHeader
.Pe32
->Signature
!= EFI_IMAGE_NT_SIGNATURE
) {
1178 // It is not a valid Pe/Coff file.
1183 if (mNtHeader
.Pe32
->FileHeader
.Machine
== IMAGE_FILE_MACHINE_IA64
&& mNtHeader
.Pe32
->OptionalHeader
.Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
1185 // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value
1186 // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the
1187 // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
1188 // then override the magic value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
1190 Magic
= EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
;
1193 // Get the magic value from the PE/COFF Optional Header
1195 Magic
= mNtHeader
.Pe32
->OptionalHeader
.Magic
;
1198 if (Magic
== EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
) {
1202 NumberOfRvaAndSizes
= mNtHeader
.Pe32
->OptionalHeader
.NumberOfRvaAndSizes
;
1203 if (NumberOfRvaAndSizes
> EFI_IMAGE_DIRECTORY_ENTRY_SECURITY
) {
1204 SecDataDir
= (EFI_IMAGE_DATA_DIRECTORY
*) &mNtHeader
.Pe32
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY
];
1208 // Use PE32+ offset.
1210 NumberOfRvaAndSizes
= mNtHeader
.Pe32Plus
->OptionalHeader
.NumberOfRvaAndSizes
;
1211 if (NumberOfRvaAndSizes
> EFI_IMAGE_DIRECTORY_ENTRY_SECURITY
) {
1212 SecDataDir
= (EFI_IMAGE_DATA_DIRECTORY
*) &mNtHeader
.Pe32Plus
->OptionalHeader
.DataDirectory
[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY
];
1217 // Start Image Validation.
1219 if (SecDataDir
== NULL
|| SecDataDir
->Size
== 0) {
1221 // This image is not signed. The SHA256 hash value of the image must match a record in the security database "db",
1222 // and not be reflected in the security data base "dbx".
1224 if (!HashPeImage (HASHALG_SHA256
)) {
1228 if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE1
, mImageDigest
, &mCertType
, mImageDigestSize
)) {
1230 // Image Hash is in forbidden database (DBX).
1235 if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE
, mImageDigest
, &mCertType
, mImageDigestSize
)) {
1237 // Image Hash is in allowed database (DB).
1243 // Image Hash is not found in both forbidden and allowed database.
1249 // Verify the signature of the image, multiple signatures are allowed as per PE/COFF Section 4.7
1250 // "Attribute Certificate Table".
1251 // The first certificate starts at offset (SecDataDir->VirtualAddress) from the start of the file.
1253 for (OffSet
= SecDataDir
->VirtualAddress
;
1254 OffSet
< (SecDataDir
->VirtualAddress
+ SecDataDir
->Size
);
1255 OffSet
+= WinCertificate
->dwLength
, OffSet
+= ALIGN_SIZE (OffSet
)) {
1256 WinCertificate
= (WIN_CERTIFICATE
*) (mImageBase
+ OffSet
);
1257 if ((SecDataDir
->VirtualAddress
+ SecDataDir
->Size
- OffSet
) <= sizeof (WIN_CERTIFICATE
) ||
1258 (SecDataDir
->VirtualAddress
+ SecDataDir
->Size
- OffSet
) < WinCertificate
->dwLength
) {
1263 // Verify the image's Authenticode signature, only DER-encoded PKCS#7 signed data is supported.
1265 if (WinCertificate
->wCertificateType
== WIN_CERT_TYPE_PKCS_SIGNED_DATA
) {
1267 // The certificate is formatted as WIN_CERTIFICATE_EFI_PKCS which is described in the
1268 // Authenticode specification.
1270 PkcsCertData
= (WIN_CERTIFICATE_EFI_PKCS
*) WinCertificate
;
1271 if (PkcsCertData
->Hdr
.dwLength
<= sizeof (PkcsCertData
->Hdr
)) {
1274 AuthData
= PkcsCertData
->CertData
;
1275 AuthDataSize
= PkcsCertData
->Hdr
.dwLength
- sizeof(PkcsCertData
->Hdr
);
1276 } else if (WinCertificate
->wCertificateType
== WIN_CERT_TYPE_EFI_GUID
) {
1278 // The certificate is formatted as WIN_CERTIFICATE_UEFI_GUID which is described in UEFI Spec.
1280 WinCertUefiGuid
= (WIN_CERTIFICATE_UEFI_GUID
*) WinCertificate
;
1281 if (WinCertUefiGuid
->Hdr
.dwLength
<= OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID
, CertData
)) {
1284 if (!CompareGuid (&WinCertUefiGuid
->CertType
, &gEfiCertPkcs7Guid
)) {
1287 AuthData
= WinCertUefiGuid
->CertData
;
1288 AuthDataSize
= WinCertUefiGuid
->Hdr
.dwLength
- OFFSET_OF(WIN_CERTIFICATE_UEFI_GUID
, CertData
);
1290 if (WinCertificate
->dwLength
< sizeof (WIN_CERTIFICATE
)) {
1296 Status
= HashPeImageByType (AuthData
, AuthDataSize
);
1297 if (EFI_ERROR (Status
)) {
1302 // Check the digital signature against the revoked certificate in forbidden database (dbx).
1304 if (IsPkcsSignedDataVerifiedBySignatureList (AuthData
, AuthDataSize
, EFI_IMAGE_SECURITY_DATABASE1
, &gEfiImageSecurityDatabaseGuid
)) {
1305 Action
= EFI_IMAGE_EXECUTION_AUTH_SIG_FAILED
;
1306 VerifyStatus
= EFI_ACCESS_DENIED
;
1311 // Check the digital signature against the valid certificate in allowed database (db).
1313 if (EFI_ERROR (VerifyStatus
)) {
1314 if (IsPkcsSignedDataVerifiedBySignatureList (AuthData
, AuthDataSize
, EFI_IMAGE_SECURITY_DATABASE
, &gEfiImageSecurityDatabaseGuid
)) {
1315 VerifyStatus
= EFI_SUCCESS
;
1320 // Check the image's hash value.
1322 if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE1
, mImageDigest
, &mCertType
, mImageDigestSize
)) {
1323 Action
= EFI_IMAGE_EXECUTION_AUTH_SIG_FOUND
;
1324 VerifyStatus
= EFI_ACCESS_DENIED
;
1326 } else if (EFI_ERROR (VerifyStatus
)) {
1327 if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE
, mImageDigest
, &mCertType
, mImageDigestSize
)) {
1328 VerifyStatus
= EFI_SUCCESS
;
1333 if (OffSet
!= (SecDataDir
->VirtualAddress
+ SecDataDir
->Size
)) {
1335 // The Size in Certificate Table or the attribute certicate table is corrupted.
1337 VerifyStatus
= EFI_ACCESS_DENIED
;
1340 if (!EFI_ERROR (VerifyStatus
)) {
1343 Status
= EFI_ACCESS_DENIED
;
1344 if (Action
== EFI_IMAGE_EXECUTION_AUTH_SIG_FAILED
|| Action
== EFI_IMAGE_EXECUTION_AUTH_SIG_FOUND
) {
1346 // Get image hash value as executable's signature.
1348 SignatureListSize
= sizeof (EFI_SIGNATURE_LIST
) + sizeof (EFI_SIGNATURE_DATA
) - 1 + mImageDigestSize
;
1349 SignatureList
= (EFI_SIGNATURE_LIST
*) AllocateZeroPool (SignatureListSize
);
1350 if (SignatureList
== NULL
) {
1351 Status
= EFI_OUT_OF_RESOURCES
;
1354 SignatureList
->SignatureHeaderSize
= 0;
1355 SignatureList
->SignatureListSize
= (UINT32
) SignatureListSize
;
1356 SignatureList
->SignatureSize
= (UINT32
) mImageDigestSize
;
1357 CopyMem (&SignatureList
->SignatureType
, &mCertType
, sizeof (EFI_GUID
));
1358 Signature
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) SignatureList
+ sizeof (EFI_SIGNATURE_LIST
));
1359 CopyMem (Signature
->SignatureData
, mImageDigest
, mImageDigestSize
);
1364 if (Status
!= EFI_SUCCESS
) {
1366 // Policy decides to defer or reject the image; add its information in image executable information table.
1368 AddImageExeInfo (Action
, NULL
, File
, SignatureList
, SignatureListSize
);
1369 Status
= EFI_SECURITY_VIOLATION
;
1372 if (SignatureList
!= NULL
) {
1373 FreePool (SignatureList
);
1380 Register security measurement handler.
1382 @param ImageHandle ImageHandle of the loaded driver.
1383 @param SystemTable Pointer to the EFI System Table.
1385 @retval EFI_SUCCESS The handlers were registered successfully.
1389 DxeImageVerificationLibConstructor (
1390 IN EFI_HANDLE ImageHandle
,
1391 IN EFI_SYSTEM_TABLE
*SystemTable
1394 return RegisterSecurity2Handler (
1395 DxeImageVerificationHandler
,
1396 EFI_AUTH_OPERATION_VERIFY_IMAGE
| EFI_AUTH_OPERATION_IMAGE_REQUIRED