mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:27:45 +00:00
LibELF: Use MAP_FIXED_NOREPLACE for address space reservation
This ensures that we don't corrupt our address space if a non-PIE program's requested address space happens to coincide with memory we already use.
This commit is contained in:
parent
77f9272aaf
commit
d1ef8e63f7
1 changed files with 5 additions and 1 deletions
|
@ -292,8 +292,10 @@ void DynamicLoader::load_program_headers()
|
|||
int reservation_mmap_flags = MAP_ANON | MAP_PRIVATE | MAP_NORESERVE;
|
||||
if (m_elf_image.is_dynamic())
|
||||
reservation_mmap_flags |= MAP_RANDOMIZED;
|
||||
#ifdef MAP_FIXED_NOREPLACE
|
||||
else
|
||||
reservation_mmap_flags |= MAP_FIXED;
|
||||
reservation_mmap_flags |= MAP_FIXED_NOREPLACE;
|
||||
#endif
|
||||
|
||||
// First, we make a dummy reservation mapping, in order to allocate enough VM
|
||||
// to hold all regions contiguously in the address space.
|
||||
|
@ -309,6 +311,8 @@ void DynamicLoader::load_program_headers()
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
VERIFY(requested_load_address == nullptr || reservation == requested_load_address);
|
||||
|
||||
m_base_address = VirtualAddress { reservation };
|
||||
|
||||
// Then we unmap the reservation.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue