Before the "Done" label at the end of DxeImageVerificationHandler(), we
now have a single access to "Status": we set "Status" to EFI_ACCESS_DENIED
at the top of the function. Therefore, the (Status != EFI_SUCCESS)
condition is always true under the "Done" label.
Accordingly, unnest the AddImageExeInfo() call dependent on that
condition, remove the condition, and also rename the "Done" label to
"Failed".
Functionally, this patch is a no-op. It's easier to review with:
git show -b -W
Cc: Chao Zhang <chao.b.zhang@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2129
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <
20200116190705.18816-8-lersek@redhat.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
[lersek@redhat.com: replace EFI_D_INFO w/ DEBUG_INFO for PatchCheck.py]
[lersek@redhat.com: push with Mike's R-b due to Chinese New Year
Holiday: <https://edk2.groups.io/g/devel/message/53429>; msgid
<
d3fbb76dabed4e1987c512c328c82810@intel.com>]
// The information can't be got from the invalid PeImage\r
//\r
DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: PeImage invalid. Cannot retrieve image information.\n"));\r
// The information can't be got from the invalid PeImage\r
//\r
DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: PeImage invalid. Cannot retrieve image information.\n"));\r
}\r
\r
DosHdr = (EFI_IMAGE_DOS_HEADER *) mImageBase;\r
}\r
\r
DosHdr = (EFI_IMAGE_DOS_HEADER *) mImageBase;\r
// It is not a valid Pe/Coff file.\r
//\r
DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Not a valid PE/COFF image.\n"));\r
// It is not a valid Pe/Coff file.\r
//\r
DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Not a valid PE/COFF image.\n"));\r
}\r
\r
if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
}\r
\r
if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
//\r
if (!HashPeImage (HASHALG_SHA256)) {\r
DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Failed to hash this image using %s.\n", mHashTypeStr));\r
//\r
if (!HashPeImage (HASHALG_SHA256)) {\r
DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Failed to hash this image using %s.\n", mHashTypeStr));\r
}\r
\r
if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE1, mImageDigest, &mCertType, mImageDigestSize)) {\r
}\r
\r
if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE1, mImageDigest, &mCertType, mImageDigestSize)) {\r
// Image Hash is in forbidden database (DBX).\r
//\r
DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Image is not signed and %s hash of image is forbidden by DBX.\n", mHashTypeStr));\r
// Image Hash is in forbidden database (DBX).\r
//\r
DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Image is not signed and %s hash of image is forbidden by DBX.\n", mHashTypeStr));\r
}\r
\r
if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE, mImageDigest, &mCertType, mImageDigestSize)) {\r
}\r
\r
if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE, mImageDigest, &mCertType, mImageDigestSize)) {\r
// Image Hash is not found in both forbidden and allowed database.\r
//\r
DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Image is not signed and %s hash of image is not found in DB/DBX.\n", mHashTypeStr));\r
// Image Hash is not found in both forbidden and allowed database.\r
//\r
DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Image is not signed and %s hash of image is not found in DB/DBX.\n", mHashTypeStr));\r
SignatureListSize = sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + mImageDigestSize;\r
SignatureList = (EFI_SIGNATURE_LIST *) AllocateZeroPool (SignatureListSize);\r
if (SignatureList == NULL) {\r
SignatureListSize = sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + mImageDigestSize;\r
SignatureList = (EFI_SIGNATURE_LIST *) AllocateZeroPool (SignatureListSize);\r
if (SignatureList == NULL) {\r
}\r
SignatureList->SignatureHeaderSize = 0;\r
SignatureList->SignatureListSize = (UINT32) SignatureListSize;\r
}\r
SignatureList->SignatureHeaderSize = 0;\r
SignatureList->SignatureListSize = (UINT32) SignatureListSize;\r
CopyMem (Signature->SignatureData, mImageDigest, mImageDigestSize);\r
}\r
\r
CopyMem (Signature->SignatureData, mImageDigest, mImageDigestSize);\r
}\r
\r
-Done:\r
- if (Status != EFI_SUCCESS) {\r
- //\r
- // Policy decides to defer or reject the image; add its information in image executable information table.\r
- //\r
- NameStr = ConvertDevicePathToText (File, FALSE, TRUE);\r
- AddImageExeInfo (Action, NameStr, File, SignatureList, SignatureListSize);\r
- if (NameStr != NULL) {\r
- DEBUG((EFI_D_INFO, "The image doesn't pass verification: %s\n", NameStr));\r
- FreePool(NameStr);\r
- }\r
- Status = EFI_SECURITY_VIOLATION;\r
+Failed:\r
+ //\r
+ // Policy decides to defer or reject the image; add its information in image executable information table.\r
+ //\r
+ NameStr = ConvertDevicePathToText (File, FALSE, TRUE);\r
+ AddImageExeInfo (Action, NameStr, File, SignatureList, SignatureListSize);\r
+ if (NameStr != NULL) {\r
+ DEBUG ((DEBUG_INFO, "The image doesn't pass verification: %s\n", NameStr));\r
+ FreePool(NameStr);\r
+ Status = EFI_SECURITY_VIOLATION;\r
\r
if (SignatureList != NULL) {\r
FreePool (SignatureList);\r
\r
if (SignatureList != NULL) {\r
FreePool (SignatureList);\r