mirror of
https://github.com/RGBCube/serenity
synced 2025-07-17 01:17:35 +00:00
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.
This commit is contained in:
parent
5b37c0a71a
commit
e55ef70e5e
2 changed files with 4 additions and 32 deletions
|
@ -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:
|
// 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
|
// The region must be RW
|
||||||
if (!(region.is_readable() && region.is_writable() && !region.is_executable()))
|
if (!(region.is_readable() && region.is_writable() && !region.is_executable()))
|
||||||
return false;
|
return false;
|
||||||
|
@ -84,11 +80,8 @@ static bool should_make_executable_exception_for_dynamic_loader(bool make_readab
|
||||||
return true;
|
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_readable = prot & PROT_READ;
|
||||||
bool make_writable = prot & PROT_WRITE;
|
bool make_writable = prot & PROT_WRITE;
|
||||||
bool make_executable = prot & PROT_EXEC;
|
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;
|
return false;
|
||||||
|
|
||||||
if (make_executable && region->has_been_writable()) {
|
if (make_executable && region->has_been_writable()) {
|
||||||
if (should_make_executable_exception_for_dynamic_loader(make_readable, make_writable, make_executable, *region)) {
|
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;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
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 (auto* whole_region = find_region_from_range(range_to_mprotect)) {
|
||||||
if (!whole_region->is_mmap())
|
if (!whole_region->is_mmap())
|
||||||
return -EPERM;
|
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))
|
||||||
if (!validate_mmap_prot(prot, whole_region->is_stack(), whole_region->vmobject().is_anonymous(), whole_region, &is_making_executable_exception_for_dynamic_loader))
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (whole_region->access() == prot_to_region_access_flags(prot))
|
if (whole_region->access() == prot_to_region_access_flags(prot))
|
||||||
return 0;
|
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_writable(prot & PROT_WRITE);
|
||||||
whole_region->set_executable(prot & PROT_EXEC);
|
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();
|
whole_region->remap();
|
||||||
return 0;
|
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 (auto* old_region = find_region_containing(range_to_mprotect)) {
|
||||||
if (!old_region->is_mmap())
|
if (!old_region->is_mmap())
|
||||||
return -EPERM;
|
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))
|
||||||
if (!validate_mmap_prot(prot, old_region->is_stack(), old_region->vmobject().is_anonymous(), old_region, &is_making_executable_exception_for_dynamic_loader))
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (old_region->access() == prot_to_region_access_flags(prot))
|
if (old_region->access() == prot_to_region_access_flags(prot))
|
||||||
return 0;
|
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_writable(prot & PROT_WRITE);
|
||||||
new_region.set_executable(prot & PROT_EXEC);
|
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.
|
// Unmap the old region here, specifying that we *don't* want the VM deallocated.
|
||||||
old_region->unmap(Region::ShouldDeallocateVirtualMemoryRange::No);
|
old_region->unmap(Region::ShouldDeallocateVirtualMemoryRange::No);
|
||||||
deallocate_region(*old_region);
|
deallocate_region(*old_region);
|
||||||
|
|
|
@ -50,8 +50,6 @@ class Region final
|
||||||
|
|
||||||
MAKE_SLAB_ALLOCATED(Region)
|
MAKE_SLAB_ALLOCATED(Region)
|
||||||
public:
|
public:
|
||||||
// 76543210
|
|
||||||
// eXWR xwr
|
|
||||||
enum Access : u8 {
|
enum Access : u8 {
|
||||||
Read = 1,
|
Read = 1,
|
||||||
Write = 2,
|
Write = 2,
|
||||||
|
@ -59,7 +57,6 @@ public:
|
||||||
HasBeenReadable = 16,
|
HasBeenReadable = 16,
|
||||||
HasBeenWritable = 32,
|
HasBeenWritable = 32,
|
||||||
HasBeenExecutable = 64,
|
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);
|
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_writable() const { return m_access & Access::HasBeenWritable; }
|
||||||
bool has_been_executable() const { return m_access & Access::HasBeenExecutable; }
|
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; }
|
bool is_cacheable() const { return m_cacheable; }
|
||||||
const String& name() const { return m_name; }
|
const String& name() const { return m_name; }
|
||||||
unsigned access() const { return m_access; }
|
unsigned access() const { return m_access; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue