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:51:36 +0800 |
commit | ee9ec6e6426f8f36bb9cd1301eb836959ef1412e (patch) | |
tree | b9dbdeef713ced4f0f4c3053259f2ec69009e80c | |
parent | 2bfddc064b1cd1f4539350bff1473a9c371865d8 (diff) | |
download | edk2-ee9ec6e6426f8f36bb9cd1301eb836959ef1412e.zip edk2-ee9ec6e6426f8f36bb9cd1301eb836959ef1412e.tar.gz edk2-ee9ec6e6426f8f36bb9cd1301eb836959ef1412e.tar.bz2 |
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 4b86f50..23eb87e 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;
}
|