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

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