|
|
fcb437 |
From dea2c718df8b58f5147c7674797bf65df649c53e Mon Sep 17 00:00:00 2001
|
|
|
fcb437 |
From: Laszlo Ersek <lersek@redhat.com>
|
|
|
fcb437 |
Date: Thu, 19 Nov 2020 12:50:34 +0100
|
|
|
fcb437 |
Subject: [PATCH] MdeModulePkg/LzmaCustomDecompressLib: catch 4GB+ uncompressed
|
|
|
fcb437 |
buffer sizes
|
|
|
fcb437 |
MIME-Version: 1.0
|
|
|
fcb437 |
Content-Type: text/plain; charset=UTF-8
|
|
|
fcb437 |
Content-Transfer-Encoding: 8bit
|
|
|
fcb437 |
|
|
|
fcb437 |
RH-Author: Laszlo Ersek (lersek)
|
|
|
fcb437 |
RH-MergeRequest: 1: prevent integer overflow / heap corruption in LZMA decompression [rhel-8.4.0.z]
|
|
|
fcb437 |
RH-Commit: [1/1] a8ec492d7ebb6ae3c51513f501f72d5418b71f17
|
|
|
fcb437 |
RH-Bugzilla: 1952953
|
|
|
fcb437 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
fcb437 |
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
|
|
|
fcb437 |
|
|
|
fcb437 |
The LzmaUefiDecompressGetInfo() function
|
|
|
fcb437 |
[MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c] currently
|
|
|
fcb437 |
silently truncates the UINT64 "DecodedSize" property of the compressed
|
|
|
fcb437 |
blob to the UINT32 "DestinationSize" output parameter.
|
|
|
fcb437 |
|
|
|
fcb437 |
If "DecodedSize" is 0x1_0000_0100, for example, then the subsequent memory
|
|
|
fcb437 |
allocation (for decompression) will likely succeed (allocating 0x100 bytes
|
|
|
fcb437 |
only), but then the LzmaUefiDecompress() function (which re-fetches the
|
|
|
fcb437 |
uncompressed buffer size from the same LZMA header into a "SizeT"
|
|
|
fcb437 |
variable) will overwrite the buffer.
|
|
|
fcb437 |
|
|
|
fcb437 |
Catch (DecodedSize > MAX_UINT32) in LzmaUefiDecompressGetInfo() at once.
|
|
|
fcb437 |
This should not be a practical limitation. (The issue cannot be fixed for
|
|
|
fcb437 |
32-bit systems without spec modifications anyway, given that the
|
|
|
fcb437 |
"OutputSize" output parameter of
|
|
|
fcb437 |
EFI_GUIDED_SECTION_EXTRACTION_PROTOCOL.ExtractSection() has type UINTN,
|
|
|
fcb437 |
not UINT64.)
|
|
|
fcb437 |
|
|
|
fcb437 |
Cc: Dandan Bi <dandan.bi@intel.com>
|
|
|
fcb437 |
Cc: Hao A Wu <hao.a.wu@intel.com>
|
|
|
fcb437 |
Cc: Jian J Wang <jian.j.wang@intel.com>
|
|
|
fcb437 |
Cc: Liming Gao <gaoliming@byosoft.com.cn>
|
|
|
fcb437 |
Cc: Philippe Mathieu-Daud <philmd@redhat.com>
|
|
|
fcb437 |
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1816
|
|
|
fcb437 |
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
fcb437 |
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
|
|
|
fcb437 |
Reviewed-by: Philippe Mathieu-Daud <philmd@redhat.com>
|
|
|
fcb437 |
Message-Id: <20201119115034.12897-2-lersek@redhat.com>
|
|
|
fcb437 |
(cherry picked from commit e7bd0dd26db7e56aa8ca70132d6ea916ee6f3db0)
|
|
|
fcb437 |
---
|
|
|
fcb437 |
.../Library/LzmaCustomDecompressLib/LzmaDecompress.c | 7 +++++++
|
|
|
fcb437 |
.../LzmaCustomDecompressLib/LzmaDecompressLibInternal.h | 5 +++++
|
|
|
fcb437 |
2 files changed, 12 insertions(+)
|
|
|
fcb437 |
|
|
|
fcb437 |
diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c b/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c
|
|
|
fcb437 |
index c58912eb6a..8f7c242dca 100644
|
|
|
fcb437 |
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c
|
|
|
fcb437 |
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c
|
|
|
fcb437 |
@@ -127,6 +127,10 @@ GetDecodedSizeOfBuf(
|
|
|
fcb437 |
in DestinationSize and the size of the scratch
|
|
|
fcb437 |
buffer was returned in ScratchSize.
|
|
|
fcb437 |
|
|
|
fcb437 |
+ @retval RETURN_UNSUPPORTED DestinationSize cannot be output because the
|
|
|
fcb437 |
+ uncompressed buffer size (in bytes) does not fit
|
|
|
fcb437 |
+ in a UINT32. Output parameters have not been
|
|
|
fcb437 |
+ modified.
|
|
|
fcb437 |
**/
|
|
|
fcb437 |
RETURN_STATUS
|
|
|
fcb437 |
EFIAPI
|
|
|
fcb437 |
@@ -142,6 +146,9 @@ LzmaUefiDecompressGetInfo (
|
|
|
fcb437 |
ASSERT(SourceSize >= LZMA_HEADER_SIZE);
|
|
|
fcb437 |
|
|
|
fcb437 |
DecodedSize = GetDecodedSizeOfBuf((UINT8*)Source);
|
|
|
fcb437 |
+ if (DecodedSize > MAX_UINT32) {
|
|
|
fcb437 |
+ return RETURN_UNSUPPORTED;
|
|
|
fcb437 |
+ }
|
|
|
fcb437 |
|
|
|
fcb437 |
*DestinationSize = (UINT32)DecodedSize;
|
|
|
fcb437 |
*ScratchSize = SCRATCH_BUFFER_REQUEST_SIZE;
|
|
|
fcb437 |
diff --git a/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompressLibInternal.h b/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompressLibInternal.h
|
|
|
fcb437 |
index 26f110ba2a..fbafd5f100 100644
|
|
|
fcb437 |
--- a/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompressLibInternal.h
|
|
|
fcb437 |
+++ b/MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompressLibInternal.h
|
|
|
fcb437 |
@@ -9,6 +9,7 @@
|
|
|
fcb437 |
#ifndef __LZMADECOMPRESSLIB_INTERNAL_H__
|
|
|
fcb437 |
#define __LZMADECOMPRESSLIB_INTERNAL_H__
|
|
|
fcb437 |
|
|
|
fcb437 |
+#include <Base.h>
|
|
|
fcb437 |
#include <PiPei.h>
|
|
|
fcb437 |
#include <Library/BaseLib.h>
|
|
|
fcb437 |
#include <Library/BaseMemoryLib.h>
|
|
|
fcb437 |
@@ -45,6 +46,10 @@
|
|
|
fcb437 |
in DestinationSize and the size of the scratch
|
|
|
fcb437 |
buffer was returned in ScratchSize.
|
|
|
fcb437 |
|
|
|
fcb437 |
+ @retval RETURN_UNSUPPORTED DestinationSize cannot be output because the
|
|
|
fcb437 |
+ uncompressed buffer size (in bytes) does not fit
|
|
|
fcb437 |
+ in a UINT32. Output parameters have not been
|
|
|
fcb437 |
+ modified.
|
|
|
fcb437 |
**/
|
|
|
fcb437 |
RETURN_STATUS
|
|
|
fcb437 |
EFIAPI
|
|
|
fcb437 |
--
|
|
|
fcb437 |
2.27.0
|
|
|
fcb437 |
|