summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2021-12-22 12:43:20 +0100
committerAndreas Kling <kling@serenityos.org>2021-12-23 23:08:10 +0100
commitd1ef8e63f75b18a744ba65105a0e7e0aac56e6c2 (patch)
treecb7486ea36fec460845ae538fb7b0e1f94568fea /Userland/Libraries
parent77f9272aaf7d882f37567069df13ade5adee9bbf (diff)
downloadserenity-d1ef8e63f75b18a744ba65105a0e7e0aac56e6c2.zip
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.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibELF/DynamicLoader.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/Userland/Libraries/LibELF/DynamicLoader.cpp b/Userland/Libraries/LibELF/DynamicLoader.cpp
index 548ad4b44a..d0332c2f62 100644
--- a/Userland/Libraries/LibELF/DynamicLoader.cpp
+++ b/Userland/Libraries/LibELF/DynamicLoader.cpp
@@ -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.