Blame SOURCES/edk2-SecurityPkg-DxeImageVerificationHandler-unnest-AddIm.patch

6009e6
From 3e06fe42d63856e48c6457dbb7e816b82416c9ca Mon Sep 17 00:00:00 2001
6009e6
From: Laszlo Ersek <lersek@redhat.com>
6009e6
Date: Fri, 31 Jan 2020 12:42:44 +0100
6009e6
Subject: [PATCH 08/12] SecurityPkg/DxeImageVerificationHandler: unnest
6009e6
 AddImageExeInfo() call
6009e6
MIME-Version: 1.0
6009e6
Content-Type: text/plain; charset=UTF-8
6009e6
Content-Transfer-Encoding: 8bit
6009e6
6009e6
RH-Author: Laszlo Ersek <lersek@redhat.com>
6009e6
Message-id: <20200131124248.22369-9-lersek@redhat.com>
6009e6
Patchwork-id: 93610
6009e6
O-Subject: [RHEL-8.2.0 edk2 PATCH 08/12] SecurityPkg/DxeImageVerificationHandler: unnest AddImageExeInfo() call
6009e6
Bugzilla: 1751993
6009e6
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6009e6
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
6009e6
6009e6
Before the "Done" label at the end of DxeImageVerificationHandler(), we
6009e6
now have a single access to "Status": we set "Status" to EFI_ACCESS_DENIED
6009e6
at the top of the function. Therefore, the (Status != EFI_SUCCESS)
6009e6
condition is always true under the "Done" label.
6009e6
6009e6
Accordingly, unnest the AddImageExeInfo() call dependent on that
6009e6
condition, remove the condition, and also rename the "Done" label to
6009e6
"Failed".
6009e6
6009e6
Functionally, this patch is a no-op. It's easier to review with:
6009e6
6009e6
  git show -b -W
6009e6
6009e6
Cc: Chao Zhang <chao.b.zhang@intel.com>
6009e6
Cc: Jian J Wang <jian.j.wang@intel.com>
6009e6
Cc: Jiewen Yao <jiewen.yao@intel.com>
6009e6
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2129
6009e6
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
6009e6
Message-Id: <20200116190705.18816-8-lersek@redhat.com>
6009e6
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
6009e6
[lersek@redhat.com: replace EFI_D_INFO w/ DEBUG_INFO for PatchCheck.py]
6009e6
[lersek@redhat.com: push with Mike's R-b due to Chinese New Year
6009e6
 Holiday: <https://edk2.groups.io/g/devel/message/53429>; msgid
6009e6
 <d3fbb76dabed4e1987c512c328c82810@intel.com>]
6009e6
(cherry picked from commit c602e97446a8e818bf09182f5dc9f3fa409ece95)
6009e6
6009e6
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
6009e6
---
6009e6
 .../DxeImageVerificationLib.c                      | 34 ++++++++++------------
6009e6
 1 file changed, 16 insertions(+), 18 deletions(-)
6009e6
6009e6
diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
6009e6
index 6ccce1f..51968bd 100644
6009e6
--- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
6009e6
+++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
6009e6
@@ -1676,7 +1676,7 @@ DxeImageVerificationHandler (
6009e6
     // The information can't be got from the invalid PeImage
6009e6
     //
6009e6
     DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: PeImage invalid. Cannot retrieve image information.\n"));
6009e6
-    goto Done;
6009e6
+    goto Failed;
6009e6
   }
6009e6
 
6009e6
   DosHdr = (EFI_IMAGE_DOS_HEADER *) mImageBase;
6009e6
@@ -1698,7 +1698,7 @@ DxeImageVerificationHandler (
6009e6
     // It is not a valid Pe/Coff file.
6009e6
     //
6009e6
     DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Not a valid PE/COFF image.\n"));
6009e6
-    goto Done;
6009e6
+    goto Failed;
6009e6
   }
6009e6
 
