Blame SOURCES/edk2-SecurityPkg-DxeImageVerificationHandler-keep-PE-COFF.patch

6009e6
From 37b5981bf7eb94314b62810da495d724873d904a Mon Sep 17 00:00:00 2001
6009e6
From: Laszlo Ersek <lersek@redhat.com>
6009e6
Date: Fri, 31 Jan 2020 12:42:40 +0100
6009e6
Subject: [PATCH 04/12] SecurityPkg/DxeImageVerificationHandler: keep PE/COFF
6009e6
 info status internal
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-5-lersek@redhat.com>
6009e6
Patchwork-id: 93609
6009e6
O-Subject: [RHEL-8.2.0 edk2 PATCH 04/12] SecurityPkg/DxeImageVerificationHandler: keep PE/COFF info status internal
6009e6
Bugzilla: 1751993
6009e6
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6009e6
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
6009e6
6009e6
The PeCoffLoaderGetImageInfo() function may return various error codes,
6009e6
such as RETURN_INVALID_PARAMETER and RETURN_UNSUPPORTED.
6009e6
6009e6
Such error values should not be assigned to our "Status" variable in the
6009e6
DxeImageVerificationHandler() function, because "Status" generally stands
6009e6
for the main exit value of the function. And
6009e6
SECURITY2_FILE_AUTHENTICATION_HANDLER functions are expected to return one
6009e6
of EFI_SUCCESS, EFI_SECURITY_VIOLATION, and EFI_ACCESS_DENIED only.
6009e6
6009e6
Introduce the "PeCoffStatus" helper variable for keeping the return value
6009e6
of PeCoffLoaderGetImageInfo() internal to the function. If
6009e6
PeCoffLoaderGetImageInfo() fails, we'll jump to the "Done" label with
6009e6
"Status" being EFI_ACCESS_DENIED, inherited from the top of the function.
6009e6
6009e6
Note that this is consistent with the subsequent PE/COFF Signature check,
6009e6
where we jump to the "Done" label with "Status" having been re-set to
6009e6
EFI_ACCESS_DENIED.
6009e6
6009e6
As a consequence, we can at once remove the
6009e6
6009e6
  Status = EFI_ACCESS_DENIED;
6009e6
6009e6
assignment right after the "PeCoffStatus" check.
6009e6
6009e6
This patch does not change the control flow in the function, it only
6009e6
changes the "Status" outcome from API-incompatible error codes to
6009e6
EFI_ACCESS_DENIED, under some circumstances.
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-4-lersek@redhat.com>
6009e6
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
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 61a9fa589a15e9005bec293f9766c78b60fbc9fc)
6009e6
6009e6
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
6009e6
---
6009e6
 .../Library/DxeImageVerificationLib/DxeImageVerificationLib.c      | 7 +++----
6009e6
 1 file changed, 3 insertions(+), 4 deletions(-)
6009e6
6009e6
diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
6009e6
index 8204c9c..e6c8a54 100644
6009e6
--- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
6009e6
+++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
6009e6
@@ -1580,6 +1580,7 @@ DxeImageVerificationHandler (
6009e6
   EFI_IMAGE_DATA_DIRECTORY             *SecDataDir;
6009e6
   UINT32                               OffSet;
6009e6
   CHAR16                               *NameStr;
6009e6
+  RETURN_STATUS                        PeCoffStatus;
6009e6
 
6009e6
   SignatureList     = NULL;
6009e6
   SignatureListSize = 0;
6009e6
@@ -1669,8 +1670,8 @@ DxeImageVerificationHandler (
6009e6
   //
6009e6
   // Get information about the image being loaded
6009e6
   //
6009e6
-  Status = PeCoffLoaderGetImageInfo (&ImageContext);
6009e6
-  if (EFI_ERROR (Status)) {
6009e6
+  PeCoffStatus = PeCoffLoaderGetImageInfo (&ImageContext);
6009e6
+  if (RETURN_ERROR (PeCoffStatus)) {
6009e6
     //
6009e6
     // The information can't be got from the invalid PeImage
6009e6
     //
6009e6
@@ -1678,8 +1679,6 @@ DxeImageVerificationHandler (
6009e6
     goto Done;
6009e6
   }
6009e6
 
6009e6
-  Status = EFI_ACCESS_DENIED;
6009e6
-
6009e6
   DosHdr = (EFI_IMAGE_DOS_HEADER *) mImageBase;
6009e6
   if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
6009e6
     //
6009e6
-- 
6009e6
1.8.3.1
6009e6