render / rpms / edk2

Forked from rpms/edk2 3 months ago
Clone

Blame SOURCES/edk2-NetworkPkg-IScsiDxe-fix-IScsiHexToBin-hex-parsing.patch

c4e3b2
From b0b03cadbee4f8560e4eb284b8d12a5ccc697281 Mon Sep 17 00:00:00 2001
c4e3b2
From: Laszlo Ersek <lersek@redhat.com>
c4e3b2
Date: Tue, 8 Jun 2021 14:12:57 +0200
c4e3b2
Subject: [PATCH 08/11] NetworkPkg/IScsiDxe: fix IScsiHexToBin() hex parsing
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: [8/10] d336a24538fe8b4a53f7fd249ae94cd2c3c22cb5
c4e3b2
RH-Bugzilla: 1961100
c4e3b2
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
c4e3b2
c4e3b2
The IScsiHexToBin() function has the following parser issues:
c4e3b2
c4e3b2
(1) If the *subject sequence* in "HexStr" is empty, the function returns
c4e3b2
    EFI_SUCCESS (with "BinLength" set to 0 on output). Such inputs should
c4e3b2
    be rejected.
c4e3b2
c4e3b2
(2) The function mis-handles a "HexStr" that ends with a stray nibble. For
c4e3b2
    example, if "HexStr" is "0xABC", the function decodes it to the bytes
c4e3b2
    {0xAB, 0x0C}, sets "BinLength" to 2 on output, and returns
c4e3b2
    EFI_SUCCESS. Such inputs should be rejected.
c4e3b2
c4e3b2
(3) If an invalid hex char is found in "HexStr", the function treats it as
c4e3b2
    end-of-hex-string, and returns EFI_SUCCESS. Such inputs should be
c4e3b2
    rejected.
c4e3b2
c4e3b2
All of the above cases are remotely triggerable, as shown in a subsequent
c4e3b2
patch, which adds error checking to the IScsiHexToBin() call sites. While
c4e3b2
the initiator is not immediately compromised, incorrectly parsing CHAP_R
c4e3b2
from the target, in case of mutual authentication, is not great.
c4e3b2
c4e3b2
Extend the interface contract of IScsiHexToBin() with
c4e3b2
EFI_INVALID_PARAMETER, for reporting issues (1) through (3), and implement
c4e3b2
the new checks.
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-9-lersek@redhat.com>
c4e3b2
(cherry picked from commit 47b76780b487dbfde4efb6843b16064c4a97e94d)
c4e3b2
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
c4e3b2
---
c4e3b2
 NetworkPkg/IScsiDxe/IScsiMisc.c | 12 ++++++++++--
c4e3b2
 NetworkPkg/IScsiDxe/IScsiMisc.h |  1 +
c4e3b2
 2 files changed, 11 insertions(+), 2 deletions(-)
c4e3b2
c4e3b2
diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.c b/NetworkPkg/IScsiDxe/IScsiMisc.c
c4e3b2
index 014700e87a..f0f4992b07 100644
c4e3b2
--- a/NetworkPkg/IScsiDxe/IScsiMisc.c
c4e3b2
+++ b/NetworkPkg/IScsiDxe/IScsiMisc.c
c4e3b2
@@ -376,6 +376,7 @@ IScsiBinToHex (
c4e3b2
 
c4e3b2
   @retval EFI_SUCCESS           The hexadecimal string is converted into a
c4e3b2
                                 binary encoded buffer.
c4e3b2
+  @retval EFI_INVALID_PARAMETER Invalid hex encoding found in HexStr.
c4e3b2
   @retval EFI_BUFFER_TOO_SMALL  The binary buffer is too small to hold the
c4e3b2
                                 converted data.
c4e3b2
 **/
c4e3b2
@@ -402,14 +403,21 @@ IScsiHexToBin (
c4e3b2
 
c4e3b2
   Length = AsciiStrLen (HexStr);
c4e3b2
 
c4e3b2
+  //
c4e3b2
+  // Reject an empty hex string; reject a stray nibble.
c4e3b2
+  //
c4e3b2
+  if (Length == 0 || Length % 2 != 0) {
c4e3b2
+    return EFI_INVALID_PARAMETER;
c4e3b2
+  }
c4e3b2
+
c4e3b2
   for (Index = 0; Index < Length; Index ++) {
c4e3b2
     TemStr[0] = HexStr[Index];
c4e3b2
     Digit = (UINT8) AsciiStrHexToUint64 (TemStr);
c4e3b2
     if (Digit == 0 && TemStr[0] != '0') {
c4e3b2
       //
c4e3b2
-      // Invalid Lun Char.
c4e3b2
+      // Invalid Hex Char.
c4e3b2
       //
c4e3b2
-      break;
c4e3b2
+      return EFI_INVALID_PARAMETER;
c4e3b2
     }
c4e3b2
     if ((Index & 1) == 0) {
c4e3b2
       BinBuffer [Index/2] = Digit;
c4e3b2
diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.h b/NetworkPkg/IScsiDxe/IScsiMisc.h
c4e3b2
index 28cf408cd5..404a482e57 100644
c4e3b2
--- a/NetworkPkg/IScsiDxe/IScsiMisc.h
c4e3b2
+++ b/NetworkPkg/IScsiDxe/IScsiMisc.h
c4e3b2
@@ -171,6 +171,7 @@ IScsiBinToHex (
c4e3b2
 
c4e3b2
   @retval EFI_SUCCESS           The hexadecimal string is converted into a
c4e3b2
                                 binary encoded buffer.
c4e3b2
+  @retval EFI_INVALID_PARAMETER Invalid hex encoding found in HexStr.
c4e3b2
   @retval EFI_BUFFER_TOO_SMALL  The binary buffer is too small to hold the
c4e3b2
                                 converted data.
c4e3b2
 **/
c4e3b2
-- 
c4e3b2
2.27.0
c4e3b2