diff options
author | Liming Gao <liming.gao@intel.com> | 2018-10-16 10:06:11 +0800 |
---|---|---|
committer | Liming Gao <liming.gao@intel.com> | 2018-10-24 09:44:05 +0800 |
commit | 167e6e48af8dfd558aa3c7497959092d58b26d54 (patch) | |
tree | 699f52e46b8c6016330539ad807ed2402c6cfd3f | |
parent | 5c693e581e6ab2c8e9daac170616d867272399d9 (diff) | |
download | edk2-167e6e48af8dfd558aa3c7497959092d58b26d54.tar.gz edk2-167e6e48af8dfd558aa3c7497959092d58b26d54.tar.bz2 edk2-167e6e48af8dfd558aa3c7497959092d58b26d54.zip |
MdePkg: Add more checker in UefiDecompressLib to access the valid buffer only (CVE FIX)
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 <brent.holtsclaw@intel.com>
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
(cherry picked from commit 2ec7953d49677142c5f7552e9e3d96fb406ba0c4)
-rw-r--r-- | MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c index e818543d92..0c6b1fe4ee 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;
}
|