edk2/MdeModulePkg
Piotr Wejman 66346d5ede MdeModulePkg: Fix FreePages not existent memory
Commit 2d69507a4d added an attribute check to
prevent freeing memory that is read-only, read-protected, or for which
attribute retrieval fails. In such cases the code returned EFI_SUCCESS and
leaked the memory.

This introduced a regression in the System Architecture Compliance Suite
(ACS) BS.FreePages – Not Existent Memory test.
Link: https://github.com/tianocore/edk2-test/blob/edk2-test-stable202509/uefi-sct/Doc/TestCaseSpec/03_Services_Boot_Services.md#freepages
Test number: 5.1.2.2.1

GetMemoryAttributes() returns EFI_UNSUPPORTED for memory regions outside
system memory. The previous change treated all errors as a reason to leak
memory, while only the EFI_NO_MAPPING error code should trigger that
behavior. As a result, freeing non-existent memory incorrectly returned
EFI_SUCCESS instead of EFI_NOT_FOUND.

To fix this, memory is now leaked only when:
- GetMemoryAttributes() returns EFI_NO_MAPPING (inconsistent attributes),
  or
- GetMemoryAttributes() succeeds and the pages are marked RO or RP.

All other errors fall through to CoreInternalFreePages(), restoring the
previous and correct behavior.

Signed-off-by: Piotr Wejman <piotr.wejman@arm.com>
2025-12-30 01:36:38 +00:00
..
Application MdeModulePkg/UiApp: Remove unused variable 2025-09-04 01:43:03 +00:00
Bus MdeModulePkg/UfsPassThruDxe:Fix Ufs DM Command issue 2025-12-24 06:41:24 +00:00
Core MdeModulePkg: Fix FreePages not existent memory 2025-12-30 01:36:38 +00:00
Include MdeModulePkg: fix various typos 2025-11-21 21:49:59 +00:00
Library MdeModulePkg/BrotliCustomDecompressLib: Undefine _MSC_VER for GCC 2025-12-24 03:36:31 +00:00
Logo MdeModulePkg: Remove ARM32 Support 2025-09-25 22:04:10 +00:00
Test MdeModulePkg/Test/Include: Fix SecurityManagement include guard 2025-09-19 04:41:29 +00:00
Universal MdeModulePkg/Universal/DebugServicePei: Correct function and entry point 2025-12-23 23:34:09 +00:00
MdeModulePkg.ci.yaml MdeModulePkg: Add duplicate exception for gUiAppFileGuid 2025-03-06 14:18:10 +01:00
MdeModulePkg.dec MdeModulePkg: Define PCD for SATA ready for operation timeout. 2025-11-22 17:01:23 +00:00
MdeModulePkg.dsc MdeModulePkg: Remove ARM32 Support 2025-09-25 22:04:10 +00:00
MdeModulePkg.uni MdeModulePkg: Deprecate EFI_UNICODE_COLLATION_PROTOCOL_GUID 2025-09-05 13:50:50 +00:00
MdeModulePkgExtra.uni MdeModulePkg: Replace BSD License with BSD+Patent License 2019-04-09 10:58:08 -07:00