render / rpms / edk2

Forked from rpms/edk2 2 months ago
Clone

Blame SOURCES/edk2-NetworkPkg-IScsiDxe-assert-that-IScsiBinToHex-always.patch

c4e3b2
From 713a76945fb7962d97be9c0f8a54a32da5f683d2 Mon Sep 17 00:00:00 2001
c4e3b2
From: Laszlo Ersek <lersek@redhat.com>
c4e3b2
Date: Tue, 8 Jun 2021 14:12:55 +0200
c4e3b2
Subject: [PATCH 06/11] NetworkPkg/IScsiDxe: assert that IScsiBinToHex() always
c4e3b2
 succeeds
c4e3b2
MIME-Version: 1.0
c4e3b2
Content-Type: text/plain; charset=UTF-8
c4e3b2
Content-Transfer-Encoding: 8bit
c4e3b2
c4e3b2
RH-Author: Laszlo Ersek <lersek@redhat.com>
c4e3b2
RH-MergeRequest: 1: NetworkPkg/IScsiDxe: fix IScsiHexToBin() security and functionality bugs [RHEL-9, c9s]
c4e3b2
RH-Commit: [6/10] f75dedb1034e5feb5fd268c99184d3e392ef9beb
c4e3b2
RH-Bugzilla: 1961100
c4e3b2
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
c4e3b2
c4e3b2
IScsiBinToHex() is called for encoding:
c4e3b2
c4e3b2
- the answer to the target's challenge; that is, CHAP_R;
c4e3b2
c4e3b2
- the challenge for the target, in case mutual authentication is enabled;
c4e3b2
  that is, CHAP_C.
c4e3b2
c4e3b2
The initiator controls the size of both blobs, the sizes of their hex
c4e3b2
encodings are correctly calculated in "RspLen" and "ChallengeLen".
c4e3b2
Therefore the IScsiBinToHex() calls never fail; assert that.
c4e3b2
c4e3b2
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
c4e3b2
Cc: Maciej Rabeda <maciej.rabeda@linux.intel.com>
c4e3b2
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
c4e3b2
Cc: Siyuan Fu <siyuan.fu@intel.com>
c4e3b2
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3356
c4e3b2
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
c4e3b2
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
c4e3b2
Reviewed-by: Maciej Rabeda <maciej.rabeda@linux.intel.com>
c4e3b2
Message-Id: <20210608121259.32451-7-lersek@redhat.com>
c4e3b2
(cherry picked from commit d90fff40cb2502b627370a77f5608c8a178c3f78)
c4e3b2
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
c4e3b2
---
c4e3b2
 NetworkPkg/IScsiDxe/IScsiCHAP.c | 27 +++++++++++++++------------
c4e3b2
 1 file changed, 15 insertions(+), 12 deletions(-)
c4e3b2
c4e3b2
diff --git a/NetworkPkg/IScsiDxe/IScsiCHAP.c b/NetworkPkg/IScsiDxe/IScsiCHAP.c
c4e3b2
index 9e192ce292..dbe3c8ef46 100644
c4e3b2
--- a/NetworkPkg/IScsiDxe/IScsiCHAP.c
c4e3b2
+++ b/NetworkPkg/IScsiDxe/IScsiCHAP.c
c4e3b2
@@ -391,6 +391,7 @@ IScsiCHAPToSendReq (
c4e3b2
   UINT32                      RspLen;
c4e3b2
   CHAR8                       *Challenge;
c4e3b2
   UINT32                      ChallengeLen;
c4e3b2
+  EFI_STATUS                  BinToHexStatus;
c4e3b2
 
c4e3b2
   ASSERT (Conn->CurrentStage == ISCSI_SECURITY_NEGOTIATION);
c4e3b2
 
c4e3b2
@@ -471,12 +472,13 @@ IScsiCHAPToSendReq (
c4e3b2
     //
c4e3b2
     // CHAP_R=<R>
c4e3b2
     //
c4e3b2
-    IScsiBinToHex (
c4e3b2
-      (UINT8 *) AuthData->CHAPResponse,
c4e3b2
-      ISCSI_CHAP_RSP_LEN,
c4e3b2
-      Response,
c4e3b2
-      &RspLen
c4e3b2
-      );
c4e3b2
+    BinToHexStatus = IScsiBinToHex (
c4e3b2
+                       (UINT8 *) AuthData->CHAPResponse,
c4e3b2
+                       ISCSI_CHAP_RSP_LEN,
c4e3b2
+                       Response,
c4e3b2
+                       &RspLen
c4e3b2
+                       );
c4e3b2
+    ASSERT_EFI_ERROR (BinToHexStatus);
c4e3b2
     IScsiAddKeyValuePair (Pdu, ISCSI_KEY_CHAP_RESPONSE, Response);
c4e3b2
 
c4e3b2
     if (AuthData->AuthConfig->CHAPType == ISCSI_CHAP_MUTUAL) {
c4e3b2
@@ -490,12 +492,13 @@ IScsiCHAPToSendReq (
c4e3b2
       // CHAP_C=<C>
c4e3b2
       //
c4e3b2
       IScsiGenRandom ((UINT8 *) AuthData->OutChallenge, ISCSI_CHAP_RSP_LEN);
c4e3b2
-      IScsiBinToHex (
c4e3b2
-        (UINT8 *) AuthData->OutChallenge,
c4e3b2
-        ISCSI_CHAP_RSP_LEN,
c4e3b2
-        Challenge,
c4e3b2
-        &ChallengeLen
c4e3b2
-        );
c4e3b2
+      BinToHexStatus = IScsiBinToHex (
c4e3b2
+                         (UINT8 *) AuthData->OutChallenge,
c4e3b2
+                         ISCSI_CHAP_RSP_LEN,
c4e3b2
+                         Challenge,
c4e3b2
+                         &ChallengeLen
c4e3b2
+                         );
c4e3b2
+      ASSERT_EFI_ERROR (BinToHexStatus);
c4e3b2
       IScsiAddKeyValuePair (Pdu, ISCSI_KEY_CHAP_CHALLENGE, Challenge);
c4e3b2
 
c4e3b2
       Conn->AuthStep = ISCSI_CHAP_STEP_FOUR;
c4e3b2
-- 
c4e3b2
2.27.0
c4e3b2