From f0facba2e1458636c73399b8b0aea8c8db47f5f2 Mon Sep 17 00:00:00 2001 From: Jon Maloy Date: Tue, 1 Oct 2024 18:40:41 -0400 Subject: [PATCH 3/3] MdePkg: Fix overflow issue in BasePeCoffLib RH-Author: Jon Maloy RH-MergeRequest: 79: MdePkg: Fix overflow issue in BasePeCoffLib RH-Jira: RHEL-60829 RH-Acked-by: Oliver Steffen RH-Commit: [1/1] 295f85a105fe778de5e555a65fdd2b7297c721a6 JIRA: https://issues.redhat.com/browse/RHEL-60829 CVE: CVE-2024-38796 Upstream: Merged commit c95233b8525ca6828921affd1496146cff262e65 Author: Doug Flick Date: Fri Sep 27 12:08:55 2024 -0700 MdePkg: Fix overflow issue in BasePeCoffLib The RelocDir->Size is a UINT32 value, and RelocDir->VirtualAddress is also a UINT32 value. The current code does not check for overflow when adding RelocDir->Size to RelocDir->VirtualAddress. This patch adds a check to ensure that the addition does not overflow. Signed-off-by: Doug Flick Authored-by: sriraamx gobichettipalayam Signed-off-by: Jon Maloy --- MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c index 86ff2e769b..128090d98e 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -1054,7 +1054,7 @@ PeCoffLoaderRelocateImage ( RelocDir = &Hdr.Te->DataDirectory[0]; } - if ((RelocDir != NULL) && (RelocDir->Size > 0)) { + if ((RelocDir != NULL) && (RelocDir->Size > 0) && (RelocDir->Size - 1 < MAX_UINT32 - RelocDir->VirtualAddress)) { RelocBase = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress, TeStrippedOffset); RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress ( ImageContext, -- 2.39.3