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