render / rpms / edk2

Forked from rpms/edk2 3 months ago
Clone

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

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