Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MdePkg: Fix overflow issue in BasePeCoffLib: PeCoffLoaderRelocateImage #6249

Merged

Conversation

Flickdm
Copy link
Contributor

@Flickdm Flickdm commented Sep 27, 2024

Description

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.

  • Breaking change?
  • Impacts security?
  • Includes tests?

How This Was Tested

In BasePeCoff.c, the PeCoffLoaderRelocateImage() does RelocDir→VirtualAddress + ReloDir→Size- 1
inside the function was overflowing and causing memory corruption.
so added the below check for avoiding the memory corruption before calculating the RelocBase and RelocBaseEnd.
if ((RelocDir != NULL) && (RelocDir->Size > 0) && (RelocDir->Size -1 < MAX_UINT32 - RelocDir->VirtualAddress))

With this condition added the max value while adding size and address is always less than MAX_UINT32.
Hence there won’t be integer overflow with possible values for RelocDir->VirtualAddress and RelocDir->Size.

Have tested the fix in real platform and confirmed the image is booting fine.

Integration Instructions

N/A

@github-actions github-actions bot added the impact:security This change has a direct security impact such as changing a crypto algorithm. label Sep 27, 2024
@Flickdm Flickdm force-pushed the security-fix/cve-2024-38796/advisory branch from 35d0384 to 758cc44 Compare September 27, 2024 20:33
@Flickdm Flickdm force-pushed the security-fix/cve-2024-38796/advisory branch from 758cc44 to 24f3a7c Compare September 27, 2024 20:34
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 <dougflick@microsoft.com>
Authored-by: sriraamx gobichettipalayam <sri..@intel.com>
@Flickdm Flickdm force-pushed the security-fix/cve-2024-38796/advisory branch from 24f3a7c to a3ab23d Compare September 30, 2024 15:56
@mdkinney mdkinney added the push Auto push patch series in PR if all checks pass label Sep 30, 2024
@mergify mergify bot merged commit c95233b into tianocore:master Sep 30, 2024
126 checks passed
Flickdm added a commit to Flickdm/edk2 that referenced this pull request Sep 30, 2024
This change adds parantheses to the if condition detecting overflow in
the PeCoffLoaderRelocateImage function to improve readability.

Follow on change for:
    REF!: tianocore#6249

Authored-By: Doug Flick <dougflick@microsoft.com>
Flickdm added a commit to Flickdm/edk2 that referenced this pull request Sep 30, 2024
This change adds parantheses to the if condition detecting overflow in
the PeCoffLoaderRelocateImage function to improve readability.

Follow on change for:
    REF!: tianocore#6249

Signed-off-by: Doug Flick <dougflick@microsoft.com>
Flickdm added a commit to Flickdm/edk2 that referenced this pull request Oct 2, 2024
This change adds parantheses to the if condition detecting overflow in
the PeCoffLoaderRelocateImage function to improve readability.

Follow on change for:
    REF!: tianocore#6249

Signed-off-by: Doug Flick <dougflick@microsoft.com>
@Flickdm Flickdm deleted the security-fix/cve-2024-38796/advisory branch October 2, 2024 17:57
mergify bot pushed a commit that referenced this pull request Oct 2, 2024
This change adds parantheses to the if condition detecting overflow in
the PeCoffLoaderRelocateImage function to improve readability.

Follow on change for:
    REF!: #6249

Signed-off-by: Doug Flick <dougflick@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact:security This change has a direct security impact such as changing a crypto algorithm. push Auto push patch series in PR if all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants