Blame SOURCES/edk2-NetworkPkg-IScsiDxe-wrap-IScsiCHAP-source-files-to-8.patch

12bdf0
From 28e260828557340709ef14e8132e96b54128c5a3 Mon Sep 17 00:00:00 2001
12bdf0
From: Laszlo Ersek <lersek@redhat.com>
12bdf0
Date: Tue, 8 Jun 2021 14:12:50 +0200
12bdf0
Subject: [PATCH 01/10] NetworkPkg/IScsiDxe: wrap IScsiCHAP source files to 80
12bdf0
 characters
12bdf0
MIME-Version: 1.0
12bdf0
Content-Type: text/plain; charset=UTF-8
12bdf0
Content-Transfer-Encoding: 8bit
12bdf0
12bdf0
RH-Author: Laszlo Ersek <lersek@redhat.com>
12bdf0
RH-MergeRequest: 5: NetworkPkg/IScsiDxe: fix IScsiHexToBin() security and functionality bugs [rhel-8.5.0, post-rebase]
12bdf0
RH-Commit: [1/10] 7ae9c45fbc0ffd807a95fad802619cd838257cc8
12bdf0
RH-Bugzilla: 1956408
12bdf0
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12bdf0
12bdf0
Working with overlong lines is difficult for me; rewrap the CHAP-related
12bdf0
source files in IScsiDxe to 80 characters width. No functional changes.
12bdf0
12bdf0
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
12bdf0
Cc: Maciej Rabeda <maciej.rabeda@linux.intel.com>
12bdf0
Cc: Philippe Mathieu-Daud <philmd@redhat.com>
12bdf0
Cc: Siyuan Fu <siyuan.fu@intel.com>
12bdf0
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3356
12bdf0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
12bdf0
Reviewed-by: Maciej Rabeda <maciej.rabeda@linux.intel.com>
12bdf0
Reviewed-by: Philippe Mathieu-Daud <philmd@redhat.com>
12bdf0
Message-Id: <20210608121259.32451-2-lersek@redhat.com>
12bdf0
(cherry picked from commit 83761337ec91fbd459c55d7d956fcc25df3bfa50)
12bdf0
---
12bdf0
 NetworkPkg/IScsiDxe/IScsiCHAP.c | 90 +++++++++++++++++++++++++--------
12bdf0
 NetworkPkg/IScsiDxe/IScsiCHAP.h |  3 +-
12bdf0
 2 files changed, 71 insertions(+), 22 deletions(-)
12bdf0
12bdf0
diff --git a/NetworkPkg/IScsiDxe/IScsiCHAP.c b/NetworkPkg/IScsiDxe/IScsiCHAP.c
12bdf0
index 355c6f129f..cbbc56ae5b 100644
12bdf0
--- a/NetworkPkg/IScsiDxe/IScsiCHAP.c
12bdf0
+++ b/NetworkPkg/IScsiDxe/IScsiCHAP.c
12bdf0
@@ -1,5 +1,6 @@
12bdf0
 /** @file
12bdf0
-  This file is for Challenge-Handshake Authentication Protocol (CHAP) Configuration.
12bdf0
+  This file is for Challenge-Handshake Authentication Protocol (CHAP)
12bdf0
+  Configuration.
12bdf0
 
12bdf0
 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
12bdf0
 SPDX-License-Identifier: BSD-2-Clause-Patent
12bdf0
@@ -18,9 +19,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
12bdf0
   @param[in]   ChallengeLength    The length of iSCSI CHAP challenge message.
12bdf0
   @param[out]  ChapResponse       The calculation of the expected hash value.
12bdf0
 
12bdf0
-  @retval EFI_SUCCESS             The expected hash value was calculatedly successfully.
12bdf0
-  @retval EFI_PROTOCOL_ERROR      The length of the secret should be at least the
12bdf0
-                                  length of the hash value for the hashing algorithm chosen.
12bdf0
+  @retval EFI_SUCCESS             The expected hash value was calculatedly
12bdf0
+                                  successfully.
12bdf0
+  @retval EFI_PROTOCOL_ERROR      The length of the secret should be at least
12bdf0
+                                  the length of the hash value for the hashing
12bdf0
+                                  algorithm chosen.
12bdf0
   @retval EFI_PROTOCOL_ERROR      MD5 hash operation fail.
12bdf0
   @retval EFI_OUT_OF_RESOURCES    Fail to allocate resource to complete MD5.
12bdf0
 
12bdf0
@@ -94,8 +97,10 @@ Exit:
12bdf0
   @param[in]   AuthData             iSCSI CHAP authentication data.
12bdf0
   @param[in]   TargetResponse       The response from target.
12bdf0
 
12bdf0
-  @retval EFI_SUCCESS               The response from target passed authentication.
12bdf0
-  @retval EFI_SECURITY_VIOLATION    The response from target was not expected value.
12bdf0
+  @retval EFI_SUCCESS               The response from target passed
12bdf0
+                                    authentication.
12bdf0
+  @retval EFI_SECURITY_VIOLATION    The response from target was not expected
12bdf0
+                                    value.
12bdf0
   @retval Others                    Other errors as indicated.
12bdf0
 
12bdf0
 **/
12bdf0
@@ -193,7 +198,10 @@ IScsiCHAPOnRspReceived (
12bdf0
     //
12bdf0
     // The first Login Response.
12bdf0
     //
12bdf0
-    Value = IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_TARGET_PORTAL_GROUP_TAG);
12bdf0
+    Value = IScsiGetValueByKeyFromList (
12bdf0
+              KeyValueList,
12bdf0
+              ISCSI_KEY_TARGET_PORTAL_GROUP_TAG
12bdf0
+              );
12bdf0
     if (Value == NULL) {
12bdf0
       goto ON_EXIT;
12bdf0
     }
12bdf0
@@ -205,13 +213,17 @@ IScsiCHAPOnRspReceived (
12bdf0
 
12bdf0
     Session->TargetPortalGroupTag = (UINT16) Result;
12bdf0
 
12bdf0
-    Value                         = IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_AUTH_METHOD);
12bdf0
+    Value                         = IScsiGetValueByKeyFromList (
12bdf0
+                                      KeyValueList,
12bdf0
+                                      ISCSI_KEY_AUTH_METHOD
12bdf0
+                                      );
12bdf0
     if (Value == NULL) {
12bdf0
       goto ON_EXIT;
12bdf0
     }
12bdf0
     //
12bdf0
-    // Initiator mandates CHAP authentication but target replies without "CHAP", or
12bdf0
-    // initiator suggets "None" but target replies with some kind of auth method.
12bdf0
+    // Initiator mandates CHAP authentication but target replies without
12bdf0
+    // "CHAP", or initiator suggets "None" but target replies with some kind of
12bdf0
+    // auth method.
12bdf0
     //
12bdf0
     if (Session->AuthType == ISCSI_AUTH_TYPE_NONE) {
12bdf0
       if (AsciiStrCmp (Value, ISCSI_KEY_VALUE_NONE) != 0) {
12bdf0
@@ -236,7 +248,10 @@ IScsiCHAPOnRspReceived (
12bdf0
     //
12bdf0
     // The Target replies with CHAP_A= CHAP_I= CHAP_C=<C>
12bdf0
     //
12bdf0
-    Value = IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_CHAP_ALGORITHM);
12bdf0
+    Value = IScsiGetValueByKeyFromList (
12bdf0
+              KeyValueList,
12bdf0
+              ISCSI_KEY_CHAP_ALGORITHM
12bdf0
+              );
12bdf0
     if (Value == NULL) {
12bdf0
       goto ON_EXIT;
12bdf0
     }
12bdf0
@@ -249,12 +264,18 @@ IScsiCHAPOnRspReceived (
12bdf0
       goto ON_EXIT;
12bdf0
     }
12bdf0
 
12bdf0
-    Identifier = IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_CHAP_IDENTIFIER);
12bdf0
+    Identifier = IScsiGetValueByKeyFromList (
12bdf0
+                   KeyValueList,
12bdf0
+                   ISCSI_KEY_CHAP_IDENTIFIER
12bdf0
+                   );
12bdf0
     if (Identifier == NULL) {
12bdf0
       goto ON_EXIT;
12bdf0
     }
12bdf0
 
12bdf0
-    Challenge = IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_CHAP_CHALLENGE);
12bdf0
+    Challenge = IScsiGetValueByKeyFromList (
12bdf0
+                  KeyValueList,
12bdf0
+                  ISCSI_KEY_CHAP_CHALLENGE
12bdf0
+                  );
12bdf0
     if (Challenge == NULL) {
12bdf0
       goto ON_EXIT;
12bdf0
     }
12bdf0
@@ -269,7 +290,11 @@ IScsiCHAPOnRspReceived (
12bdf0
 
12bdf0
     AuthData->InIdentifier      = (UINT32) Result;
12bdf0
     AuthData->InChallengeLength = ISCSI_CHAP_AUTH_MAX_LEN;
12bdf0
-    IScsiHexToBin ((UINT8 *) AuthData->InChallenge, &AuthData->InChallengeLength, Challenge);
12bdf0
+    IScsiHexToBin (
12bdf0
+      (UINT8 *) AuthData->InChallenge,
12bdf0
+      &AuthData->InChallengeLength,
12bdf0
+      Challenge
12bdf0
+      );
12bdf0
     Status = IScsiCHAPCalculateResponse (
12bdf0
                AuthData->InIdentifier,
12bdf0
                AuthData->AuthConfig->CHAPSecret,
12bdf0
@@ -303,7 +328,10 @@ IScsiCHAPOnRspReceived (
12bdf0
       goto ON_EXIT;
12bdf0
     }
12bdf0
 
12bdf0
-    Response = IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_CHAP_RESPONSE);
12bdf0
+    Response = IScsiGetValueByKeyFromList (
12bdf0
+                 KeyValueList,
12bdf0
+                 ISCSI_KEY_CHAP_RESPONSE
12bdf0
+                 );
12bdf0
     if (Response == NULL) {
12bdf0
       goto ON_EXIT;
12bdf0
     }
12bdf0
@@ -341,7 +369,8 @@ ON_EXIT:
12bdf0
   @param[in, out]  Pdu         The PDU to send out.
12bdf0
 
12bdf0
   @retval EFI_SUCCESS           All check passed and the phase-related CHAP
12bdf0
-                                authentication info is filled into the iSCSI PDU.
12bdf0
+                                authentication info is filled into the iSCSI
12bdf0
+                                PDU.
12bdf0
   @retval EFI_OUT_OF_RESOURCES  Failed to allocate memory.
12bdf0
   @retval EFI_PROTOCOL_ERROR    Some kind of protocol error occurred.
12bdf0
 
12bdf0
@@ -392,7 +421,11 @@ IScsiCHAPToSendReq (
12bdf0
     // It's the initial Login Request. Fill in the key=value pairs mandatory
12bdf0
     // for the initial Login Request.
12bdf0
     //
12bdf0
-    IScsiAddKeyValuePair (Pdu, ISCSI_KEY_INITIATOR_NAME, mPrivate->InitiatorName);
12bdf0
+    IScsiAddKeyValuePair (
12bdf0
+      Pdu,
12bdf0
+      ISCSI_KEY_INITIATOR_NAME,
12bdf0
+      mPrivate->InitiatorName
12bdf0
+      );
12bdf0
     IScsiAddKeyValuePair (Pdu, ISCSI_KEY_SESSION_TYPE, "Normal");
12bdf0
     IScsiAddKeyValuePair (
12bdf0
       Pdu,
12bdf0
@@ -413,7 +446,8 @@ IScsiCHAPToSendReq (
12bdf0
 
12bdf0
   case ISCSI_CHAP_STEP_ONE:
12bdf0
     //
12bdf0
-    // First step, send the Login Request with CHAP_A=<A1,A2...> key-value pair.
12bdf0
+    // First step, send the Login Request with CHAP_A=<A1,A2...> key-value
12bdf0
+    // pair.
12bdf0
     //
12bdf0
     AsciiSPrint (ValueStr, sizeof (ValueStr), "%d", ISCSI_CHAP_ALGORITHM_MD5);
12bdf0
     IScsiAddKeyValuePair (Pdu, ISCSI_KEY_CHAP_ALGORITHM, ValueStr);
12bdf0
@@ -429,11 +463,20 @@ IScsiCHAPToSendReq (
12bdf0
     //
12bdf0
     // CHAP_N=<N>
12bdf0
     //
12bdf0
-    IScsiAddKeyValuePair (Pdu, ISCSI_KEY_CHAP_NAME, (CHAR8 *) &AuthData->AuthConfig->CHAPName);
12bdf0
+    IScsiAddKeyValuePair (
12bdf0
+      Pdu,
12bdf0
+      ISCSI_KEY_CHAP_NAME,
12bdf0
+      (CHAR8 *) &AuthData->AuthConfig->CHAPName
12bdf0
+      );
12bdf0
     //
12bdf0
     // CHAP_R=<R>
12bdf0
     //
12bdf0
-    IScsiBinToHex ((UINT8 *) AuthData->CHAPResponse, ISCSI_CHAP_RSP_LEN, Response, &RspLen);
12bdf0
+    IScsiBinToHex (
12bdf0
+      (UINT8 *) AuthData->CHAPResponse,
12bdf0
+      ISCSI_CHAP_RSP_LEN,
12bdf0
+      Response,
12bdf0
+      &RspLen
12bdf0
+      );
12bdf0
     IScsiAddKeyValuePair (Pdu, ISCSI_KEY_CHAP_RESPONSE, Response);
12bdf0
 
12bdf0
     if (AuthData->AuthConfig->CHAPType == ISCSI_CHAP_MUTUAL) {
12bdf0
@@ -448,7 +491,12 @@ IScsiCHAPToSendReq (
12bdf0
       //
12bdf0
       IScsiGenRandom ((UINT8 *) AuthData->OutChallenge, ISCSI_CHAP_RSP_LEN);
12bdf0
       AuthData->OutChallengeLength = ISCSI_CHAP_RSP_LEN;
12bdf0
-      IScsiBinToHex ((UINT8 *) AuthData->OutChallenge, ISCSI_CHAP_RSP_LEN, Challenge, &ChallengeLen);
12bdf0
+      IScsiBinToHex (
12bdf0
+        (UINT8 *) AuthData->OutChallenge,
12bdf0
+        ISCSI_CHAP_RSP_LEN,
12bdf0
+        Challenge,
12bdf0
+        &ChallengeLen
12bdf0
+        );
12bdf0
       IScsiAddKeyValuePair (Pdu, ISCSI_KEY_CHAP_CHALLENGE, Challenge);
12bdf0
 
12bdf0
       Conn->AuthStep = ISCSI_CHAP_STEP_FOUR;
12bdf0
diff --git a/NetworkPkg/IScsiDxe/IScsiCHAP.h b/NetworkPkg/IScsiDxe/IScsiCHAP.h
12bdf0
index 140bba0dcd..5e59fb678b 100644
12bdf0
--- a/NetworkPkg/IScsiDxe/IScsiCHAP.h
12bdf0
+++ b/NetworkPkg/IScsiDxe/IScsiCHAP.h
12bdf0
@@ -88,7 +88,8 @@ IScsiCHAPOnRspReceived (
12bdf0
   @param[in, out]  Pdu         The PDU to send out.
12bdf0
 
12bdf0
   @retval EFI_SUCCESS           All check passed and the phase-related CHAP
12bdf0
-                                authentication info is filled into the iSCSI PDU.
12bdf0
+                                authentication info is filled into the iSCSI
12bdf0
+                                PDU.
12bdf0
   @retval EFI_OUT_OF_RESOURCES  Failed to allocate memory.
12bdf0
   @retval EFI_PROTOCOL_ERROR    Some kind of protocol error occurred.
12bdf0
 
12bdf0
-- 
12bdf0
2.27.0
12bdf0