diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-30 10:06:52 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-30 10:06:52 +0100 |
commit | e55ef70e5e054e182481fc683fc2a3364384408c (patch) | |
tree | a64c1ae3524bd071440dcff8d5d45a019094d1de /Kernel | |
parent | 5b37c0a71ad7a2bbcfe9f73ac1f0305abd133d8c (diff) | |
download | serenity-e55ef70e5e054e182481fc683fc2a3364384408c.zip |
Kernel: Remove "has made executable exception for dynamic loader" flag
As Idan pointed out, this flag is actually not needed, since we don't
allow transitioning from previously-executable to writable anyway.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Syscalls/mmap.cpp | 26 | ||||
-rw-r--r-- | Kernel/VM/Region.h | 10 |
2 files changed, 4 insertions, 32 deletions
diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp index 6233e3ba43..0fc5b5940e 100644 --- a/Kernel/Syscalls/mmap.cpp +++ b/Kernel/Syscalls/mmap.cpp @@ -46,10 +46,6 @@ static bool should_make_executable_exception_for_dynamic_loader(bool make_readab // The exception is only made if all the following criteria is fulfilled: - // This exception has not been made for the same region already - if (region.has_made_executable_exception_for_dynamic_loader()) - return false; - // The region must be RW if (!(region.is_readable() && region.is_writable() && !region.is_executable())) return false; @@ -84,11 +80,8 @@ static bool should_make_executable_exception_for_dynamic_loader(bool make_readab return true; } -static bool validate_mmap_prot(int prot, bool map_stack, bool map_anonymous, const Region* region = nullptr, bool* is_making_executable_exception_for_dynamic_loader = nullptr) +static bool validate_mmap_prot(int prot, bool map_stack, bool map_anonymous, const Region* region = nullptr) { - if (is_making_executable_exception_for_dynamic_loader) - *is_making_executable_exception_for_dynamic_loader = false; - bool make_readable = prot & PROT_READ; bool make_writable = prot & PROT_WRITE; bool make_executable = prot & PROT_EXEC; @@ -111,11 +104,8 @@ static bool validate_mmap_prot(int prot, bool map_stack, bool map_anonymous, con return false; if (make_executable && region->has_been_writable()) { - if (should_make_executable_exception_for_dynamic_loader(make_readable, make_writable, make_executable, *region)) { - ASSERT(is_making_executable_exception_for_dynamic_loader); - *is_making_executable_exception_for_dynamic_loader = true; + if (should_make_executable_exception_for_dynamic_loader(make_readable, make_writable, make_executable, *region)) return true; - } return false; } @@ -293,8 +283,7 @@ int Process::sys$mprotect(void* addr, size_t size, int prot) if (auto* whole_region = find_region_from_range(range_to_mprotect)) { if (!whole_region->is_mmap()) return -EPERM; - bool is_making_executable_exception_for_dynamic_loader = false; - if (!validate_mmap_prot(prot, whole_region->is_stack(), whole_region->vmobject().is_anonymous(), whole_region, &is_making_executable_exception_for_dynamic_loader)) + if (!validate_mmap_prot(prot, whole_region->is_stack(), whole_region->vmobject().is_anonymous(), whole_region)) return -EINVAL; if (whole_region->access() == prot_to_region_access_flags(prot)) return 0; @@ -306,9 +295,6 @@ int Process::sys$mprotect(void* addr, size_t size, int prot) whole_region->set_writable(prot & PROT_WRITE); whole_region->set_executable(prot & PROT_EXEC); - if (is_making_executable_exception_for_dynamic_loader) - whole_region->set_has_made_executable_exception_for_dynamic_loader(); - whole_region->remap(); return 0; } @@ -317,8 +303,7 @@ int Process::sys$mprotect(void* addr, size_t size, int prot) if (auto* old_region = find_region_containing(range_to_mprotect)) { if (!old_region->is_mmap()) return -EPERM; - bool is_making_executable_exception_for_dynamic_loader = false; - if (!validate_mmap_prot(prot, old_region->is_stack(), old_region->vmobject().is_anonymous(), old_region, &is_making_executable_exception_for_dynamic_loader)) + if (!validate_mmap_prot(prot, old_region->is_stack(), old_region->vmobject().is_anonymous(), old_region)) return -EINVAL; if (old_region->access() == prot_to_region_access_flags(prot)) return 0; @@ -337,9 +322,6 @@ int Process::sys$mprotect(void* addr, size_t size, int prot) new_region.set_writable(prot & PROT_WRITE); new_region.set_executable(prot & PROT_EXEC); - if (is_making_executable_exception_for_dynamic_loader) - new_region.set_has_made_executable_exception_for_dynamic_loader(); - // Unmap the old region here, specifying that we *don't* want the VM deallocated. old_region->unmap(Region::ShouldDeallocateVirtualMemoryRange::No); deallocate_region(*old_region); diff --git a/Kernel/VM/Region.h b/Kernel/VM/Region.h index 93385ad887..37e2b616c6 100644 --- a/Kernel/VM/Region.h +++ b/Kernel/VM/Region.h @@ -50,8 +50,6 @@ class Region final MAKE_SLAB_ALLOCATED(Region) public: - // 76543210 - // eXWR xwr enum Access : u8 { Read = 1, Write = 2, @@ -59,7 +57,6 @@ public: HasBeenReadable = 16, HasBeenWritable = 32, HasBeenExecutable = 64, - HasMadeExecutableExceptionForDynamicLoader = 128, }; static NonnullOwnPtr<Region> create_user_accessible(Process*, const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable, bool shared); @@ -78,13 +75,6 @@ public: bool has_been_writable() const { return m_access & Access::HasBeenWritable; } bool has_been_executable() const { return m_access & Access::HasBeenExecutable; } - bool has_made_executable_exception_for_dynamic_loader() const { return m_access & Access::HasMadeExecutableExceptionForDynamicLoader; } - void set_has_made_executable_exception_for_dynamic_loader() - { - ASSERT(!has_made_executable_exception_for_dynamic_loader()); - m_access |= Access::HasMadeExecutableExceptionForDynamicLoader; - } - bool is_cacheable() const { return m_cacheable; } const String& name() const { return m_name; } unsigned access() const { return m_access; } |