TianoCore EDK2 master
|
Go to the source code of this file.
Variables | |
GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN | mOnGuarding = FALSE |
GLOBAL_REMOVE_IF_UNREFERENCED UINT64 | mGuardedMemoryMap = 0 |
GLOBAL_REMOVE_IF_UNREFERENCED UINTN | mMapLevel = 1 |
GLOBAL_REMOVE_IF_UNREFERENCED UINTN | mLevelShift [GUARDED_HEAP_MAP_TABLE_DEPTH] = GUARDED_HEAP_MAP_TABLE_DEPTH_SHIFTS |
GLOBAL_REMOVE_IF_UNREFERENCED UINTN | mLevelMask [GUARDED_HEAP_MAP_TABLE_DEPTH] = GUARDED_HEAP_MAP_TABLE_DEPTH_MASKS |
GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS | mLastPromotedPage = BASE_4GB |
UEFI Heap Guard functions.
Copyright (c) 2017-2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file HeapGuard.c.
Adjust the base and number of pages to really allocate according to Guard.
[in,out] | Memory | Base address of free memory. |
[in,out] | NumberOfPages | Size of memory to allocate. |
Definition at line 982 of file HeapGuard.c.
Adjust the start address and number of pages to free according to Guard.
The purpose of this function is to keep the shared Guard page with adjacent memory block if it's still in guard, or free it if no more sharing. Another is to reserve pages as Guard pages in partial page free situation.
[in,out] | Memory | Base address of memory to free. |
[in,out] | NumberOfPages | Size of memory to free. |
Definition at line 884 of file HeapGuard.c.
Adjust address of free memory according to existing and/or required Guard.
This function will check if there're existing Guard pages of adjacent memory blocks, and try to use it as the Guard page of the memory to be allocated.
[in] | Start | Start address of free memory block. |
[in] | Size | Size of free memory block. |
[in] | SizeRequested | Size of memory to allocate. |
Definition at line 825 of file HeapGuard.c.
Adjust the pool head position to make sure the Guard page is adjavent to pool tail or pool head.
[in] | Memory | Base address of memory allocated. |
[in] | NoPages | Number of pages actually allocated. |
[in] | Size | Size of memory requested. (plus pool head/tail overhead) |
Definition at line 1016 of file HeapGuard.c.
Get the page base address according to pool head address.
[in] | Memory | Head address of pool to free. |
[in] | NoPages | Number of pages actually allocated. |
[in] | Size | Size of memory requested. (plus pool head/tail overhead) |
Definition at line 1047 of file HeapGuard.c.
Set corresponding bits in bitmap table to 0 according to the address.
[in] | Address | Start address to set for. |
[in] | BitNumber | Number of bits to set. |
[in] | BitMap | Pointer to bitmap which covers the Address. |
Definition at line 113 of file HeapGuard.c.
VOID EFIAPI ClearGuardedMemoryBits | ( | IN EFI_PHYSICAL_ADDRESS | Address, |
IN UINTN | NumberOfPages | ||
) |
Clear corresponding bits in bitmap table according to given memory range.
[in] | Address | Memory address to unset from. |
[in] | NumberOfPages | Number of pages to unset guard. |
Definition at line 349 of file HeapGuard.c.
EFI_STATUS CoreConvertPagesWithGuard | ( | IN UINT64 | Start, |
IN UINTN | NumberOfPages, | ||
IN EFI_MEMORY_TYPE | NewType | ||
) |
Allocate or free guarded memory.
[in] | Start | Start address of memory to allocate or free. |
[in] | NumberOfPages | Memory size in pages. |
[in] | NewType | Memory type to convert to. |
Definition at line 1079 of file HeapGuard.c.
VOID EFIAPI DumpGuardedMemoryBitmap | ( | VOID | ) |
Dump the guarded memory bit map.
Definition at line 1659 of file HeapGuard.c.
UINTN FindGuardedMemoryMap | ( | IN EFI_PHYSICAL_ADDRESS | Address, |
IN BOOLEAN | AllocMapUnit, | ||
OUT UINT64 ** | BitMap | ||
) |
Locate the pointer of bitmap from the guarded memory bitmap tables, which covers the given Address.
[in] | Address | Start address to search the bitmap for. |
[in] | AllocMapUnit | Flag to indicate memory allocation for the table. |
[out] | BitMap | Pointer to bitmap which covers the Address. |
Definition at line 217 of file HeapGuard.c.
Get corresponding bits in bitmap table according to the address.
The value of bit 0 corresponds to the status of memory at given Address. No more than 64 bits can be retrieved in one call.
[in] | Address | Start address to retrieve bits for. |
[in] | BitNumber | Number of bits to get. |
[in] | BitMap | Pointer to bitmap which covers the Address. |
Definition at line 168 of file HeapGuard.c.
UINT64 GetGuardedMemoryBits | ( | IN EFI_PHYSICAL_ADDRESS | Address, |
IN UINTN | NumberOfPages | ||
) |
Retrieve corresponding bits in bitmap table according to given memory range.
[in] | Address | Memory address to retrieve from. |
[in] | NumberOfPages | Number of pages to retrieve. |
Definition at line 385 of file HeapGuard.c.
UINTN EFIAPI GetGuardMapBit | ( | IN EFI_PHYSICAL_ADDRESS | Address | ) |
Get bit value in bitmap table for the given address.
[in] | Address | The address to retrieve for. |
Definition at line 431 of file HeapGuard.c.
VOID GetLastGuardedFreePageAddress | ( | OUT EFI_PHYSICAL_ADDRESS * | Address | ) |
Find the address of top-most guarded free page.
[out] | Address | Start address of top-most guarded free page. |
Definition at line 1225 of file HeapGuard.c.
VOID GuardAllFreedPages | ( | VOID | ) |
Mark all pages freed before CPU Arch Protocol as not-present.
Definition at line 1365 of file HeapGuard.c.
VOID EFIAPI GuardFreedPages | ( | IN EFI_PHYSICAL_ADDRESS | BaseAddress, |
IN UINTN | Pages | ||
) |
Record freed pages as well as mark them as not-present.
[in] | BaseAddress | Base address of just freed pages. |
[in] | Pages | Number of freed pages. |
Definition at line 1295 of file HeapGuard.c.
VOID EFIAPI GuardFreedPagesChecked | ( | IN EFI_PHYSICAL_ADDRESS | BaseAddress, |
IN UINTN | Pages | ||
) |
Record freed pages as well as mark them as not-present, if enabled.
[in] | BaseAddress | Base address of just freed pages. |
[in] | Pages | Number of freed pages. |
Definition at line 1350 of file HeapGuard.c.
VOID HeapGuardCpuArchProtocolNotify | ( | VOID | ) |
Notify function used to set all Guard pages before CPU Arch Protocol installed.
Definition at line 1604 of file HeapGuard.c.
BOOLEAN EFIAPI IsGuardPage | ( | IN EFI_PHYSICAL_ADDRESS | Address | ) |
Check to see if the page at the given address is a Guard page or not.
[in] | Address | The address to check for. |
Definition at line 461 of file HeapGuard.c.
BOOLEAN IsHeapGuardEnabled | ( | UINT8 | GuardType | ) |
Check to see if the heap guard is enabled for page and/or pool allocation.
[in] | GuardType | Specify the sub-type(s) of Heap Guard. |
Definition at line 674 of file HeapGuard.c.
BOOLEAN EFIAPI IsMemoryGuarded | ( | IN EFI_PHYSICAL_ADDRESS | Address | ) |
Check to see if the page at the given address is guarded or not.
[in] | Address | The address to check for. |
Definition at line 486 of file HeapGuard.c.
BOOLEAN IsMemoryTypeToGuard | ( | IN EFI_MEMORY_TYPE | MemoryType, |
IN EFI_ALLOCATE_TYPE | AllocateType, | ||
IN UINT8 | PageOrPool | ||
) |
Check to see if the memory at the given address should be guarded or not.
[in] | MemoryType | Memory type to check. |
[in] | AllocateType | Allocation type to check. |
[in] | PageOrPool | Indicate a page allocation or pool allocation. |
Definition at line 587 of file HeapGuard.c.
BOOLEAN IsPageTypeToGuard | ( | IN EFI_MEMORY_TYPE | MemoryType, |
IN EFI_ALLOCATE_TYPE | AllocateType | ||
) |
Check to see if the page at the given address should be guarded or not.
[in] | MemoryType | Page type to check. |
[in] | AllocateType | Allocation type to check. |
Definition at line 658 of file HeapGuard.c.
BOOLEAN IsPoolTypeToGuard | ( | IN EFI_MEMORY_TYPE | MemoryType | ) |
Check to see if the pool at the given address should be guarded or not.
[in] | MemoryType | Pool type to check. |
Definition at line 637 of file HeapGuard.c.
VOID MarkFreedPages | ( | IN EFI_PHYSICAL_ADDRESS | BaseAddress, |
IN UINTN | Pages | ||
) |
Record freed pages.
[in] | BaseAddress | Base address of just freed pages. |
[in] | Pages | Number of freed pages. |
Definition at line 1277 of file HeapGuard.c.
VOID MergeGuardPages | ( | IN EFI_MEMORY_DESCRIPTOR * | MemoryMapEntry, |
IN EFI_PHYSICAL_ADDRESS | MaxAddress | ||
) |
This function checks to see if the given memory map descriptor in a memory map can be merged with any guarded free pages.
MemoryMapEntry | A pointer to a descriptor in MemoryMap. |
MaxAddress | Maximum address to stop the merge. |
Definition at line 1476 of file HeapGuard.c.
BOOLEAN PromoteGuardedFreePages | ( | OUT EFI_PHYSICAL_ADDRESS * | StartAddress, |
OUT EFI_PHYSICAL_ADDRESS * | EndAddress | ||
) |
Put part (at most 64 pages a time) guarded free pages back to free page pool.
Freed memory guard is used to detect Use-After-Free (UAF) memory issue, which makes use of 'Used then throw away' way to detect any illegal access to freed memory. The thrown-away memory will be marked as not-present so that any access to those memory (after free) will be caught by page-fault exception.
The problem is that this will consume lots of memory space. Once no memory left in pool to allocate, we have to restore part of the freed pages to their normal function. Otherwise the whole system will stop functioning.
StartAddress | Start address of promoted memory. |
EndAddress | End address of promoted memory. |
Definition at line 1531 of file HeapGuard.c.
VOID SetAllGuardPages | ( | VOID | ) |
Set all Guard pages which cannot be set before CPU Arch Protocol installed.
Definition at line 1115 of file HeapGuard.c.
Set corresponding bits in bitmap table to 1 according to the address.
[in] | Address | Start address to set for. |
[in] | BitNumber | Number of bits to set. |
[in] | BitMap | Pointer to bitmap which covers the Address. |
Definition at line 57 of file HeapGuard.c.
VOID EFIAPI SetGuardedMemoryBits | ( | IN EFI_PHYSICAL_ADDRESS | Address, |
IN UINTN | NumberOfPages | ||
) |
Set corresponding bits in bitmap table to 1 according to given memory range.
[in] | Address | Memory address to guard from. |
[in] | NumberOfPages | Number of pages to guard. |
Definition at line 312 of file HeapGuard.c.
VOID SetGuardForMemory | ( | IN EFI_PHYSICAL_ADDRESS | Memory, |
IN UINTN | NumberOfPages | ||
) |
Set head Guard and tail Guard for the given memory range.
[in] | Memory | Base address of memory to set guard for. |
[in] | NumberOfPages | Memory size in pages. |
Definition at line 690 of file HeapGuard.c.
VOID EFIAPI SetGuardPage | ( | IN EFI_PHYSICAL_ADDRESS | BaseAddress | ) |
Set the page at the given address to be a Guard page.
This is done by changing the page table attribute to be NOT PRSENT.
[in] | BaseAddress | Page address to Guard at |
Definition at line 504 of file HeapGuard.c.
Helper function to convert a UINT64 value in binary to a string.
[in] | Value | Value of a UINT64 integer. |
[out] | BinString | String buffer to contain the conversion result. |
Definition at line 1635 of file HeapGuard.c.
VOID UnsetGuardForMemory | ( | IN EFI_PHYSICAL_ADDRESS | Memory, |
IN UINTN | NumberOfPages | ||
) |
Unset head Guard and tail Guard for the given memory range.
[in] | Memory | Base address of memory to unset guard for. |
[in] | NumberOfPages | Memory size in pages. |
Definition at line 726 of file HeapGuard.c.
VOID EFIAPI UnsetGuardPage | ( | IN EFI_PHYSICAL_ADDRESS | BaseAddress | ) |
Unset the Guard page at the given address to the normal memory.
This is done by changing the page table attribute to be PRSENT.
[in] | BaseAddress | Page address to Guard at. |
Definition at line 539 of file HeapGuard.c.
GLOBAL_REMOVE_IF_UNREFERENCED UINT64 mGuardedMemoryMap = 0 |
Definition at line 24 of file HeapGuard.c.
GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS mLastPromotedPage = BASE_4GB |
Definition at line 44 of file HeapGuard.c.
GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelMask[GUARDED_HEAP_MAP_TABLE_DEPTH] = GUARDED_HEAP_MAP_TABLE_DEPTH_MASKS |
Definition at line 38 of file HeapGuard.c.
GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelShift[GUARDED_HEAP_MAP_TABLE_DEPTH] = GUARDED_HEAP_MAP_TABLE_DEPTH_SHIFTS |
Definition at line 36 of file HeapGuard.c.
GLOBAL_REMOVE_IF_UNREFERENCED UINTN mMapLevel = 1 |
Definition at line 31 of file HeapGuard.c.
GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mOnGuarding = FALSE |
Definition at line 17 of file HeapGuard.c.