From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.136; helo=mga12.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A0BBF21CAD998 for ; Mon, 22 Oct 2018 08:18:44 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Oct 2018 08:18:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,412,1534834800"; d="scan'208";a="79995440" Received: from lgao4-mobl1.ccr.corp.intel.com ([10.255.31.133]) by fmsmga007.fm.intel.com with ESMTP; 22 Oct 2018 08:18:43 -0700 From: Liming Gao To: edk2-devel@lists.01.org Cc: Holtsclaw Brent Date: Mon, 22 Oct 2018 23:18:09 +0800 Message-Id: <20181022151811.29644-2-liming.gao@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20181022151811.29644-1-liming.gao@intel.com> References: <20181022151811.29644-1-liming.gao@intel.com> Subject: [PATCH v2 1/3] MdePkg: Add more checker in UefiDecompressLib to access the valid buffer only(CVE FIX) X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Oct 2018 15:18:44 -0000 Fix CVE-2017-5731,CVE-2017-5732,CVE-2017-5733,CVE-2017-5734,CVE-2017-5735 https://bugzilla.tianocore.org/show_bug.cgi?id=686 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Holtsclaw Brent Signed-off-by: Liming Gao Reviewed-by: Star Zeng --- .../BaseUefiDecompressLib/BaseUefiDecompressLib.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c index dc89157..9fc637e 100644 --- a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c +++ b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c @@ -152,6 +152,7 @@ MakeTable ( UINT16 Mask; UINT16 WordOfStart; UINT16 WordOfCount; + UINT16 MaxTableLength; // // The maximum mapping table width supported by this internal @@ -164,6 +165,9 @@ MakeTable ( } for (Index = 0; Index < NumOfChar; Index++) { + if (BitLen[Index] > 16) { + return (UINT16) BAD_TABLE; + } Count[BitLen[Index]]++; } @@ -205,6 +209,7 @@ MakeTable ( Avail = NumOfChar; Mask = (UINT16) (1U << (15 - TableBits)); + MaxTableLength = (UINT16) (1U << TableBits); for (Char = 0; Char < NumOfChar; Char++) { @@ -218,6 +223,9 @@ MakeTable ( if (Len <= TableBits) { for (Index = Start[Len]; Index < NextCode; Index++) { + if (Index >= MaxTableLength) { + return (UINT16) BAD_TABLE; + } Table[Index] = Char; } @@ -620,11 +628,16 @@ Decode ( // Write BytesRemain of bytes into mDstBase // BytesRemain--; + while ((INT16) (BytesRemain) >= 0) { - Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++]; if (Sd->mOutBuf >= Sd->mOrigSize) { goto Done; } + if (DataIdx >= Sd->mOrigSize) { + Sd->mBadTableFlag = (UINT16) BAD_TABLE; + goto Done; + } + Sd->mDstBase[Sd->mOutBuf++] = Sd->mDstBase[DataIdx++]; BytesRemain--; } @@ -694,7 +707,7 @@ UefiDecompressGetInfo ( } CompressedSize = ReadUnaligned32 ((UINT32 *)Source); - if (SourceSize < (CompressedSize + 8)) { + if (SourceSize < (CompressedSize + 8) || (CompressedSize + 8) < 8) { return RETURN_INVALID_PARAMETER; } -- 2.10.0.windows.1