6009e6
   if (mNtHeader.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
6009e6
@@ -1729,7 +1729,7 @@ DxeImageVerificationHandler (
6009e6
     //
6009e6
     if (!HashPeImage (HASHALG_SHA256)) {
6009e6
       DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Failed to hash this image using %s.\n", mHashTypeStr));
6009e6
-      goto Done;
6009e6
+      goto Failed;
6009e6
     }
6009e6
 
6009e6
     if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE1, mImageDigest, &mCertType, mImageDigestSize)) {
6009e6
@@ -1737,7 +1737,7 @@ DxeImageVerificationHandler (
6009e6
       // Image Hash is in forbidden database (DBX).
6009e6
       //
6009e6
       DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Image is not signed and %s hash of image is forbidden by DBX.\n", mHashTypeStr));
6009e6
-      goto Done;
6009e6
+      goto Failed;
6009e6
     }
6009e6
 
6009e6
     if (IsSignatureFoundInDatabase (EFI_IMAGE_SECURITY_DATABASE, mImageDigest, &mCertType, mImageDigestSize)) {
6009e6
@@ -1751,7 +1751,7 @@ DxeImageVerificationHandler (
6009e6
     // Image Hash is not found in both forbidden and allowed database.
6009e6
     //
6009e6
     DEBUG ((DEBUG_INFO, "DxeImageVerificationLib: Image is not signed and %s hash of image is not found in DB/DBX.\n", mHashTypeStr));
6009e6
-    goto Done;
6009e6
+    goto Failed;
6009e6
   }
6009e6
 
6009e6
   //
6009e6
@@ -1860,7 +1860,7 @@ DxeImageVerificationHandler (
6009e6
     SignatureListSize = sizeof (EFI_SIGNATURE_LIST) + sizeof (EFI_SIGNATURE_DATA) - 1 + mImageDigestSize;
6009e6
     SignatureList     = (EFI_SIGNATURE_LIST *) AllocateZeroPool (SignatureListSize);
6009e6
     if (SignatureList == NULL) {
6009e6
-      goto Done;
6009e6
+      goto Failed;
6009e6
     }
6009e6
     SignatureList->SignatureHeaderSize  = 0;
6009e6
     SignatureList->SignatureListSize    = (UINT32) SignatureListSize;
6009e6
@@ -1870,19 +1870,17 @@ DxeImageVerificationHandler (
6009e6
     CopyMem (Signature->SignatureData, mImageDigest, mImageDigestSize);
6009e6
   }
6009e6
 
6009e6
-Done:
6009e6
-  if (Status != EFI_SUCCESS) {
6009e6
-    //
6009e6
-    // Policy decides to defer or reject the image; add its information in image executable information table.
6009e6
-    //
6009e6
-    NameStr = ConvertDevicePathToText (File, FALSE, TRUE);
6009e6
-    AddImageExeInfo (Action, NameStr, File, SignatureList, SignatureListSize);
6009e6
-    if (NameStr != NULL) {
6009e6
-      DEBUG((EFI_D_INFO, "The image doesn't pass verification: %s\n", NameStr));
6009e6
-      FreePool(NameStr);
6009e6
-    }
6009e6
-    Status = EFI_SECURITY_VIOLATION;
6009e6
+Failed:
6009e6
+  //
6009e6
+  // Policy decides to defer or reject the image; add its information in image executable information table.
6009e6
+  //
6009e6
+  NameStr = ConvertDevicePathToText (File, FALSE, TRUE);
6009e6
+  AddImageExeInfo (Action, NameStr, File, SignatureList, SignatureListSize);
6009e6
+  if (NameStr != NULL) {
6009e6
+    DEBUG ((DEBUG_INFO, "The image doesn't pass verification: %s\n", NameStr));
6009e6
+    FreePool(NameStr);
6009e6
   }
6009e6
+  Status = EFI_SECURITY_VIOLATION;
6009e6
 
6009e6
   if (SignatureList != NULL) {
6009e6
     FreePool (SignatureList);
6009e6
-- 
6009e6
1.8.3.1
6009e6