Blame SOURCES/edk2-NetworkPkg-IScsiDxe-clean-up-ISCSI_CHAP_AUTH_DATA.Ou.patch

12bdf0
From fca7e61fa3ba21cbf6e89d75b23fea03af5d517e Mon Sep 17 00:00:00 2001
12bdf0
From: Laszlo Ersek <lersek@redhat.com>
12bdf0
Date: Tue, 8 Jun 2021 14:12:52 +0200
12bdf0
Subject: [PATCH 03/10] NetworkPkg/IScsiDxe: clean up
12bdf0
 "ISCSI_CHAP_AUTH_DATA.OutChallengeLength"
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: [3/10] cc7118399f64979f2d81fe9fc381ed22c3815f9e
12bdf0
RH-Bugzilla: 1956408
12bdf0
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12bdf0
12bdf0
The "ISCSI_CHAP_AUTH_DATA.OutChallenge" field is declared as a UINT8 array
12bdf0
with ISCSI_CHAP_AUTH_MAX_LEN (1024) elements. However, when the challenge
12bdf0
is generated and formatted, only ISCSI_CHAP_RSP_LEN (16) octets are used
12bdf0
in the array.
12bdf0
12bdf0
Change the array size to ISCSI_CHAP_RSP_LEN, and remove the (now unused)
12bdf0
ISCSI_CHAP_AUTH_MAX_LEN macro.
12bdf0
12bdf0
Remove the "ISCSI_CHAP_AUTH_DATA.OutChallengeLength" field, which is
12bdf0
superfluous too.
12bdf0
12bdf0
Most importantly, explain in a new comment *why* tying the challenge size
12bdf0
to the digest size (ISCSI_CHAP_RSP_LEN) has always made sense. (See also
12bdf0
Linux kernel commit 19f5f88ed779, "scsi: target: iscsi: tie the challenge
12bdf0
length to the hash digest size", 2019-11-06.) For sure, the motivation
12bdf0
that the new comment now explains has always been there, and has always
12bdf0
been the same, for IScsiDxe; it's just that now we spell it out too.
12bdf0
12bdf0
No change in peer-visible behavior.
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: Philippe Mathieu-Daud <philmd@redhat.com>
12bdf0
Reviewed-by: Maciej Rabeda <maciej.rabeda@linux.intel.com>
12bdf0
Message-Id: <20210608121259.32451-4-lersek@redhat.com>
12bdf0
(cherry picked from commit 95616b866187b00355042953efa5c198df07250f)
12bdf0
---
12bdf0
 NetworkPkg/IScsiDxe/IScsiCHAP.c | 3 +--
12bdf0
 NetworkPkg/IScsiDxe/IScsiCHAP.h | 9 ++++++---
12bdf0
 2 files changed, 7 insertions(+), 5 deletions(-)
12bdf0
12bdf0
diff --git a/NetworkPkg/IScsiDxe/IScsiCHAP.c b/NetworkPkg/IScsiDxe/IScsiCHAP.c
12bdf0
index df3c2eb120..9e192ce292 100644
12bdf0
--- a/NetworkPkg/IScsiDxe/IScsiCHAP.c
12bdf0
+++ b/NetworkPkg/IScsiDxe/IScsiCHAP.c
12bdf0
@@ -122,7 +122,7 @@ IScsiCHAPAuthTarget (
12bdf0
              AuthData->AuthConfig->ReverseCHAPSecret,
12bdf0
              SecretSize,
12bdf0
              AuthData->OutChallenge,
12bdf0
-             AuthData->OutChallengeLength,
12bdf0
+             ISCSI_CHAP_RSP_LEN,                      // ChallengeLength
12bdf0
              VerifyRsp
12bdf0
              );
12bdf0
 
12bdf0
@@ -490,7 +490,6 @@ IScsiCHAPToSendReq (
12bdf0
       // CHAP_C=<C>
12bdf0
       //
12bdf0
       IScsiGenRandom ((UINT8 *) AuthData->OutChallenge, ISCSI_CHAP_RSP_LEN);
12bdf0
-      AuthData->OutChallengeLength = ISCSI_CHAP_RSP_LEN;
12bdf0
       IScsiBinToHex (
12bdf0
         (UINT8 *) AuthData->OutChallenge,
12bdf0
         ISCSI_CHAP_RSP_LEN,
12bdf0
diff --git a/NetworkPkg/IScsiDxe/IScsiCHAP.h b/NetworkPkg/IScsiDxe/IScsiCHAP.h
12bdf0
index 1fc1d96ea3..35d5d6ec29 100644
12bdf0
--- a/NetworkPkg/IScsiDxe/IScsiCHAP.h
12bdf0
+++ b/NetworkPkg/IScsiDxe/IScsiCHAP.h
12bdf0
@@ -19,7 +19,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
12bdf0
 
12bdf0
 #define ISCSI_CHAP_ALGORITHM_MD5  5
12bdf0
 
12bdf0
-#define ISCSI_CHAP_AUTH_MAX_LEN   1024
12bdf0
 ///
12bdf0
 /// MD5_HASHSIZE
12bdf0
 ///
12bdf0
@@ -59,9 +58,13 @@ typedef struct _ISCSI_CHAP_AUTH_DATA {
12bdf0
   //
12bdf0
   // Auth-data to be sent out for mutual authentication.
12bdf0
   //
12bdf0
+  // While the challenge size is technically independent of the hashing
12bdf0
+  // algorithm, it is good practice to avoid hashing *fewer bytes* than the
12bdf0
+  // digest size. In other words, it's good practice to feed *at least as many
12bdf0
+  // bytes* to the hashing algorithm as the hashing algorithm will output.
12bdf0
+  //
12bdf0
   UINT32                        OutIdentifier;
12bdf0
-  UINT8                         OutChallenge[ISCSI_CHAP_AUTH_MAX_LEN];
12bdf0
-  UINT32                        OutChallengeLength;
12bdf0
+  UINT8                         OutChallenge[ISCSI_CHAP_RSP_LEN];
12bdf0
 } ISCSI_CHAP_AUTH_DATA;
12bdf0
 
12bdf0
 /**
12bdf0
-- 
12bdf0
2.27.0
12bdf0