diff options
author | Andreas Kling <awesomekling@gmail.com> | 2018-11-03 11:36:45 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2018-11-03 11:36:45 +0100 |
commit | da13c9a2648de7c7d799952389e228e739dc486d (patch) | |
tree | 62f5c37e0116a5e9353faa6e7a66b9174477c311 /Kernel | |
parent | aa6d06b47ee7f510f153fa2971be75533a9295ee (diff) | |
download | serenity-da13c9a2648de7c7d799952389e228e739dc486d.zip |
Map pages in read-only ELF sections as non-writable.
This is so cool! :^) Now you'll crash if you try to write into your
.text or .rodata segments.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/MemoryManager.cpp | 6 | ||||
-rw-r--r-- | Kernel/MemoryManager.h | 4 | ||||
-rw-r--r-- | Kernel/Process.cpp | 6 |
3 files changed, 10 insertions, 6 deletions
diff --git a/Kernel/MemoryManager.cpp b/Kernel/MemoryManager.cpp index f86cbd315b..7dd4cd6cb5 100644 --- a/Kernel/MemoryManager.cpp +++ b/Kernel/MemoryManager.cpp @@ -304,8 +304,8 @@ void MemoryManager::map_region_at_address(PageDirectory* page_directory, Region& auto page_laddr = laddr.offset(i * PAGE_SIZE); auto pte = ensurePTE(page_directory, page_laddr); pte.setPhysicalPageBase(zone.m_pages[i].get()); - pte.setPresent(true); - pte.setWritable(true); + pte.setPresent(true); // FIXME: Maybe we could use the is_readable flag here? + pte.setWritable(region.is_writable); pte.setUserAllowed(user_allowed); flushTLB(page_laddr); #ifdef MM_DEBUG @@ -430,7 +430,7 @@ RetainPtr<Region> Region::clone() // FIXME: Implement COW regions. auto clone_zone = MM.createZone(zone->size()); - auto clone_region = adopt(*new Region(linearAddress, size, move(clone_zone), String(name))); + auto clone_region = adopt(*new Region(linearAddress, size, move(clone_zone), String(name), is_readable, is_writable)); // FIXME: It would be cool to make the src_alias a read-only mapping. byte* src_alias = MM.create_kernel_alias_for_region(*this); diff --git a/Kernel/MemoryManager.h b/Kernel/MemoryManager.h index 3c3df0d58d..0ebe056666 100644 --- a/Kernel/MemoryManager.h +++ b/Kernel/MemoryManager.h @@ -38,7 +38,7 @@ private: }; struct Region : public Retainable<Region> { - Region(LinearAddress, size_t, RetainPtr<Zone>&&, String&&); + Region(LinearAddress, size_t, RetainPtr<Zone>&&, String&&, bool r, bool w); ~Region(); RetainPtr<Region> clone(); @@ -46,6 +46,8 @@ struct Region : public Retainable<Region> { size_t size { 0 }; RetainPtr<Zone> zone; String name; + bool is_readable { true }; + bool is_writable { true }; }; #define MM MemoryManager::the() diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 1f622fc2c1..8f9ac2bcbc 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -147,7 +147,7 @@ Region* Process::allocate_region(LinearAddress laddr, size_t size, String&& name auto zone = MM.createZone(size); ASSERT(zone); - m_regions.append(adopt(*new Region(laddr, size, move(zone), move(name)))); + m_regions.append(adopt(*new Region(laddr, size, move(zone), move(name), is_readable, is_writable))); MM.mapRegion(*this, *m_regions.last()); return m_regions.last().ptr(); @@ -1260,11 +1260,13 @@ Process* Process::kernelProcess() return s_kernelProcess; } -Region::Region(LinearAddress a, size_t s, RetainPtr<Zone>&& z, String&& n) +Region::Region(LinearAddress a, size_t s, RetainPtr<Zone>&& z, String&& n, bool r, bool w) : linearAddress(a) , size(s) , zone(move(z)) , name(move(n)) + , is_readable(r) + , is_writable(w) { } |