render / rpms / edk2

Forked from rpms/edk2 3 months ago
Clone

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

63d87e
From 37b5981bf7eb94314b62810da495d724873d904a Mon Sep 17 00:00:00 2001
63d87e
From: Laszlo Ersek <lersek@redhat.com>
63d87e
Date: Fri, 31 Jan 2020 12:42:40 +0100
63d87e
Subject: [PATCH 04/12] SecurityPkg/DxeImageVerificationHandler: keep PE/COFF
63d87e
 info status internal
63d87e
MIME-Version: 1.0
63d87e
Content-Type: text/plain; charset=UTF-8
63d87e
Content-Transfer-Encoding: 8bit
63d87e
63d87e
RH-Author: Laszlo Ersek <lersek@redhat.com>
63d87e
Message-id: <20200131124248.22369-5-lersek@redhat.com>
63d87e
Patchwork-id: 93609
63d87e
O-Subject: [RHEL-8.2.0 edk2 PATCH 04/12] SecurityPkg/DxeImageVerificationHandler: keep PE/COFF info status internal
63d87e
Bugzilla: 1751993
63d87e
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
63d87e
RH-Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
63d87e
63d87e
The PeCoffLoaderGetImageInfo() function may return various error codes,
63d87e
such as RETURN_INVALID_PARAMETER and RETURN_UNSUPPORTED.
63d87e
63d87e
Such error values should not be assigned to our "Status" variable in the
63d87e
DxeImageVerificationHandler() function, because "Status" generally stands
63d87e
for the main exit value of the function. And
63d87e
SECURITY2_FILE_AUTHENTICATION_HANDLER functions are expected to return one
63d87e
of EFI_SUCCESS, EFI_SECURITY_VIOLATION, and EFI_ACCESS_DENIED only.
63d87e
63d87e
Introduce the "PeCoffStatus" helper variable for keeping the return value
63d87e
of PeCoffLoaderGetImageInfo() internal to the function. If
63d87e
PeCoffLoaderGetImageInfo() fails, we'll jump to the "Done" label with
63d87e
"Status" being EFI_ACCESS_DENIED, inherited from the top of the function.
63d87e
63d87e
Note that this is consistent with the subsequent PE/COFF Signature check,
63d87e
where we jump to the "Done" label with "Status" having been re-set to
63d87e
EFI_ACCESS_DENIED.
63d87e
63d87e
As a consequence, we can at once remove the
63d87e
63d87e
  Status = EFI_ACCESS_DENIED;
63d87e
63d87e
assignment right after the "PeCoffStatus" check.
63d87e
63d87e
This patch does not change the control flow in the function, it only
63d87e
changes the "Status" outcome from API-incompatible error codes to
63d87e
EFI_ACCESS_DENIED, under some circumstances.
63d87e
63d87e
Cc: Chao Zhang <chao.b.zhang@intel.com>
63d87e
Cc: Jian J Wang <jian.j.wang@intel.com>
63d87e
Cc: Jiewen Yao <jiewen.yao@intel.com>
63d87e
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2129
63d87e
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
63d87e
Message-Id: <20200116190705.18816-4-lersek@redhat.com>
63d87e
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
63d87e
[lersek@redhat.com: push with Mike's R-b due to Chinese New Year
63d87e
 Holiday: <https://edk2.groups.io/g/devel/message/53429>; msgid
63d87e
 <d3fbb76dabed4e1987c512c328c82810@intel.com>]
63d87e
(cherry picked from commit 61a9fa589a15e9005bec293f9766c78b60fbc9fc)
63d87e
63d87e
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
63d87e
---
63d87e
 .../Library/DxeImageVerificationLib/DxeImageVerificationLib.c      | 7 +++----
63d87e
 1 file changed, 3 insertions(+), 4 deletions(-)
63d87e
63d87e
diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
63d87e
index 8204c9c..e6c8a54 100644
63d87e
--- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
63d87e
+++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c
63d87e
@@ -1580,6 +1580,7 @@ DxeImageVerificationHandler (
63d87e
   EFI_IMAGE_DATA_DIRECTORY             *SecDataDir;
63d87e
   UINT32                               OffSet;
63d87e
   CHAR16                               *NameStr;
63d87e
+  RETURN_STATUS                        PeCoffStatus;
63d87e
 
63d87e
   SignatureList     = NULL;
63d87e
   SignatureListSize = 0;
63d87e
@@ -1669,8 +1670,8 @@ DxeImageVerificationHandler (
63d87e
   //
63d87e
   // Get information about the image being loaded
63d87e
   //
63d87e
-  Status = PeCoffLoaderGetImageInfo (&ImageContext);
63d87e
-  if (EFI_ERROR (Status)) {
63d87e
+  PeCoffStatus = PeCoffLoaderGetImageInfo (&ImageContext);
63d87e
+  if (RETURN_ERROR (PeCoffStatus)) {
63d87e
     //
63d87e
     // The information can't be got from the invalid PeImage
63d87e
     //
63d87e
@@ -1678,8 +1679,6 @@ DxeImageVerificationHandler (
63d87e
     goto Done;
63d87e
   }
63d87e
 
63d87e
-  Status = EFI_ACCESS_DENIED;
63d87e
-
63d87e
   DosHdr = (EFI_IMAGE_DOS_HEADER *) mImageBase;
63d87e
   if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
63d87e
     //
63d87e
-- 
63d87e
1.8.3.1
63d87e