Skip to content

Commit

Permalink
MdePkg: Add more checker in UefiDecompressLib to access the valid buf…
Browse files Browse the repository at this point in the history
…fer 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>
  • Loading branch information
lgao4 committed Oct 24, 2018
1 parent 68099b5 commit 2ec7953
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ MakeTable (
UINT16 Mask;
UINT16 WordOfStart;
UINT16 WordOfCount;
UINT16 MaxTableLength;

//
// The maximum mapping table width supported by this internal
Expand All @@ -164,6 +165,9 @@ MakeTable (
}

for (Index = 0; Index < NumOfChar; Index++) {
if (BitLen[Index] > 16) {
return (UINT16) BAD_TABLE;
}
Count[BitLen[Index]]++;
}

Expand Down Expand Up @@ -205,6 +209,7 @@ MakeTable (

Avail = NumOfChar;
Mask = (UINT16) (1U << (15 - TableBits));
MaxTableLength = (UINT16) (1U << TableBits);

for (Char = 0; Char < NumOfChar; Char++) {

Expand All @@ -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;
}

Expand Down Expand Up @@ -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--;
}
Expand Down Expand Up @@ -694,7 +707,7 @@ UefiDecompressGetInfo (
}

CompressedSize = ReadUnaligned32 ((UINT32 *)Source);
if (SourceSize < (CompressedSize + 8)) {
if (SourceSize < (CompressedSize + 8) || (CompressedSize + 8) < 8) {
return RETURN_INVALID_PARAMETER;
}

Expand Down

0 comments on commit 2ec7953

Please sign in to comment.