From: Liming Gao <liming.gao@intel.com>
To: edk2-devel@lists.01.org
Cc: Holtsclaw Brent <brent.holtsclaw@intel.com>
Subject: [Patch 2/3] IntelFrameworkModulePkg: Add more checker in UefiTianoDecompressLib
Date: Tue, 16 Oct 2018 10:06:12 +0800 [thread overview]
Message-ID: <1539655573-5456-3-git-send-email-liming.gao@intel.com> (raw)
In-Reply-To: <1539655573-5456-1-git-send-email-liming.gao@intel.com>
https://bugzilla.tianocore.org/show_bug.cgi?id=686
To make sure the valid buffer be accessed only.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Holtsclaw Brent <brent.holtsclaw@intel.com>
Signed-off-by: Liming Gao <liming.gao@intel.com>
---
.../BaseUefiTianoCustomDecompressLib.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.c b/IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.c
index ab7987a..39999a0 100644
--- a/IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.c
+++ b/IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.c
@@ -143,6 +143,7 @@ MakeTable (
UINT16 Mask;
UINT16 WordOfStart;
UINT16 WordOfCount;
+ UINT16 MaxTableLength;
//
// The maximum mapping table width supported by this internal
@@ -155,6 +156,9 @@ MakeTable (
}
for (Index = 0; Index < NumOfChar; Index++) {
+ if (BitLen[Index] > 16) {
+ return (UINT16) BAD_TABLE;
+ }
Count[BitLen[Index]]++;
}
@@ -196,6 +200,7 @@ MakeTable (
Avail = NumOfChar;
Mask = (UINT16) (1U << (15 - TableBits));
+ MaxTableLength = (UINT16) (1U << TableBits);
for (Char = 0; Char < NumOfChar; Char++) {
@@ -209,6 +214,9 @@ MakeTable (
if (Len <= TableBits) {
for (Index = Start[Len]; Index < NextCode; Index++) {
+ if (Index >= MaxTableLength) {
+ return (UINT16) BAD_TABLE;
+ }
Table[Index] = Char;
}
@@ -615,10 +623,14 @@ Decode (
//
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--;
}
@@ -688,7 +700,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
next prev parent reply other threads:[~2018-10-16 2:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-16 2:06 [Patch 0/3] Add more checker for Tianocompress and Ueficompress Liming Gao
2018-10-16 2:06 ` [Patch 1/3] MdePkg: Add more checker in UefiDecompressLib to access the valid buffer only Liming Gao
2018-10-16 2:06 ` Liming Gao [this message]
2018-10-16 2:06 ` [Patch 3/3] BaseTools: Add more checker in Decompress algorithm to access the valid buffer Liming Gao
2018-10-18 12:28 ` Zhu, Yonghong
2018-10-18 3:04 ` [Patch 0/3] Add more checker for Tianocompress and Ueficompress Zeng, Star
2018-10-18 13:02 ` Laszlo Ersek
2018-10-18 13:36 ` Gao, Liming
2018-10-18 16:01 ` Laszlo Ersek
2018-10-19 6:40 ` Gao, Liming
2018-10-19 11:24 ` Laszlo Ersek
2018-10-19 14:40 ` Gao, Liming
2018-10-22 8:30 ` Laszlo Ersek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1539655573-5456-3-git-send-email-liming.gao@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox