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

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